Close private tabs tests (#8999)

fennec/beta
Oana Horvath 4 years ago committed by GitHub
parent ef42becbf9
commit 7e9811b20c
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -14,9 +14,9 @@ import org.junit.Before
import org.junit.Rule import org.junit.Rule
import org.junit.Test import org.junit.Test
import org.mozilla.fenix.helpers.AndroidAssetDispatcher import org.mozilla.fenix.helpers.AndroidAssetDispatcher
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.helpers.HomeActivityTestRule import org.mozilla.fenix.helpers.HomeActivityTestRule
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper
import org.mozilla.fenix.helpers.ext.waitNotNull
import org.mozilla.fenix.ui.robots.homeScreen import org.mozilla.fenix.ui.robots.homeScreen
import org.mozilla.fenix.ui.robots.navigationToolbar import org.mozilla.fenix.ui.robots.navigationToolbar
@ -31,6 +31,7 @@ import org.mozilla.fenix.ui.robots.navigationToolbar
* - Close tab * - Close tab
* - Swipe to close tab * - Swipe to close tab
* - Undo close tab * - Undo close tab
* - Close private tabs persistent notification
* *
*/ */
@ -215,4 +216,52 @@ class TabbedBrowsingTest {
} }
} }
} }
@Test
fun closePrivateTabTest() {
var genericURLS = TestAssetHelper.getGenericAssets(mockWebServer)
homeScreen {
}.togglePrivateBrowsingMode()
genericURLS.forEachIndexed { index, element ->
navigationToolbar {
}.openNewTabAndEnterToBrowser(element.url) {
verifyPageContent(element.content)
}.openHomeScreen {
verifyExistingOpenTabs("Test_Page_${index + 1}")
verifyCloseTabsButton("Test_Page_${index + 1}")
closeTabViaXButton("Test_Page_${index + 1}")
verifySnackBarText("Private tab closed")
snackBarButtonClick("UNDO")
verifyExistingOpenTabs("Test_Page_${index + 1}")
verifyCloseTabsButton("Test_Page_${index + 1}")
swipeTabRight("Test_Page_${index + 1}")
verifySnackBarText("Private tab closed")
snackBarButtonClick("UNDO")
verifyExistingOpenTabs("Test_Page_${index + 1}")
verifyCloseTabsButton("Test_Page_${index + 1}")
swipeTabLeft("Test_Page_${index + 1}")
verifySnackBarText("Private tab closed")
snackBarButtonClick("UNDO")
verifyExistingOpenTabs("Test_Page_${index + 1}")
verifyCloseTabsButton("Test_Page_${index + 1}")
}
}
}
@Test
fun closePrivateTabsNotificationTest() {
val defaultWebPage = TestAssetHelper.getGenericAsset(mockWebServer, 1)
homeScreen {
}.togglePrivateBrowsingMode()
navigationToolbar {
}.enterURLAndEnterToBrowser(defaultWebPage.url) {
mDevice.openNotification()
verifyPrivateTabsNotification()
}.clickClosePrivateTabsNotification {
verifyPrivateSessionMessage()
}
}
} }

@ -22,16 +22,17 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.platform.app.InstrumentationRegistry import androidx.test.platform.app.InstrumentationRegistry
import androidx.test.uiautomator.By import androidx.test.uiautomator.By
import androidx.test.uiautomator.By.text
import androidx.test.uiautomator.UiDevice import androidx.test.uiautomator.UiDevice
import androidx.test.uiautomator.UiSelector
import androidx.test.uiautomator.Until import androidx.test.uiautomator.Until
import org.hamcrest.CoreMatchers
import org.hamcrest.CoreMatchers.allOf import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString import org.hamcrest.CoreMatchers.containsString
import org.junit.Assert.assertTrue import org.junit.Assert.assertTrue
import org.mozilla.fenix.R import org.mozilla.fenix.R
import org.mozilla.fenix.ext.components import org.mozilla.fenix.ext.components
import org.mozilla.fenix.helpers.Constants.LongClickDuration import org.mozilla.fenix.helpers.Constants.LongClickDuration
import org.mozilla.fenix.helpers.TestAssetHelper import org.mozilla.fenix.helpers.TestAssetHelper.waitingTime
import org.mozilla.fenix.helpers.click import org.mozilla.fenix.helpers.click
import org.mozilla.fenix.helpers.ext.waitNotNull import org.mozilla.fenix.helpers.ext.waitNotNull
@ -51,7 +52,7 @@ class BrowserRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")), Until.findObject(By.res("org.mozilla.fenix.debug:id/mozac_browser_toolbar_url_view")),
TestAssetHelper.waitingTime waitingTime
) )
onView(withId(R.id.mozac_browser_toolbar_url_view)) onView(withId(R.id.mozac_browser_toolbar_url_view))
.check(matches(withText(containsString(url)))) .check(matches(withText(containsString(url))))
@ -74,7 +75,7 @@ class BrowserRobot {
*/ */
fun verifyPageContent(expectedText: String) { fun verifyPageContent(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text(expectedText)), waitingTime)
} }
fun verifyTabCounter(expectedText: String) { fun verifyTabCounter(expectedText: String) {
@ -84,7 +85,7 @@ class BrowserRobot {
fun verifySnackBarText(expectedText: String) { fun verifySnackBarText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text(expectedText)), waitingTime)
onView(withText(expectedText)).check( onView(withText(expectedText)).check(
matches(isCompletelyDisplayed()) matches(isCompletelyDisplayed())
@ -95,37 +96,37 @@ class BrowserRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.textContains(containsURL.toString())), Until.findObject(By.textContains(containsURL.toString())),
TestAssetHelper.waitingTime waitingTime
) )
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in new tab")), Until.findObject(text("Open link in new tab")),
TestAssetHelper.waitingTime waitingTime
) )
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in private tab")), Until.findObject(text("Open link in private tab")),
TestAssetHelper.waitingTime waitingTime
) )
mDevice.waitNotNull(Until.findObject(By.text("Copy link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Copy link")), waitingTime)
mDevice.waitNotNull(Until.findObject(By.text("Share link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Share link")), waitingTime)
} }
fun verifyLinkImageContextMenuItems(containsURL: Uri) { fun verifyLinkImageContextMenuItems(containsURL: Uri) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.textContains(containsURL.toString()))) mDevice.waitNotNull(Until.findObject(By.textContains(containsURL.toString())))
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in new tab")), TestAssetHelper.waitingTime Until.findObject(text("Open link in new tab")), waitingTime
) )
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in private tab")), TestAssetHelper.waitingTime Until.findObject(text("Open link in private tab")), waitingTime
) )
mDevice.waitNotNull(Until.findObject(By.text("Copy link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Copy link")), waitingTime)
mDevice.waitNotNull(Until.findObject(By.text("Share link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Share link")), waitingTime)
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open image in new tab")), TestAssetHelper.waitingTime Until.findObject(text("Open image in new tab")), waitingTime
) )
mDevice.waitNotNull(Until.findObject(By.text("Save image")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Save image")), waitingTime)
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Copy image location")), TestAssetHelper.waitingTime Until.findObject(text("Copy image location")), waitingTime
) )
} }
@ -133,50 +134,55 @@ class BrowserRobot {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.textContains(containsTitle))) mDevice.waitNotNull(Until.findObject(By.textContains(containsTitle)))
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open image in new tab")), Until.findObject(text("Open image in new tab")),
TestAssetHelper.waitingTime waitingTime
) )
mDevice.waitNotNull(Until.findObject(By.text("Save image")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Save image")), waitingTime)
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Copy image location")), TestAssetHelper.waitingTime Until.findObject(text("Copy image location")), waitingTime
) )
} }
fun verifyPrivateTabsNotification() {
mDevice.wait(Until.hasObject(text("Close private tabs")), waitingTime)
assertPrivateTabsNotification()
}
fun clickContextOpenLinkInNewTab() { fun clickContextOpenLinkInNewTab() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in new tab")), Until.findObject(text("Open link in new tab")),
TestAssetHelper.waitingTime waitingTime
) )
val menuOpenInNewTab = mDevice.findObject(By.text("Open link in new tab")) val menuOpenInNewTab = mDevice.findObject(text("Open link in new tab"))
menuOpenInNewTab.click() menuOpenInNewTab.click()
} }
fun clickContextOpenLinkInPrivateTab() { fun clickContextOpenLinkInPrivateTab() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open link in private tab")), Until.findObject(text("Open link in private tab")),
TestAssetHelper.waitingTime waitingTime
) )
val menuOpenInPrivateTab = mDevice.findObject(By.text("Open link in private tab")) val menuOpenInPrivateTab = mDevice.findObject(text("Open link in private tab"))
menuOpenInPrivateTab.click() menuOpenInPrivateTab.click()
} }
fun clickContextCopyLink() { fun clickContextCopyLink() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text("Copy link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Copy link")), waitingTime)
val menuCopyLink = mDevice.findObject(By.text("Copy link")) val menuCopyLink = mDevice.findObject(text("Copy link"))
menuCopyLink.click() menuCopyLink.click()
} }
fun clickContextShareLink(url: Uri) { fun clickContextShareLink(url: Uri) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text("Share link")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Share link")), waitingTime)
val menuShareLink = mDevice.findObject(By.text("Share link")) val menuShareLink = mDevice.findObject(text("Share link"))
menuShareLink.click() menuShareLink.click()
// verify share intent is launched and matched with associated passed in URL // verify share intent is launched and matched with associated passed in URL
@ -205,37 +211,37 @@ class BrowserRobot {
fun clickContextCopyImageLocation() { fun clickContextCopyImageLocation() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Copy image location")), Until.findObject(text("Copy image location")),
TestAssetHelper.waitingTime waitingTime
) )
val menuCopyImageLocation = mDevice.findObject(By.text("Copy image location")) val menuCopyImageLocation = mDevice.findObject(text("Copy image location"))
menuCopyImageLocation.click() menuCopyImageLocation.click()
} }
fun clickContextOpenImageNewTab() { fun clickContextOpenImageNewTab() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.text("Open image in new tab")), Until.findObject(text("Open image in new tab")),
TestAssetHelper.waitingTime waitingTime
) )
val menuOpenImageNewTab = mDevice.findObject(By.text("Open image in new tab")) val menuOpenImageNewTab = mDevice.findObject(text("Open image in new tab"))
menuOpenImageNewTab.click() menuOpenImageNewTab.click()
} }
fun clickContextSaveImage() { fun clickContextSaveImage() {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text("Save image")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text("Save image")), waitingTime)
val menuSaveImage = mDevice.findObject(By.text("Save image")) val menuSaveImage = mDevice.findObject(text("Save image"))
menuSaveImage.click() menuSaveImage.click()
} }
fun waitForCollectionSavedPopup() { fun waitForCollectionSavedPopup() {
mDevice.wait( mDevice.wait(
Until.findObject(By.text("Tab saved!")), Until.findObject(text("Tab saved!")),
TestAssetHelper.waitingTime waitingTime
) )
} }
@ -249,17 +255,17 @@ class BrowserRobot {
fun clickLinkMatchingText(expectedText: String) { fun clickLinkMatchingText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text(expectedText)), waitingTime)
val element = mDevice.findObject(By.text(expectedText)) val element = mDevice.findObject(text(expectedText))
element.click() element.click()
} }
fun longClickMatchingText(expectedText: String) { fun longClickMatchingText(expectedText: String) {
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
mDevice.waitNotNull(Until.findObject(By.text(expectedText)), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObject(text(expectedText)), waitingTime)
val element = mDevice.findObject(By.text(expectedText)) val element = mDevice.findObject(text(expectedText))
element.click(LongClickDuration.LONG_CLICK_DURATION) element.click(LongClickDuration.LONG_CLICK_DURATION)
} }
@ -270,21 +276,21 @@ class BrowserRobot {
} }
fun verifySaveLoginPromptIsShown() { fun verifySaveLoginPromptIsShown() {
mDevice.waitNotNull(Until.findObjects(By.text("test@example.com")), TestAssetHelper.waitingTime) mDevice.waitNotNull(Until.findObjects(text("test@example.com")), waitingTime)
val submitButton = mDevice.findObject(By.res("submit")) val submitButton = mDevice.findObject(By.res("submit"))
submitButton.clickAndWait(Until.newWindow(), TestAssetHelper.waitingTime) submitButton.clickAndWait(Until.newWindow(), waitingTime)
// Click save to save the login // Click save to save the login
mDevice.waitNotNull(Until.findObjects(By.text("Save"))) mDevice.waitNotNull(Until.findObjects(text("Save")))
} }
fun saveLoginFromPrompt(optionToSaveLogin: String) { fun saveLoginFromPrompt(optionToSaveLogin: String) {
mDevice.findObject(By.text(optionToSaveLogin)).click() mDevice.findObject(text(optionToSaveLogin)).click()
} }
class Transition { class Transition {
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation()) private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
private fun threeDotButton() = onView( private fun threeDotButton() = onView(
CoreMatchers.allOf( allOf(
ViewMatchers.withContentDescription( ViewMatchers.withContentDescription(
"Menu" "Menu"
) )
@ -314,12 +320,20 @@ class BrowserRobot {
mDevice.waitNotNull( mDevice.waitNotNull(
Until.findObject(By.res("org.mozilla.fenix.debug:id/header_text")), Until.findObject(By.res("org.mozilla.fenix.debug:id/header_text")),
TestAssetHelper.waitingTime waitingTime
) )
HomeScreenRobot().interact() HomeScreenRobot().interact()
return HomeScreenRobot.Transition() return HomeScreenRobot.Transition()
} }
fun clickClosePrivateTabsNotification(interact: HomeScreenRobot.() -> Unit): HomeScreenRobot.Transition {
mDevice.wait(Until.hasObject(text("Close private tabs")), waitingTime)
closePrivateTabsNotification().clickAndWaitForNewWindow(waitingTime)
HomeScreenRobot().interact()
return HomeScreenRobot.Transition()
}
} }
} }
@ -331,10 +345,18 @@ fun browserScreen(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
private fun dismissOnboardingButton() = onView(withId(R.id.close_onboarding)) private fun dismissOnboardingButton() = onView(withId(R.id.close_onboarding))
fun dismissTrackingOnboarding() { fun dismissTrackingOnboarding() {
mDevice.wait(Until.findObject(By.res("close_onboarding")), TestAssetHelper.waitingTime) mDevice.wait(Until.findObject(By.res("close_onboarding")), waitingTime)
dismissOnboardingButton().click() dismissOnboardingButton().click()
} }
fun navURLBar() = onView(withId(R.id.mozac_browser_toolbar_url_view)) fun navURLBar() = onView(withId(R.id.mozac_browser_toolbar_url_view))
private fun tabsCounter() = onView(withId(R.id.mozac_browser_toolbar_browser_actions)) private fun tabsCounter() = onView(withId(R.id.mozac_browser_toolbar_browser_actions))
private fun closePrivateTabsNotification() =
mDevice.findObject(UiSelector().text("Close private tabs"))
private fun assertPrivateTabsNotification() {
mDevice.findObject(UiSelector().text("Firefox Preview (Private)")).exists()
mDevice.findObject(UiSelector().text("Close private tabs")).exists()
}

Loading…
Cancel
Save