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

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

Issue 2151063002: refactor DownloadManagerService to eliminate variable access on 2 different threads (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rename testcases Created 4 years, 5 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 | « chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java ('k') | 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.app.DownloadManager; 7 import android.app.DownloadManager;
8 import android.content.Context; 8 import android.content.Context;
9 import android.content.Intent; 9 import android.content.Intent;
10 import android.os.Environment; 10 import android.os.Environment;
(...skipping 313 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 .setDownloadGuid(UUID.randomUUID().toString()) 324 .setDownloadGuid(UUID.randomUUID().toString())
325 .build(); 325 .build();
326 } 326 }
327 327
328 private Context getTestContext() { 328 private Context getTestContext() {
329 return new AdvancedMockContext(getInstrumentation().getTargetContext()); 329 return new AdvancedMockContext(getInstrumentation().getTargetContext());
330 } 330 }
331 331
332 @MediumTest 332 @MediumTest
333 @Feature({"Download"}) 333 @Feature({"Download"})
334 public void testDownloadProgressIsCalled() throws InterruptedException { 334 public void testAllDownloadProgressIsCalledForSlowUpdates() throws Interrupt edException {
335 MockDownloadNotifier notifier = new MockDownloadNotifier(getTestContext( )); 335 MockDownloadNotifier notifier = new MockDownloadNotifier(getTestContext( ));
336 DownloadManagerServiceForTest dService = new DownloadManagerServiceForTe st( 336 DownloadManagerServiceForTest dService = new DownloadManagerServiceForTe st(
337 getTestContext(), notifier, UPDATE_DELAY_FOR_TEST); 337 getTestContext(), notifier, UPDATE_DELAY_FOR_TEST);
338 DownloadInfo downloadInfo = getDownloadInfo(); 338 DownloadInfo downloadInfo = getDownloadInfo();
339 339
340 notifier.expect(MethodID.DOWNLOAD_PROGRESS, downloadInfo); 340 notifier.expect(MethodID.DOWNLOAD_PROGRESS, downloadInfo);
341 dService.onDownloadUpdated(downloadInfo); 341 dService.onDownloadUpdated(downloadInfo);
342 notifier.waitTillExpectedCallsComplete(); 342 notifier.waitTillExpectedCallsComplete();
343 343
344 // Now post multiple download updated calls and make sure all are receiv ed. 344 // Now post multiple download updated calls and make sure all are receiv ed.
(...skipping 10 matching lines...) Expand all
355 dService.onDownloadUpdated(update1); 355 dService.onDownloadUpdated(update1);
356 Thread.sleep(DELAY_BETWEEN_CALLS); 356 Thread.sleep(DELAY_BETWEEN_CALLS);
357 dService.onDownloadUpdated(update2); 357 dService.onDownloadUpdated(update2);
358 Thread.sleep(DELAY_BETWEEN_CALLS); 358 Thread.sleep(DELAY_BETWEEN_CALLS);
359 dService.onDownloadUpdated(update3); 359 dService.onDownloadUpdated(update3);
360 notifier.waitTillExpectedCallsComplete(); 360 notifier.waitTillExpectedCallsComplete();
361 } 361 }
362 362
363 @MediumTest 363 @MediumTest
364 @Feature({"Download"}) 364 @Feature({"Download"})
365 public void testOnlyOneProgressForFastUpdates() throws InterruptedException { 365 public void testOnlyTwoProgressForFastUpdates() throws InterruptedException {
366 MockDownloadNotifier notifier = new MockDownloadNotifier(getTestContext( )); 366 MockDownloadNotifier notifier = new MockDownloadNotifier(getTestContext( ));
367 DownloadManagerServiceForTest dService = new DownloadManagerServiceForTe st( 367 DownloadManagerServiceForTest dService = new DownloadManagerServiceForTe st(
368 getTestContext(), notifier, LONG_UPDATE_DELAY_FOR_TEST); 368 getTestContext(), notifier, LONG_UPDATE_DELAY_FOR_TEST);
369 DownloadInfo downloadInfo = getDownloadInfo(); 369 DownloadInfo downloadInfo = getDownloadInfo();
370 DownloadInfo update1 = Builder.fromDownloadInfo(downloadInfo) 370 DownloadInfo update1 = Builder.fromDownloadInfo(downloadInfo)
371 .setPercentCompleted(10).build(); 371 .setPercentCompleted(10).build();
372 DownloadInfo update2 = Builder.fromDownloadInfo(downloadInfo) 372 DownloadInfo update2 = Builder.fromDownloadInfo(downloadInfo)
373 .setPercentCompleted(30).build(); 373 .setPercentCompleted(20).build();
374 DownloadInfo update3 = Builder.fromDownloadInfo(downloadInfo) 374 DownloadInfo update3 = Builder.fromDownloadInfo(downloadInfo)
375 .setPercentCompleted(30).build(); 375 .setPercentCompleted(30).build();
376 376
377 // Should only get one update call, the last update. 377 // Should get 2 update calls, the first and the last. The 2nd update wil l be merged into
378 notifier.expect(MethodID.DOWNLOAD_PROGRESS, update3); 378 // the last one.
379 notifier.expect(MethodID.DOWNLOAD_PROGRESS, update1)
380 .andThen(MethodID.DOWNLOAD_PROGRESS, update3);
379 dService.onDownloadUpdated(update1); 381 dService.onDownloadUpdated(update1);
380 Thread.sleep(DELAY_BETWEEN_CALLS); 382 Thread.sleep(DELAY_BETWEEN_CALLS);
381 dService.onDownloadUpdated(update2); 383 dService.onDownloadUpdated(update2);
382 Thread.sleep(DELAY_BETWEEN_CALLS); 384 Thread.sleep(DELAY_BETWEEN_CALLS);
383 dService.onDownloadUpdated(update3); 385 dService.onDownloadUpdated(update3);
384 Thread.sleep(DELAY_BETWEEN_CALLS); 386 Thread.sleep(DELAY_BETWEEN_CALLS);
385 notifier.waitTillExpectedCallsComplete(); 387 notifier.waitTillExpectedCallsComplete();
386 } 388 }
387 389
388 @MediumTest 390 @MediumTest
(...skipping 252 matching lines...) Expand 10 before | Expand all | Expand 10 after
641 .setHasUserGesture(false) 643 .setHasUserGesture(false)
642 .build())); 644 .build()));
643 assertFalse( 645 assertFalse(
644 DownloadManagerService.shouldOpenAfterDownload(new DownloadInfo. Builder() 646 DownloadManagerService.shouldOpenAfterDownload(new DownloadInfo. Builder()
645 .setContentDisposition("filename=test.pdf") 647 .setContentDisposition("filename=test.pdf")
646 .setMimeType("application/pdf") 648 .setMimeType("application/pdf")
647 .setHasUserGesture(false) 649 .setHasUserGesture(false)
648 .build())); 650 .build()));
649 } 651 }
650 } 652 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/download/DownloadManagerService.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698