2012-06-10 16:44:50 -07:00
|
|
|
/* Any copyright is dedicated to the public domain.
|
|
|
|
http://creativecommons.org/publicdomain/zero/1.0/ */
|
2012-06-09 09:05:31 -07:00
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
// Test that an iframe with the |mozbrowser| attribute emits mozbrowserloadX
|
|
|
|
// events when this page is in the whitelist.
|
|
|
|
|
|
|
|
"use strict";
|
2012-01-20 09:02:48 -08:00
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-03-28 12:51:10 -07:00
|
|
|
browserElementTestHelpers.setEnabledPref(true);
|
|
|
|
browserElementTestHelpers.addPermission();
|
2012-01-20 09:02:48 -08:00
|
|
|
|
|
|
|
function runTest() {
|
2012-03-28 11:36:03 -07:00
|
|
|
// Load emptypage1 into the iframe, wait for that to finish loading, then
|
2012-03-28 11:36:01 -07:00
|
|
|
// call runTest2.
|
|
|
|
//
|
2012-05-08 09:20:35 -07:00
|
|
|
// This should trigger loadstart, locationchange, and loadend events.
|
2012-03-28 11:36:01 -07:00
|
|
|
|
|
|
|
var seenLoadEnd = false;
|
|
|
|
var seenLoadStart = false;
|
2012-05-08 09:20:35 -07:00
|
|
|
var seenLocationChange = false;
|
2012-01-20 09:02:48 -08:00
|
|
|
|
2012-01-26 15:03:22 -08:00
|
|
|
var iframe = document.createElement('iframe');
|
2014-10-30 19:39:15 -07:00
|
|
|
iframe.setAttribute('mozbrowser', 'true');
|
2012-01-26 15:03:22 -08:00
|
|
|
iframe.id = 'iframe';
|
2013-06-06 14:40:49 -07:00
|
|
|
iframe.src = 'http://example.com/tests/dom/browser-element/mochitest/file_browserElement_LoadEvents.html';
|
2012-03-28 11:36:01 -07:00
|
|
|
|
|
|
|
function loadstart(e) {
|
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
|
|
|
ok(!seenLoadEnd, 'loadstart before loadend.');
|
|
|
|
ok(!seenLoadStart, 'Just one loadstart event.');
|
2012-06-10 16:44:50 -07:00
|
|
|
ok(!seenLocationChange, 'loadstart before locationchange.');
|
2012-03-28 11:36:01 -07:00
|
|
|
seenLoadStart = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
function locationchange(e) {
|
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
2012-05-08 09:20:35 -07:00
|
|
|
ok(!seenLocationChange, 'Just one locationchange event.');
|
|
|
|
seenLocationChange = true;
|
|
|
|
ok(seenLoadStart, 'Location change after load start.');
|
|
|
|
ok(!seenLoadEnd, 'Location change before load end.');
|
2012-06-10 16:44:50 -07:00
|
|
|
ok(e.detail, browserElementTestHelpers.emptyPage1, "event's reported location");
|
2012-03-28 11:36:01 -07:00
|
|
|
}
|
|
|
|
|
|
|
|
function loadend(e) {
|
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
|
|
|
ok(seenLoadStart, 'loadend after loadstart.');
|
|
|
|
ok(!seenLoadEnd, 'Just one loadend event.');
|
2013-05-30 21:14:16 -07:00
|
|
|
ok(seenLocationChange, 'loadend after locationchange.');
|
2013-06-06 14:40:49 -07:00
|
|
|
is(e.detail.backgroundColor, 'rgb(0, 128, 0)', 'Expected background color reported')
|
2012-03-28 11:36:01 -07:00
|
|
|
seenLoadEnd = true;
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe.addEventListener('mozbrowserloadstart', loadstart);
|
|
|
|
iframe.addEventListener('mozbrowserlocationchange', locationchange);
|
|
|
|
iframe.addEventListener('mozbrowserloadend', loadend);
|
|
|
|
|
|
|
|
function waitForAllCallbacks() {
|
2012-05-08 09:20:35 -07:00
|
|
|
if (!seenLoadStart || !seenLoadEnd) {
|
2012-03-28 11:36:01 -07:00
|
|
|
SimpleTest.executeSoon(waitForAllCallbacks);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
iframe.removeEventListener('mozbrowserloadstart', loadstart);
|
|
|
|
iframe.removeEventListener('mozbrowserlocationchange', locationchange);
|
|
|
|
iframe.removeEventListener('mozbrowserloadend', loadend);
|
|
|
|
runTest2();
|
|
|
|
}
|
|
|
|
|
2012-01-26 15:03:22 -08:00
|
|
|
document.body.appendChild(iframe);
|
2012-03-28 11:36:01 -07:00
|
|
|
waitForAllCallbacks();
|
2012-01-26 15:03:22 -08:00
|
|
|
}
|
|
|
|
|
|
|
|
function runTest2() {
|
2012-03-28 11:36:01 -07:00
|
|
|
var seenLoadStart = false;
|
|
|
|
var seenLoadEnd = false;
|
|
|
|
var seenLocationChange = false;
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
// Add this event listener to the document; the events should bubble.
|
|
|
|
document.addEventListener('mozbrowserloadstart', function(e) {
|
2012-03-28 11:36:01 -07:00
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
2012-01-20 09:02:48 -08:00
|
|
|
ok(!seenLoadStart, 'Just one loadstart event.');
|
|
|
|
seenLoadStart = true;
|
|
|
|
ok(!seenLoadEnd, 'Got mozbrowserloadstart before loadend.');
|
|
|
|
ok(!seenLocationChange, 'Got mozbrowserloadstart before locationchange.');
|
|
|
|
});
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
var iframe = document.getElementById('iframe');
|
2012-01-20 09:02:48 -08:00
|
|
|
iframe.addEventListener('mozbrowserlocationchange', function(e) {
|
2012-03-28 11:36:01 -07:00
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
2012-01-20 09:02:48 -08:00
|
|
|
ok(!seenLocationChange, 'Just one locationchange event.');
|
|
|
|
seenLocationChange = true;
|
|
|
|
ok(seenLoadStart, 'Location change after load start.');
|
|
|
|
ok(!seenLoadEnd, 'Location change before load end.');
|
2012-06-10 16:44:50 -07:00
|
|
|
ok(e.detail, browserElementTestHelpers.emptyPage2, "event's reported location");
|
2012-01-20 09:02:48 -08:00
|
|
|
});
|
|
|
|
|
2012-03-28 11:36:01 -07:00
|
|
|
iframe.addEventListener('mozbrowserloadend', function(e) {
|
|
|
|
ok(e.isTrusted, 'Event should be trusted.');
|
2012-01-20 09:02:48 -08:00
|
|
|
ok(!seenLoadEnd, 'Just one load end event.');
|
|
|
|
seenLoadEnd = true;
|
|
|
|
ok(seenLoadStart, 'Load end after load start.');
|
|
|
|
ok(seenLocationChange, 'Load end after location change.');
|
2013-06-06 14:40:49 -07:00
|
|
|
is(e.detail.backgroundColor, 'transparent', 'Expected background color reported')
|
2012-01-20 09:02:48 -08:00
|
|
|
});
|
|
|
|
|
2012-06-10 16:44:50 -07:00
|
|
|
iframe.src = browserElementTestHelpers.emptyPage2;
|
2012-01-20 09:02:48 -08:00
|
|
|
|
2012-03-28 11:36:01 -07:00
|
|
|
function waitForAllCallbacks() {
|
2012-05-08 09:20:35 -07:00
|
|
|
if (!seenLoadStart || !seenLoadEnd || !seenLocationChange) {
|
2012-03-28 11:36:01 -07:00
|
|
|
SimpleTest.executeSoon(waitForAllCallbacks);
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
|
|
|
SimpleTest.finish();
|
2012-01-20 09:02:48 -08:00
|
|
|
}
|
|
|
|
|
2012-03-28 11:36:01 -07:00
|
|
|
waitForAllCallbacks();
|
2012-01-20 09:02:48 -08:00
|
|
|
}
|
|
|
|
|
2013-03-28 12:51:10 -07:00
|
|
|
addEventListener('testready', runTest);
|