michael@0: /* Any copyright is dedicated to the public domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Bug 795317: Test that the browser element sanitizes its URIs by removing the michael@0: // "unexposable" parts before sending them in the locationchange event. michael@0: michael@0: "use strict"; michael@0: SimpleTest.waitForExplicitFinish(); michael@0: browserElementTestHelpers.setEnabledPref(true); michael@0: browserElementTestHelpers.addPermission(); michael@0: michael@0: var iframe; michael@0: michael@0: function testPassword() { michael@0: function locationchange(e) { michael@0: var uri = e.detail; michael@0: is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html', michael@0: "Username and password shouldn't be exposed in uri."); michael@0: SimpleTest.finish(); michael@0: } michael@0: michael@0: iframe.addEventListener('mozbrowserlocationchange', locationchange); michael@0: iframe.src = "http://iamuser:iampassword@mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html"; michael@0: } michael@0: michael@0: function testWyciwyg() { michael@0: var locationChangeCount = 0; michael@0: michael@0: function locationchange(e) { michael@0: // locationChangeCount: michael@0: // 0 - the first load. michael@0: // 1 - after document.write(). michael@0: if (locationChangeCount == 0) { michael@0: locationChangeCount ++; michael@0: } else if (locationChangeCount == 1) { michael@0: var uri = e.detail; michael@0: is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_wyciwyg.html', "Scheme in string shouldn't be wyciwyg"); michael@0: iframe.removeEventListener('mozbrowserlocationchange', locationchange); michael@0: SimpleTest.executeSoon(testPassword); michael@0: } michael@0: } michael@0: michael@0: // file_wyciwyg.html calls document.write() to create a wyciwyg channel. michael@0: iframe.src = 'file_wyciwyg.html'; michael@0: iframe.addEventListener('mozbrowserlocationchange', locationchange); michael@0: } michael@0: michael@0: function runTest() { michael@0: iframe = document.createElement('iframe'); michael@0: SpecialPowers.wrap(iframe).mozbrowser = true; michael@0: document.body.appendChild(iframe); michael@0: testWyciwyg(); michael@0: } michael@0: michael@0: addEventListener('testready', runTest);