| Index: chrome/android/javatests/src/org/chromium/chrome/browser/HistoryUITest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/HistoryUITest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/HistoryUITest.java
|
| index 0607cf41846555f622e14cef4dcb1facd43e7351..248e44b0bded815872bb0dc50383aec0ec11ba3f 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/HistoryUITest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/HistoryUITest.java
|
| @@ -5,10 +5,18 @@
|
| package org.chromium.chrome.browser;
|
|
|
| import android.preference.PreferenceScreen;
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.LargeTest;
|
| import android.support.test.filters.MediumTest;
|
| import android.util.JsonReader;
|
|
|
| +import org.junit.After;
|
| +import org.junit.Assert;
|
| +import org.junit.Before;
|
| +import org.junit.Rule;
|
| +import org.junit.Test;
|
| +import org.junit.runner.RunWith;
|
| +
|
| import org.chromium.base.ThreadUtils;
|
| import org.chromium.base.test.util.CallbackHelper;
|
| import org.chromium.base.test.util.CommandLineFlags;
|
| @@ -21,7 +29,8 @@ import org.chromium.chrome.browser.preferences.privacy.ClearBrowsingDataPreferen
|
| import org.chromium.chrome.browser.tab.EmptyTabObserver;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| import org.chromium.chrome.browser.tab.TabObserver;
|
| -import org.chromium.chrome.test.ChromeActivityTestCaseBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| import org.chromium.chrome.test.util.ActivityUtils;
|
| import org.chromium.content.browser.ContentViewCore;
|
| import org.chromium.content.browser.test.util.Criteria;
|
| @@ -37,31 +46,29 @@ import java.util.concurrent.TimeoutException;
|
| /**
|
| * UI Tests for the history page.
|
| */
|
| -@CommandLineFlags.Add("disable-features=AndroidHistoryManager")
|
| -public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({"disable-features=AndroidHistoryManager",
|
| + ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG})
|
| +public class HistoryUITest {
|
| + @Rule
|
| + public ChromeActivityTestRule<ChromeActivity> mActivityTestRule =
|
| + new ChromeActivityTestRule<>(ChromeActivity.class);
|
| +
|
| private static final String HISTORY_URL = "chrome://history-frame/";
|
|
|
| private EmbeddedTestServer mTestServer;
|
|
|
| - public HistoryUITest() {
|
| - super(ChromeActivity.class);
|
| - }
|
| -
|
| - @Override
|
| - protected void setUp() throws Exception {
|
| - super.setUp();
|
| - mTestServer = EmbeddedTestServer.createAndStartServer(getInstrumentation().getContext());
|
| + @Before
|
| + public void setUp() throws Exception {
|
| + mActivityTestRule.startMainActivityOnBlankPage();
|
| + mTestServer = EmbeddedTestServer.createAndStartServer(
|
| + InstrumentationRegistry.getInstrumentation().getContext());
|
| }
|
|
|
| - @Override
|
| - protected void tearDown() throws Exception {
|
| + @After
|
| + public void tearDown() throws Exception {
|
| mTestServer.stopAndDestroyServer();
|
| - super.tearDown();
|
| - }
|
| -
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityOnBlankPage();
|
| }
|
|
|
| private static class HistoryItem {
|
| @@ -75,15 +82,17 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
|
|
| private HistoryItem[] getHistoryContents() throws InterruptedException, TimeoutException {
|
| - getInstrumentation().waitForIdleSync();
|
| - String jsResults = runJavaScriptCodeInCurrentTab(new StringBuilder()
|
| - .append("var rawResults = document.querySelectorAll('.title');\n")
|
| - .append("var results = [];\n")
|
| - .append("for (i = 0; i < rawResults.length; ++i) {\n")
|
| - .append(" results.push([rawResults[i].childNodes[0].href,\n")
|
| - .append(" rawResults[i].childNodes[0].childNodes[0].textContent]);\n")
|
| - .append("}\n")
|
| - .append("results").toString());
|
| + InstrumentationRegistry.getInstrumentation().waitForIdleSync();
|
| + String jsResults = mActivityTestRule.runJavaScriptCodeInCurrentTab(
|
| + new StringBuilder()
|
| + .append("var rawResults = document.querySelectorAll('.title');\n")
|
| + .append("var results = [];\n")
|
| + .append("for (i = 0; i < rawResults.length; ++i) {\n")
|
| + .append(" results.push([rawResults[i].childNodes[0].href,\n")
|
| + .append(" rawResults[i].childNodes[0].childNodes[0].textContent]);\n")
|
| + .append("}\n")
|
| + .append("results")
|
| + .toString());
|
|
|
| JsonReader jsonReader = new JsonReader(new StringReader(jsResults));
|
| Vector<HistoryItem> results = new Vector<HistoryItem>();
|
| @@ -91,18 +100,18 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| jsonReader.beginArray();
|
| while (jsonReader.hasNext()) {
|
| jsonReader.beginArray();
|
| - assertTrue(jsonReader.hasNext());
|
| + Assert.assertTrue(jsonReader.hasNext());
|
| String url = jsonReader.nextString();
|
| - assertTrue(jsonReader.hasNext());
|
| + Assert.assertTrue(jsonReader.hasNext());
|
| String title = jsonReader.nextString();
|
| - assertFalse(jsonReader.hasNext());
|
| + Assert.assertFalse(jsonReader.hasNext());
|
| jsonReader.endArray();
|
| results.add(new HistoryItem(url, title));
|
| }
|
| jsonReader.endArray();
|
| jsonReader.close();
|
| } catch (IOException ioe) {
|
| - fail("Failed to evaluate JavaScript: " + jsResults + "\n" + ioe);
|
| + Assert.fail("Failed to evaluate JavaScript: " + jsResults + "\n" + ioe);
|
| }
|
|
|
| HistoryItem[] history = new HistoryItem[results.size()];
|
| @@ -112,7 +121,7 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
|
|
| private void removeSelectedHistoryEntryAtIndex(int index)
|
| throws InterruptedException, TimeoutException {
|
| - runJavaScriptCodeInCurrentTab(
|
| + mActivityTestRule.runJavaScriptCodeInCurrentTab(
|
| "document.getElementsByClassName('remove-entry')[" + index + "].click();");
|
| }
|
|
|
| @@ -146,18 +155,20 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| });
|
| }
|
|
|
| + @Test
|
| @MediumTest
|
| @Feature({"History"})
|
| @RetryOnFailure
|
| public void testSearchHistory() throws InterruptedException, TimeoutException {
|
| // Introduce some entries in the history page.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/get_title_test.html"));
|
| - loadUrl(HISTORY_URL);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 2);
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| + mActivityTestRule.loadUrl(
|
| + mTestServer.getURL("/chrome/test/data/android/get_title_test.html"));
|
| + mActivityTestRule.loadUrl(HISTORY_URL);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 2);
|
|
|
| // Search for one of them.
|
| - Tab tab = getActivity().getActivityTab();
|
| + Tab tab = mActivityTestRule.getActivity().getActivityTab();
|
| final CallbackHelper loadCallback = new CallbackHelper();
|
| TabObserver observer = new EmptyTabObserver() {
|
| @Override
|
| @@ -168,19 +179,20 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| }
|
| };
|
| tab.addObserver(observer);
|
| - runJavaScriptCodeInCurrentTab("historyView.setSearch('about')");
|
| + mActivityTestRule.runJavaScriptCodeInCurrentTab("historyView.setSearch('about')");
|
| loadCallback.waitForCallback(0);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 1);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 1);
|
|
|
| // Delete the search term.
|
| - runJavaScriptCodeInCurrentTab("historyView.setSearch('')");
|
| + mActivityTestRule.runJavaScriptCodeInCurrentTab("historyView.setSearch('')");
|
| loadCallback.waitForCallback(1);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 2);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 2);
|
| tab.removeObserver(observer);
|
| }
|
|
|
| // @LargeTest
|
| // @Feature({"History"})
|
| + @Test
|
| @DisabledTest
|
| public void testRemovingEntries() throws InterruptedException, TimeoutException {
|
| // Urls will be visited in reverse order to preserve the array ordering
|
| @@ -192,64 +204,69 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
|
|
| String[] testTitles = new String[testUrls.length];
|
| for (int i = testUrls.length - 1; i >= 0; --i) {
|
| - loadUrl(testUrls[i]);
|
| - testTitles[i] = getActivity().getActivityTab().getTitle();
|
| + mActivityTestRule.loadUrl(testUrls[i]);
|
| + testTitles[i] = mActivityTestRule.getActivity().getActivityTab().getTitle();
|
| }
|
|
|
| // Check that the history page contains the visited pages.
|
| - loadUrl(HISTORY_URL);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 2);
|
| + mActivityTestRule.loadUrl(HISTORY_URL);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 2);
|
|
|
| HistoryItem[] history = getHistoryContents();
|
| for (int i = 0; i < testUrls.length; ++i) {
|
| - assertEquals(testUrls[i], history[i].url);
|
| - assertEquals(testTitles[i], history[i].title);
|
| + Assert.assertEquals(testUrls[i], history[i].url);
|
| + Assert.assertEquals(testTitles[i], history[i].title);
|
| }
|
|
|
| // Remove the first entry from history.
|
| - assertTrue(history.length >= 1);
|
| + Assert.assertTrue(history.length >= 1);
|
| removeSelectedHistoryEntryAtIndex(0);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 1);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 1);
|
|
|
| // Check that now the first result is the second visited page.
|
| history = getHistoryContents();
|
| - assertEquals(testUrls[1], history[0].url);
|
| - assertEquals(testTitles[1], history[0].title);
|
| + Assert.assertEquals(testUrls[1], history[0].url);
|
| + Assert.assertEquals(testTitles[1], history[0].title);
|
| }
|
|
|
| + @Test
|
| @LargeTest
|
| @Feature({"History"})
|
| @RetryOnFailure
|
| public void testClearBrowsingData() throws InterruptedException, TimeoutException {
|
| // Introduce some entries in the history page.
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
| - loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| - loadUrl(HISTORY_URL);
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 2);
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/google.html"));
|
| + mActivityTestRule.loadUrl(mTestServer.getURL("/chrome/test/data/android/about.html"));
|
| + mActivityTestRule.loadUrl(HISTORY_URL);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 2);
|
|
|
| // Trigger cleaning up all the browsing data. JS finishing events will make it synchronous
|
| // to us.
|
| final Preferences prefActivity = ActivityUtils.waitForActivity(
|
| - getInstrumentation(), Preferences.class, new Runnable() {
|
| + InstrumentationRegistry.getInstrumentation(), Preferences.class, new Runnable() {
|
| @Override
|
| public void run() {
|
| try {
|
| - runJavaScriptCodeInCurrentTab("openClearBrowsingData()");
|
| + mActivityTestRule.runJavaScriptCodeInCurrentTab(
|
| + "openClearBrowsingData()");
|
| } catch (InterruptedException e) {
|
| - fail("Exception occurred while attempting to open clear browing data");
|
| + Assert.fail("Exception occurred while attempting to open clear browing"
|
| + + " data");
|
| } catch (TimeoutException e) {
|
| - fail("Exception occurred while attempting to open clear browing data");
|
| + Assert.fail("Exception occurred while attempting to open clear browing"
|
| + + " data");
|
| }
|
| }
|
| });
|
| - assertNotNull("Could not find the preferences activity", prefActivity);
|
| + Assert.assertNotNull("Could not find the preferences activity", prefActivity);
|
|
|
| final ClearBrowsingDataPreferences clearBrowsingFragment =
|
| (ClearBrowsingDataPreferences) prefActivity.getFragmentForTest();
|
| - assertNotNull("Could not find clear browsing data fragment", clearBrowsingFragment);
|
| + Assert.assertNotNull("Could not find clear browsing data fragment", clearBrowsingFragment);
|
|
|
| final ChromeActivity mainActivity = ActivityUtils.waitForActivity(
|
| - getInstrumentation(), getActivity().getClass(), new Runnable() {
|
| + InstrumentationRegistry.getInstrumentation(),
|
| + mActivityTestRule.getActivity().getClass(), new Runnable() {
|
| @Override
|
| public void run() {
|
| ThreadUtils.runOnUiThread(new Runnable() {
|
| @@ -266,7 +283,7 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| });
|
| }
|
| });
|
| - assertNotNull("Main never resumed", mainActivity);
|
| + Assert.assertNotNull("Main never resumed", mainActivity);
|
| CriteriaHelper.pollUiThread(new Criteria("Main tab never restored") {
|
| @Override
|
| public boolean isSatisfied() {
|
| @@ -277,6 +294,6 @@ public class HistoryUITest extends ChromeActivityTestCaseBase<ChromeActivity> {
|
| });
|
| JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| mainActivity.getCurrentContentViewCore().getWebContents(), "reloadHistory()");
|
| - waitForResultCount(getActivity().getCurrentContentViewCore(), 0);
|
| + waitForResultCount(mActivityTestRule.getActivity().getCurrentContentViewCore(), 0);
|
| }
|
| }
|
|
|