OLD | NEW |
(Empty) | |
| 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 |
| 3 // found in the LICENSE file. |
| 4 |
| 5 package org.chromium.chrome.browser; |
| 6 |
| 7 import static org.chromium.base.test.util.Restriction.RESTRICTION_TYPE_NON_LOW_E
ND_DEVICE; |
| 8 |
| 9 import android.test.suitebuilder.annotation.LargeTest; |
| 10 import android.view.KeyEvent; |
| 11 |
| 12 import com.google.android.apps.chrome.R; |
| 13 |
| 14 import org.chromium.base.ThreadUtils; |
| 15 import org.chromium.base.test.util.DisabledTest; |
| 16 import org.chromium.base.test.util.Feature; |
| 17 import org.chromium.base.test.util.Restriction; |
| 18 import org.chromium.chrome.browser.omnibox.UrlBar; |
| 19 import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| 20 import org.chromium.chrome.test.util.ChromeTabUtils; |
| 21 import org.chromium.chrome.test.util.PrerenderTestHelper; |
| 22 import org.chromium.chrome.test.util.TestHttpServerClient; |
| 23 import org.chromium.chrome.test.util.browser.TabTitleObserver; |
| 24 import org.chromium.content.browser.test.util.KeyUtils; |
| 25 import org.chromium.ui.base.PageTransition; |
| 26 |
| 27 import java.util.concurrent.TimeoutException; |
| 28 |
| 29 /** |
| 30 * Prerender tests. |
| 31 * |
| 32 * Tests are disabled on low-end devices. These only support one renderer for pe
rformance reasons. |
| 33 */ |
| 34 public class PrerenderTest extends ChromeTabbedActivityTestBase { |
| 35 |
| 36 // junit.framework.Assert has |
| 37 // assertEquals(Object,Object) |
| 38 // assertEquals(String,String) and |
| 39 // assertNotSame(Object,Object), but no |
| 40 // assertNotSame(String,String). |
| 41 // Since String equality needs equals() and object equality uses |
| 42 // ==, the lack of a proper API means it's easy to use object |
| 43 // equality by accident since Object is a base class of String. |
| 44 // But that's not what you want! |
| 45 void assertNotEquals(String expected, String actual) { |
| 46 assertFalse(expected.equals(actual)); |
| 47 } |
| 48 |
| 49 /** |
| 50 * We are using Autocomplete Action Predictor to decide whether or not to pr
erender. |
| 51 /* Without any training data the default action should be no-prerender. |
| 52 */ |
| 53 @LargeTest |
| 54 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
| 55 @Feature({"TabContents"}) |
| 56 public void testNoPrerender() throws InterruptedException { |
| 57 String testUrl = TestHttpServerClient.getUrl( |
| 58 "chrome/test/data/android/prerender/google.html"); |
| 59 final Tab tab = getActivity().getActivityTab(); |
| 60 |
| 61 // Mimic user behavior: touch to focus then type some URL. |
| 62 // Since this is a URL, it should be prerendered. |
| 63 // Type one character at a time to properly simulate input |
| 64 // to the action predictor. |
| 65 typeInOmnibox(testUrl, true); |
| 66 |
| 67 assertFalse("URL should not have been prerendered.", |
| 68 PrerenderTestHelper.waitForPrerenderUrl(tab, testUrl, true)); |
| 69 // Navigate should not use the prerendered version. |
| 70 assertEquals(TabLoadStatus.DEFAULT_PAGE_LOAD, |
| 71 loadUrlInTab(testUrl, PageTransition.TYPED | PageTransition.FROM
_ADDRESS_BAR, tab)); |
| 72 } |
| 73 |
| 74 /* |
| 75 @LargeTest |
| 76 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
| 77 @Feature({"TabContents"}) |
| 78 crbug.com/339668 |
| 79 */ |
| 80 @DisabledTest |
| 81 public void testPrerenderNotDead() throws InterruptedException, TimeoutExcep
tion { |
| 82 String testUrl = TestHttpServerClient.getUrl( |
| 83 "chrome/test/data/android/prerender/google.html"); |
| 84 PrerenderTestHelper.trainAutocompleteActionPredictorAndTestPrerender(tes
tUrl, this); |
| 85 final Tab tab = getActivity().getActivityTab(); |
| 86 // Navigate should use the prerendered version. |
| 87 assertEquals(TabLoadStatus.FULL_PRERENDERED_PAGE_LOAD, |
| 88 loadUrlInTab(testUrl, PageTransition.TYPED | PageTransition.FROM
_ADDRESS_BAR, tab)); |
| 89 |
| 90 // Prerender again with new text; make sure we get something different. |
| 91 String newTitle = "Welcome to the YouTube"; |
| 92 testUrl = TestHttpServerClient.getUrl("chrome/test/data/android/prerende
r/youtube.html"); |
| 93 PrerenderTestHelper.trainAutocompleteActionPredictorAndTestPrerender(tes
tUrl, this); |
| 94 |
| 95 // Make sure the current tab title is NOT from the prerendered page. |
| 96 assertNotEquals(newTitle, tab.getTitle()); |
| 97 |
| 98 TabTitleObserver observer = new TabTitleObserver(tab, newTitle); |
| 99 |
| 100 // Now commit and see the new title. |
| 101 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 102 assertNotNull("urlBar is null", urlBar); |
| 103 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEvent.KEYCO
DE_ENTER); |
| 104 |
| 105 observer.waitForTitleUpdate(5); |
| 106 assertEquals(newTitle, tab.getTitle()); |
| 107 } |
| 108 |
| 109 /** |
| 110 * Tests that we do get the page load finished notification even when a page
has been fully |
| 111 * prerendered. |
| 112 */ |
| 113 /* |
| 114 @LargeTest |
| 115 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
| 116 @Feature({"TabContents"}) |
| 117 crbug.com/339668 |
| 118 */ |
| 119 @DisabledTest |
| 120 public void testPageLoadFinishNotification() throws InterruptedException { |
| 121 String url = TestHttpServerClient.getUrl("chrome/test/data/android/prere
nder/google.html"); |
| 122 PrerenderTestHelper.trainAutocompleteActionPredictorAndTestPrerender(url
, this); |
| 123 // Now let's press enter to validate the suggestion. The prerendered pag
e should be |
| 124 // committed and we should get a page load finished notification (which
would trigger the |
| 125 // page load). |
| 126 ChromeTabUtils.waitForTabPageLoaded(getActivity().getActivityTab(), new
Runnable() { |
| 127 @Override |
| 128 public void run() { |
| 129 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.u
rl_bar); |
| 130 assertNotNull("urlBar is null", urlBar); |
| 131 KeyUtils.singleKeyEventView(getInstrumentation(), urlBar, KeyEve
nt.KEYCODE_ENTER); |
| 132 } |
| 133 }); |
| 134 } |
| 135 |
| 136 /** |
| 137 * Tests that we don't crash when dismissing a prerendered page with infobar
s and unlonad |
| 138 * handler (See bug 5757331). |
| 139 * Note that this bug happened with the instant code. Now that we use Wicked
Fast, we don't |
| 140 * deal with infobars ourselves. |
| 141 */ |
| 142 /* |
| 143 @LargeTest |
| 144 @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE}) |
| 145 @Feature({"TabContents"}) |
| 146 crbug.com/339668 |
| 147 */ |
| 148 @DisabledTest |
| 149 public void testInfoBarDismissed() throws InterruptedException { |
| 150 final String url = TestHttpServerClient.getUrl( |
| 151 "chrome/test/data/geolocation/geolocation_on_load.html"); |
| 152 PrerenderTestHelper.trainAutocompleteActionPredictorAndTestPrerender(url
, this); |
| 153 // Let's clear the URL bar, this will discard the prerendered WebContent
s and close the |
| 154 // infobars. |
| 155 final UrlBar urlBar = (UrlBar) getActivity().findViewById(R.id.url_bar); |
| 156 assertNotNull(urlBar); |
| 157 ThreadUtils.runOnUiThreadBlocking(new Runnable() { |
| 158 @Override |
| 159 public void run() { |
| 160 urlBar.requestFocus(); |
| 161 urlBar.setText(""); |
| 162 } |
| 163 }); |
| 164 } |
| 165 |
| 166 @Override |
| 167 public void startMainActivity() throws InterruptedException { |
| 168 startMainActivityOnBlankPage(); |
| 169 } |
| 170 } |
OLD | NEW |