|
1 <!DOCTYPE html> |
|
2 <!-- |
|
3 Any copyright is dedicated to the Public Domain. |
|
4 http://creativecommons.org/publicdomain/zero/1.0/ |
|
5 --> |
|
6 |
|
7 <html> |
|
8 |
|
9 <head> |
|
10 <meta charset="utf8"> |
|
11 <title></title> |
|
12 |
|
13 <script type="application/javascript" |
|
14 src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script> |
|
15 <link rel="stylesheet" type="text/css" |
|
16 href="chrome://mochikit/content/tests/SimpleTest/test.css"> |
|
17 |
|
18 <script type="application/javascript;version=1.8"> |
|
19 const { classes: Cc, interfaces: Ci, utils: Cu } = Components; |
|
20 const { Services } = Cu.import("resource://gre/modules/Services.jsm", {}); |
|
21 const { gDevToolsExtensions } = Cu.import("resource://gre/modules/devtools/DevToolsExtensions.jsm", {}); |
|
22 Cu.import("resource://gre/modules/devtools/Loader.jsm"); |
|
23 const { require } = devtools; |
|
24 const tabs = require('sdk/tabs'); |
|
25 const { getMostRecentBrowserWindow, getInnerId } = require('sdk/window/utils'); |
|
26 const { PageMod } = require('sdk/page-mod'); |
|
27 |
|
28 var _tests = []; |
|
29 function addTest(test) { |
|
30 _tests.push(test); |
|
31 } |
|
32 |
|
33 function runNextTest() { |
|
34 if (_tests.length == 0) { |
|
35 SimpleTest.finish() |
|
36 return; |
|
37 } |
|
38 _tests.shift()(); |
|
39 } |
|
40 |
|
41 window.onload = function() { |
|
42 SimpleTest.waitForExplicitFinish(); |
|
43 runNextTest(); |
|
44 } |
|
45 |
|
46 addTest(function () { |
|
47 let TEST_URL = 'data:text/html;charset=utf-8,test'; |
|
48 |
|
49 let mod = PageMod({ |
|
50 include: TEST_URL, |
|
51 contentScriptWhen: 'ready', |
|
52 contentScript: 'null;' |
|
53 }); |
|
54 |
|
55 tabs.open({ |
|
56 url: TEST_URL, |
|
57 onLoad: function(tab) { |
|
58 let id = getInnerId(getMostRecentBrowserWindow().gBrowser.selectedTab.linkedBrowser.contentWindow); |
|
59 |
|
60 // getting |
|
61 is(gDevToolsExtensions.getContentGlobals({ |
|
62 'inner-window-id': id |
|
63 }).length, 1, 'found a global for inner-id = ' + id); |
|
64 |
|
65 Services.obs.addObserver(function observer(subject, topic, data) { |
|
66 if (id == subject.QueryInterface(Components.interfaces.nsISupportsPRUint64).data) { |
|
67 Services.obs.removeObserver(observer, 'inner-window-destroyed'); |
|
68 setTimeout(function() { |
|
69 // closing the tab window should have removed the global |
|
70 is(gDevToolsExtensions.getContentGlobals({ |
|
71 'inner-window-id': id |
|
72 }).length, 0, 'did not find a global for inner-id = ' + id); |
|
73 |
|
74 mod.destroy(); |
|
75 runNextTest(); |
|
76 }) |
|
77 } |
|
78 }, 'inner-window-destroyed', false); |
|
79 |
|
80 tab.close(); |
|
81 } |
|
82 }); |
|
83 }) |
|
84 |
|
85 addTest(function testAddRemoveGlobal() { |
|
86 let global = {}; |
|
87 let globalDetails = { |
|
88 global: global, |
|
89 'inner-window-id': 5 |
|
90 }; |
|
91 |
|
92 // adding |
|
93 gDevToolsExtensions.addContentGlobal(globalDetails); |
|
94 |
|
95 // getting |
|
96 is(gDevToolsExtensions.getContentGlobals({ |
|
97 'inner-window-id': 5 |
|
98 }).length, 1, 'found a global for inner-id = 5'); |
|
99 is(gDevToolsExtensions.getContentGlobals({ |
|
100 'inner-window-id': 4 |
|
101 }).length, 0, 'did not find a global for inner-id = 4'); |
|
102 |
|
103 // remove |
|
104 gDevToolsExtensions.removeContentGlobal(globalDetails); |
|
105 |
|
106 // getting again |
|
107 is(gDevToolsExtensions.getContentGlobals({ |
|
108 'inner-window-id': 5 |
|
109 }).length, 0, 'did not find a global for inner-id = 5'); |
|
110 |
|
111 runNextTest(); |
|
112 }); |
|
113 |
|
114 </script> |
|
115 </head> |
|
116 <body></body> |
|
117 </html> |