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

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

Issue 2773903003: Add way to get native VR UI information from Java (Closed)
Patch Set: Switch to using names instead of IDs Created 3 years, 9 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
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 04bb75a72477136a9415c69d4736545e4efe5d5a..5a09640e8d9308acd37b08dc7b4191d071371adf 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
@@ -15,6 +15,7 @@ import static org.chromium.chrome.test.util.ChromeRestriction.RESTRICTION_TYPE_W
import android.support.test.filters.SmallTest;
import org.chromium.base.Log;
+import org.chromium.base.ThreadUtils;
import org.chromium.base.test.util.CommandLineFlags;
import org.chromium.base.test.util.Restriction;
import org.chromium.base.test.util.UrlUtils;
@@ -26,6 +27,7 @@ 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;
@@ -133,6 +135,25 @@ public class WebVrTest extends ChromeTabbedActivityTestBase {
}
/**
+ * Helper function to run the given Javascript, return the return value,
+ * and fail if a timeout occurs so we don't have to catch or declare
+ * exceptions all the time.
+ * @param timeout The timeout in millseconds before a failure
+ * @param js The Javascript to run
+ * @param webContents The WebContents object to run the Javascript in
+ * @return The return value of the Javascript
+ */
+ private String runJavascriptFatal(int timeout, String js, 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
@@ -297,4 +318,54 @@ public class WebVrTest extends ChromeTabbedActivityTestBase {
executeStepAndWait("stepCheckFrameDataWhileNonFocusedTab()", mWebContents);
endTest(mWebContents);
}
+
+ /**
+ * Tests that the insecure origin warning is not displayed on secure contexts.
+ */
+ @SmallTest
+ public void testNoWarningOnSecureSite() throws InterruptedException {
+ String testName = "test_no_warning_on_secure_site";
+ loadUrl(getHtmlTestFile(testName), PAGE_LOAD_TIMEOUT_S);
+ assertTrue("VRDisplay found", vrDisplayFound(mWebContents));
+ enterVrTap();
+ VrUtils.waitForVrSupported(POLL_TIMEOUT_LONG_MS);
+
+ WebContents uiContents = VrUtils.getVrShellUiContents(POLL_TIMEOUT_SHORT_MS);
+ // Even though we're presenting, the UI might not have been fully initialized yet.
+ assertTrue("vrShellUi object exists",
+ pollJavascriptBoolean(
+ POLL_TIMEOUT_LONG_MS, "typeof vrShellUi != 'undefined'", uiContents));
+
+ final String[] elementNames = {
+ "#webvr-not-secure-transient", "#webvr-not-secure-permanent"};
+ final CountDownLatch nativeReplyLatch = new CountDownLatch(1);
+ final VrShellImpl vrShell = (VrShellImpl) VrShellDelegate.getVrShellForTesting();
+
+ // Need to run on the UI thread otherwise native crashes due to trying to
+ // post to the GL thread from a thread other the one that it was created on.
+ ThreadUtils.runOnUiThread(new Runnable() {
+ @Override
+ public void run() {
+ vrShell.requestUiElementInfoFromNativeForTesting(elementNames, new Runnable() {
+ @Override
+ public void run() {
+ nativeReplyLatch.countDown();
+ }
+ });
+ }
+ });
+
+ nativeReplyLatch.await();
+ assertFalse("Transient warning not visible",
+ vrShell.getUiElementInfoJsonForTesting()
+ .get(elementNames[0])
+ .optBoolean("isVisible", true));
+ assertFalse("Permanent warning not visible",
+ vrShell.getUiElementInfoJsonForTesting()
+ .get(elementNames[1])
+ .optBoolean("isVisible", true));
+ }
+
+ // TODO(bsheedy): Find a good way to test that the security warning shows
+ // on insecure sites, as file:// and localhost URLs are considered secure.
}

Powered by Google App Engine
This is Rietveld 408576698