| Index: chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java
|
| index e019908d66cc59b30ca6db3f0490214d4c2320cc..869fbf4012641203f92d1a9f3c723190ebe996f7 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java
|
| @@ -38,9 +38,24 @@ public class DownloadTest extends DownloadTestBase {
|
|
|
| private EmbeddedTestServer mTestServer;
|
|
|
| + private static final String TEST_DOWNLOAD_DIRECTORY = "/chrome/test/data/android/download/";
|
| +
|
| + private static final String FILENAME_WALLPAPER = "[large]wallpaper.dm";
|
| + private static final String FILENAME_TEXT = "superbo.txt";
|
| + private static final String FILENAME_TEXT_1 = "superbo (1).txt";
|
| + private static final String FILENAME_TEXT_2 = "superbo (2).txt";
|
| + private static final String FILENAME_APK = "test.apk";
|
| + private static final String FILENAME_GZIP = "test.gzip";
|
| +
|
| + private static final String[] TEST_FILES = new String[] {
|
| + FILENAME_WALLPAPER, FILENAME_TEXT, FILENAME_TEXT_1, FILENAME_TEXT_2, FILENAME_APK,
|
| + FILENAME_GZIP
|
| + };
|
| +
|
| @Override
|
| protected void setUp() throws Exception {
|
| super.setUp();
|
| + deleteTestFiles();
|
| mTestServer = EmbeddedTestServer.createAndStartFileServer(
|
| getInstrumentation().getContext(), Environment.getExternalStorageDirectory());
|
| }
|
| @@ -48,6 +63,7 @@ public class DownloadTest extends DownloadTestBase {
|
| @Override
|
| protected void tearDown() throws Exception {
|
| mTestServer.stopAndDestroyServer();
|
| + deleteTestFiles();
|
| super.tearDown();
|
| }
|
|
|
| @@ -59,7 +75,7 @@ public class DownloadTest extends DownloadTestBase {
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| public void testHttpGetDownload() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/get.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
|
|
| @@ -68,14 +84,14 @@ public class DownloadTest extends DownloadTestBase {
|
| singleClickView(currentView);
|
| callbackHelper.waitForCallback(callCount);
|
|
|
| - assertEquals(mTestServer.getURL("/chrome/test/data/android/download/test.gzip"),
|
| + assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_GZIP),
|
| callbackHelper.getDownloadInfo().getUrl());
|
| }
|
|
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| public void testDangerousDownload() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/dangerous.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| singleClickView(currentView);
|
| @@ -85,14 +101,14 @@ public class DownloadTest extends DownloadTestBase {
|
| int callCount = callbackHelper.getCallCount();
|
| assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getInfoBars().get(0)));
|
| callbackHelper.waitForCallback(callCount);
|
| - assertEquals(mTestServer.getURL("/chrome/test/data/android/download/test.apk"),
|
| + assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_APK),
|
| callbackHelper.getDownloadInfo().getUrl());
|
| }
|
|
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| public void testDangerousDownloadCancel() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/dangerous.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| TouchCommon.longPressView(currentView);
|
| @@ -121,21 +137,21 @@ public class DownloadTest extends DownloadTestBase {
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| public void testHttpPostDownload() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
|
|
| int callCount = getChromeDownloadCallCount();
|
| singleClickView(currentView);
|
| assertTrue(waitForChromeDownloadToFinish(callCount));
|
| - assertTrue(hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| + assertTrue(hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| }
|
|
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| @DisabledTest(message = "crbug.com/286315")
|
| public void testCloseEmptyDownloadTab() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/get.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html"));
|
| waitForFocus();
|
| final int initialTabCount = getActivity().getCurrentTabModel().getCount();
|
| View currentView = getActivity().getActivityTab().getView();
|
| @@ -146,7 +162,7 @@ public class DownloadTest extends DownloadTestBase {
|
| getInstrumentation().invokeContextMenuAction(getActivity(),
|
| R.id.contextmenu_open_in_new_tab, 0);
|
| callbackHelper.waitForCallback(callCount);
|
| - assertEquals(mTestServer.getURL("/chrome/test/data/android/download/test.gzip"),
|
| + assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_GZIP),
|
| callbackHelper.getDownloadInfo().getUrl());
|
|
|
| CriteriaHelper.pollUiThread(
|
| @@ -164,7 +180,7 @@ public class DownloadTest extends DownloadTestBase {
|
| // Snackbar overlaps the infobar which is clicked in this test.
|
| getActivity().getSnackbarManager().disableForTesting();
|
| // Download a file.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| int callCount = getChromeDownloadCallCount();
|
| @@ -173,7 +189,7 @@ public class DownloadTest extends DownloadTestBase {
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| // Download a file with the same name.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| currentView = getActivity().getActivityTab().getView();
|
| callCount = getChromeDownloadCallCount();
|
| @@ -184,9 +200,9 @@ public class DownloadTest extends DownloadTestBase {
|
| assertTrue("Failed to finish downloading file for the second time.",
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| - assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| + assertTrue("Missing first download", hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| assertFalse("Should not have second download",
|
| - hasDownload("superbo (1).txt", SUPERBO_CONTENTS));
|
| + hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
|
| }
|
|
|
| @MediumTest
|
| @@ -194,7 +210,7 @@ public class DownloadTest extends DownloadTestBase {
|
| @DisabledTest(message = "crbug.com/597230")
|
| public void testDuplicateHttpPostDownload_CreateNew() throws Exception {
|
| // Download a file.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| int callCount = getChromeDownloadCallCount();
|
| @@ -203,7 +219,7 @@ public class DownloadTest extends DownloadTestBase {
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| // Download a file with the same name.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| currentView = getActivity().getActivityTab().getView();
|
| callCount = getChromeDownloadCallCount();
|
| @@ -214,9 +230,9 @@ public class DownloadTest extends DownloadTestBase {
|
| assertTrue("Failed to finish downloading file for the second time.",
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| - assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| + assertTrue("Missing first download", hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| assertTrue("Missing second download",
|
| - hasDownload("superbo (1).txt", SUPERBO_CONTENTS));
|
| + hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
|
| }
|
|
|
| @MediumTest
|
| @@ -224,7 +240,7 @@ public class DownloadTest extends DownloadTestBase {
|
| @FlakyTest(message = "crbug.com/415711")
|
| public void testDuplicateHttpPostDownload_Dismiss() throws Exception {
|
| // Download a file.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| int callCount = getChromeDownloadCallCount();
|
| @@ -233,7 +249,7 @@ public class DownloadTest extends DownloadTestBase {
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| // Download a file with the same name.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| currentView = getActivity().getActivityTab().getView();
|
| callCount = getChromeDownloadCallCount();
|
| @@ -244,18 +260,18 @@ public class DownloadTest extends DownloadTestBase {
|
| assertFalse("Download should not happen when closing infobar",
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| - assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| + assertTrue("Missing first download", hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| assertFalse("Should not have second download",
|
| - hasDownload("superbo (1).txt", SUPERBO_CONTENTS));
|
| + hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
|
| }
|
|
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| @DisabledTest(message = "crbug.com/597230")
|
| public void testDuplicateHttpPostDownload_AllowMultipleInfoBars() throws Exception {
|
| - assertFalse(hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| + assertFalse(hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| // Download a file.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
| int callCount = getChromeDownloadCallCount();
|
| @@ -264,14 +280,14 @@ public class DownloadTest extends DownloadTestBase {
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| // Download the file for the second time.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| currentView = getActivity().getActivityTab().getView();
|
| singleClickView(currentView);
|
| assertPollForInfoBarSize(1);
|
|
|
| // Download the file for the third time.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/post.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "post.html"));
|
| waitForFocus();
|
| currentView = getActivity().getActivityTab().getView();
|
| singleClickView(currentView);
|
| @@ -290,9 +306,9 @@ public class DownloadTest extends DownloadTestBase {
|
| assertTrue("Failed to finish downloading the third file.",
|
| waitForChromeDownloadToFinish(callCount));
|
|
|
| - assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_CONTENTS));
|
| - assertTrue("Missing second download", hasDownload("superbo (1).txt", SUPERBO_CONTENTS));
|
| - assertTrue("Missing third download", hasDownload("superbo (2).txt", SUPERBO_CONTENTS));
|
| + assertTrue("Missing first download", hasDownload(FILENAME_TEXT, SUPERBO_CONTENTS));
|
| + assertTrue("Missing second download", hasDownload(FILENAME_TEXT_1, SUPERBO_CONTENTS));
|
| + assertTrue("Missing third download", hasDownload(FILENAME_TEXT_2, SUPERBO_CONTENTS));
|
| }
|
|
|
| private void goToLastTab() throws Exception {
|
| @@ -349,12 +365,12 @@ public class DownloadTest extends DownloadTestBase {
|
| @Feature({"Downloads"})
|
| public void testDuplicateHttpPostDownload_OpenNewTabAndReplace() throws Exception {
|
| final String url =
|
| - mTestServer.getURL("/chrome/test/data/android/download/get.html");
|
| + mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html");
|
|
|
| // Create the file in advance so that duplicate download infobar can show up.
|
| File dir = Environment.getExternalStoragePublicDirectory(Environment.DIRECTORY_DOWNLOADS);
|
| assertTrue(dir.isDirectory());
|
| - final File file = new File(dir, "test.gzip");
|
| + final File file = new File(dir, FILENAME_GZIP);
|
| try {
|
| if (!file.exists()) {
|
| assertTrue(file.createNewFile());
|
| @@ -386,7 +402,7 @@ public class DownloadTest extends DownloadTestBase {
|
| @MediumTest
|
| @Feature({"Downloads"})
|
| public void testUrlEscaping() throws Exception {
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/download/urlescaping.html"));
|
| + loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "urlescaping.html"));
|
| waitForFocus();
|
| View currentView = getActivity().getActivityTab().getView();
|
|
|
| @@ -394,8 +410,7 @@ public class DownloadTest extends DownloadTestBase {
|
| int callCount = callbackHelper.getCallCount();
|
| singleClickView(currentView);
|
| callbackHelper.waitForCallback(callCount);
|
| - assertEquals(mTestServer.getURL(
|
| - "/chrome/test/data/android/download/[large]wallpaper.dm"),
|
| + assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_WALLPAPER),
|
| callbackHelper.getDownloadInfo().getUrl());
|
| }
|
|
|
| @@ -423,4 +438,12 @@ public class DownloadTest extends DownloadTestBase {
|
| }
|
| });
|
| }
|
| +
|
| + /**
|
| + * Makes sure there are no files with names identical to the ones this test uses in the
|
| + * downloads directory
|
| + */
|
| + private void deleteTestFiles() {
|
| + deleteFilesInDownloadDirectory(TEST_FILES);
|
| + }
|
| }
|
|
|