Skip to content

Commit 8ba6e4b

Browse files
authored
removing old sticky search code (#789)
* removing old sticky search code * remove pixels from the experiment * remove shared preference * remove untranslated strings * cleaning up names and unused references * clean unused references from tests
1 parent e4e7759 commit 8ba6e4b

24 files changed

+15
-798
lines changed

app/src/androidTest/java/com/duckduckgo/app/notification/AndroidNotificationSchedulerTest.kt

Lines changed: 5 additions & 84 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,6 @@ import androidx.work.WorkManager
2424
import com.duckduckgo.app.CoroutineTestRule
2525
import com.duckduckgo.app.notification.NotificationScheduler.*
2626
import com.duckduckgo.app.notification.model.SchedulableNotification
27-
import com.duckduckgo.app.notification.model.SearchNotification
2827
import com.duckduckgo.app.statistics.VariantManager
2928
import com.duckduckgo.app.statistics.VariantManager.Companion.DEFAULT_VARIANT
3029
import com.nhaarman.mockitokotlin2.any
@@ -48,7 +47,6 @@ class AndroidNotificationSchedulerTest {
4847
private val variantManager: VariantManager = mock()
4948
private val clearNotification: SchedulableNotification = mock()
5049
private val privacyNotification: SchedulableNotification = mock()
51-
private val searchPromptNotification: SearchNotification = mock()
5250

5351
private val context = InstrumentationRegistry.getInstrumentation().targetContext
5452
private var workManager = WorkManager.getInstance(context)
@@ -60,136 +58,59 @@ class AndroidNotificationSchedulerTest {
6058
testee = NotificationScheduler(
6159
workManager,
6260
clearNotification,
63-
privacyNotification,
64-
searchPromptNotification
61+
privacyNotification
6562
)
6663
}
6764

68-
@After
69-
fun resetWorkers() {
70-
workManager.cancelAllWorkByTag(NotificationScheduler.CONTINUOUS_APP_USE_REQUEST_TAG)
71-
}
72-
73-
@Test
74-
fun whenPrivacyNotificationClearDataAndSearchPromptCanShowThenBothAreScheduled() = runBlocking<Unit> {
75-
whenever(privacyNotification.canShow()).thenReturn(true)
76-
whenever(clearNotification.canShow()).thenReturn(true)
77-
whenever(searchPromptNotification.canShow()).thenReturn(true)
78-
testee.scheduleNextNotification()
79-
80-
assertUnusedAppNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
81-
assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker::class.jvmName)
82-
}
83-
8465
@Test
85-
fun whenPrivacyNotificationClearDataAndSearchPromptCanShowThenPrivacyNotificationScheduled() = runBlocking<Unit> {
66+
fun whenPrivacyNotificationClearDataCanShowThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
8667
whenever(privacyNotification.canShow()).thenReturn(true)
8768
whenever(clearNotification.canShow()).thenReturn(true)
88-
whenever(searchPromptNotification.canShow()).thenReturn(false)
8969
testee.scheduleNextNotification()
9070

9171
assertUnusedAppNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
92-
assertNoContinuousAppNotificationScheduled()
9372
}
9473

9574
@Test
96-
fun whenPrivacyNotificationAndSearchPromptCanShowButClearDataCannotThenThenBothAreScheduled() = runBlocking<Unit> {
75+
fun whenPrivacyNotificationCanShowButClearDataCannotThenPrivacyNotificationIsScheduled() = runBlocking<Unit> {
9776
whenever(privacyNotification.canShow()).thenReturn(true)
9877
whenever(clearNotification.canShow()).thenReturn(false)
99-
whenever(searchPromptNotification.canShow()).thenReturn(true)
10078
testee.scheduleNextNotification()
10179

10280
assertUnusedAppNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
103-
assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker::class.jvmName)
10481
}
10582

10683
@Test
107-
fun whenPrivacyNotificationCanShowButClearDataAndSearchPromptCannotThenPrivacyNotificationScheduled() = runBlocking<Unit> {
108-
whenever(privacyNotification.canShow()).thenReturn(true)
109-
whenever(clearNotification.canShow()).thenReturn(false)
110-
whenever(searchPromptNotification.canShow()).thenReturn(false)
111-
testee.scheduleNextNotification()
112-
113-
assertUnusedAppNotificationScheduled(PrivacyNotificationWorker::class.jvmName)
114-
assertNoContinuousAppNotificationScheduled()
115-
}
116-
117-
@Test
118-
fun whenPrivacyNotificationAndSearchPromptCannotShowAndClearNotificationCanShowThenBothAreScheduled() = runBlocking<Unit> {
84+
fun whenPrivacyNotificationCannotShowAndClearNotificationCanShowThenClearNotificationIsScheduled() = runBlocking<Unit> {
11985
whenever(privacyNotification.canShow()).thenReturn(false)
12086
whenever(clearNotification.canShow()).thenReturn(true)
121-
whenever(searchPromptNotification.canShow()).thenReturn(true)
12287
testee.scheduleNextNotification()
12388

12489
assertUnusedAppNotificationScheduled(ClearDataNotificationWorker::class.jvmName)
125-
assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker::class.jvmName)
12690
}
12791

12892
@Test
129-
fun whenPrivacyNotificationAndClearNotificationCannotShowButSearchPromptCanShowThenNotificationScheduled() = runBlocking<Unit> {
93+
fun whenPrivacyNotificationAndClearNotificationCannotShowThenNoNotificationScheduled() = runBlocking<Unit> {
13094
whenever(privacyNotification.canShow()).thenReturn(false)
13195
whenever(clearNotification.canShow()).thenReturn(false)
132-
whenever(searchPromptNotification.canShow()).thenReturn(true)
13396
testee.scheduleNextNotification()
13497

135-
assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker::class.jvmName)
13698
assertNoUnusedAppNotificationScheduled()
13799
}
138100

139-
@Test
140-
fun whenPrivacyNotificationAndClearNotificationCannotShowButSearchPromptCanThenSearchPromptNotificationScheduled() = runBlocking<Unit> {
141-
whenever(privacyNotification.canShow()).thenReturn(false)
142-
whenever(clearNotification.canShow()).thenReturn(false)
143-
whenever(searchPromptNotification.canShow()).thenReturn(true)
144-
145-
testee.scheduleNextNotification()
146-
147-
assertContinuousAppUseNotificationScheduled(SearchPromptNotificationWorker::class.jvmName)
148-
assertNoUnusedAppNotificationScheduled()
149-
}
150-
151-
@Test
152-
fun whenNoNotificationCanShowThenNoNotificationScheduled() = runBlocking<Unit> {
153-
whenever(privacyNotification.canShow()).thenReturn(false)
154-
whenever(clearNotification.canShow()).thenReturn(false)
155-
whenever(searchPromptNotification.canShow()).thenReturn(false)
156-
testee.scheduleNextNotification()
157-
158-
assertNoNotificationScheduled()
159-
}
160-
161101
private fun assertUnusedAppNotificationScheduled(workerName: String) {
162102
assertTrue(getUnusedAppScheduledWorkers().any { it.tags.contains(workerName) })
163103
}
164104

165-
private fun assertContinuousAppUseNotificationScheduled(workerName: String) {
166-
assertTrue(getContinuousAppUseScheduledWorkers().any { it.tags.contains(workerName) })
167-
}
168-
169105
private fun assertNoUnusedAppNotificationScheduled() {
170106
assertTrue(getUnusedAppScheduledWorkers().isEmpty())
171107
}
172108

173-
private fun assertNoContinuousAppNotificationScheduled() {
174-
assertTrue(getContinuousAppUseScheduledWorkers().isEmpty())
175-
}
176-
177-
private fun assertNoNotificationScheduled() {
178-
assertTrue(getUnusedAppScheduledWorkers().isEmpty())
179-
assertTrue(getContinuousAppUseScheduledWorkers().isEmpty())
180-
}
181-
182109
private fun getUnusedAppScheduledWorkers(): List<WorkInfo> {
183110
return workManager
184111
.getWorkInfosByTag(NotificationScheduler.UNUSED_APP_WORK_REQUEST_TAG)
185112
.get()
186113
.filter { it.state == WorkInfo.State.ENQUEUED }
187114
}
188115

189-
private fun getContinuousAppUseScheduledWorkers(): List<WorkInfo> {
190-
return workManager
191-
.getWorkInfosByTag(NotificationScheduler.CONTINUOUS_APP_USE_REQUEST_TAG)
192-
.get()
193-
.filter { it.state == WorkInfo.State.ENQUEUED }
194-
}
195116
}

app/src/androidTest/java/com/duckduckgo/app/settings/SettingsViewModelTest.kt

Lines changed: 1 addition & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -67,9 +67,6 @@ class SettingsViewModelTest {
6767
@Mock
6868
private lateinit var mockVariantManager: VariantManager
6969

70-
@Mock
71-
private lateinit var notificationScheduler: AndroidNotificationScheduler
72-
7370
@Mock
7471
private lateinit var mockPixel: Pixel
7572

@@ -82,7 +79,7 @@ class SettingsViewModelTest {
8279
context = InstrumentationRegistry.getInstrumentation().targetContext
8380
commandCaptor = argumentCaptor()
8481

85-
testee = SettingsViewModel(mockAppSettingsDataStore, mockDefaultBrowserDetector, mockVariantManager, mockPixel, notificationScheduler)
82+
testee = SettingsViewModel(mockAppSettingsDataStore, mockDefaultBrowserDetector, mockVariantManager, mockPixel)
8683
testee.command.observeForever(commandObserver)
8784

8885
whenever(mockAppSettingsDataStore.automaticallyClearWhenOption).thenReturn(APP_EXIT_ONLY)
@@ -230,32 +227,5 @@ class SettingsViewModelTest {
230227
assertEquals(Command.LaunchAppIcon, commandCaptor.firstValue)
231228
}
232229

233-
@Test
234-
fun whenSearchNotificationWasPreviouslyEnabledThenViewStateIndicatesIt() {
235-
whenever(mockAppSettingsDataStore.searchNotificationEnabled).thenReturn(true)
236-
testee.start()
237-
assertTrue(latestViewState().searchNotificationEnabled)
238-
}
239-
240-
@Test
241-
fun whenSearchNotificationToggledOnThenDataStoreIsUpdatedAndNotificationShown() {
242-
testee.onSearchNotificationSettingChanged(true)
243-
verify(mockAppSettingsDataStore).searchNotificationEnabled = true
244-
verify(notificationScheduler).launchStickySearchNotification()
245-
verify(mockPixel).fire(Pixel.PixelName.QUICK_SEARCH_NOTIFICATION_ENABLED)
246-
247-
assertTrue(latestViewState().searchNotificationEnabled)
248-
}
249-
250-
@Test
251-
fun whenSearchNotificationToggledOffThenDataStoreIsUpdatedAndNotificationRemoved() {
252-
testee.onSearchNotificationSettingChanged(false)
253-
verify(mockAppSettingsDataStore).searchNotificationEnabled = false
254-
verify(notificationScheduler).dismissStickySearchNotification()
255-
verify(mockPixel).fire(Pixel.PixelName.QUICK_SEARCH_NOTIFICATION_DISABLED)
256-
257-
assertFalse(latestViewState().searchNotificationEnabled)
258-
}
259-
260230
private fun latestViewState() = testee.viewState.value!!
261231
}

app/src/androidTest/java/com/duckduckgo/app/statistics/VariantManagerTest.kt

Lines changed: 0 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -43,23 +43,6 @@ class VariantManagerTest {
4343
assertEquals(0, variant.features.size)
4444
}
4545

46-
// Search Notification Experiment
47-
48-
@Test
49-
fun searchNotificationControlVariantIsActiveAndHasNoFeatures() {
50-
val variant = variants.first { it.key == "mf" }
51-
assertEqualsDouble(1.0, variant.weight)
52-
assertEquals(0, variant.features.size)
53-
}
54-
55-
@Test
56-
fun searchNotificationVariantIsActiveAndHasStickySearchNotificationFeature() {
57-
val variant = variants.first { it.key == "mg" }
58-
assertEqualsDouble(1.0, variant.weight)
59-
assertEquals(1, variant.features.size)
60-
assertTrue(variant.hasFeature(StickySearchNotification))
61-
}
62-
6346
@Test
6447
fun verifyNoDuplicateVariantNames() {
6548
val existingNames = mutableSetOf<String>()

app/src/main/java/com/duckduckgo/app/di/DaggerWorkerFactory.kt

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -25,15 +25,10 @@ import com.duckduckgo.app.fire.DataClearingWorker
2525
import com.duckduckgo.app.global.view.ClearDataAction
2626
import com.duckduckgo.app.notification.NotificationScheduler.ClearDataNotificationWorker
2727
import com.duckduckgo.app.notification.NotificationScheduler.PrivacyNotificationWorker
28-
import com.duckduckgo.app.notification.NotificationScheduler.SearchPromptNotificationWorker
29-
import com.duckduckgo.app.notification.NotificationScheduler.StickySearchNotificationWorker
30-
import com.duckduckgo.app.notification.NotificationScheduler.DismissSearchNotificationWorker
3128
import com.duckduckgo.app.notification.NotificationFactory
3229
import com.duckduckgo.app.notification.db.NotificationDao
3330
import com.duckduckgo.app.notification.model.ClearDataNotification
3431
import com.duckduckgo.app.notification.model.PrivacyProtectionNotification
35-
import com.duckduckgo.app.notification.model.SearchPromptNotification
36-
import com.duckduckgo.app.notification.model.StickySearchNotification
3732
import com.duckduckgo.app.settings.db.SettingsDataStore
3833
import com.duckduckgo.app.statistics.api.OfflinePixelScheduler
3934
import com.duckduckgo.app.statistics.api.OfflinePixelSender
@@ -49,8 +44,6 @@ class DaggerWorkerFactory(
4944
private val notificationFactory: NotificationFactory,
5045
private val clearDataNotification: ClearDataNotification,
5146
private val privacyProtectionNotification: PrivacyProtectionNotification,
52-
private val stickySearchPromptNotification: SearchPromptNotification,
53-
private val stickySearchNotification: StickySearchNotification,
5447
private val pixel: Pixel
5548
) : WorkerFactory() {
5649

@@ -66,9 +59,6 @@ class DaggerWorkerFactory(
6659
is DataClearingWorker -> injectDataClearWorker(instance)
6760
is ClearDataNotificationWorker -> injectClearDataNotificationWorker(instance)
6861
is PrivacyNotificationWorker -> injectPrivacyNotificationWorker(instance)
69-
is SearchPromptNotificationWorker -> injectSearchPromptNotificationWorker(instance)
70-
is StickySearchNotificationWorker -> injectStickySearchNotificationWorker(instance)
71-
is DismissSearchNotificationWorker -> injectDismissSearchNotificationWorker(instance)
7262
else -> Timber.i("No injection required for worker $workerClassName")
7363
}
7464

@@ -105,25 +95,4 @@ class DaggerWorkerFactory(
10595
worker.notification = privacyProtectionNotification
10696
}
10797

108-
private fun injectSearchPromptNotificationWorker(worker: SearchPromptNotificationWorker) {
109-
worker.manager = notificationManager
110-
worker.notificationDao = notificationDao
111-
worker.factory = notificationFactory
112-
worker.pixel = pixel
113-
worker.notification = stickySearchPromptNotification
114-
}
115-
116-
private fun injectStickySearchNotificationWorker(worker: StickySearchNotificationWorker) {
117-
worker.manager = notificationManager
118-
worker.notificationDao = notificationDao
119-
worker.factory = notificationFactory
120-
worker.pixel = pixel
121-
worker.notification = stickySearchNotification
122-
}
123-
124-
private fun injectDismissSearchNotificationWorker(worker: DismissSearchNotificationWorker) {
125-
worker.manager = notificationManager
126-
worker.notificationDao = notificationDao
127-
worker.notification = stickySearchNotification
128-
}
12998
}

app/src/main/java/com/duckduckgo/app/di/NotificationModule.kt

Lines changed: 2 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -27,11 +27,8 @@ import com.duckduckgo.app.notification.AndroidNotificationScheduler
2727
import com.duckduckgo.app.notification.db.NotificationDao
2828
import com.duckduckgo.app.notification.model.ClearDataNotification
2929
import com.duckduckgo.app.notification.model.PrivacyProtectionNotification
30-
import com.duckduckgo.app.notification.model.SearchPromptNotification
31-
import com.duckduckgo.app.notification.model.StickySearchNotification
3230
import com.duckduckgo.app.privacy.db.PrivacyProtectionCountDao
3331
import com.duckduckgo.app.settings.db.SettingsDataStore
34-
import com.duckduckgo.app.statistics.VariantManager
3532
import dagger.Module
3633
import dagger.Provides
3734
import javax.inject.Singleton
@@ -75,37 +72,17 @@ class NotificationModule {
7572
return PrivacyProtectionNotification(context, notificationDao, privacyProtectionCountDao)
7673
}
7774

78-
@Provides
79-
fun provideStickySearchNotification(
80-
context: Context,
81-
notificationDao: NotificationDao
82-
): StickySearchNotification {
83-
return StickySearchNotification(context, notificationDao)
84-
}
85-
86-
@Provides
87-
fun provideSearchPromptNotification(
88-
context: Context,
89-
notificationDao: NotificationDao,
90-
variantManager: VariantManager,
91-
settingsDataStore: SettingsDataStore
92-
): SearchPromptNotification {
93-
return SearchPromptNotification(context, notificationDao, variantManager, settingsDataStore)
94-
}
95-
9675
@Provides
9776
@Singleton
9877
fun providesNotificationScheduler(
9978
workManager: WorkManager,
10079
clearDataNotification: ClearDataNotification,
101-
privacyProtectionNotification: PrivacyProtectionNotification,
102-
stickySearchNotification: StickySearchNotification
80+
privacyProtectionNotification: PrivacyProtectionNotification
10381
): AndroidNotificationScheduler {
10482
return NotificationScheduler(
10583
workManager,
10684
clearDataNotification,
107-
privacyProtectionNotification,
108-
stickySearchNotification
85+
privacyProtectionNotification
10986
)
11087
}
11188

app/src/main/java/com/duckduckgo/app/di/WorkerModule.kt

Lines changed: 0 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,6 @@ import com.duckduckgo.app.notification.NotificationFactory
2626
import com.duckduckgo.app.notification.db.NotificationDao
2727
import com.duckduckgo.app.notification.model.ClearDataNotification
2828
import com.duckduckgo.app.notification.model.PrivacyProtectionNotification
29-
import com.duckduckgo.app.notification.model.SearchPromptNotification
30-
import com.duckduckgo.app.notification.model.StickySearchNotification
3129
import com.duckduckgo.app.settings.db.SettingsDataStore
3230
import com.duckduckgo.app.statistics.api.OfflinePixelSender
3331
import com.duckduckgo.app.statistics.pixels.Pixel
@@ -59,8 +57,6 @@ class WorkerModule {
5957
notificationFactory: NotificationFactory,
6058
clearDataNotification: ClearDataNotification,
6159
privacyProtectionNotification: PrivacyProtectionNotification,
62-
stickySearchNotification: StickySearchNotification,
63-
stickySearchPromptNotification: SearchPromptNotification,
6460
pixel: Pixel
6561
): WorkerFactory {
6662
return DaggerWorkerFactory(
@@ -72,8 +68,6 @@ class WorkerModule {
7268
notificationFactory,
7369
clearDataNotification,
7470
privacyProtectionNotification,
75-
stickySearchPromptNotification,
76-
stickySearchNotification,
7771
pixel
7872
)
7973
}

app/src/main/java/com/duckduckgo/app/global/ViewModelFactory.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -157,8 +157,7 @@ class ViewModelFactory @Inject constructor(
157157
appSettingsPreferencesStore,
158158
defaultBrowserDetector,
159159
variantManager,
160-
pixel,
161-
notificationScheduler
160+
pixel
162161
)
163162
}
164163

0 commit comments

Comments
 (0)