| 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 ed62c5a9238ee08b103176e7dab30be67246ba56..bc60e6c37a0a0c3ce7119594f671e70bc0763f8c 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
|
| @@ -806,13 +806,46 @@
|
| }
|
|
|
| /**
|
| - * Click to cause the panel to show, tap the Bar to expand, then close.
|
| + * 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.35f 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.35f);
|
| + waitForPanelToClose();
|
| + }
|
| +
|
| + /**
|
| + * Taps the base page at the given x, y position.
|
| + */
|
| + private void tapBasePage(float x, float y) {
|
| + View root = getActivity().getWindow().getDecorView().getRootView();
|
| + x *= root.getWidth();
|
| + y *= root.getHeight();
|
| + TouchCommon.singleClickView(root, (int) x, (int) y);
|
| + }
|
| +
|
| + /**
|
| + * Click various places to cause the panel to show, expand, then close.
|
| */
|
| private void clickToExpandAndClosePanel() throws InterruptedException, TimeoutException {
|
| clickWordNode("states");
|
| + tapBarToExpandAndClosePanel();
|
| + waitForSelectionDissolved();
|
| + }
|
| +
|
| + /**
|
| + * Tap on the peeking Bar to expand the panel, then taps on the base page to close it.
|
| + */
|
| + private void tapBarToExpandAndClosePanel() throws InterruptedException {
|
| tapPeekingBarToExpandAndAssert();
|
| - closePanel();
|
| - waitForSelectionDissolved();
|
| + tapBasePageToClosePanel();
|
| }
|
|
|
| /**
|
| @@ -1077,8 +1110,8 @@
|
| assertLoadedNormalPriorityUrl();
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
|
|
| - // close the panel.
|
| - closePanel();
|
| + // tap the base page to close.
|
| + tapBasePageToClosePanel();
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| assertNoContentViewCore();
|
| }
|
| @@ -1703,7 +1736,7 @@
|
| pressAppMenuKey();
|
| assertAppMenuVisibility(false);
|
|
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
|
|
| pressAppMenuKey();
|
| assertAppMenuVisibility(true);
|
| @@ -1869,7 +1902,7 @@
|
|
|
| /**
|
| * Tests that ContextualSearchObserver gets notified when user brings up contextual search
|
| - * panel via long press and when the panel is dismissed.
|
| + * panel via long press and then dismisses the panel by tapping on the base page.
|
| */
|
| @SmallTest
|
| @Feature({"ContextualSearch"})
|
| @@ -1882,13 +1915,13 @@
|
| longPressNode("states");
|
| assertEquals(0, observer.hideCount);
|
|
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertEquals(1, observer.hideCount);
|
| }
|
|
|
| /**
|
| * Tests that ContextualSearchObserver gets notified when user brings up contextual search
|
| - * panel via tap and when the panel is dismissed.
|
| + * panel via tap and then dismisses the panel by tapping on the base page.
|
| */
|
| @SmallTest
|
| @Feature({"ContextualSearch"})
|
| @@ -1899,7 +1932,7 @@
|
| clickWordNode("states");
|
| assertEquals(0, observer.hideCount);
|
|
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertEquals(1, observer.hideCount);
|
| }
|
|
|
| @@ -2122,7 +2155,7 @@
|
| assertFalse(mPanel.isPeekPromoVisible());
|
|
|
| // After closing the Panel the Promo should still be invisible.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertFalse(mPanel.isPeekPromoVisible());
|
|
|
| // Click elsewhere to clear the selection.
|
| @@ -2156,7 +2189,7 @@
|
| assertContentViewCoreVisible();
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| }
|
|
|
| @@ -2179,7 +2212,7 @@
|
| assertContentViewCoreVisible();
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| }
|
|
|
| @@ -2213,7 +2246,7 @@
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| }
|
| @@ -2249,7 +2282,7 @@
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| assertEquals(1, mFakeServer.getLoadedUrlCount());
|
| }
|
| @@ -2288,7 +2321,7 @@
|
| assertNotSame(cvc2, cvc3);
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| assertEquals(3, mFakeServer.getLoadedUrlCount());
|
| }
|
| @@ -2334,7 +2367,7 @@
|
| assertNotSame(cvc1, cvc2);
|
|
|
| // Closing the Panel should destroy the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
| assertNoContentViewCore();
|
| assertEquals(2, mFakeServer.getLoadedUrlCount());
|
| }
|
| @@ -2389,7 +2422,7 @@
|
| String url = mFakeServer.getLoadedUrl();
|
|
|
| // Close the Panel without seeing the Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
|
|
| // Now check that the URL has been removed from history.
|
| assertTrue(mFakeServer.hasRemovedUrl(url));
|
| @@ -2412,7 +2445,7 @@
|
| tapPeekingBarToExpandAndAssert();
|
|
|
| // Close the Panel.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
|
|
| // Now check that the URL has not been removed from history, since the Content was seen.
|
| assertFalse(mFakeServer.hasRemovedUrl(url));
|
| @@ -2447,7 +2480,7 @@
|
| assertNotSame(url2, url3);
|
|
|
| // Close the Panel without seeing any Content.
|
| - closePanel();
|
| + tapBasePageToClosePanel();
|
|
|
| // Now check that all three URLs have been removed from history.
|
| assertEquals(3, mFakeServer.getLoadedUrlCount());
|
| @@ -2565,14 +2598,15 @@
|
|
|
| /**
|
| * Tests that Contextual Search works in fullscreen. Specifically, tests that tapping a word
|
| - * peeks the panel, expanding the bar results in the bar ending at the correct spot in the page.
|
| + * peeks the panel, expanding the bar results in the bar ending at the correct spot in the page
|
| + * and tapping the base page closes the panel.
|
| */
|
| @SmallTest
|
| @Feature({"ContextualSearch"})
|
| @Restriction({ChromeRestriction.RESTRICTION_TYPE_PHONE, RESTRICTION_TYPE_NON_LOW_END_DEVICE})
|
| public void testTapContentAndExpandPanelInFullscreen()
|
| throws InterruptedException, TimeoutException {
|
| - // Toggle tab to fullscreen.
|
| + // Toggle tab to fulllscreen.
|
| FullscreenTestUtils.togglePersistentFullscreenAndAssert(getActivity().getActivityTab(),
|
| true, getActivity());
|
|
|
| @@ -2583,6 +2617,9 @@
|
| tapPeekingBarToExpandAndAssert();
|
| assertEquals(mManager.getContextualSearchPanel().getHeight(),
|
| mManager.getContextualSearchPanel().getPanelHeightFromState(PanelState.EXPANDED));
|
| +
|
| + // Tap the base page and assert that the panel is closed.
|
| + tapBasePageToClosePanel();
|
| }
|
|
|
| /**
|
|
|