Skip to content

Commit

Permalink
Merge branch 'release/5.217.0' into main
Browse files Browse the repository at this point in the history
  • Loading branch information
daxtheduck committed Oct 16, 2024
2 parents b3918b5 + e496633 commit d37c5f7
Show file tree
Hide file tree
Showing 83 changed files with 6,834 additions and 5,465 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,7 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
.flavorNameProvider({ appBuildConfig.flavor.name })
.featureName(%S)
.appVariantProvider({ appBuildConfig.variantName })
.localeProvider({ appBuildConfig.deviceLocale })
// save empty variants will force the default variant to be set
.forceDefaultVariantProvider({ variantManager.updateVariants(emptyList()) })
.build()
Expand Down Expand Up @@ -353,6 +354,7 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
.addType(createJsonRolloutDataClass(generatedPackage, module))
.addType(createJsonRolloutStepDataClass(generatedPackage, module))
.addType(createJsonToggleTargetDataClass(generatedPackage, module))
.addType(createJsonToggleCohortDataClass(generatedPackage, module))
.addType(createJsonToggleDataClass(generatedPackage, module))
.addType(createJsonFeatureDataClass(generatedPackage, module))
.addType(createJsonExceptionDataClass(generatedPackage, module))
Expand Down Expand Up @@ -493,6 +495,7 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
enable = isEnabled,
minSupportedVersion = feature.minSupportedVersion,
targets = emptyList(),
cohorts = emptyList(),
)
)
Expand All @@ -508,20 +511,33 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
val previousStateValue = previousState?.enable ?: this.feature.get().invokeMethod(subfeature.key).isEnabled()
val previousRolloutThreshold = previousState?.rolloutThreshold
val previousAssignedCohort = previousState?.assignedCohort
val newStateValue = (jsonToggle.state == "enabled" || (appBuildConfig.flavor == %T && jsonToggle.state == "internal"))
val targets = jsonToggle?.targets?.map { target ->
Toggle.State.Target(
variantKey = target.variantKey,
localeCountry = target.localeCountry,
localeLanguage = target.localeLanguage,
)
} ?: emptyList()
val cohorts = jsonToggle?.cohorts?.map { cohort ->
Toggle.State.Cohort(
name = cohort.name,
weight = cohort.weight,
)
} ?: emptyList()
val config = jsonToggle?.config ?: emptyMap()
this.feature.get().invokeMethod(subfeature.key).setRawStoredState(
Toggle.State(
remoteEnableState = newStateValue,
enable = previousStateValue,
minSupportedVersion = jsonToggle.minSupportedVersion?.toInt(),
rollout = jsonToggle?.rollout?.steps?.map { it.percent },
rolloutThreshold = previousRolloutThreshold,
assignedCohort = previousAssignedCohort,
targets = targets,
cohorts = cohorts,
config = config,
),
)
} catch(e: Throwable) {
Expand Down Expand Up @@ -706,9 +722,31 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameter("variantKey", String::class.asClassName())
.addParameter("localeCountry", String::class.asClassName())
.addParameter("localeLanguage", String::class.asClassName())
.build(),
)
.addProperty(PropertySpec.builder("variantKey", String::class.asClassName()).initializer("variantKey").build())
.addProperty(PropertySpec.builder("localeCountry", String::class.asClassName()).initializer("localeCountry").build())
.addProperty(PropertySpec.builder("localeLanguage", String::class.asClassName()).initializer("localeLanguage").build())
.build()
}

private fun createJsonToggleCohortDataClass(
generatedPackage: String,
module: ModuleDescriptor,
): TypeSpec {
return TypeSpec.classBuilder(FqName("$generatedPackage.JsonToggleCohort").asClassName(module))
.addModifiers(KModifier.PRIVATE)
.addModifiers(KModifier.DATA)
.primaryConstructor(
FunSpec.constructorBuilder()
.addParameter("name", String::class.asClassName())
.addParameter("weight", Int::class.asClassName())
.build(),
)
.addProperty(PropertySpec.builder("name", String::class.asClassName()).initializer("name").build())
.addProperty(PropertySpec.builder("weight", Int::class.asClassName()).initializer("weight").build())
.build()
}

Expand Down Expand Up @@ -737,6 +775,14 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
"targets",
List::class.asClassName().parameterizedBy(FqName("JsonToggleTarget").asClassName(module)),
)
.addParameter(
"cohorts",
List::class.asClassName().parameterizedBy(FqName("JsonToggleCohort").asClassName(module)),
)
.addParameter(
"config",
Map::class.asClassName().parameterizedBy(String::class.asClassName(), String::class.asClassName()),
)
.build(),
)
.addProperty(
Expand All @@ -763,6 +809,18 @@ class ContributesRemoteFeatureCodeGenerator : CodeGenerator {
.initializer("targets")
.build(),
)
.addProperty(
PropertySpec
.builder("cohorts", List::class.asClassName().parameterizedBy(FqName("JsonToggleCohort").asClassName(module)))
.initializer("cohorts")
.build(),
)
.addProperty(
PropertySpec
.builder("config", Map::class.asClassName().parameterizedBy(String::class.asClassName(), String::class.asClassName()))
.initializer("config")
.build(),
)
.build()
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -104,6 +104,7 @@ import com.duckduckgo.app.browser.newtab.FavoritesQuickAccessAdapter.QuickAccess
import com.duckduckgo.app.browser.omnibar.OmnibarEntryConverter
import com.duckduckgo.app.browser.omnibar.model.OmnibarPosition.BOTTOM
import com.duckduckgo.app.browser.omnibar.model.OmnibarPosition.TOP
import com.duckduckgo.app.browser.refreshpixels.RefreshPixelSender
import com.duckduckgo.app.browser.remotemessage.RemoteMessagingModel
import com.duckduckgo.app.browser.session.WebViewSessionStorage
import com.duckduckgo.app.browser.viewstate.BrowserViewState
Expand Down Expand Up @@ -468,6 +469,8 @@ class BrowserTabViewModelTest {

private val subscriptions: Subscriptions = mock()

private val refreshPixelSender: RefreshPixelSender = mock()

private val privacyProtectionsPopupExperimentExternalPixels: PrivacyProtectionsPopupExperimentExternalPixels = mock {
runBlocking { whenever(mock.getPixelParams()).thenReturn(emptyMap()) }
}
Expand Down Expand Up @@ -638,6 +641,7 @@ class BrowserTabViewModelTest {
duckPlayer = mockDuckPlayer,
duckPlayerJSHelper = DuckPlayerJSHelper(mockDuckPlayer, mockAppBuildConfig, mockPixel, mockDuckDuckGoUrlDetector),
loadingBarExperimentManager = loadingBarExperimentManager,
refreshPixelSender = refreshPixelSender,
)

testee.loadData("abc", null, false, false)
Expand Down Expand Up @@ -5917,6 +5921,27 @@ class BrowserTabViewModelTest {
testee.omnibarViewState.removeObserver { observer(it) }
}

@Test
fun whenHandleMenuRefreshActionThenSendMenuRefreshPixels() {
testee.handleMenuRefreshAction()

verify(refreshPixelSender).sendMenuRefreshPixels()
}

@Test
fun whenHandlePullToRefreshActionThenSendPullToRefreshPixels() {
testee.handlePullToRefreshAction()

verify(refreshPixelSender).sendPullToRefreshPixels()
}

@Test
fun whenFireCustomTabRefreshPixelThenSendCustomTabRefreshPixel() {
testee.fireCustomTabRefreshPixel()

verify(refreshPixelSender).sendCustomTabRefreshPixel()
}

private fun aCredential(): LoginCredentials {
return LoginCredentials(domain = null, username = null, password = null)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ import com.duckduckgo.experiments.api.loadingbarexperiment.LoadingBarExperimentM
import com.duckduckgo.history.api.NavigationHistory
import com.duckduckgo.privacy.config.api.AmpLinks
import com.duckduckgo.subscriptions.api.Subscriptions
import com.duckduckgo.user.agent.api.ClientBrandHintProvider
import java.math.BigInteger
import java.security.cert.X509Certificate
import java.security.interfaces.RSAPublicKey
Expand All @@ -90,6 +91,7 @@ import org.junit.Test
import org.mockito.ArgumentMatchers.anyString
import org.mockito.kotlin.any
import org.mockito.kotlin.argumentCaptor
import org.mockito.kotlin.doNothing
import org.mockito.kotlin.eq
import org.mockito.kotlin.mock
import org.mockito.kotlin.never
Expand Down Expand Up @@ -139,6 +141,7 @@ class BrowserWebViewClientTest {
private val mockDuckPlayer: DuckPlayer = mock()
private val navigationHistory: NavigationHistory = mock()
private val loadingBarExperimentManager: LoadingBarExperimentManager = mock()
private val mockDuckDuckGoUrlDetector: DuckDuckGoUrlDetector = mock()

@UiThreadTest
@Before
Expand Down Expand Up @@ -173,6 +176,7 @@ class BrowserWebViewClientTest {
subscriptions,
mockDuckPlayer,
loadingBarExperimentManager,
mockDuckDuckGoUrlDetector,
)
testee.webViewClientListener = listener
whenever(webResourceRequest.url).thenReturn(Uri.EMPTY)
Expand Down Expand Up @@ -395,6 +399,26 @@ class BrowserWebViewClientTest {
verify(subscriptions).launchPrivacyPro(any(), any())
}

@UiThreadTest
@Test
fun whenShouldOverrideWithShouldNavigateToDuckPlayerFromSerpThenAddQueryParam() {
val urlType = SpecialUrlDetector.UrlType.ShouldLaunchDuckPlayerLink("duck://player/1234".toUri())
whenever(specialUrlDetector.determineType(initiatingUrl = any(), uri = any())).thenReturn(urlType)
whenever(webResourceRequest.isForMainFrame).thenReturn(true)
whenever(webResourceRequest.isRedirect).thenReturn(false)
whenever(webResourceRequest.url).thenReturn("www.youtube.com/watch?v=1234".toUri())
whenever(mockDuckDuckGoUrlDetector.isDuckDuckGoUrl(any())).thenReturn(true)
val mockClientProvider: ClientBrandHintProvider = mock()
whenever(mockClientProvider.shouldChangeBranding(any())).thenReturn(false)
testee.clientProvider = mockClientProvider
doNothing().whenever(listener).willOverrideUrl(any())
val mockWebView = getImmediatelyInvokedMockWebView()
whenever(mockWebView.url).thenReturn("www.duckduckgo.com")

assertTrue(testee.shouldOverrideUrlLoading(mockWebView, webResourceRequest))
verify(mockWebView).loadUrl("www.youtube.com/watch?v=1234&origin=serp_auto")
}

@UiThreadTest
@Test
fun whenAppLinkDetectedAndIsHandledThenReturnTrue() {
Expand Down
Loading

0 comments on commit d37c5f7

Please sign in to comment.