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

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

Issue 2080173006: customtabs: Allowing prerendering on cellular also disables throttling. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Add a test. Created 4 years, 6 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/customtabs/RequestThrottler.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.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;
11 import android.content.Intent; 11 import android.content.Intent;
12 import android.net.Uri; 12 import android.net.Uri;
13 import android.os.Build; 13 import android.os.Build;
14 import android.os.Bundle; 14 import android.os.Bundle;
15 import android.os.Process; 15 import android.os.Process;
16 import android.support.customtabs.CustomTabsService; 16 import android.support.customtabs.CustomTabsService;
17 import android.support.customtabs.CustomTabsSessionToken; 17 import android.support.customtabs.CustomTabsSessionToken;
18 import android.test.InstrumentationTestCase; 18 import android.test.InstrumentationTestCase;
19 import android.test.suitebuilder.annotation.SmallTest; 19 import android.test.suitebuilder.annotation.SmallTest;
20 20
21 import org.chromium.base.PathUtils; 21 import org.chromium.base.PathUtils;
22 import org.chromium.base.ThreadUtils; 22 import org.chromium.base.ThreadUtils;
23 import org.chromium.base.library_loader.LibraryLoader; 23 import org.chromium.base.library_loader.LibraryLoader;
24 import org.chromium.base.library_loader.LibraryProcessType; 24 import org.chromium.base.library_loader.LibraryProcessType;
25 import org.chromium.base.test.util.Restriction; 25 import org.chromium.base.test.util.Restriction;
26 import org.chromium.chrome.browser.preferences.PrefServiceBridge;
26 import org.chromium.content_public.browser.WebContents; 27 import org.chromium.content_public.browser.WebContents;
27 28
28 import java.util.ArrayList; 29 import java.util.ArrayList;
29 import java.util.List; 30 import java.util.List;
31 import java.util.concurrent.Callable;
32 import java.util.concurrent.FutureTask;
30 33
31 /** Tests for CustomTabsConnection. */ 34 /** Tests for CustomTabsConnection. */
32 public class CustomTabsConnectionTest extends InstrumentationTestCase { 35 public class CustomTabsConnectionTest extends InstrumentationTestCase {
33 private CustomTabsConnection mCustomTabsConnection; 36 private CustomTabsConnection mCustomTabsConnection;
34 private static final String URL = "http://www.google.com"; 37 private static final String URL = "http://www.google.com";
35 private static final String URL2 = "https://www.android.com"; 38 private static final String URL2 = "https://www.android.com";
36 private static final String INVALID_SCHEME_URL = "intent://www.google.com"; 39 private static final String INVALID_SCHEME_URL = "intent://www.google.com";
37 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome"; 40 private static final String PRIVATE_DATA_DIRECTORY_SUFFIX = "chrome";
38 41
39 private Context mContext; 42 private Context mContext;
40 43
41 @Override 44 @Override
42 protected void setUp() throws Exception { 45 protected void setUp() throws Exception {
43 super.setUp(); 46 super.setUp();
44 mContext = getInstrumentation().getTargetContext().getApplicationContext (); 47 mContext = getInstrumentation().getTargetContext().getApplicationContext ();
45 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX, 48 PathUtils.setPrivateDataDirectorySuffix(PRIVATE_DATA_DIRECTORY_SUFFIX,
46 mContext); 49 mContext);
47 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER) 50 LibraryLoader.get(LibraryProcessType.PROCESS_BROWSER)
48 .ensureInitialized(mContext); 51 .ensureInitialized(mContext);
49 mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application ) mContext); 52 mCustomTabsConnection = CustomTabsTestUtils.setUpConnection((Application ) mContext);
53 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
50 } 54 }
51 55
52 @Override 56 @Override
53 protected void tearDown() throws Exception { 57 protected void tearDown() throws Exception {
54 super.tearDown(); 58 super.tearDown();
55 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection); 59 CustomTabsTestUtils.cleanupSessions(mCustomTabsConnection);
56 } 60 }
57 61
58 /** 62 /**
59 * Tests that we can create a new session. Registering with a null callback 63 * Tests that we can create a new session. Registering with a null callback
(...skipping 389 matching lines...) Expand 10 before | Expand all | Expand 10 after
449 public void testThrottlingAcrossSessions() { 453 public void testThrottlingAcrossSessions() {
450 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue); 454 CustomTabsSessionToken token = assertWarmupAndMayLaunchUrl(null, URL, tr ue);
451 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 455 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
452 CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, t rue); 456 CustomTabsSessionToken token2 = assertWarmupAndMayLaunchUrl(null, URL, t rue);
453 mCustomTabsConnection.resetThrottling(mContext, Process.myUid()); 457 mCustomTabsConnection.resetThrottling(mContext, Process.myUid());
454 for (int i = 0; i < 10; i++) { 458 for (int i = 0; i < 10; i++) {
455 mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null ); 459 mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null );
456 } 460 }
457 assertWarmupAndMayLaunchUrl(token2, URL, false); 461 assertWarmupAndMayLaunchUrl(token2, URL, false);
458 } 462 }
463
464 @SmallTest
465 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
466 public void testBanningWorks() {
467 mCustomTabsConnection.ban(mContext, Process.myUid());
468 final CustomTabsSessionToken token =
469 CustomTabsSessionToken.createDummySessionTokenForTesting();
470 assertTrue(mCustomTabsConnection.newSession(token));
471
472 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null));
473 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
474 @Override
475 public void run() {
476 assertSpareWebContentsNotNullAndDestroy();
477 String referrer = mCustomTabsConnection.getReferrerForSession(to ken).getUrl();
478 assertNull(mCustomTabsConnection.takePrerenderedUrl(token, URL, referrer));
479 }
480 });
481 }
482
483 @SmallTest
484 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
485 public void testBanningDisabledForCellular() {
486 mCustomTabsConnection.ban(mContext, Process.myUid());
487 final CustomTabsSessionToken token =
488 CustomTabsSessionToken.createDummySessionTokenForTesting();
489 assertTrue(mCustomTabsConnection.newSession(token));
490 mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true );
491
492 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), nul l, null));
493 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
494 @Override
495 public void run() {
496 assertNull(mCustomTabsConnection.takeSpareWebContents());
497 String referrer = mCustomTabsConnection.getReferrerForSession(to ken).getUrl();
498 WebContents prerender = mCustomTabsConnection.takePrerenderedUrl (
499 token, URL, referrer);
500 assertNotNull(prerender);
501 prerender.destroy();
502 }
503 });
504 }
505
506 @SmallTest
507 @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
508 public void testCellularPrerenderingDoesntOverrideSettings() throws Exceptio n {
509 CustomTabsSessionToken token = CustomTabsSessionToken.createDummySession TokenForTesting();
510 assertTrue(mCustomTabsConnection.newSession(token));
511 mCustomTabsConnection.setShouldPrerenderOnCellularForSession(token, true );
512 mCustomTabsConnection.warmup(0);
513
514 // Needs the browser process to be initialized.
515 FutureTask<Boolean> result = ThreadUtils.runOnUiThread(new Callable<Bool ean>() {
516 @Override
517 public Boolean call() {
518 PrefServiceBridge prefs = PrefServiceBridge.getInstance();
519 boolean result = prefs.getNetworkPredictionEnabled();
520 prefs.setNetworkPredictionEnabled(false);
521 return result;
522 }});
523 final boolean enabled = result.get();
524
525 try {
526 assertTrue(mCustomTabsConnection.mayLaunchUrl(token, Uri.parse(URL), null, null));
527 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
528 @Override
529 public void run() {
530 assertSpareWebContentsNotNullAndDestroy();
531 }
532 });
533 } finally {
534 ThreadUtils.runOnUiThreadBlocking(new Runnable() {
535 @Override
536 public void run() {
537 PrefServiceBridge.getInstance().setNetworkPredictionEnabled( enabled);
538 }
539 });
540 }
541 }
459 } 542 }
OLDNEW
« no previous file with comments | « chrome/android/java/src/org/chromium/chrome/browser/customtabs/RequestThrottler.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698