OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser.download; |
| 6 |
| 7 import android.test.FlakyTest; |
| 8 import android.test.suitebuilder.annotation.MediumTest; |
| 9 import android.view.View; |
| 10 |
| 11 import org.chromium.base.test.util.Feature; |
| 12 import org.chromium.chrome.R; |
| 13 import org.chromium.chrome.browser.infobar.InfoBar; |
| 14 import org.chromium.chrome.test.util.InfoBarUtil; |
| 15 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 16 import org.chromium.content.browser.test.util.Criteria; |
| 17 import org.chromium.content.browser.test.util.CriteriaHelper; |
| 18 import org.chromium.content.browser.test.util.TouchCommon; |
| 19 |
| 20 /** |
| 21 * Tests Chrome download feature by attempting to download some files. |
| 22 */ |
| 23 public class DownloadTest extends DownloadTestBase { |
| 24 private static final String SUPERBO_CONTENTS = |
| 25 "plain text response from a POST"; |
| 26 |
| 27 @Override |
| 28 public void startMainActivity() throws InterruptedException { |
| 29 startMainActivityOnBlankPage(); |
| 30 } |
| 31 |
| 32 /** |
| 33 * Bug http://crbug.com/253711 |
| 34 * |
| 35 * @MediumTest |
| 36 * @Feature({"Downloads"}) |
| 37 */ |
| 38 @FlakyTest |
| 39 public void testHttpGetDownload() throws Exception { |
| 40 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/g
et.html")); |
| 41 waitForFocus(); |
| 42 View currentView = getActivity().getActivityTab().getView(); |
| 43 |
| 44 singleClickView(currentView); |
| 45 assertTrue(waitForGetDownloadToFinish()); |
| 46 checkLastDownload("test.gzip"); |
| 47 } |
| 48 |
| 49 /** |
| 50 * Bug http://crbug/286315 |
| 51 * |
| 52 * @MediumTest |
| 53 * @Feature({"Downloads"}) |
| 54 */ |
| 55 @FlakyTest |
| 56 public void testDangerousDownload() throws Exception { |
| 57 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/d
angerous.html")); |
| 58 waitForFocus(); |
| 59 View currentView = getActivity().getActivityTab().getView(); |
| 60 singleClickView(currentView); |
| 61 assertPollForInfoBarSize(1); |
| 62 assertTrue("OK button wasn't found", InfoBarUtil.clickPrimaryButton(getI
nfoBars().get(0))); |
| 63 assertTrue(waitForGetDownloadToFinish()); |
| 64 checkLastDownload("test.apk"); |
| 65 } |
| 66 |
| 67 /** |
| 68 * Bug http://crbug/253711 |
| 69 * |
| 70 * @MediumTest |
| 71 * @Feature({"Downloads"}) |
| 72 */ |
| 73 @FlakyTest |
| 74 public void testHttpPostDownload() throws Exception { |
| 75 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 76 waitForFocus(); |
| 77 View currentView = getActivity().getActivityTab().getView(); |
| 78 |
| 79 singleClickView(currentView); |
| 80 assertTrue(waitForChromeDownloadToFinish()); |
| 81 assertTrue(hasDownload("superbo.txt", SUPERBO_CONTENTS)); |
| 82 } |
| 83 |
| 84 /** |
| 85 * Bug 5431234 |
| 86 * |
| 87 * @MediumTest |
| 88 * @Feature({"Downloads"}) |
| 89 */ |
| 90 @FlakyTest |
| 91 public void testCloseEmptyDownloadTab() throws Exception { |
| 92 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/g
et.html")); |
| 93 waitForFocus(); |
| 94 int initialTabCount = getActivity().getCurrentTabModel().getCount(); |
| 95 View currentView = getActivity().getActivityTab().getView(); |
| 96 TouchCommon.longPressView(currentView, currentView.getWidth() / 2, |
| 97 currentView.getHeight() / 2); |
| 98 |
| 99 getInstrumentation().invokeContextMenuAction(getActivity(), |
| 100 R.id.contextmenu_open_in_new_tab, 0); |
| 101 assertTrue(waitForGetDownloadToFinish()); |
| 102 checkLastDownload("test.gzip"); |
| 103 |
| 104 assertEquals("Did not close new blank tab for download", initialTabCount
, |
| 105 getActivity().getCurrentTabModel().getCount()); |
| 106 } |
| 107 |
| 108 /* |
| 109 Bug http://crbug/415711 |
| 110 */ |
| 111 @MediumTest |
| 112 @Feature({"Downloads"}) |
| 113 public void testDuplicateHttpPostDownload_Overwrite() throws Exception { |
| 114 // Download a file. |
| 115 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 116 waitForFocus(); |
| 117 View currentView = getActivity().getActivityTab().getView(); |
| 118 singleClickView(currentView); |
| 119 assertTrue("Failed to finish downloading file for the first time.", |
| 120 waitForChromeDownloadToFinish()); |
| 121 |
| 122 // Download a file with the same name. |
| 123 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 124 waitForFocus(); |
| 125 currentView = getActivity().getActivityTab().getView(); |
| 126 singleClickView(currentView); |
| 127 assertPollForInfoBarSize(1); |
| 128 assertTrue("OVERWRITE button wasn't found", |
| 129 InfoBarUtil.clickPrimaryButton(getInfoBars().get(0))); |
| 130 assertTrue("Failed to finish downloading file for the second time.", |
| 131 waitForChromeDownloadToFinish()); |
| 132 |
| 133 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_
CONTENTS)); |
| 134 assertFalse("Should not have second download", |
| 135 hasDownload("superbo (1).txt", SUPERBO_CONTENTS)); |
| 136 } |
| 137 |
| 138 /** |
| 139 * Bug http://crbug/253711 |
| 140 * Bug http://crbug/415711 |
| 141 * |
| 142 * @MediumTest |
| 143 * @Feature({"Downloads"}) |
| 144 */ |
| 145 @FlakyTest |
| 146 public void testDuplicateHttpPostDownload_CreateNew() throws Exception { |
| 147 // Download a file. |
| 148 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 149 waitForFocus(); |
| 150 View currentView = getActivity().getActivityTab().getView(); |
| 151 singleClickView(currentView); |
| 152 assertTrue("Failed to finish downloading file for the first time.", |
| 153 waitForChromeDownloadToFinish()); |
| 154 |
| 155 // Download a file with the same name. |
| 156 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 157 waitForFocus(); |
| 158 currentView = getActivity().getActivityTab().getView(); |
| 159 singleClickView(currentView); |
| 160 assertPollForInfoBarSize(1); |
| 161 assertTrue("CREATE NEW button wasn't found", |
| 162 InfoBarUtil.clickSecondaryButton(getInfoBars().get(0))); |
| 163 assertTrue("Failed to finish downloading file for the second time.", |
| 164 waitForChromeDownloadToFinish()); |
| 165 |
| 166 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_
CONTENTS)); |
| 167 assertTrue("Missing second download", |
| 168 hasDownload("superbo (1).txt", SUPERBO_CONTENTS)); |
| 169 } |
| 170 |
| 171 /* |
| 172 Bug http://crbug/415711 |
| 173 */ |
| 174 @MediumTest |
| 175 @Feature({"Downloads"}) |
| 176 public void testDuplicateHttpPostDownload_Dismiss() throws Exception { |
| 177 // Download a file. |
| 178 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 179 waitForFocus(); |
| 180 View currentView = getActivity().getActivityTab().getView(); |
| 181 singleClickView(currentView); |
| 182 assertTrue("Failed to finish downloading file for the first time.", |
| 183 waitForChromeDownloadToFinish()); |
| 184 |
| 185 // Download a file with the same name. |
| 186 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 187 waitForFocus(); |
| 188 currentView = getActivity().getActivityTab().getView(); |
| 189 singleClickView(currentView); |
| 190 assertPollForInfoBarSize(1); |
| 191 assertTrue("Close button wasn't found", |
| 192 InfoBarUtil.clickCloseButton(getInfoBars().get(0))); |
| 193 assertFalse( |
| 194 "Download should not happen when closing infobar", waitForChrome
DownloadToFinish()); |
| 195 |
| 196 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_
CONTENTS)); |
| 197 assertFalse("Should not have second download", |
| 198 hasDownload("superbo (1).txt", SUPERBO_CONTENTS)); |
| 199 } |
| 200 |
| 201 /* |
| 202 Bug http://crbug/415711 |
| 203 */ |
| 204 @MediumTest |
| 205 @Feature({"Downloads"}) |
| 206 public void testDuplicateHttpPostDownload_AllowMultipleInfoBars() throws Exc
eption { |
| 207 assertFalse(hasDownload("superbo.txt", SUPERBO_CONTENTS)); |
| 208 // Download a file. |
| 209 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 210 waitForFocus(); |
| 211 View currentView = getActivity().getActivityTab().getView(); |
| 212 singleClickView(currentView); |
| 213 assertTrue("Failed to finish downloading file for the first time.", |
| 214 waitForChromeDownloadToFinish()); |
| 215 |
| 216 // Download the file for the second time. |
| 217 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 218 waitForFocus(); |
| 219 currentView = getActivity().getActivityTab().getView(); |
| 220 singleClickView(currentView); |
| 221 assertPollForInfoBarSize(1); |
| 222 |
| 223 // Download the file for the third time. |
| 224 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/p
ost.html")); |
| 225 waitForFocus(); |
| 226 currentView = getActivity().getActivityTab().getView(); |
| 227 singleClickView(currentView); |
| 228 assertPollForInfoBarSize(2); |
| 229 |
| 230 // Now create two new files by clicking on the infobars. |
| 231 assertTrue("CREATE NEW button wasn't found", |
| 232 InfoBarUtil.clickSecondaryButton(getInfoBars().get(0))); |
| 233 assertTrue( |
| 234 "Failed to finish downloading the second file.", waitForChromeDo
wnloadToFinish()); |
| 235 assertPollForInfoBarSize(1); |
| 236 assertTrue("CREATE NEW button wasn't found", |
| 237 InfoBarUtil.clickSecondaryButton(getInfoBars().get(0))); |
| 238 assertTrue("Failed to finish downloading the third file.", waitForChrome
DownloadToFinish()); |
| 239 |
| 240 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_
CONTENTS)); |
| 241 assertTrue("Missing second download", hasDownload("superbo (1).txt", SUP
ERBO_CONTENTS)); |
| 242 assertTrue("Missing third download", hasDownload("superbo (2).txt", SUPE
RBO_CONTENTS)); |
| 243 } |
| 244 |
| 245 /* |
| 246 @MediumTest |
| 247 @Feature({"Downloads"}) |
| 248 Bug http://crbug/253711 |
| 249 */ |
| 250 @FlakyTest |
| 251 public void testUrlEscaping() throws Exception { |
| 252 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/u
rlescaping.html")); |
| 253 waitForFocus(); |
| 254 View currentView = getActivity().getActivityTab().getView(); |
| 255 |
| 256 singleClickView(currentView); |
| 257 assertTrue(waitForGetDownloadToFinish()); |
| 258 checkLastDownload("[large]wallpaper.dm"); |
| 259 } |
| 260 |
| 261 private void waitForFocus() { |
| 262 View currentView = getActivity().getActivityTab().getView(); |
| 263 if (!currentView.hasFocus()) { |
| 264 singleClickView(currentView); |
| 265 } |
| 266 getInstrumentation().waitForIdleSync(); |
| 267 } |
| 268 |
| 269 /** |
| 270 * Wait until info bar size becomes the given size and the last info bar bec
omes ready if there |
| 271 * is one more more. |
| 272 * @param size The size of info bars to poll for. |
| 273 */ |
| 274 private void assertPollForInfoBarSize(final int size) throws InterruptedExce
ption { |
| 275 assertTrue("There should be " + size + " infobar but there are " |
| 276 + getInfoBars().size() + " infobars.", |
| 277 CriteriaHelper.pollForUIThreadCriteria(new Criteria() { |
| 278 @Override |
| 279 public boolean isSatisfied() { |
| 280 if (getInfoBars().size() != size) return false; |
| 281 if (size == 0) return true; |
| 282 InfoBar infoBar = getInfoBars().get(size - 1); |
| 283 return infoBar.areControlsEnabled(); |
| 284 } |
| 285 })); |
| 286 } |
| 287 } |
OLD | NEW |