- Initiates a download - Verifies prompt - Verifies notification in notification shadestaging
parent
3df32edff0
commit
35f136b14b
@ -0,0 +1,5 @@
|
||||
<html>
|
||||
<body>
|
||||
<a href="../resources/Globe.svg" download>Page content: Globe.svg</a>
|
||||
</body>
|
||||
</html>
|
@ -0,0 +1,4 @@
|
||||
<!-- This Source Code Form is subject to the terms of the Mozilla Public
|
||||
- License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
- file, You can obtain one at http://mozilla.org/MPL/2.0/. -->
|
||||
<svg xmlns="http://www.w3.org/2000/svg" width="16" height="16" viewBox="0 0 16 16"><path fill="context-fill" d="M8 0a8 8 0 1 0 8 8 8.009 8.009 0 0 0-8-8zm5.163 4.958h-1.552a7.7 7.7 0 0 0-1.051-2.376 6.03 6.03 0 0 1 2.603 2.376zM14 8a5.963 5.963 0 0 1-.335 1.958h-1.821A12.327 12.327 0 0 0 12 8a12.327 12.327 0 0 0-.156-1.958h1.821A5.963 5.963 0 0 1 14 8zm-6 6c-1.075 0-2.037-1.2-2.567-2.958h5.135C10.037 12.8 9.075 14 8 14zM5.174 9.958a11.084 11.084 0 0 1 0-3.916h5.651A11.114 11.114 0 0 1 11 8a11.114 11.114 0 0 1-.174 1.958zM2 8a5.963 5.963 0 0 1 .335-1.958h1.821a12.361 12.361 0 0 0 0 3.916H2.335A5.963 5.963 0 0 1 2 8zm6-6c1.075 0 2.037 1.2 2.567 2.958H5.433C5.963 3.2 6.925 2 8 2zm-2.56.582a7.7 7.7 0 0 0-1.051 2.376H2.837A6.03 6.03 0 0 1 5.44 2.582zm-2.6 8.46h1.549a7.7 7.7 0 0 0 1.051 2.376 6.03 6.03 0 0 1-2.603-2.376zm7.723 2.376a7.7 7.7 0 0 0 1.051-2.376h1.552a6.03 6.03 0 0 1-2.606 2.376z"></path></svg>
|
After Width: | Height: | Size: 1.1 KiB |
@ -0,0 +1,110 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
package org.mozilla.fenix.ui
|
||||
|
||||
import android.os.Environment
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.rule.GrantPermissionRule
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import kotlinx.coroutines.runBlocking
|
||||
import okhttp3.mockwebserver.MockWebServer
|
||||
import org.junit.After
|
||||
import org.junit.Before
|
||||
import org.junit.Rule
|
||||
import org.junit.Test
|
||||
import org.mozilla.fenix.helpers.AndroidAssetDispatcher
|
||||
import org.mozilla.fenix.helpers.HomeActivityTestRule
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.ui.robots.downloadRobot
|
||||
import org.mozilla.fenix.ui.robots.homeScreen
|
||||
import org.mozilla.fenix.ui.robots.navigationToolbar
|
||||
import java.io.File
|
||||
|
||||
/**
|
||||
* Tests for verifying basic functionality of download prompt UI
|
||||
*
|
||||
* - Initiates a download
|
||||
* - Verifies download prompt
|
||||
* - Verifies download notification
|
||||
**/
|
||||
|
||||
class DownloadTest {
|
||||
|
||||
private val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
|
||||
private lateinit var mockWebServer: MockWebServer
|
||||
|
||||
/* ktlint-disable no-blank-line-before-rbrace */ // This imposes unreadable grouping.
|
||||
@get:Rule
|
||||
val activityTestRule = HomeActivityTestRule()
|
||||
|
||||
@get:Rule
|
||||
var mGrantPermissions = GrantPermissionRule.grant(
|
||||
android.Manifest.permission.WRITE_EXTERNAL_STORAGE,
|
||||
android.Manifest.permission.READ_EXTERNAL_STORAGE
|
||||
)
|
||||
|
||||
@Before
|
||||
fun setUp() {
|
||||
mockWebServer = MockWebServer().apply {
|
||||
setDispatcher(AndroidAssetDispatcher())
|
||||
start()
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
fun tearDown() {
|
||||
mockWebServer.shutdown()
|
||||
|
||||
// Clear Download
|
||||
runBlocking {
|
||||
val downloadedFile = File(
|
||||
Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS),
|
||||
"Globe.svg.html"
|
||||
)
|
||||
|
||||
if (downloadedFile.exists()) {
|
||||
downloadedFile.delete()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDownloadPrompt() {
|
||||
homeScreen { }.dismissOnboarding()
|
||||
|
||||
val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.openNewTabAndEnterToBrowser(defaultWebPage.url) {
|
||||
verifyPageContent(defaultWebPage.content)
|
||||
clickLinkMatchingText(defaultWebPage.content)
|
||||
}
|
||||
|
||||
downloadRobot {
|
||||
verifyDownloadPrompt()
|
||||
}.closePrompt {}
|
||||
}
|
||||
|
||||
@Test
|
||||
fun testDownloadNotification() {
|
||||
homeScreen { }.dismissOnboarding()
|
||||
|
||||
val defaultWebPage = TestAssetHelper.getDownloadAsset(mockWebServer)
|
||||
|
||||
navigationToolbar {
|
||||
}.openNewTabAndEnterToBrowser(defaultWebPage.url) {
|
||||
verifyPageContent(defaultWebPage.content)
|
||||
clickLinkMatchingText(defaultWebPage.content)
|
||||
}
|
||||
|
||||
downloadRobot {
|
||||
verifyDownloadPrompt()
|
||||
}.clickDownload {
|
||||
verifyDownloadNotificationPopup()
|
||||
verifyDownloadNotificationShade()
|
||||
}
|
||||
}
|
||||
}
|
@ -0,0 +1,86 @@
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
@file:Suppress("TooManyFunctions")
|
||||
|
||||
package org.mozilla.fenix.ui.robots
|
||||
|
||||
import androidx.test.espresso.Espresso.onView
|
||||
import androidx.test.espresso.assertion.ViewAssertions.matches
|
||||
import androidx.test.espresso.matcher.RootMatchers.isDialog
|
||||
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withId
|
||||
import androidx.test.espresso.matcher.ViewMatchers.withText
|
||||
import androidx.test.platform.app.InstrumentationRegistry
|
||||
import androidx.test.uiautomator.By
|
||||
import androidx.test.uiautomator.UiDevice
|
||||
import androidx.test.uiautomator.Until
|
||||
import org.hamcrest.CoreMatchers
|
||||
import org.mozilla.fenix.R
|
||||
import org.mozilla.fenix.helpers.TestAssetHelper
|
||||
import org.mozilla.fenix.helpers.click
|
||||
import org.mozilla.fenix.helpers.ext.waitNotNull
|
||||
|
||||
/**
|
||||
* Implementation of Robot Pattern for download UI handling.
|
||||
*/
|
||||
|
||||
class DownloadRobot {
|
||||
|
||||
fun verifyDownloadPrompt() = assertDownloadPrompt()
|
||||
|
||||
fun verifyDownloadNotificationPopup() = assertDownloadNotificationPopup()
|
||||
|
||||
fun verifyDownloadNotificationShade() = assertDownloadNotificationShade()
|
||||
|
||||
class Transition {
|
||||
|
||||
fun clickDownload(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition {
|
||||
clickDownloadButton().click()
|
||||
|
||||
DownloadRobot().interact()
|
||||
return DownloadRobot.Transition()
|
||||
}
|
||||
|
||||
fun closePrompt(interact: BrowserRobot.() -> Unit): BrowserRobot.Transition {
|
||||
closePromptButton().click()
|
||||
|
||||
BrowserRobot().interact()
|
||||
return BrowserRobot.Transition()
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
fun downloadRobot(interact: DownloadRobot.() -> Unit): DownloadRobot.Transition {
|
||||
DownloadRobot().interact()
|
||||
return DownloadRobot.Transition()
|
||||
}
|
||||
|
||||
private fun assertDownloadPrompt() {
|
||||
mDevice.waitNotNull(Until.findObjects(By.res("org.mozilla.fenix.debug:id/download_button")))
|
||||
}
|
||||
|
||||
private fun assertDownloadNotificationShade() {
|
||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mDevice.openNotification()
|
||||
mDevice.waitNotNull(
|
||||
Until.findObjects(By.text("Download completed")), TestAssetHelper.waitingTime
|
||||
)
|
||||
|
||||
// Go home (no UIDevice closeNotification) to close notification shade
|
||||
mDevice.pressHome()
|
||||
}
|
||||
|
||||
private fun assertDownloadNotificationPopup() {
|
||||
val mDevice = UiDevice.getInstance(InstrumentationRegistry.getInstrumentation())
|
||||
mDevice.waitNotNull(Until.findObjects(By.text("Open")), TestAssetHelper.waitingTime)
|
||||
onView(withId(R.id.download_notification_title))
|
||||
.check(matches(withText(CoreMatchers.containsString("Download completed"))))
|
||||
}
|
||||
|
||||
private fun closePromptButton() =
|
||||
onView(withId(R.id.close_button)).inRoot(isDialog()).check(matches(isDisplayed()))
|
||||
|
||||
private fun clickDownloadButton() =
|
||||
onView(withText("Download")).inRoot(isDialog()).check(matches(isDisplayed()))
|
Loading…
Reference in New Issue