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

Side by Side Diff: chrome/android/javatests/src/org/chromium/chrome/browser/customtabs/CustomTabsConnectionTest.java

Issue 2247143004: Remove app context init from LibraryLoader. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix per review. Created 4 years, 2 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
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.customtabs; 5 package org.chromium.chrome.browser.customtabs;
6 6
7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE; 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E ND_DEVICE;
8 8
9 import android.app.Application; 9 import android.app.Application;
10 import android.content.Context; 10 import android.content.Context;
(...skipping 23 matching lines...) Expand all
34 import java.util.concurrent.FutureTask; 34 import java.util.concurrent.FutureTask;
35 35
36 /** Tests for CustomTabsConnection. */ 36 /** Tests for CustomTabsConnection. */
37 public class CustomTabsConnectionTest extends InstrumentationTestCase { 37 public class CustomTabsConnectionTest extends InstrumentationTestCase {
38 private CustomTabsConnection mCustomTabsConnection; 38 private CustomTabsConnection mCustomTabsConnection;
39 private static final String URL = "http://www.google.com"; 39 private static final String URL = "http://www.google.com";
40 private static final String URL2 = "https://www.android.com"; 40 private static final String URL2 = "https://www.android.com";
41 private static final String INVALID_SCHEME_URL = "intent://www.google.com"; 41 private static final String INVALID_SCHEME_URL = "intent://www.google.com";
42 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; 42 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome";
43 43
44 private Context mContext; 44 private Context mAppContext;
45 45
46 @Override 46 @Override
47 protected void setUp() throws Exception { 47 protected void setUp() throws Exception {
48 super.setUp(); 48 super.setUp();
49 mContext = getInstrumentation().getTargetContext().getApplicationContext (); 49 mAppContext = getInstrumentation().getTargetContext().getApplicationCont ext();
50 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, 50 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, m AppContext);
51 mContext); 51 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER).ensureInitialized( );
52 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) 52 mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application ) mAppContext);
53 .ensureInitialized(mContext); 53 mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
54 mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application ) mContext);
55 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
56 } 54 }
57 55
58 @Override 56 @Override
59 protected void tearDown() throws Exception { 57 protected void tearDown() throws Exception {
60 super.tearDown(); 58 super.tearDown();
61 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection); 59 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection);
62 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 60 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
63 @Override 61 @Override
64 public void run() { 62 public void run() {
65 WarmupManager.getInstance().destroySpareWebContents(); 63 WarmupManager.getInstance().destroySpareWebContents();
(...skipping 315 matching lines...) Expand 10 before | Expand all | Expand 10 after
381 } 379 }
382 380
383 /** 381 /**
384 * Tests that 382 * Tests that
385 * {@link CustomTabsConnection#mayLaunchUrl(CustomTabsSessionToken, Uri, Bun dle, List)} 383 * {@link CustomTabsConnection#mayLaunchUrl(CustomTabsSessionToken, Uri, Bun dle, List)}
386 * can be called several times with the same, and different URLs. 384 * can be called several times with the same, and different URLs.
387 */ 385 */
388 @SmallTest 386 @SmallTest
389 public void testMultipleMayLaunchUrl() { 387 public void testMultipleMayLaunchUrl() {
390 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue); 388 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue);
391 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 389 mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
392 assertWarmupAndMayLaunchUrl(token, URL, true); 390 assertWarmupAndMayLaunchUrl(token, URL, true);
393 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 391 mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
394 assertWarmupAndMayLaunchUrl(token, URL2, true); 392 assertWarmupAndMayLaunchUrl(token, URL2, true);
395 } 393 }
396 394
397 /** 395 /**
398 * Tests that sessions are forgotten properly. 396 * Tests that sessions are forgotten properly.
399 */ 397 */
400 @SmallTest 398 @SmallTest
401 public void testForgetsSession() { 399 public void testForgetsSession() {
402 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue); 400 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue);
403 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection); 401 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection);
(...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after
482 } 480 }
483 assertWarmupAndMayLaunchUrl(token, URL, true); 481 assertWarmupAndMayLaunchUrl(token, URL, true);
484 } 482 }
485 483
486 /** 484 /**
487 * Tests that throttling applies across sessions. 485 * Tests that throttling applies across sessions.
488 */ 486 */
489 @SmallTest 487 @SmallTest
490 public void testThrottlingAcrossSessions() { 488 public void testThrottlingAcrossSessions() {
491 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue); 489 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue);
492 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 490 mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
493 CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, t rue); 491 CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, t rue);
494 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 492 mCustomTabsConnection.resetThrottling(mAppContext, Process.myUid());
495 for (int i = 0; i < 10; i++) { 493 for (int i = 0; i < 10; i++) {
496 mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null ); 494 mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null );
497 } 495 }
498 assertWarmupAndMayLaunchUrl(token2, URL, false); 496 assertWarmupAndMayLaunchUrl(token2, URL, false);
499 } 497 }
500 498
501 @SmallTest 499 @SmallTest
502 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) 500 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
503 public void testBanningWorks() { 501 public void testBanningWorks() {
504 mCustomTabsConnection.ban(mContext, Process.myUid()); 502 mCustomTabsConnection.ban(mAppContext, Process.myUid());
505 final CustomTabsSessionToken token = 503 final CustomTabsSessionToken token =
506 CustomTabsSessionToken.createDummySessionTokenForTesting(); 504 CustomTabsSessionToken.createDummySessionTokenForTesting();
507 assertTrue(mCustomTabsConnection.newSession(token)); 505 assertTrue(mCustomTabsConnection.newSession(token));
508 506
509 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null)); 507 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null));
510 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 508 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
511 @Override 509 @Override
512 public void run() { 510 public void run() {
513 assertSpareWebContentsNotNullAndDestroy(); 511 assertSpareWebContentsNotNullAndDestroy();
514 String referrer = mCustomTabsConnection.getReferrerForSession(to ken).getUrl(); 512 String referrer = mCustomTabsConnection.getReferrerForSession(to ken).getUrl();
515 assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer)); 513 assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
516 } 514 }
517 }); 515 });
518 } 516 }
519 517
520 @SmallTest 518 @SmallTest
521 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE) 519 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
522 public void testBanningDisabledForCellular() { 520 public void testBanningDisabledForCellular() {
523 mCustomTabsConnection.ban(mContext, Process.myUid()); 521 mCustomTabsConnection.ban(mAppContext, Process.myUid());
524 final CustomTabsSessionToken token = 522 final CustomTabsSessionToken token =
525 CustomTabsSessionToken.createDummySessionTokenForTesting(); 523 CustomTabsSessionToken.createDummySessionTokenForTesting();
526 assertTrue(mCustomTabsConnection.newSession(token)); 524 assertTrue(mCustomTabsConnection.newSession(token));
527 mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true ); 525 mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true );
528 526
529 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null)); 527 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null));
530 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 528 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
531 @Override 529 @Override
532 public void run() { 530 public void run() {
533 assertNull(WarmupManager.getInstance().takeSpareWebContents(fals e, false)); 531 assertNull(WarmupManager.getInstance().takeSpareWebContents(fals e, false));
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
570 } finally { 568 } finally {
571 ThreadUtils.runOnUiThreadBlocking(new Runnable() { 569 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
572 @Override 570 @Override
573 public void run() { 571 public void run() {
574 PrefServiceBridge.getInstance().setNetworkPredictionEnabled( enabled); 572 PrefServiceBridge.getInstance().setNetworkPredictionEnabled( enabled);
575 } 573 }
576 }); 574 });
577 } 575 }
578 } 576 }
579 } 577 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698