Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(5)

Unified Diff: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java

Issue 2842023002: Refactor VR e2e tests (Closed)
Patch Set: Rebase Created 3 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestBase.java ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
diff --git a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
index 5cb22c6f626abf0b57f47d144dc547360d33a78a..248d64f134c961a52d0556d10005cbab3061343e 100644
--- a/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
+++ b/chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/WebVrTest.java
@@ -4,9 +4,6 @@
package org.chromium.chrome.browser.vr_shell;
-import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_CHECK_INTERVAL_LONG_MS;
-import static org.chromium.chrome.browser.vr_shell.VrUtils.POLL_CHECK_INTERVAL_SHORT_MS;
-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 static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_VIEWER_DAYDREAM;
import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_WEBVR_SUPPORTED;
@@ -17,213 +14,22 @@ import android.support.test.filters.MediumTest;
import android.support.test.filters.SmallTest;
import android.widget.TextView;
-import org.chromium.base.Log;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.DisabledTest;
import org.chromium.base.test.util.Restriction;
-import org.chromium.base.test.util.UrlUtils;
import org.chromium.chrome.R;
-import org.chromium.chrome.test.ChromeTabbedActivityTestBase;
-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.CountDownLatch;
import java.util.concurrent.TimeUnit;
-import java.util.concurrent.TimeoutException;
/**
- * This is a workaround for testing aspects of WebVR that aren't testable with
- * WebVR's mocked layout tests, such as E2E tests.
- *
- * The general test flow is:
- * - Load the HTML file containing the test, which:
- * - Loads the WebVR boilerplate code and some test functions
- * - Sets up common elements like the canvas and synchronization variable
- * - Sets up any steps that need to be triggered by the Java code
- * - Check if any VRDisplay objects were found and fail the test if it doesn't
- * match what we expect for that test
- * - Repeat:
- * - Run any necessary Java-side code, e.g. trigger a user action
- * - Trigger the next JavaScript test step and wait for it to finish
- *
- * The JavaScript code will automatically process test results once all
- * testharness.js tests are done, just like in layout tests. Once the results
- * are processed, the JavaScript code will automatically signal the Java code,
- * which can then grab the results and pass/fail the instrumentation test.
+ * End-to-end tests for WebVR using the WebVR test framework from
+ * VrTestBase.
*/
@CommandLineFlags.Add("enable-webvr")
@Restriction(RESTRICTION_TYPE_WEBVR_SUPPORTED)
-public class WebVrTest extends ChromeTabbedActivityTestBase {
+public class WebVrTest extends VrTestBase {
private static final String TAG = "WebVrTest";
- private static final String TEST_DIR = "chrome/test/data/android/webvr_instrumentation";
- private static final int PAGE_LOAD_TIMEOUT_S = 10;
-
- private WebContents mWebContents;
-
- @Override
- protected void setUp() throws Exception {
- super.setUp();
- mWebContents = getActivity().getActivityTab().getWebContents();
- }
-
- @Override
- public void startMainActivity() throws InterruptedException {
- startMainActivityOnBlankPage();
- }
-
- /**
- * 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
- */
- private String getHtmlTestFile(String testName) {
- return "file://" + UrlUtils.getIsolatedTestFilePath(TEST_DIR) + "/html/" + testName
- + ".html";
- }
-
- /**
- * 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
- * @return Whether a VRDisplay was found
- */
- private boolean vrDisplayFound(WebContents webContents) {
- pollJavaScriptBoolean("vrDisplayPromiseDone", POLL_TIMEOUT_SHORT_MS, webContents);
- return !runJavaScriptOrFail("vrDisplay", POLL_TIMEOUT_SHORT_MS, webContents).equals("null");
- }
-
- /**
- * Use to tap in the middle of the screen, triggering the canvas' onclick
- * to fulfil WebVR's gesture requirement for presenting.
- */
- private void enterVrTap() {
- ClickUtils.mouseSingleClickView(
- 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
- */
- private void enterVrTapAndWait(WebContents webContents) {
- enterVrTap();
- waitOnJavaScriptStep(webContents);
- }
-
- /**
- * Use to simulate a Daydream View NFC scan without blocking afterwards
- */
- private void simNfcScan() {
- VrUtils.simNfc(getActivity());
- }
-
- /**
- * 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
- */
- private void simNfcScanAndWait(WebContents webContents) {
- simNfcScan();
- waitOnJavaScriptStep(webContents);
- }
-
- /**
- * Helper function to run the given JavaScript, return the return value,
- * and fail if a timeout/interrupt occurs so we don't have to catch or
- * 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
- */
- private 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);
- }
- 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
- * @return "Passed" if test passed, String with failure reason otherwise
- */
- private String checkResults(WebContents webContents) {
- if (runJavaScriptOrFail("testPassed", POLL_TIMEOUT_SHORT_MS, webContents).equals("true")) {
- return "Passed";
- }
- return runJavaScriptOrFail("resultString", POLL_TIMEOUT_SHORT_MS, webContents);
- }
-
- /**
- * 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
- */
- private void endTest(WebContents webContents) {
- assertEquals("Passed", checkResults(webContents));
- }
-
- /**
- * Polls the provided JavaScript boolean until the timeout is reached or
- * 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
- * @return True if the boolean evaluated to true, false if timed out
- */
- private boolean pollJavaScriptBoolean(
- final String boolName, int timeoutMs, final WebContents webContents) {
- 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);
- } catch (InterruptedException | TimeoutException e) {
- // Expected to happen regularly, do nothing
- }
- return Boolean.parseBoolean(result);
- }
- }), timeoutMs, POLL_CHECK_INTERVAL_LONG_MS);
- } catch (AssertionError e) {
- Log.d(TAG, "pollJavaScriptBoolean() timed out");
- return false;
- }
- return true;
- }
-
- /**
- * 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
- */
- private void waitOnJavaScriptStep(WebContents webContents) {
- assertTrue("Polling JavaScript boolean javascriptDone succeeded",
- pollJavaScriptBoolean("javascriptDone", POLL_TIMEOUT_LONG_MS, webContents));
- // Reset the synchronization boolean
- runJavaScriptOrFail("javascriptDone = false", POLL_TIMEOUT_SHORT_MS, webContents);
- }
-
- /**
- * Executes a JavaScript step function using the given WebContents.
- * @param stepFunction The JavaScript step function to call
- * @param webContents The WebContents for the tab the JavaScript is in
- */
- private void executeStepAndWait(String stepFunction, WebContents webContents) {
- // Run the step and block
- JavaScriptUtils.executeJavaScript(webContents, stepFunction);
- waitOnJavaScriptStep(webContents);
- }
/**
* Tests that a successful requestPresent call actually enters VR
« no previous file with comments | « chrome/android/javatests/src/org/chromium/chrome/browser/vr_shell/VrTestBase.java ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698