| Index: chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManagerTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManagerTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManagerTest.java
|
| index 8b8290a3649c49e0e0ba45943a362f7209c0fecf..0dc28a8b4e641cca8daac1279053c0d3de5e85af 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManagerTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/contextualsearch/ContextualSearchManagerTest.java
|
| @@ -61,12 +61,7 @@
|
|
|
| import java.util.concurrent.TimeoutException;
|
|
|
| -// TODO(pedrosimonetti): Create class with limited API to encapsulate the internals of simulations.
|
| -// TODO(pedrosimonetti): Separate tests into different classes grouped by type of tests. Examples:
|
| -// Gestures (Tap, LongPress), Search Term Resolution (resolves, expand selection, prevent preload,
|
| -// translation), Panel interaction (tap, fling up/down, close), Content (creation, loading,
|
| -// visibility, history, delayed load), Tab Promotion, Policy (add tests to check if policies
|
| -// affect the behavior correctly), General (remaining tests), etc.
|
| +// TODO(pedrosimonetti): add tests for recent regressions crbug.com/543319.
|
|
|
| /**
|
| * Tests the Contextual Search Manager using instrumentation tests.
|
| @@ -103,24 +98,18 @@
|
|
|
| if (mManager != null) {
|
| mPanel = mManager.getContextualSearchPanel();
|
| -
|
| - mSelectionController = mManager.getSelectionController();
|
| - mPolicy = ContextualSearchPolicy.getInstance(getActivity());
|
| - mPolicy.overrideDecidedStateForTesting(true);
|
| - resetCounters();
|
| -
|
| - mFakeServer = new ContextualSearchFakeServer(
|
| - mPolicy,
|
| - this,
|
| - mManager,
|
| + mFakeServer = new ContextualSearchFakeServer(mManager,
|
| mManager.getOverlayContentDelegate(),
|
| new OverlayContentProgressObserver(),
|
| getActivity());
|
|
|
| mPanel.setOverlayPanelContentFactory(mFakeServer);
|
| mManager.setNetworkCommunicator(mFakeServer);
|
| -
|
| - registerFakeSearches();
|
| + mSelectionController = mManager.getSelectionController();
|
| + mPolicy = ContextualSearchPolicy.getInstance(getActivity());
|
| +
|
| + mPolicy.overrideDecidedStateForTesting(true);
|
| + resetCounters();
|
| }
|
|
|
| IntentFilter filter = new IntentFilter(Intent.ACTION_VIEW);
|
| @@ -130,130 +119,62 @@
|
| filter, new Instrumentation.ActivityResult(Activity.RESULT_OK, null), true);
|
| }
|
|
|
| - //============================================================================================
|
| - // Public API
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * Simulates a long-press on the given node.
|
| - * @param nodeId A string containing the node ID.
|
| - */
|
| - public void longPressNode(String nodeId) throws InterruptedException, TimeoutException {
|
| - Tab tab = getActivity().getActivityTab();
|
| - DOMUtils.longPressNode(this, tab.getContentViewCore(), nodeId);
|
| - waitForPanelToPeekAndAssert();
|
| - }
|
| -
|
| - /**
|
| - * Simulates a click on the given node.
|
| - * @param nodeId A string containing the node ID.
|
| - */
|
| - public void clickNode(String nodeId) throws InterruptedException, TimeoutException {
|
| - Tab tab = getActivity().getActivityTab();
|
| - DOMUtils.clickNode(this, tab.getContentViewCore(), nodeId);
|
| - }
|
| -
|
| - /**
|
| - * Waits for the selected text string to be the given string, and asserts.
|
| - * @param text The string to wait for the selection to become.
|
| - */
|
| - public void waitForSelectionToBe(final String text) throws InterruptedException {
|
| - assertTrue("Bar never showed desired text.",
|
| - CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return TextUtils.equals(text, getSelectedText());
|
| - }
|
| - }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL));
|
| - }
|
| -
|
| - /**
|
| - * Waits for the FakeTapSearch to become ready.
|
| - * @param search A given FakeTapSearch.
|
| - */
|
| - public void waitForSearchTermResolutionToStart(
|
| - final ContextualSearchFakeServer.FakeTapSearch search) throws InterruptedException {
|
| - assertTrue("Fake Search Term Resolution never started.",
|
| - CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return search.didStartSearchTermResolution();
|
| - }
|
| - }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL));
|
| - }
|
| -
|
| - /**
|
| - * Waits for the FakeTapSearch to become ready.
|
| - * @param search A given FakeTapSearch.
|
| - */
|
| - public void waitForSearchTermResolutionToFinish(
|
| - final ContextualSearchFakeServer.FakeTapSearch search) throws InterruptedException {
|
| - assertTrue("Fake Search was never ready.",
|
| - CriteriaHelper.pollForCriteria(new Criteria() {
|
| - @Override
|
| - public boolean isSatisfied() {
|
| - return search.didFinishSearchTermResolution();
|
| - }
|
| - }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL));
|
| - }
|
| -
|
| - /**
|
| - * Runs the given Runnable in the main thread.
|
| - * @param runnable The Runnable.
|
| - */
|
| - public void runOnMainSync(Runnable runnable) {
|
| - getInstrumentation().runOnMainSync(runnable);
|
| - }
|
| -
|
| @Override
|
| public void startMainActivity() throws InterruptedException {
|
| startMainActivityWithURL(TEST_PAGE);
|
| }
|
|
|
| - //============================================================================================
|
| - // Fake Searches Helpers
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * Simulates a long-press triggered search.
|
| - *
|
| - * @param nodeId The id of the node to be long-pressed.
|
| - * @throws InterruptedException
|
| - * @throws TimeoutException
|
| - */
|
| - private void simulateLongPressSearch(String nodeId)
|
| - throws InterruptedException, TimeoutException {
|
| - ContextualSearchFakeServer.FakeLongPressSearch search =
|
| - mFakeServer.getFakeLongPressSearch(nodeId);
|
| - search.simulate();
|
| - waitForPanelToPeekAndAssert();
|
| - }
|
| -
|
| - /**
|
| - * Simulates a tap triggered search.
|
| - *
|
| - * @param nodeId The id of the node to be tapped.
|
| - * @throws InterruptedException
|
| - * @throws TimeoutException
|
| - */
|
| - private void simulateTapSearch(String nodeId) throws InterruptedException, TimeoutException {
|
| - ContextualSearchFakeServer.FakeTapSearch search = mFakeServer.getFakeTapSearch(nodeId);
|
| - search.simulate();
|
| - assertLoadedSearchTermMatches(search.getSearchTerm());
|
| - waitForPanelToPeekAndAssert();
|
| - }
|
| -
|
| - /**
|
| - * Registers all fake searches to be used in tests.
|
| - */
|
| - private void registerFakeSearches() {
|
| - mFakeServer.registerFakeSearches();
|
| - }
|
| -
|
| - //============================================================================================
|
| - // Fake Response
|
| - // TODO(pedrosimonetti): remove these methods and use the new infrastructure instead.
|
| - //============================================================================================
|
| + /**
|
| + * Simulates a click on the given node.
|
| + * @param nodeId A string containing the node ID.
|
| + */
|
| + private void clickNode(String nodeId) throws InterruptedException, TimeoutException {
|
| + Tab tab = getActivity().getActivityTab();
|
| + DOMUtils.clickNode(this, tab.getContentViewCore(), nodeId);
|
| + }
|
| +
|
| + /**
|
| + * Simulates a click on the given word node.
|
| + * Waits for the bar to peek.
|
| + * @param nodeId A string containing the node ID.
|
| + */
|
| + private void clickWordNode(String nodeId) throws InterruptedException, TimeoutException {
|
| + clickNode(nodeId);
|
| + waitForPanelToPeekAndAssert();
|
| + }
|
| +
|
| + /**
|
| + * Simulates a key press.
|
| + * @param keycode The key's code.
|
| + */
|
| + private void pressKey(int keycode) {
|
| + getInstrumentation().sendKeyDownUpSync(keycode);
|
| + getInstrumentation().waitForIdleSync();
|
| + }
|
| +
|
| + /**
|
| + * Simulates pressing back button.
|
| + */
|
| + private void pressBackButton() {
|
| + pressKey(KeyEvent.KEYCODE_BACK);
|
| + }
|
| +
|
| + /**
|
| + * @return The selected text.
|
| + */
|
| + private String getSelectedText() {
|
| + return mSelectionController.getSelectedText();
|
| + }
|
| +
|
| + /**
|
| + * Simulates a long-press on the given node.
|
| + * @param nodeId A string containing the node ID.
|
| + */
|
| + private void longPressNode(String nodeId) throws InterruptedException, TimeoutException {
|
| + Tab tab = getActivity().getActivityTab();
|
| + DOMUtils.longPressNode(this, tab.getContentViewCore(), nodeId);
|
| + waitForPanelToPeekAndAssert();
|
| + }
|
|
|
| /**
|
| * Posts a fake response on the Main thread.
|
| @@ -270,8 +191,8 @@
|
| private final int mEndAdjust;
|
|
|
| public FakeResponseOnMainThread(boolean isNetworkUnavailable, int responseCode,
|
| - String searchTerm, String displayText, String alternateTerm,
|
| - boolean doPreventPreload, int startAdjust, int endAdjudst) {
|
| + String searchTerm, String displayText, String alternateTerm,
|
| + boolean doPreventPreload, int startAdjust, int endAdjudst) {
|
| mIsNetworkUnavailable = isNetworkUnavailable;
|
| mResponseCode = responseCode;
|
| mSearchTerm = searchTerm;
|
| @@ -314,147 +235,6 @@
|
| }
|
| }
|
|
|
| - //============================================================================================
|
| - // Content Helpers
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * @return The Panel's ContentViewCore.
|
| - */
|
| - private ContentViewCore getPanelContentViewCore() {
|
| - return mPanel.getContentViewCore();
|
| - }
|
| -
|
| - /**
|
| - * @return Whether the Panel's ContentViewCore is visible.
|
| - */
|
| - private boolean isContentViewCoreVisible() {
|
| - ContextualSearchFakeServer.ContentViewCoreWrapper contentViewCore =
|
| - (ContextualSearchFakeServer.ContentViewCoreWrapper) getPanelContentViewCore();
|
| - return contentViewCore != null ? contentViewCore.isVisible() : false;
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the Panel's ContentViewCore is created.
|
| - */
|
| - private void assertContentViewCoreCreated() {
|
| - assertNotNull(getPanelContentViewCore());
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the Panel's ContentViewCore is not created.
|
| - */
|
| - private void assertNoContentViewCore() {
|
| - assertNull(getPanelContentViewCore());
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the Panel's ContentViewCore is visible.
|
| - */
|
| - private void assertContentViewCoreVisible() {
|
| - assertTrue(isContentViewCoreVisible());
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the Panel's ContentViewCore onShow() method was never called.
|
| - */
|
| - private void assertNeverCalledContentViewCoreOnShow() {
|
| - assertFalse(mFakeServer.didEverCallContentViewCoreOnShow());
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the Panel's ContentViewCore is created
|
| - */
|
| - private void assertContentViewCoreCreatedButNeverMadeVisible() {
|
| - assertContentViewCoreCreated();
|
| - assertFalse(isContentViewCoreVisible());
|
| - assertNeverCalledContentViewCoreOnShow();
|
| - }
|
| -
|
| - /**
|
| - * Fakes navigation of the Content View to the URL was previously requested.
|
| - * @param isFailure whether the request resulted in a failure.
|
| - */
|
| - private void fakeContentViewDidNavigate(boolean isFailure) {
|
| - String url = mFakeServer.getLoadedUrl();
|
| - mManager.getOverlayContentDelegate().onMainFrameNavigation(url, isFailure);
|
| - }
|
| -
|
| - /**
|
| - * A ContentViewCore that has some methods stubbed out for testing.
|
| - * TODO(pedrosimonetti): consider using the real ContentViewCore instead.
|
| - */
|
| - private static final class StubbedContentViewCore extends ContentViewCore {
|
| - private boolean mIsFocusedNodeEditable;
|
| -
|
| - public StubbedContentViewCore(Context context) {
|
| - super(context);
|
| - }
|
| -
|
| - /**
|
| - * Mocks the result of isFocusedNodeEditable() for testing.
|
| - * @param isFocusedNodeEditable Whether the focused node is editable.
|
| - */
|
| - public void setIsFocusedNodeEditableForTest(boolean isFocusedNodeEditable) {
|
| - mIsFocusedNodeEditable = isFocusedNodeEditable;
|
| - }
|
| -
|
| - @Override
|
| - public boolean isFocusedNodeEditable() {
|
| - return mIsFocusedNodeEditable;
|
| - }
|
| - }
|
| -
|
| - //============================================================================================
|
| - // Other Helpers
|
| - // TODO(pedrosimonetti): organize into sections.
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * Simulates a click on the given word node.
|
| - * Waits for the bar to peek.
|
| - * @param nodeId A string containing the node ID.
|
| - */
|
| - private void clickWordNode(String nodeId) throws InterruptedException, TimeoutException {
|
| - clickNode(nodeId);
|
| - waitForPanelToPeekAndAssert();
|
| - }
|
| -
|
| - /**
|
| - * Simulates a key press.
|
| - * @param keycode The key's code.
|
| - */
|
| - private void pressKey(int keycode) {
|
| - getInstrumentation().sendKeyDownUpSync(keycode);
|
| - getInstrumentation().waitForIdleSync();
|
| - }
|
| -
|
| - /**
|
| - * Simulates pressing back button.
|
| - */
|
| - private void pressBackButton() {
|
| - pressKey(KeyEvent.KEYCODE_BACK);
|
| - }
|
| -
|
| - /**
|
| - * @return The selected text.
|
| - */
|
| - private String getSelectedText() {
|
| - return mSelectionController.getSelectedText();
|
| - }
|
| -
|
| - /**
|
| - * Asserts that the loaded search term matches the provided value.
|
| - * @param searchTerm The provided search term.
|
| - */
|
| - private void assertLoadedSearchTermMatches(String searchTerm) {
|
| - boolean doesMatch = false;
|
| - if (mFakeServer != null) {
|
| - doesMatch = mFakeServer.getLoadedUrl().contains("q=" + searchTerm);
|
| - }
|
| - assertTrue(doesMatch);
|
| - }
|
| -
|
| private void assertContainsParameters(String searchTerm, String alternateTerm) {
|
| assertTrue(mFakeServer == null || mFakeServer.getSearchTermRequested() == null
|
| || mFakeServer.getLoadedUrl().contains(searchTerm)
|
| @@ -497,7 +277,7 @@
|
| && mFakeServer.getLoadedUrl().contains(LOW_PRIORITY_SEARCH_ENDPOINT));
|
| assertTrue("Low priority request does not have the required prefetch parameter!",
|
| mFakeServer.getLoadedUrl() != null
|
| - && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH_PREFETCH_PARAM));
|
| + && mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH_PREFETCH_PARAM));
|
| }
|
|
|
| private void assertLoadedNormalPriorityUrl() {
|
| @@ -508,12 +288,20 @@
|
| && mFakeServer.getLoadedUrl().contains(NORMAL_PRIORITY_SEARCH_ENDPOINT));
|
| assertTrue("Normal priority request should not have the prefetch parameter, but did!",
|
| mFakeServer.getLoadedUrl() != null
|
| - && !mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH_PREFETCH_PARAM));
|
| + && !mFakeServer.getLoadedUrl().contains(CONTEXTUAL_SEARCH_PREFETCH_PARAM));
|
| }
|
|
|
| private void assertNoSearchesLoaded() {
|
| - assertEquals(0, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(0, mFakeServer.loadedUrlCount());
|
| assertLoadedNoUrl();
|
| + }
|
| +
|
| + private void assertContentViewCoreCreated() {
|
| + assertTrue(mFakeServer.didCreateContentView());
|
| + }
|
| +
|
| + private void assertNoContentViewCore() {
|
| + assertFalse(mFakeServer.didCreateContentView());
|
| }
|
|
|
| /**
|
| @@ -530,6 +318,16 @@
|
| private void assertTapPromoCounterDisabledAt(int expectedCount) {
|
| assertFalse(mPolicy.getPromoTapCounter().isEnabled());
|
| assertEquals(expectedCount, mPolicy.getPromoTapCounter().getCount());
|
| + }
|
| +
|
| + /**
|
| + * Fakes navigation of the Content View with the given httpResult code.
|
| + * The URL of the navigation is the one requested previously.
|
| + * @param isFailure If the request resulted in a failure.
|
| + */
|
| + private void fakeContentViewDidNavigate(boolean isFailure) {
|
| + String url = mFakeServer.getLoadedUrl();
|
| + mManager.getOverlayContentDelegate().onMainFrameNavigation(url, isFailure);
|
| }
|
|
|
| /**
|
| @@ -619,6 +417,20 @@
|
| }
|
|
|
| /**
|
| + * Waits for the selected text string to be the given string, and asserts.
|
| + * @param text The string to wait for the selection to become.
|
| + */
|
| + private void waitForSelectionToBe(final String text) throws InterruptedException {
|
| + assertTrue("Bar never showed desired text.",
|
| + CriteriaHelper.pollForCriteria(new Criteria() {
|
| + @Override
|
| + public boolean isSatisfied() {
|
| + return TextUtils.equals(text, getSelectedText());
|
| + }
|
| + }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL));
|
| + }
|
| +
|
| + /**
|
| * Waits for the selection to be dissolved.
|
| * Use this method any time a test repeatedly establishes and dissolves a selection to ensure
|
| * that the selection has been completely dissolved before simulating the next selection event.
|
| @@ -642,13 +454,24 @@
|
| waitForSelectionDissolved();
|
| }
|
|
|
| - private void waitToPreventDoubleTapRecognition() throws InterruptedException {
|
| - // Avoid issues with double-tap detection by ensuring sequential taps
|
| - // aren't treated as such. Double-tapping can also select words much as
|
| - // longpress, in turn showing the pins and preventing contextual tap
|
| - // refinement from nearby taps. The double-tap timeout is sufficiently
|
| - // short that this shouldn't conflict with tap refinement by the user.
|
| - Thread.sleep(ViewConfiguration.getDoubleTapTimeout());
|
| + /**
|
| + * A ContentViewCore that has some methods stubbed out for testing.
|
| + */
|
| + private static final class StubbedContentViewCore extends ContentViewCore {
|
| + private boolean mIsFocusedNodeEditable;
|
| +
|
| + public StubbedContentViewCore(Context context) {
|
| + super(context);
|
| + }
|
| +
|
| + public void setIsFocusedNodeEditableForTest(boolean isFocusedNodeEditable) {
|
| + mIsFocusedNodeEditable = isFocusedNodeEditable;
|
| + }
|
| +
|
| + @Override
|
| + public boolean isFocusedNodeEditable() {
|
| + return mIsFocusedNodeEditable;
|
| + }
|
| }
|
|
|
| /**
|
| @@ -669,21 +492,14 @@
|
| }
|
|
|
| /**
|
| - * Swipes the panel up to its expanded state.
|
| + * Swipes the panel up to it's expanded size.
|
| */
|
| private void swipePanelUp() {
|
| swipe(0.5f, 0.95f, 0.5f, 0.55f, 1000);
|
| }
|
|
|
| /**
|
| - * Swipes the panel down to its peeked state.
|
| - */
|
| - private void swipePanelDown() {
|
| - swipe(0.5f, 0.55f, 0.5f, 0.95f, 1000);
|
| - }
|
| -
|
| - /**
|
| - * Swipes the panel up to its maximized state.
|
| + * Swipes the panel up to it's maximized size.
|
| */
|
| private void swipePanelUpToTop() {
|
| swipe(0.5f, 0.95f, 0.5f, 0.05f, 1000);
|
| @@ -700,15 +516,7 @@
|
| * Taps the base page near the top.
|
| */
|
| private void tapBasePageToClosePanel() throws InterruptedException {
|
| - // TODO(pedrosimonetti): This is not reliable. Find a better approach.
|
| - // We use the far right side (x == 0.9f) to prevent simulating a tap on top of an
|
| - // existing long-press selection (the pins are a tap target). This might not work on RTL.
|
| - // We are using y == 0.2f because otherwise it will fail for long press cases.
|
| - // It might be better to get the position of the Panel and tap just about outside
|
| - // the Panel. I suspect some Flaky tests are caused by this problem (ones involving
|
| - // long press and trying to close with the bar peeking, with a long press selection
|
| - // established).
|
| - tapBasePage(0.9f, 0.2f);
|
| + tapBasePage(0.1f, 0.1f);
|
| waitForPanelToCloseAndAssert();
|
| }
|
|
|
| @@ -831,10 +639,6 @@
|
| }, TEST_TIMEOUT, DEFAULT_POLLING_INTERVAL);
|
| }
|
|
|
| - //============================================================================================
|
| - // Test Cases
|
| - //============================================================================================
|
| -
|
| /**
|
| * Tests whether the contextual search panel hides when omnibox is clicked.
|
| */
|
| @@ -943,13 +747,13 @@
|
| fakeResponse(false, 200, "Intelligence", "United States Intelligence", "alternate-term",
|
| false);
|
| assertContainsParameters("Intelligence", "alternate-term");
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertLoadedLowPriorityUrl();
|
|
|
| waitForPanelToPeekAndAssert();
|
| swipePanelUp();
|
| waitForPanelToExpandAndAssert();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertLoadedLowPriorityUrl();
|
| }
|
|
|
| @@ -963,10 +767,6 @@
|
| public void testLongPressSwipeExpand() throws InterruptedException, TimeoutException {
|
| longPressNode("intelligence");
|
| assertNoContentViewCore();
|
| -
|
| - // TODO(pedrosimonetti): Long press does not resolve so we shouldn't be faking one.
|
| - // Consider changing the fake server to create a fake response automatically,
|
| - // when one is requested by the Manager.
|
|
|
| // Fake a search term resolution response.
|
| fakeResponse(false, 200, "Intelligence", "United States Intelligence", "alternate-term",
|
| @@ -980,11 +780,11 @@
|
| waitForPanelToExpandAndAssert();
|
| assertContentViewCoreCreated();
|
| assertLoadedNormalPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // tap the base page to close.
|
| tapBasePageToClosePanel();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertNoContentViewCore();
|
| }
|
|
|
| @@ -1019,16 +819,16 @@
|
| // Fake a search term resolution response.
|
| fakeResponse(false, 200, "states", "United States Intelligence", "alternate-term", false);
|
| assertContainsParameters("states", "alternate-term");
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertLoadedLowPriorityUrl();
|
| assertContentViewCoreCreated();
|
| tapPeekingBarToExpandAndAssert();
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // tap the base page to close.
|
| tapBasePageToClosePanel();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertNoContentViewCore();
|
| }
|
|
|
| @@ -1044,20 +844,20 @@
|
|
|
| // We should not make a second-request until we get a good response from the first-request.
|
| assertLoadedNoUrl();
|
| - assertEquals(0, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(0, mFakeServer.loadedUrlCount());
|
| fakeResponse(false, 200, "states", "United States Intelligence", "alternate-term", false);
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // When the second request succeeds, we should not issue a new request.
|
| fakeContentViewDidNavigate(false);
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // When the bar opens, we should not make any additional request.
|
| tapPeekingBarToExpandAndAssert();
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
| assertLoadedLowPriorityUrl();
|
| }
|
|
|
| @@ -1074,20 +874,20 @@
|
|
|
| // We should not make a SERP request until we get a good response from the resolve request.
|
| assertLoadedNoUrl();
|
| - assertEquals(0, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(0, mFakeServer.loadedUrlCount());
|
| fakeResponse(false, 200, "states", "United States Intelligence", "alternate-term", false);
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // When the second request fails, we should not issue a new request.
|
| fakeContentViewDidNavigate(true);
|
| assertLoadedLowPriorityUrl();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(1, mFakeServer.loadedUrlCount());
|
|
|
| // Once the bar opens, we make a new request at normal priority.
|
| tapPeekingBarToExpandAndAssert();
|
| assertLoadedNormalPriorityUrl();
|
| - assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| + assertEquals(2, mFakeServer.loadedUrlCount());
|
| }
|
|
|
| /**
|
| @@ -1654,7 +1454,6 @@
|
| assertContainsParameters("states", "alternate-term");
|
| assertLoadedNormalPriorityUrl();
|
| assertContentViewCoreCreated();
|
| - assertContentViewCoreVisible();
|
| }
|
|
|
| /**
|
| @@ -2196,327 +1995,4 @@
|
| waitForPanelToPeekAndAssert();
|
| assertFalse(mPanel.isPeekPromoVisible());
|
| }
|
| -
|
| - //============================================================================================
|
| - // Content Tests
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * Tests that tap followed by expand makes Content visible.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testTapContentVisibility() throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure Content is not visible.
|
| - simulateTapSearch("search");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| -
|
| - // Expanding the Panel should make the Content visible.
|
| - tapPeekingBarToExpandAndAssert();
|
| - assertContentViewCoreVisible();
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - }
|
| -
|
| - /**
|
| - * Tests that long press followed by expand creates Content and makes it visible.
|
| - *
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testLongPressContentVisibility() throws InterruptedException, TimeoutException {
|
| - // Simulate a long press and make sure no Content is created.
|
| - simulateLongPressSearch("search");
|
| - assertNoContentViewCore();
|
| - assertNoSearchesLoaded();
|
| -
|
| - // Expanding the Panel should make the Content visible.
|
| - tapPeekingBarToExpandAndAssert();
|
| - assertContentViewCoreCreated();
|
| - assertContentViewCoreVisible();
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - }
|
| -
|
| - /**
|
| - * Tests swiping panel up and down after a tap search will only load the Content once.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testTapMultipleSwipeOnlyLoadsContentOnce()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure Content is not visible.
|
| - simulateTapSearch("search");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel should make the Content visible.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel down should not change the visibility or load content again.
|
| - swipePanelDown();
|
| - waitForPanelToPeekAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel up should not change the visibility or load content again.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - }
|
| -
|
| - /**
|
| - * Tests swiping panel up and down after a long press search will only load the Content once.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testLongPressMultipleSwipeOnlyLoadsContentOnce()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a long press and make sure no Content is created.
|
| - simulateLongPressSearch("search");
|
| - assertNoContentViewCore();
|
| - assertNoSearchesLoaded();
|
| -
|
| - // Swiping the Panel should load the URL and make the Content visible.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreCreated();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel down should not change the visibility or load content again.
|
| - swipePanelDown();
|
| - waitForPanelToPeekAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel up should not change the visibility or load content again.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - }
|
| -
|
| - /**
|
| - * Tests that chained tap searches create new Content.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testChainedSearchCreatesNewContent()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure Content is not visible.
|
| - simulateTapSearch("search");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - ContentViewCore cvc1 = getPanelContentViewCore();
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Simulate a new tap and make sure a new Content is created.
|
| - simulateTapSearch("term");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| - ContentViewCore cvc2 = getPanelContentViewCore();
|
| - assertNotSame(cvc1, cvc2);
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Simulate a new tap and make sure a new Content is created.
|
| - simulateTapSearch("resolution");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(3, mFakeServer.getLoadedUrlCount());
|
| - ContentViewCore cvc3 = getPanelContentViewCore();
|
| - assertNotSame(cvc2, cvc3);
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - assertEquals(3, mFakeServer.getLoadedUrlCount());
|
| - }
|
| -
|
| - /**
|
| - * Tests that chained searches load correctly.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction({RESTRICTION_TYPE_NON_LOW_END_DEVICE})
|
| - public void testChainedSearchLoadsCorrectSearchTerm()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure Content is not visible.
|
| - simulateTapSearch("search");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - ContentViewCore cvc1 = getPanelContentViewCore();
|
| -
|
| - // Swiping the Panel should make the Content visible.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel down should not change the visibility or load content again.
|
| - swipePanelDown();
|
| - waitForPanelToPeekAndAssert();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Now simulate a long press, leaving the Panel peeking.
|
| - simulateLongPressSearch("resolution");
|
| -
|
| - // Swiping the Panel up should load and display the new search.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreCreated();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| - assertLoadedSearchTermMatches("Resolution");
|
| - ContentViewCore cvc2 = getPanelContentViewCore();
|
| - assertNotSame(cvc1, cvc2);
|
| -
|
| - // Closing the Panel should destroy the Content.
|
| - tapBasePageToClosePanel();
|
| - assertNoContentViewCore();
|
| - assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| - }
|
| -
|
| - /**
|
| - * Tests that chained searches make Content visible when opening the Panel.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testChainedSearchContentVisibility()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure Content is not visible.
|
| - simulateTapSearch("search");
|
| - assertContentViewCoreCreatedButNeverMadeVisible();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - ContentViewCore cvc1 = getPanelContentViewCore();
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Now simulate a long press, leaving the Panel peeking.
|
| - simulateLongPressSearch("resolution");
|
| - assertNeverCalledContentViewCoreOnShow();
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| -
|
| - // Swiping the Panel up should load and display the new search.
|
| - swipePanelUp();
|
| - waitForPanelToExpandAndAssert();
|
| - assertContentViewCoreCreated();
|
| - assertContentViewCoreVisible();
|
| - assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| - assertLoadedSearchTermMatches("Resolution");
|
| - ContentViewCore cvc2 = getPanelContentViewCore();
|
| - assertNotSame(cvc1, cvc2);
|
| - }
|
| -
|
| - //============================================================================================
|
| - // History Removal Tests
|
| - //============================================================================================
|
| -
|
| - /**
|
| - * Tests that a tap followed by closing the Panel removes the loaded URL from history.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testTapCloseRemovedFromHistory()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure a URL was loaded.
|
| - simulateTapSearch("search");
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - String url = mFakeServer.getLoadedUrl();
|
| -
|
| - // Close the Panel without seeing the Content.
|
| - tapBasePageToClosePanel();
|
| -
|
| - // Now check that the URL has been removed from history.
|
| - assertTrue(mFakeServer.hasRemovedUrl(url));
|
| - }
|
| -
|
| - /**
|
| - * Tests that a tap followed by opening the Panel does not remove the loaded URL from history.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testTapExpandNotRemovedFromHistory()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure a URL was loaded.
|
| - simulateTapSearch("search");
|
| - assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| - String url = mFakeServer.getLoadedUrl();
|
| -
|
| - // Expand Panel so that the Content becomes visible.
|
| - tapPeekingBarToExpandAndAssert();
|
| -
|
| - // Close the Panel.
|
| - tapBasePageToClosePanel();
|
| -
|
| - // Now check that the URL has not been removed from history, since the Content was seen.
|
| - assertFalse(mFakeServer.hasRemovedUrl(url));
|
| - }
|
| -
|
| - /**
|
| - * Tests that chained searches without opening the Panel removes all loaded URLs from history.
|
| - */
|
| - @SmallTest
|
| - @Feature({"ContextualSearch"})
|
| - @Restriction(RESTRICTION_TYPE_NON_LOW_END_DEVICE)
|
| - public void testChainedTapsRemovedFromHistory()
|
| - throws InterruptedException, TimeoutException {
|
| - // Simulate a tap and make sure a URL was loaded.
|
| - simulateTapSearch("search");
|
| - String url1 = mFakeServer.getLoadedUrl();
|
| - assertNotNull(url1);
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Simulate another tap and make sure another URL was loaded.
|
| - simulateTapSearch("term");
|
| - String url2 = mFakeServer.getLoadedUrl();
|
| - assertNotSame(url1, url2);
|
| -
|
| - waitToPreventDoubleTapRecognition();
|
| -
|
| - // Simulate another tap and make sure another URL was loaded.
|
| - simulateTapSearch("resolution");
|
| - String url3 = mFakeServer.getLoadedUrl();
|
| - assertNotSame(url2, url3);
|
| -
|
| - // Close the Panel without seeing any Content.
|
| - tapBasePageToClosePanel();
|
| -
|
| - // Now check that all three URLs have been removed from history.
|
| - assertEquals(3, mFakeServer.getLoadedUrlCount());
|
| - assertTrue(mFakeServer.hasRemovedUrl(url1));
|
| - assertTrue(mFakeServer.hasRemovedUrl(url2));
|
| - assertTrue(mFakeServer.hasRemovedUrl(url3));
|
| - }
|
| }
|
|
|