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 the onmozbrowsertitlechange event works.
|
2012-01-26 15:03:22 -08:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
SimpleTest.waitForExplicitFinish();
|
2013-03-28 12:51:10 -07:00
|
|
|
browserElementTestHelpers.setEnabledPref(true);
|
|
|
|
browserElementTestHelpers.addPermission();
|
2012-01-26 15:03:22 -08:00
|
|
|
|
|
|
|
function runTest() {
|
|
|
|
var iframe1 = document.createElement('iframe');
|
2014-10-30 19:39:15 -07:00
|
|
|
iframe1.setAttribute('mozbrowser', 'true');
|
2012-01-26 15:03:22 -08:00
|
|
|
document.body.appendChild(iframe1);
|
|
|
|
|
|
|
|
// iframe2 is a red herring; we modify its title but don't listen for
|
|
|
|
// titlechanges; we want to make sure that its titlechange events aren't
|
|
|
|
// picked up by the listener on iframe1.
|
|
|
|
var iframe2 = document.createElement('iframe');
|
2014-10-30 19:39:15 -07:00
|
|
|
iframe2.setAttribute('mozbrowser', 'true');
|
2012-01-26 15:03:22 -08:00
|
|
|
document.body.appendChild(iframe2);
|
|
|
|
|
2012-03-28 11:36:01 -07:00
|
|
|
// iframe3 is another red herring. It's not a mozbrowser, so we shouldn't
|
|
|
|
// get any titlechange events on it.
|
|
|
|
var iframe3 = document.createElement('iframe');
|
|
|
|
document.body.appendChild(iframe3);
|
|
|
|
|
2012-01-26 15:03:22 -08:00
|
|
|
var numTitleChanges = 0;
|
|
|
|
|
|
|
|
iframe1.addEventListener('mozbrowsertitlechange', function(e) {
|
2012-05-08 09:20:35 -07:00
|
|
|
// Ignore empty titles; these come from about:blank.
|
|
|
|
if (e.detail == '')
|
|
|
|
return;
|
|
|
|
|
2012-01-26 15:03:22 -08:00
|
|
|
numTitleChanges++;
|
|
|
|
|
|
|
|
if (numTitleChanges == 1) {
|
|
|
|
is(e.detail, 'Title');
|
2012-05-08 09:20:35 -07:00
|
|
|
SpecialPowers.getBrowserFrameMessageManager(iframe1)
|
|
|
|
.loadFrameScript("data:,content.document.title='New title';",
|
|
|
|
/* allowDelayedLoad = */ false);
|
|
|
|
SpecialPowers.getBrowserFrameMessageManager(iframe2)
|
|
|
|
.loadFrameScript("data:,content.document.title='BAD TITLE 2';",
|
|
|
|
/* allowDelayedLoad = */ false);
|
2012-01-26 15:03:22 -08:00
|
|
|
}
|
|
|
|
else if (numTitleChanges == 2) {
|
|
|
|
is(e.detail, 'New title');
|
|
|
|
iframe1.src = 'data:text/html,<html><head><title>Title 3</title></head><body></body></html>';
|
|
|
|
}
|
|
|
|
else if (numTitleChanges == 3) {
|
|
|
|
is(e.detail, 'Title 3');
|
|
|
|
SimpleTest.finish();
|
|
|
|
}
|
|
|
|
else {
|
|
|
|
ok(false, 'Too many titlechange events.');
|
|
|
|
}
|
|
|
|
});
|
|
|
|
|
2012-03-28 11:36:01 -07:00
|
|
|
iframe3.addEventListener('mozbrowsertitlechange', function(e) {
|
|
|
|
ok(false, 'Should not get a titlechange event for iframe3.');
|
|
|
|
});
|
|
|
|
|
2012-01-26 15:03:22 -08:00
|
|
|
iframe1.src = 'data:text/html,<html><head><title>Title</title></head><body></body></html>';
|
|
|
|
iframe2.src = 'data:text/html,<html><head><title>BAD TITLE</title></head><body></body></html>';
|
2012-03-28 11:36:01 -07:00
|
|
|
iframe3.src = 'data:text/html,<html><head><title>SHOULD NOT GET EVENT</title></head><body></body></html>';
|
2012-01-26 15:03:22 -08:00
|
|
|
}
|
|
|
|
|
2013-03-28 12:51:10 -07:00
|
|
|
addEventListener('testready', runTest);
|