browser/devtools/scratchpad/test/browser_scratchpad_tab_switch.js

branch
TOR_BUG_9701
changeset 15
b8a032363ba2
equal deleted inserted replaced
-1:000000000000 0:17a682b1d02a
1 /* vim: set ts=2 et sw=2 tw=80: */
2 /* Any copyright is dedicated to the Public Domain.
3 http://creativecommons.org/publicdomain/zero/1.0/ */
4
5 let tab1;
6 let tab2;
7 let sp;
8
9 function test()
10 {
11 waitForExplicitFinish();
12
13 tab1 = gBrowser.addTab();
14 gBrowser.selectedTab = tab1;
15 gBrowser.selectedBrowser.addEventListener("load", function onLoad1() {
16 gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true);
17
18 tab2 = gBrowser.addTab();
19 gBrowser.selectedTab = tab2;
20 gBrowser.selectedBrowser.addEventListener("load", function onLoad2() {
21 gBrowser.selectedBrowser.removeEventListener("load", onLoad2, true);
22 openScratchpad(runTests);
23 }, true);
24 content.location = "data:text/html,test context switch in Scratchpad tab 2";
25 }, true);
26
27 content.location = "data:text/html,test context switch in Scratchpad tab 1";
28 }
29
30 function runTests()
31 {
32 sp = gScratchpadWindow.Scratchpad;
33
34 let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
35 let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
36 let notificationBox = sp.notificationBox;
37
38 ok(contentMenu, "found #sp-menu-content");
39 ok(browserMenu, "found #sp-menu-browser");
40 ok(notificationBox, "found Scratchpad.notificationBox");
41
42 sp.setContentContext();
43
44 is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT,
45 "executionContext is content");
46
47 is(contentMenu.getAttribute("checked"), "true",
48 "content menuitem is checked");
49
50 isnot(browserMenu.getAttribute("checked"), "true",
51 "chrome menuitem is not checked");
52
53 is(notificationBox.currentNotification, null,
54 "there is no notification currently shown for content context");
55
56 sp.setText("window.foosbug653108 = 'aloha';");
57
58 ok(!content.wrappedJSObject.foosbug653108,
59 "no content.foosbug653108");
60
61 sp.run().then(function() {
62 is(content.wrappedJSObject.foosbug653108, "aloha",
63 "content.foosbug653108 has been set");
64
65 gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true);
66 gBrowser.selectedTab = tab1;
67 });
68 }
69
70 function runTests2() {
71 gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true);
72
73 ok(!window.foosbug653108, "no window.foosbug653108");
74
75 sp.setText("window.foosbug653108");
76 sp.run().then(function([, , result]) {
77 isnot(result, "aloha", "window.foosbug653108 is not aloha");
78
79 sp.setText("window.foosbug653108 = 'ahoyhoy';");
80 sp.run().then(function() {
81 is(content.wrappedJSObject.foosbug653108, "ahoyhoy",
82 "content.foosbug653108 has been set 2");
83
84 gBrowser.selectedBrowser.addEventListener("load", runTests3, true);
85 content.location = "data:text/html,test context switch in Scratchpad location 2";
86 });
87 });
88 }
89
90 function runTests3() {
91 gBrowser.selectedBrowser.removeEventListener("load", runTests3, true);
92 // Check that the sandbox is not cached.
93
94 sp.setText("typeof foosbug653108;");
95 sp.run().then(function([, , result]) {
96 is(result, "undefined", "global variable does not exist");
97
98 tab1 = null;
99 tab2 = null;
100 sp = null;
101 finish();
102 });
103 }

mercurial