michael@0: /* Any copyright is dedicated to the public domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: // Test that data: URIs work with mozbrowserlocationchange events. michael@0: michael@0: "use strict"; michael@0: SimpleTest.waitForExplicitFinish(); michael@0: browserElementTestHelpers.setEnabledPref(true); michael@0: browserElementTestHelpers.addPermission(); michael@0: michael@0: function runTest() { michael@0: var iframe1 = document.createElement('iframe'); michael@0: SpecialPowers.wrap(iframe1).mozbrowser = true; michael@0: iframe1.id = 'iframe1'; michael@0: iframe1.addEventListener('mozbrowserloadend', function if1_loadend() { michael@0: iframe1.removeEventListener('mozbrowserloadend', if1_loadend); michael@0: ok(true, 'Got first loadend event.'); michael@0: SimpleTest.executeSoon(runTest2); michael@0: }); michael@0: iframe1.src = browserElementTestHelpers.emptyPage1; michael@0: document.body.appendChild(iframe1); michael@0: michael@0: var iframe2 = document.createElement('iframe'); michael@0: iframe2.id = 'iframe2'; michael@0: document.body.appendChild(iframe2); michael@0: } michael@0: michael@0: function runTest2() { michael@0: var iframe1 = document.getElementById('iframe1'); michael@0: var iframe2 = document.getElementById('iframe2'); michael@0: michael@0: var sawLoadEnd = false; michael@0: var sawLocationChange = false; michael@0: michael@0: iframe1.addEventListener('mozbrowserlocationchange', function(e) { michael@0: ok(e.isTrusted, 'Event should be trusted.'); michael@0: ok(!sawLocationChange, 'Just one locationchange event.'); michael@0: ok(!sawLoadEnd, 'locationchange before load.'); michael@0: is(e.detail, 'data:text/html,1', "event's reported location"); michael@0: sawLocationChange = true; michael@0: }); michael@0: michael@0: iframe1.addEventListener('mozbrowserloadend', function() { michael@0: ok(sawLocationChange, 'Loadend after locationchange.'); michael@0: ok(!sawLoadEnd, 'Just one loadend event.'); michael@0: sawLoadEnd = true; michael@0: }); michael@0: michael@0: function iframe2Load() { michael@0: if (!sawLoadEnd || !sawLocationChange) { michael@0: // Spin if iframe1 hasn't loaded yet. michael@0: SimpleTest.executeSoon(iframe2Load); michael@0: return; michael@0: } michael@0: ok(true, 'Got iframe2 load.'); michael@0: SimpleTest.finish(); michael@0: } michael@0: iframe2.addEventListener('load', iframe2Load); michael@0: michael@0: michael@0: iframe1.src = 'data:text/html,1'; michael@0: michael@0: // Load something into iframe2 to check that it doesn't trigger a michael@0: // locationchange for our iframe1 listener. michael@0: iframe2.src = browserElementTestHelpers.emptyPage2; michael@0: } michael@0: michael@0: addEventListener('testready', runTest);