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