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 62% |
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..2521ef9f27ef4846fb6be3919280cea94f61368c 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,14 +9,20 @@ 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.rules.TestRule; |
+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.content.browser.test.util.ClickUtils; |
import org.chromium.content.browser.test.util.Criteria; |
import org.chromium.content.browser.test.util.CriteriaHelper; |
import org.chromium.content.browser.test.util.JavaScriptUtils; |
-import org.chromium.content_public.browser.WebContents; |
import java.util.concurrent.Callable; |
import java.util.concurrent.TimeUnit; |
@@ -42,30 +48,17 @@ 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 implements TestRule { |
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; |
- |
- protected WebContents mWebContents; |
- |
- @Override |
- protected void setUp() throws Exception { |
- super.setUp(); |
- mWebContents = getActivity().getActivityTab().getWebContents(); |
- } |
- |
- @Override |
- public void startMainActivity() throws InterruptedException { |
- startMainActivityOnBlankPage(); |
- } |
+ static final String TEST_DIR = "chrome/test/data/android/webvr_instrumentation"; |
+ static final int PAGE_LOAD_TIMEOUT_S = 10; |
/** |
* Gets the file:// URL to the test file |
* @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"; |
} |
@@ -73,47 +66,47 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
/** |
* Blocks until the promise returned by nagivator.getVRDisplays() resolves, |
* then checks whether a VRDisplay was actually found. |
- * @param webContents The WebContents to run the JavaScript through |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
* @return Whether a VRDisplay was found |
*/ |
- protected boolean vrDisplayFound(WebContents webContents) { |
- pollJavaScriptBoolean("vrDisplayPromiseDone", POLL_TIMEOUT_SHORT_MS, webContents); |
- return !runJavaScriptOrFail("vrDisplay", POLL_TIMEOUT_SHORT_MS, webContents).equals("null"); |
+ public boolean vrDisplayFound(ChromeTabbedActivity activity) { |
+ pollJavaScriptBoolean("vrDisplayPromiseDone", POLL_TIMEOUT_SHORT_MS, activity); |
+ return !runJavaScriptOrFail("vrDisplay", POLL_TIMEOUT_SHORT_MS, activity).equals("null"); |
} |
/** |
* 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(ChromeTabbedActivity activity) { |
+ ClickUtils.mouseSingleClickView(InstrumentationRegistry.getInstrumentation(), |
+ activity.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 |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
*/ |
- protected void enterVrTapAndWait(WebContents webContents) { |
- enterVrTap(); |
- waitOnJavaScriptStep(webContents); |
+ public void enterVrTapAndWait(ChromeTabbedActivity activity) { |
+ enterVrTap(activity); |
+ waitOnJavaScriptStep(activity); |
} |
/** |
* Use to simulate a Daydream View NFC scan without blocking afterwards |
*/ |
- protected void simNfcScan() { |
- VrUtils.simNfc(getActivity()); |
+ public void simNfcScan(ChromeTabbedActivity activity) { |
+ VrUtils.simNfc(activity); |
} |
/** |
* Simulate an NFC scan and wait for the JavaScript code in the given |
- * WebContents to signal that it is done with the step. |
- * @param webContents The WebContents for the JavaScript that will be polled |
+ * ChromeTabbedActivity's WebContents to signal that it is done with the step. |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
*/ |
- protected void simNfcScanAndWait(WebContents webContents) { |
- simNfcScan(); |
- waitOnJavaScriptStep(webContents); |
+ public void simNfcScanAndWait(ChromeTabbedActivity activity) { |
+ simNfcScan(activity); |
+ waitOnJavaScriptStep(activity); |
} |
/** |
@@ -122,38 +115,37 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
* declare exceptions all the time. |
* @param js The JavaScript to run |
* @param timeout The timeout in milliseconds before a failure |
- * @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, ChromeTabbedActivity activity) { |
try { |
return JavaScriptUtils.executeJavaScriptAndWaitForResult( |
- webContents, js, timeout, TimeUnit.MILLISECONDS); |
+ activity.getActivityTab().getWebContents(), 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"; |
} |
/** |
* Ends the test harness test and checks whether there it passed |
- * @param webContents The WebContents for the tab to check results in |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
* @return "Passed" if test passed, String with failure reason otherwise |
*/ |
- protected String checkResults(WebContents webContents) { |
- if (runJavaScriptOrFail("testPassed", POLL_TIMEOUT_SHORT_MS, webContents).equals("true")) { |
+ public String checkResults(ChromeTabbedActivity activity) { |
+ if (runJavaScriptOrFail("testPassed", POLL_TIMEOUT_SHORT_MS, activity).equals("true")) { |
return "Passed"; |
} |
- return runJavaScriptOrFail("resultString", POLL_TIMEOUT_SHORT_MS, webContents); |
+ return runJavaScriptOrFail("resultString", POLL_TIMEOUT_SHORT_MS, activity); |
} |
/** |
* Helper function to end the test harness test and assert that it passed, |
* setting the failure reason as the description if it didn't. |
- * @param webContents The WebContents for the tab to check test results in |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
*/ |
- protected void endTest(WebContents webContents) { |
- assertEquals("Passed", checkResults(webContents)); |
+ public void endTest(ChromeTabbedActivity activity) { |
+ Assert.assertEquals("Passed", checkResults(activity)); |
} |
/** |
@@ -161,19 +153,20 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
* the boolean is true. |
* @param boolName The name of the JavaScript boolean or expression to poll |
* @param timeoutMs The polling timeout in milliseconds |
- * @param webContents The WebContents to run the JavaScript through |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
* @return True if the boolean evaluated to true, false if timed out |
*/ |
- protected boolean pollJavaScriptBoolean( |
- final String boolName, int timeoutMs, final WebContents webContents) { |
+ public boolean pollJavaScriptBoolean( |
+ final String boolName, int timeoutMs, final ChromeTabbedActivity activity) { |
try { |
CriteriaHelper.pollInstrumentationThread(Criteria.equals(true, new Callable<Boolean>() { |
@Override |
public Boolean call() { |
String result = "false"; |
try { |
- result = JavaScriptUtils.executeJavaScriptAndWaitForResult(webContents, |
- boolName, POLL_CHECK_INTERVAL_SHORT_MS, TimeUnit.MILLISECONDS); |
+ result = JavaScriptUtils.executeJavaScriptAndWaitForResult( |
+ activity.getActivityTab().getWebContents(), boolName, |
+ POLL_CHECK_INTERVAL_SHORT_MS, TimeUnit.MILLISECONDS); |
} catch (InterruptedException | TimeoutException e) { |
// Expected to happen regularly, do nothing |
} |
@@ -190,23 +183,28 @@ public class VrTestBase extends ChromeTabbedActivityTestBase { |
/** |
* Waits for a JavaScript step to finish, asserting that the step finished |
* instead of timing out. |
- * @param webContents The WebContents for the tab the JavaScript step is in |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
*/ |
- protected void waitOnJavaScriptStep(WebContents webContents) { |
- assertTrue("Polling JavaScript boolean javascriptDone timed out", |
- pollJavaScriptBoolean("javascriptDone", POLL_TIMEOUT_LONG_MS, webContents)); |
+ public void waitOnJavaScriptStep(ChromeTabbedActivity activity) { |
+ Assert.assertTrue("Polling JavaScript boolean javascriptDone timed out", |
+ pollJavaScriptBoolean("javascriptDone", POLL_TIMEOUT_LONG_MS, activity)); |
// Reset the synchronization boolean |
- runJavaScriptOrFail("javascriptDone = false", POLL_TIMEOUT_SHORT_MS, webContents); |
+ runJavaScriptOrFail("javascriptDone = false", POLL_TIMEOUT_SHORT_MS, activity); |
} |
/** |
- * Executes a JavaScript step function using the given WebContents. |
+ * Executes a JavaScript step function using the given ChromeTabbedActivity. |
* @param stepFunction The JavaScript step function to call |
- * @param webContents The WebContents for the tab the JavaScript is in |
+ * @param activity The ChromeTabbedActivity with the active tab in which the JavaScript runs |
*/ |
- protected void executeStepAndWait(String stepFunction, WebContents webContents) { |
+ public void executeStepAndWait(String stepFunction, ChromeTabbedActivity activity) { |
// Run the step and block |
- JavaScriptUtils.executeJavaScript(webContents, stepFunction); |
- waitOnJavaScriptStep(webContents); |
+ JavaScriptUtils.executeJavaScript(activity.getActivityTab().getWebContents(), stepFunction); |
+ waitOnJavaScriptStep(activity); |
+ } |
+ |
+ @Override |
+ public Statement apply(Statement base, Description description) { |
+ return base; |
} |
} |