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 b62ab96a94daf5c7b542b92cea21301b426efeb7..c21986ab46294123cf7119d1bd17a6b80e424e14 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 |
@@ -16,7 +16,10 @@ import android.support.test.filters.LargeTest; |
import android.support.test.filters.MediumTest; |
import android.support.test.filters.SmallTest; |
+import org.json.JSONObject; |
+ |
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; |
@@ -27,6 +30,7 @@ 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.HashMap; |
import java.util.concurrent.Callable; |
import java.util.concurrent.CountDownLatch; |
import java.util.concurrent.TimeUnit; |
@@ -136,6 +140,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 |
@@ -211,7 +234,7 @@ public class WebVrTest extends ChromeTabbedActivityTestBase { |
assertTrue("Polling Javascript boolean javascriptDone succeeded", |
pollJavascriptBoolean(POLL_TIMEOUT_LONG_MS, "javascriptDone", webContents)); |
// Reset the synchronization boolean |
- JavaScriptUtils.executeJavaScript(webContents, "javascriptDone = false"); |
+ runJavascriptFatal(POLL_TIMEOUT_SHORT_MS, "javascriptDone = false", webContents); |
} |
/** |
@@ -316,4 +339,52 @@ 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 OnUiElementInfoReplyCallback() { |
+ @Override |
+ public void onUiElementInfoReply(HashMap<String, JSONObject> reply) { |
+ assertFalse("Transient warning not visible", |
+ reply.get(elementNames[0]).optBoolean("isVisible", true)); |
+ assertFalse("Permanent warning not visible", |
+ reply.get(elementNames[1]).optBoolean("isVisible", true)); |
+ nativeReplyLatch.countDown(); |
+ } |
+ }); |
+ } |
+ }); |
+ |
+ assertTrue("Native replied in time", |
+ nativeReplyLatch.await(POLL_TIMEOUT_SHORT_MS, TimeUnit.MILLISECONDS)); |
+ } |
+ |
+ // TODO(bsheedy): Find a good way to test that the security warning shows |
+ // on insecure sites, as file:// and localhost URLs are considered secure. |
} |