OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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.prerender; | 5 package org.chromium.chrome.browser.prerender; |
6 | 6 |
7 import android.test.UiThreadTest; | 7 import android.test.UiThreadTest; |
8 import android.test.suitebuilder.annotation.MediumTest; | 8 import android.test.suitebuilder.annotation.MediumTest; |
9 import android.test.suitebuilder.annotation.SmallTest; | 9 import android.test.suitebuilder.annotation.SmallTest; |
10 | 10 |
11 import org.chromium.base.ThreadUtils; | 11 import org.chromium.base.ThreadUtils; |
12 import org.chromium.base.test.util.Feature; | 12 import org.chromium.base.test.util.Feature; |
13 import org.chromium.chrome.browser.ContentViewUtil; | 13 import org.chromium.chrome.browser.ContentViewUtil; |
14 import org.chromium.chrome.browser.profiles.Profile; | 14 import org.chromium.chrome.browser.profiles.Profile; |
15 import org.chromium.chrome.shell.ChromeShellTestBase; | 15 import org.chromium.chrome.shell.ChromeShellTestBase; |
16 import org.chromium.chrome.test.util.TestHttpServerClient; | 16 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 17 import org.chromium.content.browser.test.util.Criteria; |
| 18 import org.chromium.content.browser.test.util.CriteriaHelper; |
17 | 19 |
18 import java.util.concurrent.Callable; | 20 import java.util.concurrent.Callable; |
19 | 21 |
20 /** | 22 /** |
21 * Tests for adding and removing prerenders using the {@link ExternalPrerenderHa
ndler} | 23 * Tests for adding and removing prerenders using the {@link ExternalPrerenderHa
ndler} |
22 */ | 24 */ |
23 public class ExternalPrerenderRequestTest extends ChromeShellTestBase { | 25 public class ExternalPrerenderRequestTest extends ChromeShellTestBase { |
24 private static final String HOMEPAGE_URL = | 26 private static final String HOMEPAGE_URL = |
25 TestHttpServerClient.getUrl("chrome/test/data/android/prerender/home
page.html"); | 27 TestHttpServerClient.getUrl("chrome/test/data/android/prerender/home
page.html"); |
26 private static final String GOOGLE_URL = | 28 private static final String GOOGLE_URL = |
(...skipping 14 matching lines...) Expand all Loading... |
41 launchChromeShellWithUrl(HOMEPAGE_URL); | 43 launchChromeShellWithUrl(HOMEPAGE_URL); |
42 assertTrue(waitForActiveShellToBeDoneLoading()); | 44 assertTrue(waitForActiveShellToBeDoneLoading()); |
43 mHandler = new ExternalPrerenderHandler(); | 45 mHandler = new ExternalPrerenderHandler(); |
44 final Callable<Profile> profileCallable = new Callable<Profile>() { | 46 final Callable<Profile> profileCallable = new Callable<Profile>() { |
45 @Override | 47 @Override |
46 public Profile call() throws Exception { | 48 public Profile call() throws Exception { |
47 return Profile.getLastUsedProfile(); | 49 return Profile.getLastUsedProfile(); |
48 } | 50 } |
49 }; | 51 }; |
50 mProfile = ThreadUtils.runOnUiThreadBlocking(profileCallable); | 52 mProfile = ThreadUtils.runOnUiThreadBlocking(profileCallable); |
51 while (!ExternalPrerenderHandler.hasCookieStoreLoaded(mProfile)) | 53 final Callable<Boolean> cookieStoreCallable = new Callable<Boolean>() { |
52 Thread.sleep(CHECK_COOKIE_STORE_FREQUENCY_MS); | 54 @Override |
| 55 public Boolean call() throws Exception { |
| 56 return ExternalPrerenderHandler.checkCookieStoreLoadedForTesting
(mProfile); |
| 57 } |
| 58 }; |
| 59 assertTrue(CriteriaHelper.pollForCriteria(new Criteria() { |
| 60 @Override |
| 61 public boolean isSatisfied() { |
| 62 return ThreadUtils.runOnUiThreadBlockingNoException(cookieStoreC
allable); |
| 63 } |
| 64 }, CHECK_COOKIE_STORE_FREQUENCY_MS, 5000)); |
53 } | 65 } |
54 | 66 |
55 @MediumTest | 67 @MediumTest |
56 @UiThreadTest | 68 @UiThreadTest |
57 @Feature({"Prerender"}) | 69 @Feature({"Prerender"}) |
58 /** | 70 /** |
59 * Test adding a prerender and canceling that to add a new one. | 71 * Test adding a prerender and canceling that to add a new one. |
60 */ | 72 */ |
61 public void testAddPrerenderAndCancel() throws InterruptedException { | 73 public void testAddPrerenderAndCancel() throws InterruptedException { |
62 long webContentsPtr = mHandler.addPrerender(mProfile, GOOGLE_URL, "", 0,
0); | 74 long webContentsPtr = mHandler.addPrerender(mProfile, GOOGLE_URL, "", 0,
0); |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
96 public void testAddingPrerendersInaRow() throws InterruptedException { | 108 public void testAddingPrerendersInaRow() throws InterruptedException { |
97 long webContentsPtr = mHandler.addPrerender(mProfile, GOOGLE_URL, "", 0,
0); | 109 long webContentsPtr = mHandler.addPrerender(mProfile, GOOGLE_URL, "", 0,
0); |
98 assertTrue(ExternalPrerenderHandler.hasPrerenderedUrl( | 110 assertTrue(ExternalPrerenderHandler.hasPrerenderedUrl( |
99 mProfile, GOOGLE_URL, webContentsPtr)); | 111 mProfile, GOOGLE_URL, webContentsPtr)); |
100 Thread.sleep(PRERENDER_DELAY_MS); | 112 Thread.sleep(PRERENDER_DELAY_MS); |
101 long newWebContentsPtr = mHandler.addPrerender(mProfile, YOUTUBE_URL, ""
, 0, 0); | 113 long newWebContentsPtr = mHandler.addPrerender(mProfile, YOUTUBE_URL, ""
, 0, 0); |
102 assertTrue(ExternalPrerenderHandler.hasPrerenderedUrl( | 114 assertTrue(ExternalPrerenderHandler.hasPrerenderedUrl( |
103 mProfile, YOUTUBE_URL, newWebContentsPtr)); | 115 mProfile, YOUTUBE_URL, newWebContentsPtr)); |
104 } | 116 } |
105 } | 117 } |
OLD | NEW |