diff --git a/mobile/android/focus-android/app/src/androidTest/assets/genericPage.html b/mobile/android/focus-android/app/src/androidTest/assets/genericPage.html index 0ab2034c3f15..eee4009f6f94 100644 --- a/mobile/android/focus-android/app/src/androidTest/assets/genericPage.html +++ b/mobile/android/focus-android/app/src/androidTest/assets/genericPage.html @@ -9,6 +9,8 @@

focus test page

groovy rabbits

-

This test page does nothing.

+

+ PDF file +

diff --git a/mobile/android/focus-android/app/src/androidTest/assets/resources/pdfFile.pdf b/mobile/android/focus-android/app/src/androidTest/assets/resources/pdfFile.pdf new file mode 100644 index 000000000000..8b40fe527f6f Binary files /dev/null and b/mobile/android/focus-android/app/src/androidTest/assets/resources/pdfFile.pdf differ diff --git a/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/DownloadFileTest.kt b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/DownloadFileTest.kt index 0d3d52abac76..ea74c4a87fb3 100644 --- a/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/DownloadFileTest.kt +++ b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/DownloadFileTest.kt @@ -138,21 +138,6 @@ class DownloadFileTest { } } - @SmokeTest - @Test - fun openPdfFileTest() { - downloadFileName = "washington.pdf" - val pdfFileURL = "https://storage.googleapis.com/mobile_test_assets/public/washington.pdf" - val pdfFileContent = "Washington Crossing the Delaware" - searchScreen { - }.loadPage(downloadTestPage) { - progressBar.waitUntilGone(waitingTime) - clickLinkMatchingText(downloadFileName) - verifyPageURL(pdfFileURL) - verifyPageContent(pdfFileContent) - } - } - @SmokeTest @Test fun downloadAndOpenWebmFileTest() { diff --git a/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/PDFViewerTest.kt b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/PDFViewerTest.kt new file mode 100644 index 000000000000..108217b1c6d6 --- /dev/null +++ b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/activity/PDFViewerTest.kt @@ -0,0 +1,76 @@ +package org.mozilla.focus.activity + +import okhttp3.mockwebserver.MockWebServer +import org.junit.After +import org.junit.Before +import org.junit.Rule +import org.junit.Test +import org.mozilla.focus.activity.robots.searchScreen +import org.mozilla.focus.helpers.DeleteFilesHelper.deleteFileUsingDisplayName +import org.mozilla.focus.helpers.FeatureSettingsHelper +import org.mozilla.focus.helpers.MainActivityIntentsTestRule +import org.mozilla.focus.helpers.MockWebServerHelper +import org.mozilla.focus.helpers.TestAssetHelper.getGenericAsset +import org.mozilla.focus.helpers.TestAssetHelper.getPDFTestAsset +import org.mozilla.focus.helpers.TestHelper.getTargetContext +import org.mozilla.focus.helpers.TestHelper.permAllowBtn +import org.mozilla.focus.helpers.TestHelper.verifyDownloadedFileOnStorage +import org.mozilla.focus.helpers.TestHelper.waitingTime +import org.mozilla.focus.testAnnotations.SmokeTest + +class PDFViewerTest { + private lateinit var webServer: MockWebServer + private val featureSettingsHelper = FeatureSettingsHelper() + private val pdfLink = "PDF file" + + @get: Rule + var mActivityTestRule = MainActivityIntentsTestRule(showFirstRun = false) + + @Before + fun setUp() { + featureSettingsHelper.setCfrForTrackingProtectionEnabled(false) + webServer = MockWebServer().apply { + dispatcher = MockWebServerHelper.AndroidAssetDispatcher() + start() + } + } + + @After + fun tearDown() { + webServer.shutdown() + featureSettingsHelper.resetAllFeatureFlags() + deleteFileUsingDisplayName(getTargetContext.applicationContext, "pdfFile.pdf") + } + + @SmokeTest + @Test + fun openPdfFileTest() { + val genericPageUrl = getGenericAsset(webServer).url + val pdfDoc = getPDFTestAsset(webServer) + + searchScreen { + }.loadPage(genericPageUrl) { + progressBar.waitUntilGone(waitingTime) + clickLinkMatchingText(pdfLink) + verifyPageURL(pdfDoc.url) + verifyPageContent(pdfDoc.content) + } + } + + @SmokeTest + @Test + fun downloadPdfTest() { + val pdfDoc = getPDFTestAsset(webServer) + + searchScreen { + }.loadPage(pdfDoc.url) { + verifyPageContent(pdfDoc.content) + clickButtonWithText("Download") + // If permission dialog appears, grant it + if (permAllowBtn.waitForExists(waitingTime)) { + permAllowBtn.click() + } + verifyDownloadedFileOnStorage(pdfDoc.title) + } + } +} diff --git a/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/helpers/TestAssetHelper.kt b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/helpers/TestAssetHelper.kt index 27247458ca9d..8e1ac0142ad9 100644 --- a/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/helpers/TestAssetHelper.kt +++ b/mobile/android/focus-android/app/src/androidTest/java/org/mozilla/focus/helpers/TestAssetHelper.kt @@ -68,4 +68,10 @@ object TestAssetHelper { return TestAsset(url, "", pageTitle) } + + fun getPDFTestAsset(server: MockWebServer): TestAsset { + val url = server.url("/resources/pdfFile.pdf").toString() + + return TestAsset(url, "Page 1", "pdfFile.pdf") + } }