|
1 /* Any copyright is dedicated to the public domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 // Test that the onmozbrowsermanifestchange event works. |
|
5 "use strict"; |
|
6 |
|
7 SimpleTest.waitForExplicitFinish(); |
|
8 browserElementTestHelpers.setEnabledPref(true); |
|
9 browserElementTestHelpers.addPermission(); |
|
10 |
|
11 function createHtml(manifest) { |
|
12 return 'data:text/html,<html xmlns:xml="http://www.w3.org/XML/1998/namespace"><head>' + manifest + '<body></body></html>'; |
|
13 } |
|
14 |
|
15 function createManifest(href) { |
|
16 return '<link rel="manifest" href="' + href + '">'; |
|
17 } |
|
18 |
|
19 function runTest() { |
|
20 var iframe1 = document.createElement('iframe'); |
|
21 SpecialPowers.wrap(iframe1).mozbrowser = true; |
|
22 document.body.appendChild(iframe1); |
|
23 |
|
24 // iframe2 is a red herring; we modify its manifest link elements but don't |
|
25 // listen for manifestchanges; we want to make sure that its manifestchange |
|
26 // events aren't picked up by the listener on iframe1. |
|
27 var iframe2 = document.createElement('iframe'); |
|
28 SpecialPowers.wrap(iframe2).mozbrowser = true; |
|
29 document.body.appendChild(iframe2); |
|
30 |
|
31 // iframe3 is another red herring. It's not a mozbrowser, so we shouldn't |
|
32 // get any manifestchange events on it. |
|
33 var iframe3 = document.createElement('iframe'); |
|
34 document.body.appendChild(iframe3); |
|
35 |
|
36 var numManifestChanges = 0; |
|
37 |
|
38 iframe1.addEventListener('mozbrowsermanifestchange', function(e) { |
|
39 |
|
40 numManifestChanges++; |
|
41 |
|
42 if (numManifestChanges == 1) { |
|
43 is(e.detail.href, 'manifest.1', 'manifest.1 matches'); |
|
44 |
|
45 // We should recieve manifestchange events when the user creates new |
|
46 // manifests |
|
47 SpecialPowers.getBrowserFrameMessageManager(iframe1) |
|
48 .loadFrameScript("data:,content.document.title='New title';", |
|
49 /* allowDelayedLoad = */ false); |
|
50 |
|
51 SpecialPowers.getBrowserFrameMessageManager(iframe1) |
|
52 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", |
|
53 /* allowDelayedLoad = */ false); |
|
54 |
|
55 SpecialPowers.getBrowserFrameMessageManager(iframe2) |
|
56 .loadFrameScript("data:,content.document.head.insertAdjacentHTML('beforeend', '<link rel=manifest href=manifest.2>')", |
|
57 /* allowDelayedLoad = */ false); |
|
58 } |
|
59 else if (numManifestChanges == 2) { |
|
60 is(e.detail.href, 'manifest.2', 'manifest.2 matches'); |
|
61 |
|
62 // Full new pages should trigger manifestchange events |
|
63 iframe1.src = createHtml(createManifest('manifest.3')); |
|
64 } |
|
65 else if (numManifestChanges == 3) { |
|
66 is(e.detail.href, 'manifest.3', 'manifest.3 matches'); |
|
67 |
|
68 // Test setting a page with multiple manifest link elements |
|
69 iframe1.src = createHtml(createManifest('manifest.4a') + createManifest('manifest.4b')); |
|
70 } |
|
71 else if (numManifestChanges == 4) { |
|
72 is(e.detail.href, 'manifest.4a', 'manifest.4a matches'); |
|
73 // 2 events will be triggered by previous test, wait for next |
|
74 } |
|
75 else if (numManifestChanges == 5) { |
|
76 is(e.detail.href, 'manifest.4b', 'manifest.4b matches'); |
|
77 SimpleTest.finish(); |
|
78 } else { |
|
79 ok(false, 'Too many manifestchange events.'); |
|
80 } |
|
81 }); |
|
82 |
|
83 iframe3.addEventListener('mozbrowsermanifestchange', function(e) { |
|
84 ok(false, 'Should not get a manifestchange event for iframe3.'); |
|
85 }); |
|
86 |
|
87 |
|
88 iframe1.src = createHtml(createManifest('manifest.1')); |
|
89 // We should not recieve manifest change events for either of the below iframes |
|
90 iframe2.src = createHtml(createManifest('manifest.1')); |
|
91 iframe3.src = createHtml(createManifest('manifest.1')); |
|
92 |
|
93 } |
|
94 |
|
95 addEventListener('testready', runTest); |
|
96 |