Wed, 31 Dec 2014 06:09:35 +0100
Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.
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/ */
5 let tab1;
6 let tab2;
7 let sp;
9 function test()
10 {
11 waitForExplicitFinish();
13 tab1 = gBrowser.addTab();
14 gBrowser.selectedTab = tab1;
15 gBrowser.selectedBrowser.addEventListener("load", function onLoad1() {
16 gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true);
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);
27 content.location = "data:text/html,test context switch in Scratchpad tab 1";
28 }
30 function runTests()
31 {
32 sp = gScratchpadWindow.Scratchpad;
34 let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content");
35 let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser");
36 let notificationBox = sp.notificationBox;
38 ok(contentMenu, "found #sp-menu-content");
39 ok(browserMenu, "found #sp-menu-browser");
40 ok(notificationBox, "found Scratchpad.notificationBox");
42 sp.setContentContext();
44 is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT,
45 "executionContext is content");
47 is(contentMenu.getAttribute("checked"), "true",
48 "content menuitem is checked");
50 isnot(browserMenu.getAttribute("checked"), "true",
51 "chrome menuitem is not checked");
53 is(notificationBox.currentNotification, null,
54 "there is no notification currently shown for content context");
56 sp.setText("window.foosbug653108 = 'aloha';");
58 ok(!content.wrappedJSObject.foosbug653108,
59 "no content.foosbug653108");
61 sp.run().then(function() {
62 is(content.wrappedJSObject.foosbug653108, "aloha",
63 "content.foosbug653108 has been set");
65 gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true);
66 gBrowser.selectedTab = tab1;
67 });
68 }
70 function runTests2() {
71 gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true);
73 ok(!window.foosbug653108, "no window.foosbug653108");
75 sp.setText("window.foosbug653108");
76 sp.run().then(function([, , result]) {
77 isnot(result, "aloha", "window.foosbug653108 is not aloha");
79 sp.setText("window.foosbug653108 = 'ahoyhoy';");
80 sp.run().then(function() {
81 is(content.wrappedJSObject.foosbug653108, "ahoyhoy",
82 "content.foosbug653108 has been set 2");
84 gBrowser.selectedBrowser.addEventListener("load", runTests3, true);
85 content.location = "data:text/html,test context switch in Scratchpad location 2";
86 });
87 });
88 }
90 function runTests3() {
91 gBrowser.selectedBrowser.removeEventListener("load", runTests3, true);
92 // Check that the sandbox is not cached.
94 sp.setText("typeof foosbug653108;");
95 sp.run().then(function([, , result]) {
96 is(result, "undefined", "global variable does not exist");
98 tab1 = null;
99 tab2 = null;
100 sp = null;
101 finish();
102 });
103 }