1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/dom/browser-element/mochitest/browserElement_ExposableURI.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,55 @@ 1.4 +/* Any copyright is dedicated to the public domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +// Bug 795317: Test that the browser element sanitizes its URIs by removing the 1.8 +// "unexposable" parts before sending them in the locationchange event. 1.9 + 1.10 +"use strict"; 1.11 +SimpleTest.waitForExplicitFinish(); 1.12 +browserElementTestHelpers.setEnabledPref(true); 1.13 +browserElementTestHelpers.addPermission(); 1.14 + 1.15 +var iframe; 1.16 + 1.17 +function testPassword() { 1.18 + function locationchange(e) { 1.19 + var uri = e.detail; 1.20 + is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html', 1.21 + "Username and password shouldn't be exposed in uri."); 1.22 + SimpleTest.finish(); 1.23 + } 1.24 + 1.25 + iframe.addEventListener('mozbrowserlocationchange', locationchange); 1.26 + iframe.src = "http://iamuser:iampassword@mochi.test:8888/tests/dom/browser-element/mochitest/file_empty.html"; 1.27 +} 1.28 + 1.29 +function testWyciwyg() { 1.30 + var locationChangeCount = 0; 1.31 + 1.32 + function locationchange(e) { 1.33 + // locationChangeCount: 1.34 + // 0 - the first load. 1.35 + // 1 - after document.write(). 1.36 + if (locationChangeCount == 0) { 1.37 + locationChangeCount ++; 1.38 + } else if (locationChangeCount == 1) { 1.39 + var uri = e.detail; 1.40 + is(uri, 'http://mochi.test:8888/tests/dom/browser-element/mochitest/file_wyciwyg.html', "Scheme in string shouldn't be wyciwyg"); 1.41 + iframe.removeEventListener('mozbrowserlocationchange', locationchange); 1.42 + SimpleTest.executeSoon(testPassword); 1.43 + } 1.44 + } 1.45 + 1.46 + // file_wyciwyg.html calls document.write() to create a wyciwyg channel. 1.47 + iframe.src = 'file_wyciwyg.html'; 1.48 + iframe.addEventListener('mozbrowserlocationchange', locationchange); 1.49 +} 1.50 + 1.51 +function runTest() { 1.52 + iframe = document.createElement('iframe'); 1.53 + SpecialPowers.wrap(iframe).mozbrowser = true; 1.54 + document.body.appendChild(iframe); 1.55 + testWyciwyg(); 1.56 +} 1.57 + 1.58 +addEventListener('testready', runTest);