| Index: chrome/android/javatests/src/org/chromium/chrome/browser/JavaScriptEvalChromeTest.java
|
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/JavaScriptEvalChromeTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/JavaScriptEvalChromeTest.java
|
| index c60161fa01465188075ba69e98ba7e673b58effd..5059760ca79e6bd1583bc4284785d8e887dc907e 100644
|
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/JavaScriptEvalChromeTest.java
|
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/JavaScriptEvalChromeTest.java
|
| @@ -4,13 +4,23 @@
|
|
|
| package org.chromium.chrome.browser;
|
|
|
| +import android.support.test.InstrumentationRegistry;
|
| import android.support.test.filters.LargeTest;
|
|
|
| +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.test.util.CommandLineFlags;
|
| import org.chromium.base.test.util.Feature;
|
| import org.chromium.base.test.util.RetryOnFailure;
|
| import org.chromium.base.test.util.UrlUtils;
|
| import org.chromium.chrome.browser.tab.Tab;
|
| -import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
|
| +import org.chromium.chrome.test.ChromeActivityTestRule;
|
| +import org.chromium.chrome.test.ChromeJUnit4ClassRunner;
|
| +import org.chromium.chrome.test.ChromeTabbedActivityTestRule;
|
| import org.chromium.chrome.test.util.ChromeTabUtils;
|
| import org.chromium.content.browser.test.util.JavaScriptUtils;
|
|
|
| @@ -19,7 +29,15 @@ import java.util.concurrent.TimeoutException;
|
| /**
|
| * Tests for evaluation of JavaScript.
|
| */
|
| -public class JavaScriptEvalChromeTest extends ChromeTabbedActivityTestBase {
|
| +@RunWith(ChromeJUnit4ClassRunner.class)
|
| +@CommandLineFlags.Add({
|
| + ChromeSwitches.DISABLE_FIRST_RUN_EXPERIENCE,
|
| + ChromeActivityTestRule.DISABLE_NETWORK_PREDICTION_FLAG,
|
| +})
|
| +public class JavaScriptEvalChromeTest {
|
| + @Rule
|
| + public ChromeTabbedActivityTestRule mActivityTestRule = new ChromeTabbedActivityTestRule();
|
| +
|
| private static final String JSTEST_URL = UrlUtils.encodeHtmlDataUri(
|
| "<html><head><script>"
|
| + " var counter = 0;"
|
| @@ -28,27 +46,29 @@ public class JavaScriptEvalChromeTest extends ChromeTabbedActivityTestBase {
|
| + "</script></head>"
|
| + "<body><button id=\"test\">Test button</button></body></html>");
|
|
|
| - @Override
|
| - public void startMainActivity() throws InterruptedException {
|
| - startMainActivityWithURL(JSTEST_URL);
|
| + @Before
|
| + public void setUp() throws InterruptedException {
|
| + mActivityTestRule.startMainActivityWithURL(JSTEST_URL);
|
| }
|
|
|
| /**
|
| * Tests that evaluation of JavaScript for test purposes (using JavaScriptUtils, DOMUtils etc)
|
| * works even in presence of "background" (non-test-initiated) JavaScript evaluation activity.
|
| */
|
| + @Test
|
| @LargeTest
|
| @Feature({"Browser"})
|
| @RetryOnFailure
|
| public void testJavaScriptEvalIsCorrectlyOrderedWithinOneTab()
|
| throws InterruptedException, TimeoutException {
|
| - Tab tab1 = getActivity().getActivityTab();
|
| - ChromeTabUtils.newTabFromMenu(getInstrumentation(), getActivity());
|
| - Tab tab2 = getActivity().getActivityTab();
|
| - loadUrl(JSTEST_URL);
|
| + Tab tab1 = mActivityTestRule.getActivity().getActivityTab();
|
| + ChromeTabUtils.newTabFromMenu(
|
| + InstrumentationRegistry.getInstrumentation(), mActivityTestRule.getActivity());
|
| + Tab tab2 = mActivityTestRule.getActivity().getActivityTab();
|
| + mActivityTestRule.loadUrl(JSTEST_URL);
|
|
|
| - ChromeTabUtils.switchTabInCurrentTabModel(getActivity(), tab1.getId());
|
| - assertFalse("Tab didn't open", tab1 == tab2);
|
| + ChromeTabUtils.switchTabInCurrentTabModel(mActivityTestRule.getActivity(), tab1.getId());
|
| + Assert.assertFalse("Tab didn't open", tab1 == tab2);
|
|
|
| JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| tab1.getWebContents(), "counter = 0;");
|
| @@ -61,21 +81,17 @@ public class JavaScriptEvalChromeTest extends ChromeTabbedActivityTestBase {
|
| tab1.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
| tab2.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
| }
|
| - assertEquals("Incorrect JavaScript evaluation result on tab1",
|
| - i * 2,
|
| - Integer.parseInt(
|
| - JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| - tab1.getWebContents(), "add2()")));
|
| + Assert.assertEquals("Incorrect JavaScript evaluation result on tab1", i * 2,
|
| + Integer.parseInt(JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| + tab1.getWebContents(), "add2()")));
|
| for (int j = 0; j < 5; ++j) {
|
| // Start evaluation of a JavaScript script -- we don't need a result.
|
| tab1.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
| tab2.getWebContents().evaluateJavaScriptForTests("foobar();", null);
|
| }
|
| - assertEquals("Incorrect JavaScript evaluation result on tab2",
|
| - i * 2 + 1,
|
| - Integer.parseInt(
|
| - JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| - tab2.getWebContents(), "add2()")));
|
| + Assert.assertEquals("Incorrect JavaScript evaluation result on tab2", i * 2 + 1,
|
| + Integer.parseInt(JavaScriptUtils.executeJavaScriptAndWaitForResult(
|
| + tab2.getWebContents(), "add2()")));
|
| }
|
| }
|
| }
|
|
|