Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(728)

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/download/DownloadTest.java

Issue 1320323006: Add a test for downloading a file in a new tab multiple times (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: fix a failure when internet connection is off Created 5 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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.test.FlakyTest; 8 import android.test.FlakyTest;
8 import android.test.suitebuilder.annotation.MediumTest; 9 import android.test.suitebuilder.annotation.MediumTest;
9 import android.view.View; 10 import android.view.View;
10 11
12 import org.chromium.base.test.util.CommandLineFlags;
11 import org.chromium.base.test.util.Feature; 13 import org.chromium.base.test.util.Feature;
12 import org.chromium.chrome.R; 14 import org.chromium.chrome.R;
15 import org.chromium.chrome.browser.ChromeSwitches;
16 import org.chromium.chrome.browser.compositor.CompositorViewHolder;
17 import org.chromium.chrome.browser.compositor.layouts.LayoutManager;
18 import org.chromium.chrome.browser.compositor.layouts.StaticLayout;
13 import org.chromium.chrome.browser.infobar.InfoBar; 19 import org.chromium.chrome.browser.infobar.InfoBar;
20 import org.chromium.chrome.browser.tabmodel.TabModel;
21 import org.chromium.chrome.browser.tabmodel.TabModelUtils;
14 import org.chromium.chrome.test.util.InfoBarUtil; 22 import org.chromium.chrome.test.util.InfoBarUtil;
15 import org.chromium.chrome.test.util.TestHttpServerClient; 23 import org.chromium.chrome.test.util.TestHttpServerClient;
16 import org.chromium.content.browser.test.util.Criteria; 24 import org.chromium.content.browser.test.util.Criteria;
17 import org.chromium.content.browser.test.util.CriteriaHelper; 25 import org.chromium.content.browser.test.util.CriteriaHelper;
18 import org.chromium.content.browser.test.util.TouchCommon; 26 import org.chromium.content.browser.test.util.TouchCommon;
19 27
28 import java.io.File;
29
20 /** 30 /**
21 * Tests Chrome download feature by attempting to download some files. 31 * Tests Chrome download feature by attempting to download some files.
22 */ 32 */
23 public class DownloadTest extends DownloadTestBase { 33 public class DownloadTest extends DownloadTestBase {
24 private static final String SUPERBO_CONTENTS = 34 private static final String SUPERBO_CONTENTS =
25 "plain text response from a POST"; 35 "plain text response from a POST";
26 36
27 @Override 37 @Override
28 public void startMainActivity() throws InterruptedException { 38 public void startMainActivity() throws InterruptedException {
29 startMainActivityOnBlankPage(); 39 startMainActivityOnBlankPage();
(...skipping 205 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 assertPollForInfoBarSize(1); 245 assertPollForInfoBarSize(1);
236 assertTrue("CREATE NEW button wasn't found", 246 assertTrue("CREATE NEW button wasn't found",
237 InfoBarUtil.clickSecondaryButton(getInfoBars().get(0))); 247 InfoBarUtil.clickSecondaryButton(getInfoBars().get(0)));
238 assertTrue("Failed to finish downloading the third file.", waitForChrome DownloadToFinish()); 248 assertTrue("Failed to finish downloading the third file.", waitForChrome DownloadToFinish());
239 249
240 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_ CONTENTS)); 250 assertTrue("Missing first download", hasDownload("superbo.txt", SUPERBO_ CONTENTS));
241 assertTrue("Missing second download", hasDownload("superbo (1).txt", SUP ERBO_CONTENTS)); 251 assertTrue("Missing second download", hasDownload("superbo (1).txt", SUP ERBO_CONTENTS));
242 assertTrue("Missing third download", hasDownload("superbo (2).txt", SUPE RBO_CONTENTS)); 252 assertTrue("Missing third download", hasDownload("superbo (2).txt", SUPE RBO_CONTENTS));
243 } 253 }
244 254
255 private void goToLastTab() throws Exception {
256 final TabModel model = getActivity().getCurrentTabModel();
257 final int count = model.getCount();
258
259 getInstrumentation().runOnMainSync(new Runnable() {
260 @Override
261 public void run() {
262 TabModelUtils.setIndex(model, count - 1);
263 }
264 });
265
266 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
267 @Override
268 public boolean isSatisfied() {
269 return getActivity().getActivityTab() == model.getTabAt(count - 1)
270 && getActivity().getActivityTab().isReady();
271 }
272 }));
273 }
274
275 private void waitForNewTabToStabilize(final int numTabsAfterNewTab)
276 throws InterruptedException {
277 // Wait until we have a new tab first. This should be called before chec king the active
278 // layout because the active layout changes StaticLayout --> SimpleAnima tionLayout
279 // --> (tab added) --> StaticLayout.
280 assertTrue("Actual tab count: " + getActivity().getCurrentTabModel().get Count(),
281 CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
282 @Override
283 public boolean isSatisfied() {
284 return getActivity().getCurrentTabModel().getCount() >= numTabsAfterNewTab;
285 }
286 }));
287
288 // Now wait until the new tab animation finishes. Something wonky happen s
289 // if we try to go to the new tab before this.
290 assertTrue(CriteriaHelper.pollForUIThreadCriteria(new Criteria() {
291 @Override
292 public boolean isSatisfied() {
293 CompositorViewHolder compositorViewHolder =
294 (CompositorViewHolder) getActivity().findViewById(
295 R.id.compositor_view_holder);
296 LayoutManager layoutManager = compositorViewHolder.getLayoutMana ger();
297
298 return layoutManager.getActiveLayout() instanceof StaticLayout;
299 }
300 }));
301 }
302
303 /*
304 Bug http://crbug/481758
305 */
306 @CommandLineFlags.Add(ChromeSwitches.DISABLE_DOCUMENT_MODE)
307 @MediumTest
308 @Feature({"Downloads"})
309 public void testDuplicateHttpPostDownload_OpenNewTabAndReplace() throws Exce ption {
310 final String url =
311 TestHttpServerClient.getUrl("chrome/test/data/android/download/g et.html");
312
313 // Create the file in advance so that duplicate download infobar can sho w up.
314 File dir = Environment.getExternalStoragePublicDirectory(Environment.DIR ECTORY_DOWNLOADS);
315 assertTrue(dir.isDirectory());
316 final File file = new File(dir, "test.gzip");
317 if (!file.exists()) {
318 assertTrue(file.createNewFile());
319 }
320
321 // Open in a new tab again.
322 loadUrl(url);
323 waitForFocus();
324
325 View currentView = getActivity().getActivityTab().getView();
326 TouchCommon.longPressView(
327 currentView, currentView.getWidth() / 2, currentView.getHeight() / 2);
328 getInstrumentation().invokeContextMenuAction(
329 getActivity(), R.id.contextmenu_open_in_new_tab, 0);
330 waitForNewTabToStabilize(2);
331
332 goToLastTab();
333 assertPollForInfoBarSize(1);
334
335 // Now create two new files by clicking on the infobars.
336 assertTrue("OVERWRITE button wasn't found",
337 InfoBarUtil.clickPrimaryButton(getInfoBars().get(0)));
338
339 // Try to wait for download to finish. This will fail if there is no ext ernal Internet
340 // connection. Android's DownloadManager will abort download request whe n there is
341 // no Internet connection, even though we are connecting to a local host .
342 waitForGetDownloadToFinish();
343 }
344
245 /* 345 /*
246 @MediumTest 346 @MediumTest
247 @Feature({"Downloads"}) 347 @Feature({"Downloads"})
248 Bug http://crbug/253711 348 Bug http://crbug/253711
249 */ 349 */
250 @FlakyTest 350 @FlakyTest
251 public void testUrlEscaping() throws Exception { 351 public void testUrlEscaping() throws Exception {
252 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/u rlescaping.html")); 352 loadUrl(TestHttpServerClient.getUrl("chrome/test/data/android/download/u rlescaping.html"));
253 waitForFocus(); 353 waitForFocus();
254 View currentView = getActivity().getActivityTab().getView(); 354 View currentView = getActivity().getActivityTab().getView();
(...skipping 23 matching lines...) Expand all
278 @Override 378 @Override
279 public boolean isSatisfied() { 379 public boolean isSatisfied() {
280 if (getInfoBars().size() != size) return false; 380 if (getInfoBars().size() != size) return false;
281 if (size == 0) return true; 381 if (size == 0) return true;
282 InfoBar infoBar = getInfoBars().get(size - 1); 382 InfoBar infoBar = getInfoBars().get(size - 1);
283 return infoBar.areControlsEnabled(); 383 return infoBar.areControlsEnabled();
284 } 384 }
285 })); 385 }));
286 } 386 }
287 } 387 }
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698