OLD | NEW |
1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 package org.chromium.chrome.browser.download; | 5 package org.chromium.chrome.browser.download; |
6 | 6 |
7 import android.os.Environment; | 7 import android.os.Environment; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.view.View; | 9 import android.view.View; |
10 | 10 |
(...skipping 27 matching lines...) Expand all Loading... |
38 "plain text response from a POST"; | 38 "plain text response from a POST"; |
39 | 39 |
40 private EmbeddedTestServer mTestServer; | 40 private EmbeddedTestServer mTestServer; |
41 | 41 |
42 private static final String TEST_DOWNLOAD_DIRECTORY = "/chrome/test/data/and
roid/download/"; | 42 private static final String TEST_DOWNLOAD_DIRECTORY = "/chrome/test/data/and
roid/download/"; |
43 | 43 |
44 private static final String FILENAME_WALLPAPER = "[large]wallpaper.dm"; | 44 private static final String FILENAME_WALLPAPER = "[large]wallpaper.dm"; |
45 private static final String FILENAME_TEXT = "superbo.txt"; | 45 private static final String FILENAME_TEXT = "superbo.txt"; |
46 private static final String FILENAME_TEXT_1 = "superbo (1).txt"; | 46 private static final String FILENAME_TEXT_1 = "superbo (1).txt"; |
47 private static final String FILENAME_TEXT_2 = "superbo (2).txt"; | 47 private static final String FILENAME_TEXT_2 = "superbo (2).txt"; |
48 private static final String FILENAME_APK = "test.apk"; | 48 private static final String FILENAME_SWF = "test.swf"; |
49 private static final String FILENAME_GZIP = "test.gzip"; | 49 private static final String FILENAME_GZIP = "test.gzip"; |
50 | 50 |
51 private static final String[] TEST_FILES = new String[] { | 51 private static final String[] TEST_FILES = new String[] { |
52 FILENAME_WALLPAPER, FILENAME_TEXT, FILENAME_TEXT_1, FILENAME_TEXT_2, FIL
ENAME_APK, | 52 FILENAME_WALLPAPER, FILENAME_TEXT, FILENAME_TEXT_1, FILENAME_TEXT_2, FIL
ENAME_SWF, |
53 FILENAME_GZIP | 53 FILENAME_GZIP |
54 }; | 54 }; |
55 | 55 |
56 @Override | 56 @Override |
57 protected void setUp() throws Exception { | 57 protected void setUp() throws Exception { |
58 super.setUp(); | 58 super.setUp(); |
59 deleteTestFiles(); | 59 deleteTestFiles(); |
60 mTestServer = EmbeddedTestServer.createAndStartFileServer( | 60 mTestServer = EmbeddedTestServer.createAndStartFileServer( |
61 getInstrumentation().getContext(), Environment.getExternalStorag
eDirectory()); | 61 getInstrumentation().getContext(), Environment.getExternalStorag
eDirectory()); |
62 } | 62 } |
(...skipping 11 matching lines...) Expand all Loading... |
74 } | 74 } |
75 | 75 |
76 @MediumTest | 76 @MediumTest |
77 @Feature({"Downloads"}) | 77 @Feature({"Downloads"}) |
78 @RetryOnFailure | 78 @RetryOnFailure |
79 public void testHttpGetDownload() throws Exception { | 79 public void testHttpGetDownload() throws Exception { |
80 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html")); | 80 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html")); |
81 waitForFocus(); | 81 waitForFocus(); |
82 View currentView = getActivity().getActivityTab().getView(); | 82 View currentView = getActivity().getActivityTab().getView(); |
83 | 83 |
84 EnqueueHttpGetDownloadCallbackHelper callbackHelper = getHttpGetDownload
CallbackHelper(); | 84 int callCount = getChromeDownloadCallCount(); |
85 int callCount = callbackHelper.getCallCount(); | |
86 singleClickView(currentView); | 85 singleClickView(currentView); |
87 callbackHelper.waitForCallback(callCount); | 86 assertTrue(waitForChromeDownloadToFinish(callCount)); |
88 | 87 assertTrue(hasDownload(FILENAME_GZIP, null)); |
89 assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_GZIP)
, | |
90 callbackHelper.getDownloadInfo().getUrl()); | |
91 } | 88 } |
92 | 89 |
93 @MediumTest | 90 @MediumTest |
94 @Feature({"Downloads"}) | 91 @Feature({"Downloads"}) |
95 @RetryOnFailure | 92 @RetryOnFailure |
96 public void testDangerousDownload() throws Exception { | 93 public void testDangerousDownload() throws Exception { |
97 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html")); | 94 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html")); |
98 waitForFocus(); | 95 waitForFocus(); |
99 View currentView = getActivity().getActivityTab().getView(); | 96 View currentView = getActivity().getActivityTab().getView(); |
100 singleClickView(currentView); | 97 singleClickView(currentView); |
101 assertPollForInfoBarSize(1); | 98 assertPollForInfoBarSize(1); |
102 | |
103 EnqueueHttpGetDownloadCallbackHelper callbackHelper = getHttpGetDownload
CallbackHelper(); | |
104 int callCount = callbackHelper.getCallCount(); | |
105 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getI
nfoBars().get(0))); | 99 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getI
nfoBars().get(0))); |
106 callbackHelper.waitForCallback(callCount); | 100 int callCount = getChromeDownloadCallCount(); |
107 assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_APK), | 101 assertTrue(waitForChromeDownloadToFinish(callCount)); |
108 callbackHelper.getDownloadInfo().getUrl()); | 102 assertTrue(hasDownload(FILENAME_SWF, null)); |
109 } | 103 } |
110 | 104 |
111 @MediumTest | 105 @MediumTest |
112 @Feature({"Downloads"}) | 106 @Feature({"Downloads"}) |
113 @RetryOnFailure | 107 @RetryOnFailure |
114 public void testDangerousDownloadCancel() throws Exception { | 108 public void testDangerousDownloadCancel() throws Exception { |
115 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html")); | 109 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "dangerous.html")); |
116 waitForFocus(); | 110 waitForFocus(); |
117 View currentView = getActivity().getActivityTab().getView(); | 111 View currentView = getActivity().getActivityTab().getView(); |
118 TouchCommon.longPressView(currentView); | 112 TouchCommon.longPressView(currentView); |
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
155 @MediumTest | 149 @MediumTest |
156 @Feature({"Downloads"}) | 150 @Feature({"Downloads"}) |
157 @DisabledTest(message = "crbug.com/286315") | 151 @DisabledTest(message = "crbug.com/286315") |
158 public void testCloseEmptyDownloadTab() throws Exception { | 152 public void testCloseEmptyDownloadTab() throws Exception { |
159 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html")); | 153 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "get.html")); |
160 waitForFocus(); | 154 waitForFocus(); |
161 final int initialTabCount = getActivity().getCurrentTabModel().getCount(
); | 155 final int initialTabCount = getActivity().getCurrentTabModel().getCount(
); |
162 View currentView = getActivity().getActivityTab().getView(); | 156 View currentView = getActivity().getActivityTab().getView(); |
163 TouchCommon.longPressView(currentView); | 157 TouchCommon.longPressView(currentView); |
164 | 158 |
165 EnqueueHttpGetDownloadCallbackHelper callbackHelper = getHttpGetDownload
CallbackHelper(); | 159 int callCount = getChromeDownloadCallCount(); |
166 int callCount = callbackHelper.getCallCount(); | |
167 getInstrumentation().invokeContextMenuAction(getActivity(), | 160 getInstrumentation().invokeContextMenuAction(getActivity(), |
168 R.id.contextmenu_open_in_new_tab, 0); | 161 R.id.contextmenu_open_in_new_tab, 0); |
169 callbackHelper.waitForCallback(callCount); | 162 assertTrue(waitForChromeDownloadToFinish(callCount)); |
170 assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_GZIP)
, | 163 assertTrue(hasDownload(FILENAME_GZIP, null)); |
171 callbackHelper.getDownloadInfo().getUrl()); | |
172 | 164 |
173 CriteriaHelper.pollUiThread( | 165 CriteriaHelper.pollUiThread( |
174 Criteria.equals(initialTabCount, new Callable<Integer>() { | 166 Criteria.equals(initialTabCount, new Callable<Integer>() { |
175 @Override | 167 @Override |
176 public Integer call() { | 168 public Integer call() { |
177 return getActivity().getCurrentTabModel().getCount(); | 169 return getActivity().getCurrentTabModel().getCount(); |
178 } | 170 } |
179 })); | 171 })); |
180 } | 172 } |
181 | 173 |
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
406 } | 398 } |
407 | 399 |
408 @MediumTest | 400 @MediumTest |
409 @Feature({"Downloads"}) | 401 @Feature({"Downloads"}) |
410 @RetryOnFailure | 402 @RetryOnFailure |
411 public void testUrlEscaping() throws Exception { | 403 public void testUrlEscaping() throws Exception { |
412 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "urlescaping.html")
); | 404 loadUrl(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + "urlescaping.html")
); |
413 waitForFocus(); | 405 waitForFocus(); |
414 View currentView = getActivity().getActivityTab().getView(); | 406 View currentView = getActivity().getActivityTab().getView(); |
415 | 407 |
416 EnqueueHttpGetDownloadCallbackHelper callbackHelper = getHttpGetDownload
CallbackHelper(); | 408 int callCount = getChromeDownloadCallCount(); |
417 int callCount = callbackHelper.getCallCount(); | |
418 singleClickView(currentView); | 409 singleClickView(currentView); |
419 callbackHelper.waitForCallback(callCount); | 410 assertTrue(waitForChromeDownloadToFinish(callCount)); |
420 assertEquals(mTestServer.getURL(TEST_DOWNLOAD_DIRECTORY + FILENAME_WALLP
APER), | 411 assertTrue(hasDownload(FILENAME_WALLPAPER, null)); |
421 callbackHelper.getDownloadInfo().getUrl()); | |
422 } | 412 } |
423 | 413 |
424 private void waitForFocus() { | 414 private void waitForFocus() { |
425 View currentView = getActivity().getActivityTab().getView(); | 415 View currentView = getActivity().getActivityTab().getView(); |
426 if (!currentView.hasFocus()) { | 416 if (!currentView.hasFocus()) { |
427 singleClickView(currentView); | 417 singleClickView(currentView); |
428 } | 418 } |
429 getInstrumentation().waitForIdleSync(); | 419 getInstrumentation().waitForIdleSync(); |
430 } | 420 } |
431 | 421 |
(...skipping 15 matching lines...) Expand all Loading... |
447 } | 437 } |
448 | 438 |
449 /** | 439 /** |
450 * Makes sure there are no files with names identical to the ones this test
uses in the | 440 * Makes sure there are no files with names identical to the ones this test
uses in the |
451 * downloads directory | 441 * downloads directory |
452 */ | 442 */ |
453 private void deleteTestFiles() { | 443 private void deleteTestFiles() { |
454 deleteFilesInDownloadDirectory(TEST_FILES); | 444 deleteFilesInDownloadDirectory(TEST_FILES); |
455 } | 445 } |
456 } | 446 } |
OLD | NEW |