Thu, 22 Jan 2015 13:21:57 +0100
Incorporate requested changes from Mozilla in review:
https://bugzilla.mozilla.org/show_bug.cgi?id=1123480#c6
michael@0 | 1 | /* Any copyright is dedicated to the public domain. |
michael@0 | 2 | http://creativecommons.org/publicdomain/zero/1.0/ */ |
michael@0 | 3 | |
michael@0 | 4 | // Test that the onmozbrowsertitlechange event works. |
michael@0 | 5 | "use strict"; |
michael@0 | 6 | |
michael@0 | 7 | SimpleTest.waitForExplicitFinish(); |
michael@0 | 8 | browserElementTestHelpers.setEnabledPref(true); |
michael@0 | 9 | browserElementTestHelpers.addPermission(); |
michael@0 | 10 | |
michael@0 | 11 | function runTest() { |
michael@0 | 12 | var iframe1 = document.createElement('iframe'); |
michael@0 | 13 | SpecialPowers.wrap(iframe1).mozbrowser = true; |
michael@0 | 14 | document.body.appendChild(iframe1); |
michael@0 | 15 | |
michael@0 | 16 | // iframe2 is a red herring; we modify its title but don't listen for |
michael@0 | 17 | // titlechanges; we want to make sure that its titlechange events aren't |
michael@0 | 18 | // picked up by the listener on iframe1. |
michael@0 | 19 | var iframe2 = document.createElement('iframe'); |
michael@0 | 20 | SpecialPowers.wrap(iframe2).mozbrowser = true; |
michael@0 | 21 | document.body.appendChild(iframe2); |
michael@0 | 22 | |
michael@0 | 23 | // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't |
michael@0 | 24 | // get any titlechange events on it. |
michael@0 | 25 | var iframe3 = document.createElement('iframe'); |
michael@0 | 26 | document.body.appendChild(iframe3); |
michael@0 | 27 | |
michael@0 | 28 | var numTitleChanges = 0; |
michael@0 | 29 | |
michael@0 | 30 | iframe1.addEventListener('mozbrowsertitlechange', function(e) { |
michael@0 | 31 | // Ignore empty titles; these come from about:blank. |
michael@0 | 32 | if (e.detail == '') |
michael@0 | 33 | return; |
michael@0 | 34 | |
michael@0 | 35 | numTitleChanges++; |
michael@0 | 36 | |
michael@0 | 37 | if (numTitleChanges == 1) { |
michael@0 | 38 | is(e.detail, 'Title'); |
michael@0 | 39 | SpecialPowers.getBrowserFrameMessageManager(iframe1) |
michael@0 | 40 | .loadFrameScript("data:,content.document.title='New title';", |
michael@0 | 41 | /* allowDelayedLoad = */ false); |
michael@0 | 42 | SpecialPowers.getBrowserFrameMessageManager(iframe2) |
michael@0 | 43 | .loadFrameScript("data:,content.document.title='BAD TITLE 2';", |
michael@0 | 44 | /* allowDelayedLoad = */ false); |
michael@0 | 45 | } |
michael@0 | 46 | else if (numTitleChanges == 2) { |
michael@0 | 47 | is(e.detail, 'New title'); |
michael@0 | 48 | iframe1.src = 'data:text/html,<html><head><title>Title 3</title></head><body></body></html>'; |
michael@0 | 49 | } |
michael@0 | 50 | else if (numTitleChanges == 3) { |
michael@0 | 51 | is(e.detail, 'Title 3'); |
michael@0 | 52 | SimpleTest.finish(); |
michael@0 | 53 | } |
michael@0 | 54 | else { |
michael@0 | 55 | ok(false, 'Too many titlechange events.'); |
michael@0 | 56 | } |
michael@0 | 57 | }); |
michael@0 | 58 | |
michael@0 | 59 | iframe3.addEventListener('mozbrowsertitlechange', function(e) { |
michael@0 | 60 | ok(false, 'Should not get a titlechange event for iframe3.'); |
michael@0 | 61 | }); |
michael@0 | 62 | |
michael@0 | 63 | iframe1.src = 'data:text/html,<html><head><title>Title</title></head><body></body></html>'; |
michael@0 | 64 | iframe2.src = 'data:text/html,<html><head><title>BAD TITLE</title></head><body></body></html>'; |
michael@0 | 65 | iframe3.src = 'data:text/html,<html><head><title>SHOULD NOT GET EVENT</title></head><body></body></html>'; |
michael@0 | 66 | } |
michael@0 | 67 | |
michael@0 | 68 | addEventListener('testready', runTest); |