Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
25 commits
Select commit Hold shift + click to select a range
c0e4475
removing method from interface as it's not used by external callers
cmonfortep Aug 5, 2020
f65fee4
only store sourceTabId when tab is opened after clicking on a link
cmonfortep Aug 5, 2020
74e59f1
Store sourceTabId only when tab opened from current tab
cmonfortep Aug 6, 2020
87eeaad
store sourceTabId when tab opened in background from currentTab
cmonfortep Aug 6, 2020
87e097d
When tab deleted, set to null references to that tab
cmonfortep Aug 6, 2020
bae6921
When back pressed, if sourceTab of current tab is different to null, …
cmonfortep Aug 6, 2020
ba882e0
skipHome by default if value is not passed as argument and if tab has…
cmonfortep Aug 6, 2020
5629708
use sourceTab naming instead of child
cmonfortep Aug 6, 2020
ed0633f
hasSourceTab instead of Parent Tab
cmonfortep Aug 6, 2020
44bb3c2
use room to nullify sourceTabId when tab deleted
cmonfortep Aug 6, 2020
4fd2905
Rename method to be explicit about what sourceTab will be added.
cmonfortep Aug 6, 2020
ef0ae0a
Passing around sourceTabId from tab fragment. Adds flexibility and it…
cmonfortep Aug 6, 2020
fd9238d
apply code style
cmonfortep Aug 6, 2020
d05d08e
Removing isDefaultTab param from multiple methods where it was always…
cmonfortep Aug 6, 2020
7f4cde2
remove unused method
cmonfortep Aug 6, 2020
5af2af7
Unit test new foreign key added logic
cmonfortep Aug 6, 2020
88c4928
Add necessary migration to create foreign key in table tabs
cmonfortep Aug 6, 2020
b1bbbbd
Tidy up and add new tests to TabDataRepositoryTest
cmonfortep Aug 7, 2020
fd52f6a
remove unused method
cmonfortep Aug 7, 2020
84ed2b7
update BrowserTabViewModel tests
cmonfortep Aug 7, 2020
1f1170a
udpate unit tests for BrowserViewModel
cmonfortep Aug 7, 2020
343635f
apply code style
cmonfortep Aug 7, 2020
e3e6b57
add comment to document issue with sqlite
cmonfortep Aug 7, 2020
7ab3569
apply codestyle
cmonfortep Aug 7, 2020
3795162
make method param sourceTabId non-nullable
cmonfortep Aug 7, 2020
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 16 additions & 4 deletions app/schemas/com.duckduckgo.app.global.db.AppDatabase/24.json
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
"formatVersion": 1,
"database": {
"version": 24,
"identityHash": "03673f6d5937091013955e2520b94c0e",
"identityHash": "d6df0e21b463f404e4ea0a430f7d905c",
"entities": [
{
"tableName": "tds_tracker",
Expand Down Expand Up @@ -258,7 +258,7 @@
},
{
"tableName": "tabs",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tabId` TEXT NOT NULL, `url` TEXT, `title` TEXT, `skipHome` INTEGER NOT NULL, `viewed` INTEGER NOT NULL, `position` INTEGER NOT NULL, `tabPreviewFile` TEXT, `sourceTabId` TEXT, PRIMARY KEY(`tabId`))",
"createSql": "CREATE TABLE IF NOT EXISTS `${TABLE_NAME}` (`tabId` TEXT NOT NULL, `url` TEXT, `title` TEXT, `skipHome` INTEGER NOT NULL, `viewed` INTEGER NOT NULL, `position` INTEGER NOT NULL, `tabPreviewFile` TEXT, `sourceTabId` TEXT, PRIMARY KEY(`tabId`), FOREIGN KEY(`sourceTabId`) REFERENCES `tabs`(`tabId`) ON UPDATE SET NULL ON DELETE SET NULL )",
"fields": [
{
"fieldPath": "tabId",
Expand Down Expand Up @@ -325,7 +325,19 @@
"createSql": "CREATE INDEX IF NOT EXISTS `index_tabs_tabId` ON `${TABLE_NAME}` (`tabId`)"
}
],
"foreignKeys": []
"foreignKeys": [
{
"table": "tabs",
"onDelete": "SET NULL",
"onUpdate": "SET NULL",
"columns": [
"sourceTabId"
],
"referencedColumns": [
"tabId"
]
}
]
},
{
"tableName": "tab_selection",
Expand Down Expand Up @@ -746,7 +758,7 @@
"views": [],
"setupQueries": [
"CREATE TABLE IF NOT EXISTS room_master_table (id INTEGER PRIMARY KEY,identity_hash TEXT)",
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, '03673f6d5937091013955e2520b94c0e')"
"INSERT OR REPLACE INTO room_master_table (id,identity_hash) VALUES(42, 'd6df0e21b463f404e4ea0a430f7d905c')"
]
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -476,7 +476,9 @@ class BrowserTabViewModelTest {
givenOneActiveTabSelected()
givenInvalidatedGlobalLayout()
testee.onUserSubmittedQuery("foo")
assertCommandIssued<Command.OpenInNewTab>()
assertCommandIssued<Command.OpenInNewTab> {
assertNull(sourceTabId)
}
}

@Test
Expand Down Expand Up @@ -1093,7 +1095,9 @@ class BrowserTabViewModelTest {

testee.onRefreshRequested()

assertCommandIssued<Command.OpenInNewTab>()
assertCommandIssued<Command.OpenInNewTab>() {
assertNull(sourceTabId)
}
}

@Test
Expand Down Expand Up @@ -1188,6 +1192,10 @@ class BrowserTabViewModelTest {
testee.userSelectedItemFromLongPressMenu(longPressTarget, mockMenItem)
val command = captureCommands().value as Command.OpenInNewTab
assertEquals("http://example.com", command.query)

assertCommandIssued<Command.OpenInNewTab> {
assertNotNull(sourceTabId)
}
}

@Test
Expand Down Expand Up @@ -1319,18 +1327,6 @@ class BrowserTabViewModelTest {
assertEquals(true, testee.browserViewState.value?.browserShowing)
}

@Test
fun whenOpenInNewTabThenOpenInNewTabCommandWithCorrectUrlSent() {
val url = "https://example.com"
testee.openInNewTab(url)
verify(mockCommandObserver).onChanged(commandCaptor.capture())

val command = commandCaptor.lastValue
assertTrue(command is Command.OpenInNewTab)
command as Command.OpenInNewTab
assertEquals(url, command.query)
}

@Test
fun whenRecoveringFromProcessGoneThenShowErrorWithAction() {
testee.recoverFromRenderProcessGone()
Expand All @@ -1348,6 +1344,7 @@ class BrowserTabViewModelTest {

assertCommandIssued<Command.OpenInNewTab> {
assertEquals("https://example.com", query)
assertNull(sourceTabId)
}
}

Expand Down Expand Up @@ -1558,6 +1555,16 @@ class BrowserTabViewModelTest {
assertTrue(commandCaptor.allValues.contains(Command.ShowKeyboard))
}

@Test
fun whenUserPressesBackOnATabWithASourceTabThenDeleteCurrentAndSelectSource() = coroutineRule.runBlocking {
selectedTabLiveData.value = TabEntity("TAB_ID", "https://example.com", position = 0, sourceTabId = "TAB_ID_SOURCE")
setupNavigation(isBrowsing = true)

testee.onUserPressedBack()

verify(mockTabsRepository).deleteCurrentTabAndSelectSource()
}

@Test
fun whenScheduledSurveyChangesAndInstalledDaysMatchThenCtaIsSurvey() {
testee.onSurveyChanged(Survey("abc", "http://example.com", daysInstalled = 1, status = Survey.Status.SCHEDULED))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,7 +123,14 @@ class BrowserViewModelTest {
fun whenNewTabRequestedThenTabAddedToRepository() = runBlocking<Unit> {
whenever(mockTabRepository.liveSelectedTab).doReturn(MutableLiveData())
testee.onNewTabRequested()
verify(mockTabRepository).addWithSource()
verify(mockTabRepository).add()
}

@Test
fun whenNewTabRequestedFromSourceTabThenTabAddedToRepositoryWithSourceTabId() = runBlocking<Unit> {
whenever(mockTabRepository.liveSelectedTab).doReturn(MutableLiveData())
testee.onNewTabRequested("sourceTabId")
verify(mockTabRepository).addFromSourceTab(sourceTabId = "sourceTabId")
}

@Test
Expand All @@ -132,13 +139,22 @@ class BrowserViewModelTest {
whenever(mockOmnibarEntryConverter.convertQueryToUrl(url)).thenReturn(url)
whenever(mockTabRepository.liveSelectedTab).doReturn(MutableLiveData())
testee.onOpenInNewTabRequested(url)
verify(mockTabRepository).addWithSource(url)
verify(mockTabRepository).add(url = url, skipHome = false)
}

@Test
fun whenOpenInNewTabRequestedWithSourceTabIdThenTabAddedToRepositoryWithSourceTabId() = runBlocking<Unit> {
val url = "http://example.com"
whenever(mockOmnibarEntryConverter.convertQueryToUrl(url)).thenReturn(url)
whenever(mockTabRepository.liveSelectedTab).doReturn(MutableLiveData())
testee.onOpenInNewTabRequested(url, sourceTabId = "tabId")
verify(mockTabRepository).addFromSourceTab(url = url, skipHome = false, sourceTabId = "tabId")
}

@Test
fun whenTabsUpdatedAndNoTabsThenNewTabAddedToRepository() = runBlocking<Unit> {
fun whenTabsUpdatedAndNoTabsThenDefaultTabAddedToRepository() = runBlocking<Unit> {
testee.onTabsUpdated(ArrayList())
verify(mockTabRepository).add(null, false, true)
verify(mockTabRepository).addDefaultTab()
}

@Test
Expand Down
14 changes: 12 additions & 2 deletions app/src/androidTest/java/com/duckduckgo/app/tabs/db/TabsDaoTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -206,7 +206,6 @@ class TabsDaoTest {

@Test
fun whenTabInsertedAtPositionThenOtherTabsReordered() {

testee.insertTab(TabEntity("TAB_ID1", position = 0))
testee.insertTab(TabEntity("TAB_ID2", position = 1))
testee.insertTab(TabEntity("TAB_ID3", position = 2))
Expand All @@ -226,7 +225,18 @@ class TabsDaoTest {

assertEquals(3, tabs[3].position)
assertEquals("TAB_ID3", tabs[3].tabId)

}

@Test
fun whenSourceTabDeletedThenRelatedTabsUpdated() {
val firstTab = TabEntity("TAB_ID", "http//updatedexample.com", position = 0)
val secondTab = TabEntity("TAB_ID_1", "http//updatedexample.com", position = 1, sourceTabId = "TAB_ID")
testee.insertTab(firstTab)
testee.insertTab(secondTab)

testee.deleteTab(firstTab)

assertNotNull(testee.tab("TAB_ID_1"))
assertNull(testee.tab("TAB_ID_1")?.sourceTabId)
}
}
Loading