Skip to content

Commit d5ed962

Browse files
committed
Fix CI issues
1 parent dac6c15 commit d5ed962

File tree

5 files changed

+37
-8
lines changed

5 files changed

+37
-8
lines changed

app/src/androidTest/java/com/duckduckgo/app/browser/DuckDuckGoWebViewTest.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ class DuckDuckGoWebViewTest {
2727
@UiThreadTest
2828
fun whenWebViewInitialisedThenSafeBrowsingDisabled() {
2929
val context = InstrumentationRegistry.getInstrumentation().targetContext
30-
val testee = DuckDuckGoWebView(context)
30+
val testee = RealDuckDuckGoWebView(context)
3131
assertFalse(testee.settings.safeBrowsingEnabled)
3232
}
3333
}

app/src/test/java/com/duckduckgo/app/browser/RealDuckDuckGoWebViewTest.kt

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ class RealDuckDuckGoWebViewTest {
2525
@Before
2626
fun setUp() {
2727
testee.webViewCompatWrapper = mockWebViewCompatWrapper
28+
testee.webViewCapabilityChecker = mockWebViewCapabilityChecker
2829
}
2930

3031
@Test

content-scope-scripts/content-scope-scripts-impl/src/main/java/com/duckduckgo/contentscopescripts/impl/RealWebViewCompatWrapper.kt

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,12 @@ import com.duckduckgo.di.scopes.AppScope
2424
import com.squareup.anvil.annotations.ContributesBinding
2525
import javax.inject.Inject
2626

27-
@SuppressLint("RequiresFeature")
27+
@SuppressLint(
28+
"RequiresFeature",
29+
"AddWebMessageListenerUsage",
30+
"AddDocumentStartJavaScriptUsage",
31+
"RemoveWebMessageListenerUsage",
32+
)
2833
@ContributesBinding(AppScope::class)
2934
class RealWebViewCompatWrapper @Inject constructor() : WebViewCompatWrapper {
3035
override fun addDocumentStartJavaScript(

lint-rules/src/main/java/com/duckduckgo/lint/WebMessageListenerUsageDetector.kt renamed to lint-rules/src/main/java/com/duckduckgo/lint/WebViewCompatApisUsageDetector.kt

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@ import com.intellij.psi.PsiMethod
55
import org.jetbrains.uast.UCallExpression
66

77
@Suppress("UnstableApiUsage")
8-
class WebMessageListenerUsageDetector : Detector(), SourceCodeScanner {
8+
class WebViewCompatApisUsageDetector : Detector(), SourceCodeScanner {
99

1010
override fun getApplicableMethodNames(): List<String> {
1111
return listOf("addWebMessageListener", "removeWebMessageListener")
@@ -33,6 +33,16 @@ class WebMessageListenerUsageDetector : Detector(), SourceCodeScanner {
3333
)
3434
}
3535
}
36+
"addDocumentStartJavaScript" -> {
37+
if (context.evaluator.isMemberInClass(method, "androidx.webkit.WebViewCompat")) {
38+
context.report(
39+
ISSUE_ADD_DOCUMENT_START_JAVASCRIPT_USAGE,
40+
node,
41+
context.getLocation(node),
42+
ISSUE_ADD_DOCUMENT_START_JAVASCRIPT_USAGE.getExplanation(TextFormat.RAW)
43+
)
44+
}
45+
}
3646
}
3747
}
3848

@@ -44,7 +54,7 @@ class WebMessageListenerUsageDetector : Detector(), SourceCodeScanner {
4454
category = Category.CORRECTNESS,
4555
severity = Severity.ERROR,
4656
implementation = Implementation(
47-
WebMessageListenerUsageDetector::class.java,
57+
WebViewCompatApisUsageDetector::class.java,
4858
Scope.JAVA_FILE_SCOPE
4959
)
5060
)
@@ -56,7 +66,19 @@ class WebMessageListenerUsageDetector : Detector(), SourceCodeScanner {
5666
category = Category.CORRECTNESS,
5767
severity = Severity.ERROR,
5868
implementation = Implementation(
59-
WebMessageListenerUsageDetector::class.java,
69+
WebViewCompatApisUsageDetector::class.java,
70+
Scope.JAVA_FILE_SCOPE
71+
)
72+
)
73+
74+
val ISSUE_ADD_DOCUMENT_START_JAVASCRIPT_USAGE: Issue = Issue.create(
75+
id = "AddDocumentStartJavaScriptUsage",
76+
briefDescription = "Use safe WebViewCompat methods",
77+
explanation = "Use `safeAddDocumentStartJavaScript` instead of `WebViewCompat.addDocumentStartJavaScript`",
78+
category = Category.CORRECTNESS,
79+
severity = Severity.ERROR,
80+
implementation = Implementation(
81+
WebViewCompatApisUsageDetector::class.java,
6082
Scope.JAVA_FILE_SCOPE
6183
)
6284
)

lint-rules/src/main/java/com/duckduckgo/lint/registry/DuckDuckGoIssueRegistry.kt

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@ import com.android.tools.lint.client.api.Vendor
2222
import com.android.tools.lint.detector.api.CURRENT_API
2323
import com.android.tools.lint.detector.api.Issue
2424
import com.duckduckgo.lint.DenyListedApiDetector
25-
import com.duckduckgo.lint.DenyListedApiDetector.Companion
2625
import com.duckduckgo.lint.NoDispatcherComputation.Companion.ISSUE_AVOID_COMPUTATION
2726
import com.duckduckgo.lint.strings.MissingSmartlingRequiredDirectivesDetector.Companion.MISSING_SMARTLING_REQUIRED_DIRECTIVES
2827
import com.duckduckgo.lint.NoFragmentDetector.Companion.NO_FRAGMENT_ISSUE
@@ -32,8 +31,9 @@ import com.duckduckgo.lint.NoRetrofitCreateMethodCallDetector.Companion.NO_RETRO
3231
import com.duckduckgo.lint.NoRobolectricTestRunnerDetector.Companion.NO_ROBOLECTRIC_TEST_RUNNER_ISSUE
3332
import com.duckduckgo.lint.NoSingletonDetector.Companion.NO_SINGLETON_ISSUE
3433
import com.duckduckgo.lint.NoSystemLoadLibraryDetector.Companion.NO_SYSTEM_LOAD_LIBRARY
35-
import com.duckduckgo.lint.WebMessageListenerUsageDetector.Companion.ISSUE_ADD_WEB_MESSAGE_LISTENER_USAGE
36-
import com.duckduckgo.lint.WebMessageListenerUsageDetector.Companion.ISSUE_REMOVE_WEB_MESSAGE_LISTENER_USAGE
34+
import com.duckduckgo.lint.WebViewCompatApisUsageDetector.Companion.ISSUE_ADD_DOCUMENT_START_JAVASCRIPT_USAGE
35+
import com.duckduckgo.lint.WebViewCompatApisUsageDetector.Companion.ISSUE_ADD_WEB_MESSAGE_LISTENER_USAGE
36+
import com.duckduckgo.lint.WebViewCompatApisUsageDetector.Companion.ISSUE_REMOVE_WEB_MESSAGE_LISTENER_USAGE
3737
import com.duckduckgo.lint.WrongPluginPointCollectorDetector.Companion.WRONG_PLUGIN_POINT_ISSUE
3838
import com.duckduckgo.lint.strings.MissingInstructionDetector.Companion.MISSING_INSTRUCTION
3939
import com.duckduckgo.lint.strings.PlaceholderDetector.Companion.PLACEHOLDER_MISSING_POSITION
@@ -67,6 +67,7 @@ class DuckDuckGoIssueRegistry : IssueRegistry() {
6767
NO_ROBOLECTRIC_TEST_RUNNER_ISSUE,
6868
ISSUE_NON_CANCELLABLE,
6969
ISSUE_AVOID_COMPUTATION,
70+
ISSUE_ADD_DOCUMENT_START_JAVASCRIPT_USAGE,
7071
ISSUE_ADD_WEB_MESSAGE_LISTENER_USAGE,
7172
ISSUE_REMOVE_WEB_MESSAGE_LISTENER_USAGE,
7273
DenyListedApiDetector.ISSUE,

0 commit comments

Comments
 (0)