Chromium Code Reviews| Index: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java |
| diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestBase.java b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java |
| similarity index 77% |
| rename from chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestBase.java |
| rename to chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java |
| index 5792fa21050bb1a07c7a938ef7321730cfb73f5b..86a0fb2706c6bfe070d4fab17672c4fa6577c43e 100644 |
| --- a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestBase.java |
| +++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestRule.java |
| @@ -9,9 +9,16 @@ import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_CHECK_INTERVAL_S |
| import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_TIMEOUT_LONG_MS; |
| import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_TIMEOUT_SHORT_MS; |
| +import android.support.test.InstrumentationRegistry; |
| + |
| +import org.junit.Assert; |
| +import org.junit.runner.Description; |
| +import org.junit.runners.model.Statement; |
| + |
| import org.chromium.base.Log; |
| import org.chromium.base.test.util.UrlUtils; |
| -import org.chromium.chrome.test.ChromeTabbedActivityTestBase; |
| +import org.chromium.chrome.browser.ChromeTabbedActivity; |
| +import org.chromium.chrome.test.ChromeActivityTestRule; |
| import org.chromium.content.browser.test.util.ClickUtils; |
| import org.chromium.content.browser.test.util.Criteria; |
| import org.chromium.content.browser.test.util.CriteriaHelper; |
| @@ -42,22 +49,31 @@ import java.util.concurrent.TimeoutException; |
| * are processed, the JavaScript code will automatically signal the Java code, |
| * which can then grab the results and pass/fail the instrumentation test. |
| */ |
| -public class VrTestBase extends ChromeTabbedActivityTestBase { |
| +public class VrTestRule extends ChromeActivityTestRule<ChromeTabbedActivity> { |
|
jbudorick
2017/05/10 18:31:12
This ... isn't much of a change. All of the Activi
|
| private static final String TAG = "VrTestBase"; |
| - protected static final String TEST_DIR = "chrome/test/data/android/webvr_instrumentation"; |
| - protected static final int PAGE_LOAD_TIMEOUT_S = 10; |
| + static final String TEST_DIR = "chrome/test/data/android/webvr_instrumentation"; |
| + static final int PAGE_LOAD_TIMEOUT_S = 10; |
| - protected WebContents mWebContents; |
| + private WebContents mWebContents; |
| - @Override |
| - protected void setUp() throws Exception { |
| - super.setUp(); |
| - mWebContents = getActivity().getActivityTab().getWebContents(); |
| + public VrTestRule() { |
| + super(ChromeTabbedActivity.class); |
| } |
| @Override |
| - public void startMainActivity() throws InterruptedException { |
| - startMainActivityOnBlankPage(); |
| + public Statement apply(final Statement base, Description desc) { |
| + return super.apply(new Statement() { |
| + @Override |
| + public void evaluate() throws Throwable { |
| + startMainActivityOnBlankPage(); |
| + mWebContents = getActivity().getActivityTab().getWebContents(); |
| + base.evaluate(); |
| + } |
| + }, desc); |
| + } |
| + |
| + public WebContents getWebContents() { |
| + return mWebContents; |
| } |
| /** |
| @@ -65,7 +81,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param testName The name of the test whose file will be retrieved |
| * @return The file:// URL to the specified test file |
| */ |
| - protected static String getHtmlTestFile(String testName) { |
| + public static String getHtmlTestFile(String testName) { |
| return "file://" + UrlUtils.getIsolatedTestFilePath(TEST_DIR) + "/html/" + testName |
| + ".html"; |
| } |
| @@ -76,7 +92,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param webContents The WebContents to run the JavaScript through |
| * @return Whether a VRDisplay was found |
| */ |
| - protected boolean vrDisplayFound(WebContents webContents) { |
| + public boolean vrDisplayFound(WebContents webContents) { |
| pollJavaScriptBoolean("vrDisplayPromiseDone", POLL_TIMEOUT_SHORT_MS, webContents); |
| return !runJavaScriptOrFail("vrDisplay", POLL_TIMEOUT_SHORT_MS, webContents).equals("null"); |
| } |
| @@ -85,16 +101,16 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * Use to tap in the middle of the screen, triggering the canvas' onclick |
| * to fulfil WebVR's gesture requirement for presenting. |
| */ |
| - protected void enterVrTap() { |
| - ClickUtils.mouseSingleClickView( |
| - getInstrumentation(), getActivity().getWindow().getDecorView().getRootView()); |
| + public void enterVrTap() { |
| + ClickUtils.mouseSingleClickView(InstrumentationRegistry.getInstrumentation(), |
| + getActivity().getWindow().getDecorView().getRootView()); |
| } |
| /** |
| * Taps in the middle of the screen then waits for the JavaScript step to finish. |
| * @param webContents The WebContents for the tab the JavaScript step is in |
| */ |
| - protected void enterVrTapAndWait(WebContents webContents) { |
| + public void enterVrTapAndWait(WebContents webContents) { |
| enterVrTap(); |
| waitOnJavaScriptStep(webContents); |
| } |
| @@ -102,7 +118,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| /** |
| * Use to simulate a Daydream View NFC scan without blocking afterwards |
| */ |
| - protected void simNfcScan() { |
| + public void simNfcScan() { |
| VrUtils.simNfc(getActivity()); |
| } |
| @@ -111,7 +127,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * WebContents to signal that it is done with the step. |
| * @param webContents The WebContents for the JavaScript that will be polled |
| */ |
| - protected void simNfcScanAndWait(WebContents webContents) { |
| + public void simNfcScanAndWait(WebContents webContents) { |
| simNfcScan(); |
| waitOnJavaScriptStep(webContents); |
| } |
| @@ -125,12 +141,12 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param webContents The WebContents object to run the JavaScript in |
| * @return The return value of the JavaScript |
| */ |
| - protected String runJavaScriptOrFail(String js, int timeout, WebContents webContents) { |
| + public String runJavaScriptOrFail(String js, int timeout, WebContents webContents) { |
| try { |
| return JavaScriptUtils.executeJavaScriptAndWaitForResult( |
| webContents, js, timeout, TimeUnit.MILLISECONDS); |
| } catch (InterruptedException | TimeoutException e) { |
| - fail("Fatal interruption or timeout running JavaScript: " + js); |
| + Assert.fail("Fatal interruption or timeout running JavaScript: " + js); |
| } |
| return "Not reached"; |
| } |
| @@ -140,7 +156,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param webContents The WebContents for the tab to check results in |
| * @return "Passed" if test passed, String with failure reason otherwise |
| */ |
| - protected String checkResults(WebContents webContents) { |
| + public String checkResults(WebContents webContents) { |
| if (runJavaScriptOrFail("testPassed", POLL_TIMEOUT_SHORT_MS, webContents).equals("true")) { |
| return "Passed"; |
| } |
| @@ -152,8 +168,8 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * setting the failure reason as the description if it didn't. |
| * @param webContents The WebContents for the tab to check test results in |
| */ |
| - protected void endTest(WebContents webContents) { |
| - assertEquals("Passed", checkResults(webContents)); |
| + public void endTest(WebContents webContents) { |
| + Assert.assertEquals("Passed", checkResults(webContents)); |
| } |
| /** |
| @@ -164,7 +180,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param webContents The WebContents to run the JavaScript through |
| * @return True if the boolean evaluated to true, false if timed out |
| */ |
| - protected boolean pollJavaScriptBoolean( |
| + public boolean pollJavaScriptBoolean( |
| final String boolName, int timeoutMs, final WebContents webContents) { |
| try { |
| CriteriaHelper.pollInstrumentationThread(Criteria.equals(true, new Callable<Boolean>() { |
| @@ -192,8 +208,8 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * instead of timing out. |
| * @param webContents The WebContents for the tab the JavaScript step is in |
| */ |
| - protected void waitOnJavaScriptStep(WebContents webContents) { |
| - assertTrue("Polling JavaScript boolean javascriptDone timed out", |
| + public void waitOnJavaScriptStep(WebContents webContents) { |
| + Assert.assertTrue("Polling JavaScript boolean javascriptDone timed out", |
| pollJavaScriptBoolean("javascriptDone", POLL_TIMEOUT_LONG_MS, webContents)); |
| // Reset the synchronization boolean |
| runJavaScriptOrFail("javascriptDone = false", POLL_TIMEOUT_SHORT_MS, webContents); |
| @@ -204,7 +220,7 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
| * @param stepFunction The JavaScript step function to call |
| * @param webContents The WebContents for the tab the JavaScript is in |
| */ |
| - protected void executeStepAndWait(String stepFunction, WebContents webContents) { |
| + public void executeStepAndWait(String stepFunction, WebContents webContents) { |
| // Run the step and block |
| JavaScriptUtils.executeJavaScript(webContents, stepFunction); |
| waitOnJavaScriptStep(webContents); |