Skip to content

Commit 40269e8

Browse files
0nkonalcalag
andauthored
Tab swiping (#5408)
Task/Issue URL: https://app.asana.com/0/1207418217763355/1209006734942815/f ### Description This PR includes the complete implementation of the tab-swiping functionality. ### Steps to test this PR **Make sure you’ve completed the onboarding!** #### New tab from long press - [x] Long press on a tabs button - [x] Verify a new tab is opened #### New tab from the menu - [x] Tap on the New tab menu item - [x] Verify a new tab is opened #### New tab from tab switcher - [x] Go to tab switcher - [x] Tap on the New tab button - [x] Verify a new tab is opened #### New tab recreation - [x] Open a few tabs - [x] Go to the tab switcher - [x] Add a new tab - [x] Verify a new tab is correctly displayed - [x] Go back to the tab switcher - [x] Close the NTP - [x] Tap on the new tab button - [x] Verify the new tab is correctly opened #### Swiping position - [x] Open at least 3 tabs - [x] Select the 1st one in the tab switcher - [x] Swipe to the last one - [x] Go to tab switcher and verify the correct tab is selected - [x] Tap on the 2nd tab - [x] Verify the correct tab is opened #### New link - [x] Open any website - [x] Long press on a link to open in new tab - [x] Verify the link is opened in a new tab #### New link in the background - [x] Open any website - [x] Long press on a link to open in background tab - [x] Verify the link is opened in a new tab in the background #### New link in the background - [x] Make sure the DDG app is the default browser app - [x] Open an app that can open links in custom tabs (i.e. Twitter, Facebook) - [x] Open a link in a custom tab - [x] Verify the link opens correctly - [x] Move the tab to the app - [x] Verify the tab is correctly displayed within the app #### Switch to tab - [x] Start typing a site address that’s already opened in another tab - [x] Tap on the “Switch to tab” item - [x] Verify the existing tab with the link is shown instead of opening a new tab #### Changing the omnibar position - [x] Open a few tabs - [x] Go to settings and change the omnibar position - [x] The app will reload (the cached sites are cleared) - [x] Swipe through the tabs and verify the load correctly #### Bookmarks - [x] Load a site - [x] Add it to the boorkmarks - [x] Open a different tab - [x] Go to Bookmarks and select the saved boormark - [x] Verify the bookmark loads correctly #### Default site - [x] Set some default URL in Settings -> General -> Show on App Launch - [x] Kill the app and relaunch it - [x] Verify the default site is correctly loaded in a new tab - [x] Kill the app and relaunch it - [x] Verify the default site is loaded in the same tab as before (no new tab is added) --------- Co-authored-by: Noelia Alcala <nalcalag@gmail.com>
1 parent cd17533 commit 40269e8

30 files changed

+2189
-190
lines changed

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

+22-1
Original file line numberDiff line numberDiff line change
@@ -503,13 +503,18 @@ class BrowserTabViewModelTest {
503503
private val mockBrokenSitePrompt: BrokenSitePrompt = mock()
504504
private val mockTabStatsBucketing: TabStatsBucketing = mock()
505505
private val mockDuckChatJSHelper: DuckChatJSHelper = mock()
506+
private val swipingTabsFeature = FakeFeatureToggleFactory.create(SwipingTabsFeature::class.java)
507+
private val swipingTabsFeatureProvider = SwipingTabsFeatureProvider(swipingTabsFeature)
506508

507509
private val defaultBrowserPromptsExperimentShowPopupMenuItemFlow = MutableStateFlow(false)
508510
private val mockDefaultBrowserPromptsExperiment: DefaultBrowserPromptsExperiment = mock()
509511

510512
@Before
511513
fun before() = runTest {
512514
MockitoAnnotations.openMocks(this)
515+
516+
swipingTabsFeature.self().setRawStoredState(State(enable = true))
517+
513518
db = Room.inMemoryDatabaseBuilder(context, AppDatabase::class.java)
514519
.allowMainThreadQueries()
515520
.build()
@@ -680,6 +685,7 @@ class BrowserTabViewModelTest {
680685
tabStatsBucketing = mockTabStatsBucketing,
681686
maliciousSiteBlockerWebViewIntegration = mock(),
682687
defaultBrowserPromptsExperiment = mockDefaultBrowserPromptsExperiment,
688+
swipingTabsFeature = swipingTabsFeatureProvider,
683689
)
684690

685691
testee.loadData("abc", null, false, false)
@@ -2325,14 +2331,29 @@ class BrowserTabViewModelTest {
23252331
}
23262332

23272333
@Test
2328-
fun whenUserRequestedToOpenNewTabThenNewTabCommandIssued() {
2334+
fun whenUserRequestedToOpenNewTabAndNoEmptyTabExistsThenNewTabCommandIssued() {
2335+
tabsLiveData.value = listOf(TabEntity("1", "https://example.com", position = 0))
23292336
testee.userRequestedOpeningNewTab()
23302337
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
23312338
val command = commandCaptor.lastValue
23322339
assertTrue(command is Command.LaunchNewTab)
23332340
verify(mockPixel, never()).fire(AppPixelName.TAB_MANAGER_NEW_TAB_LONG_PRESSED)
23342341
}
23352342

2343+
@Test
2344+
fun whenUserRequestedToOpenNewTabAndEmptyTabExistsThenSelectTheEmptyTab() = runTest {
2345+
val emptyTabId = "EMPTY_TAB"
2346+
whenever(mockTabRepository.flowTabs).thenReturn(flowOf(listOf(TabEntity(emptyTabId))))
2347+
testee.userRequestedOpeningNewTab()
2348+
2349+
verify(mockCommandObserver, atLeastOnce()).onChanged(commandCaptor.capture())
2350+
val command = commandCaptor.lastValue
2351+
assertFalse(command is Command.LaunchNewTab)
2352+
2353+
verify(mockTabRepository).select(emptyTabId)
2354+
verify(mockPixel, never()).fire(AppPixelName.TAB_MANAGER_NEW_TAB_LONG_PRESSED)
2355+
}
2356+
23362357
@Test
23372358
fun whenUserRequestedToOpenNewTabByLongPressThenPixelFired() {
23382359
testee.userRequestedOpeningNewTab(longPress = true)

0 commit comments

Comments
 (0)