Bug 795317: Test case r=jlebar, a=blocking-basecamp
authorPatrick Wang <kk1fff@patrickz.net>
Tue, 16 Oct 2012 19:59:04 +0800
changeset 116112 6b33ce9ec54853458e74f4d9ff7bf3b4aef7c9e4
parent 116111 4b4d24b35f88e46b1631cfc4c674dbe4e1946850
child 116113 1796bbed02993f62de0ea37e147883e74640088f
push id1708
push userakeybl@mozilla.com
push dateMon, 19 Nov 2012 21:10:21 +0000
treeherdermozilla-beta@27b14fe50103 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersjlebar, blocking-basecamp
bugs795317
milestone18.0a2
Bug 795317: Test case r=jlebar, a=blocking-basecamp
dom/browser-element/mochitest/Makefile.in
dom/browser-element/mochitest/browserElement_ExposableURI.js
dom/browser-element/mochitest/file_wyciwyg.html
dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html
dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html
--- a/dom/browser-element/mochitest/Makefile.in
+++ b/dom/browser-element/mochitest/Makefile.in
@@ -134,16 +134,19 @@ MOCHITEST_FILES = \
 		file_http_401_response.sjs \
 		browserElement_RemoveBrowserElement.js \
 		test_browserElement_inproc_RemoveBrowserElement.html \
 		browserElement_DOMRequestError.js \
 		test_browserElement_inproc_DOMRequestError.html \
 		file_browserElement_AppFramePermission.html \
 		browserElement_AppFramePermission.js \
 		test_browserElement_inproc_AppFramePermission.html \
+		file_wyciwyg.html \
+		browserElement_ExposableURI.js \
+		test_browserElement_inproc_ExposableURI.html \
 		$(NULL)
 
 # Disabled due to https://bugzilla.mozilla.org/show_bug.cgi?id=774100
 #		test_browserElement_inproc_Reload.html \
 
 # OOP tests don't work on Windows (bug 763081) or native-fennec (bug
 # 774939).
 #
@@ -196,14 +199,15 @@ MOCHITEST_FILES += \
 		test_browserElement_oop_Stop.html \
 		test_browserElement_oop_ContextmenuEvents.html \
 		test_browserElement_oop_SendEvent.html \
 		test_browserElement_oop_ScrollEvent.html \
 		test_browserElement_oop_Auth.html \
 		test_browserElement_oop_RemoveBrowserElement.html \
 		test_browserElement_oop_DOMRequestError.html \
 		test_browserElement_oop_AppFramePermission.html \
+		test_browserElement_oop_ExposableURI.html \
 		$(NULL)
 endif #}
 endif #}
 
 
 include $(topsrcdir)/config/rules.mk
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/browserElement_ExposableURI.js
@@ -0,0 +1,57 @@
+/* Any copyright is dedicated to the public domain.
+   http://creativecommons.org/publicdomain/zero/1.0/ */
+
+// Bug 795317: Test that the browser element sanitizes its URIs by removing the
+// "unexposable" parts before sending them in the locationchange event.
+
+"use strict";
+SimpleTest.waitForExplicitFinish();
+
+var iframe;
+
+
+function testPassword() {
+  function locationchange(e) {
+    var uri = e.detail;
+    is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html',
+       "Username and password shouldn't be exposed in uri.");
+    SimpleTest.finish();
+  }
+
+  iframe.addEventListener('mozbrowserlocationchange', locationchange);
+  iframe.src = "http://iamuser:iampassword@mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html";
+}
+
+function testWyciwyg() {
+  var locationChangeCount = 0;
+
+  function locationchange(e) {
+    // locationChangeCount:
+    //  0 - the first load.
+    //  1 - after document.write().
+    if (locationChangeCount == 0) {
+      locationChangeCount ++;
+    } else if (locationChangeCount == 1) {
+      var uri = e.detail;
+      is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_wyciwyg.html', "Scheme in string shouldn't be wyciwyg");
+      iframe.removeEventListener('mozbrowserlocationchange', locationchange);
+      SimpleTest.executeSoon(testPassword);
+    }
+  }
+
+  // file_wyciwyg.html calls document.write() to create a wyciwyg channel.
+  iframe.src = 'file_wyciwyg.html';
+  iframe.addEventListener('mozbrowserlocationchange', locationchange);
+}
+
+function runTest() {
+  browserElementTestHelpers.setEnabledPref(true);
+  browserElementTestHelpers.addPermission();
+
+  iframe = document.createElement('iframe');
+  iframe.mozbrowser = true;
+  document.body.appendChild(iframe);
+  testWyciwyg();
+}
+
+addEventListener('load', function() { SimpleTest.executeSoon(runTest); });
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/file_wyciwyg.html
@@ -0,0 +1,14 @@
+<html>
+<head>
+<title>test</title>
+<script type="text/javascript">
+addEventListener('load', function() {
+  window.setTimeout(function() {
+    document.write("test");
+  }, 0);
+});
+</script>
+</head>
+<body>
+</body>
+</html>
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=795317
+-->
+<head>
+  <title>Test for Bug 795317</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795317">Mozilla Bug 795317</a>
+
+<script type="application/javascript;version1.7" src="browserElement_ExposableURI.js"></script>
+
+</body>
+</html>
+
new file mode 100644
--- /dev/null
+++ b/dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html
@@ -0,0 +1,19 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=795317
+-->
+<head>
+  <title>Test for Bug 795317</title>
+  <script type="application/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
+  <script type="application/javascript" src="browserElementTestHelpers.js"></script>
+  <link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=795317">Mozilla Bug 795317</a>
+
+<script type="application/javascript;version1.7" src="browserElement_ExposableURI.js"></script>
+
+</body>
+</html>
+