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..9939e5c47d681a991b9693195ba5a2239eb5a585 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,56 @@ 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)); |
+ |
+ // Get the UI element IDs from Javascript |
+ // TODO(bsheedy): Request directly using native names once that is supported |
tiborg
2017/03/27 15:14:33
Nit: end with full stop.
bsheedy
2017/03/27 17:49:09
Done, although this TODO will be resolved before s
|
+ int transientId = Integer.parseInt(runJavascriptFatal(POLL_TIMEOUT_SHORT_MS, |
+ "vrShellUi.getUiElementId('#webvr-not-secure-transient')", uiContents)); |
+ int permanentId = Integer.parseInt(runJavascriptFatal(POLL_TIMEOUT_SHORT_MS, |
+ "vrShellUi.getUiElementId('#webvr-not-secure-permanent')", uiContents)); |
+ |
+ final int[] elementIds = {transientId, permanentId}; |
+ 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.requestUiElementInfoFromNative(elementIds, new Runnable() { |
+ @Override |
+ public void run() { |
+ nativeReplyLatch.countDown(); |
+ } |
+ }); |
+ } |
+ }); |
+ |
+ nativeReplyLatch.await(); |
+ assertFalse("Transient warning not visible", |
+ vrShell.getUiElementInfoJson().get(transientId).optBoolean("isVisible", true)); |
+ assertFalse("Permanent warning not visible", |
+ vrShell.getUiElementInfoJson().get(permanentId).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. |
} |