From a0de7d39848895f931d183701e199ad73cf112cf Mon Sep 17 00:00:00 2001 From: Patrick Wang Date: Tue, 16 Oct 2012 19:59:04 +0800 Subject: [PATCH] Bug 795317: Test case r=jlebar --- dom/browser-element/mochitest/Makefile.in | 4 ++ .../mochitest/browserElement_ExposableURI.js | 57 +++++++++++++++++++ .../mochitest/file_wyciwyg.html | 14 +++++ ...st_browserElement_inproc_ExposableURI.html | 19 +++++++ .../test_browserElement_oop_ExposableURI.html | 19 +++++++ 5 files changed, 113 insertions(+) create mode 100644 dom/browser-element/mochitest/browserElement_ExposableURI.js create mode 100644 dom/browser-element/mochitest/file_wyciwyg.html create mode 100644 dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html create mode 100644 dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html diff --git a/dom/browser-element/mochitest/Makefile.in b/dom/browser-element/mochitest/Makefile.in index 500b91aa8bf..811345a69f7 100644 --- a/dom/browser-element/mochitest/Makefile.in +++ b/dom/browser-element/mochitest/Makefile.in @@ -139,6 +139,9 @@ MOCHITEST_FILES = \ 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 @@ -201,6 +204,7 @@ MOCHITEST_FILES += \ test_browserElement_oop_RemoveBrowserElement.html \ test_browserElement_oop_DOMRequestError.html \ test_browserElement_oop_AppFramePermission.html \ + test_browserElement_oop_ExposableURI.html \ $(NULL) endif #} endif #} diff --git a/dom/browser-element/mochitest/browserElement_ExposableURI.js b/dom/browser-element/mochitest/browserElement_ExposableURI.js new file mode 100644 index 00000000000..5ef4fe9f423 --- /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); }); diff --git a/dom/browser-element/mochitest/file_wyciwyg.html b/dom/browser-element/mochitest/file_wyciwyg.html new file mode 100644 index 00000000000..f53216144b6 --- /dev/null +++ b/dom/browser-element/mochitest/file_wyciwyg.html @@ -0,0 +1,14 @@ + + +test + + + + + diff --git a/dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html b/dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html new file mode 100644 index 00000000000..089e5db4427 --- /dev/null +++ b/dom/browser-element/mochitest/test_browserElement_inproc_ExposableURI.html @@ -0,0 +1,19 @@ + + + + + Test for Bug 795317 + + + + + +Mozilla Bug 795317 + + + + + + diff --git a/dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html b/dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html new file mode 100644 index 00000000000..089e5db4427 --- /dev/null +++ b/dom/browser-element/mochitest/test_browserElement_oop_ExposableURI.html @@ -0,0 +1,19 @@ + + + + + Test for Bug 795317 + + + + + +Mozilla Bug 795317 + + + + + +