| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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.dom_distiller; | 5 package org.chromium.chrome.browser.dom_distiller; |
| 6 | 6 |
| 7 import android.support.test.InstrumentationRegistry; | 7 import android.support.test.InstrumentationRegistry; |
| 8 import android.support.test.filters.MediumTest; | 8 import android.support.test.filters.MediumTest; |
| 9 | 9 |
| 10 import org.junit.Assert; | 10 import org.junit.Assert; |
| 11 import org.junit.Before; | 11 import org.junit.Before; |
| 12 import org.junit.Rule; | 12 import org.junit.Rule; |
| 13 import org.junit.Test; | 13 import org.junit.Test; |
| 14 import org.junit.runner.RunWith; | 14 import org.junit.runner.RunWith; |
| 15 | 15 |
| 16 import org.chromium.base.test.util.CallbackHelper; |
| 16 import org.chromium.base.test.util.CommandLineFlags; | 17 import org.chromium.base.test.util.CommandLineFlags; |
| 17 import org.chromium.base.test.util.DisabledTest; | |
| 18 import org.chromium.base.test.util.Feature; | 18 import org.chromium.base.test.util.Feature; |
| 19 import org.chromium.base.test.util.Restriction; | 19 import org.chromium.base.test.util.Restriction; |
| 20 import org.chromium.chrome.browser.ChromeActivity; | 20 import org.chromium.chrome.browser.ChromeActivity; |
| 21 import org.chromium.chrome.browser.ChromeSwitches; | 21 import org.chromium.chrome.browser.ChromeSwitches; |
| 22 import org.chromium.chrome.browser.compositor.bottombar.readermode.ReaderModePan
el; | 22 import org.chromium.chrome.browser.infobar.InfoBar; |
| 23 import org.chromium.chrome.browser.infobar.InfoBarContainer; |
| 24 import org.chromium.chrome.browser.infobar.InfoBarContainer.InfoBarContainerObse
rver; |
| 25 import org.chromium.chrome.browser.infobar.ReaderModeInfoBar; |
| 26 import org.chromium.chrome.browser.tab.Tab; |
| 23 import org.chromium.chrome.test.ChromeActivityTestRule; | 27 import org.chromium.chrome.test.ChromeActivityTestRule; |
| 24 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; | 28 import org.chromium.chrome.test.ChromeJUnit4ClassRunner; |
| 25 import org.chromium.chrome.test.util.ChromeRestriction; | 29 import org.chromium.chrome.test.util.ChromeRestriction; |
| 26 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; | 30 import org.chromium.content.browser.test.util.TestCallbackHelperContainer.OnPage
FinishedHelper; |
| 27 import org.chromium.content.browser.test.util.TestWebContentsObserver; | 31 import org.chromium.content.browser.test.util.TestWebContentsObserver; |
| 28 import org.chromium.net.test.EmbeddedTestServer; | 32 import org.chromium.net.test.EmbeddedTestServer; |
| 29 | 33 |
| 30 import java.util.concurrent.TimeoutException; | 34 import java.util.concurrent.TimeoutException; |
| 31 | 35 |
| 32 /** | 36 /** |
| (...skipping 15 matching lines...) Expand all Loading... |
| 48 mActivityTestRule.startMainActivityOnBlankPage(); | 52 mActivityTestRule.startMainActivityOnBlankPage(); |
| 49 } | 53 } |
| 50 | 54 |
| 51 /** | 55 /** |
| 52 * Make sure that Reader Mode appears after navigating from a native page. | 56 * Make sure that Reader Mode appears after navigating from a native page. |
| 53 */ | 57 */ |
| 54 @Test | 58 @Test |
| 55 @Feature({"Distillability-Service"}) | 59 @Feature({"Distillability-Service"}) |
| 56 @MediumTest | 60 @MediumTest |
| 57 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) | 61 @Restriction(ChromeRestriction.RESTRICTION_TYPE_PHONE) |
| 58 @DisabledTest | |
| 59 public void testServiceAliveAfterNativePage() throws InterruptedException, T
imeoutException { | 62 public void testServiceAliveAfterNativePage() throws InterruptedException, T
imeoutException { |
| 60 EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartServer( | 63 EmbeddedTestServer testServer = EmbeddedTestServer.createAndStartServer( |
| 61 InstrumentationRegistry.getInstrumentation().getContext()); | 64 InstrumentationRegistry.getInstrumentation().getContext()); |
| 62 | 65 |
| 63 final ReaderModePanel panel = | 66 final CallbackHelper readerShownCallbackHelper = new CallbackHelper(); |
| 64 mActivityTestRule.getActivity().getReaderModeManager().getPanelF
orTesting(); | 67 |
| 68 Tab tab = mActivityTestRule.getActivity().getActivityTab(); |
| 69 tab.getInfoBarContainer().addObserver(new InfoBarContainerObserver() { |
| 70 @Override |
| 71 public void onAddInfoBar(InfoBarContainer container, InfoBar infoBar
, boolean isFirst) { |
| 72 if (infoBar instanceof ReaderModeInfoBar) readerShownCallbackHel
per.notifyCalled(); |
| 73 } |
| 74 |
| 75 @Override |
| 76 public void onRemoveInfoBar( |
| 77 InfoBarContainer container, InfoBar infoBar, boolean isLast)
{} |
| 78 |
| 79 @Override |
| 80 public void onInfoBarContainerAttachedToWindow(boolean hasInfobars)
{} |
| 81 }); |
| 65 | 82 |
| 66 TestWebContentsObserver observer = new TestWebContentsObserver( | 83 TestWebContentsObserver observer = new TestWebContentsObserver( |
| 67 mActivityTestRule.getActivity().getActivityTab().getWebContents(
)); | 84 mActivityTestRule.getActivity().getActivityTab().getWebContents(
)); |
| 68 OnPageFinishedHelper finishHelper = observer.getOnPageFinishedHelper(); | 85 OnPageFinishedHelper finishHelper = observer.getOnPageFinishedHelper(); |
| 69 | 86 |
| 70 // Navigate to a native page. | 87 // Navigate to a native page. |
| 71 int curCallCount = finishHelper.getCallCount(); | 88 int curCallCount = finishHelper.getCallCount(); |
| 72 mActivityTestRule.loadUrl("chrome://history"); | 89 mActivityTestRule.loadUrl("chrome://history"); |
| 73 finishHelper.waitForCallback(curCallCount, 1); | 90 finishHelper.waitForCallback(curCallCount, 1); |
| 74 Assert.assertFalse(panel.isShowing()); | 91 Assert.assertEquals(0, readerShownCallbackHelper.getCallCount()); |
| 75 | 92 |
| 76 // Navigate to a normal page. | 93 // Navigate to a normal page. |
| 77 curCallCount = finishHelper.getCallCount(); | 94 curCallCount = readerShownCallbackHelper.getCallCount(); |
| 78 mActivityTestRule.loadUrl(testServer.getURL(TEST_PAGE)); | 95 mActivityTestRule.loadUrl(testServer.getURL(TEST_PAGE)); |
| 79 finishHelper.waitForCallback(curCallCount, 1); | 96 readerShownCallbackHelper.waitForCallback(curCallCount, 1); |
| 80 Assert.assertTrue(panel.isShowing()); | 97 Assert.assertEquals(1, readerShownCallbackHelper.getCallCount()); |
| 81 } | 98 } |
| 82 } | 99 } |
| OLD | NEW |