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