michael@0: /* vim: set ts=2 et sw=2 tw=80: */ michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: let tab1; michael@0: let tab2; michael@0: let sp; michael@0: michael@0: function test() michael@0: { michael@0: waitForExplicitFinish(); michael@0: michael@0: tab1 = gBrowser.addTab(); michael@0: gBrowser.selectedTab = tab1; michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad1() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true); michael@0: michael@0: tab2 = gBrowser.addTab(); michael@0: gBrowser.selectedTab = tab2; michael@0: gBrowser.selectedBrowser.addEventListener("load", function onLoad2() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", onLoad2, true); michael@0: openScratchpad(runTests); michael@0: }, true); michael@0: content.location = "data:text/html,test context switch in Scratchpad tab 2"; michael@0: }, true); michael@0: michael@0: content.location = "data:text/html,test context switch in Scratchpad tab 1"; michael@0: } michael@0: michael@0: function runTests() michael@0: { michael@0: sp = gScratchpadWindow.Scratchpad; michael@0: michael@0: let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content"); michael@0: let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser"); michael@0: let notificationBox = sp.notificationBox; michael@0: michael@0: ok(contentMenu, "found #sp-menu-content"); michael@0: ok(browserMenu, "found #sp-menu-browser"); michael@0: ok(notificationBox, "found Scratchpad.notificationBox"); michael@0: michael@0: sp.setContentContext(); michael@0: michael@0: is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT, michael@0: "executionContext is content"); michael@0: michael@0: is(contentMenu.getAttribute("checked"), "true", michael@0: "content menuitem is checked"); michael@0: michael@0: isnot(browserMenu.getAttribute("checked"), "true", michael@0: "chrome menuitem is not checked"); michael@0: michael@0: is(notificationBox.currentNotification, null, michael@0: "there is no notification currently shown for content context"); michael@0: michael@0: sp.setText("window.foosbug653108 = 'aloha';"); michael@0: michael@0: ok(!content.wrappedJSObject.foosbug653108, michael@0: "no content.foosbug653108"); michael@0: michael@0: sp.run().then(function() { michael@0: is(content.wrappedJSObject.foosbug653108, "aloha", michael@0: "content.foosbug653108 has been set"); michael@0: michael@0: gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true); michael@0: gBrowser.selectedTab = tab1; michael@0: }); michael@0: } michael@0: michael@0: function runTests2() { michael@0: gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true); michael@0: michael@0: ok(!window.foosbug653108, "no window.foosbug653108"); michael@0: michael@0: sp.setText("window.foosbug653108"); michael@0: sp.run().then(function([, , result]) { michael@0: isnot(result, "aloha", "window.foosbug653108 is not aloha"); michael@0: michael@0: sp.setText("window.foosbug653108 = 'ahoyhoy';"); michael@0: sp.run().then(function() { michael@0: is(content.wrappedJSObject.foosbug653108, "ahoyhoy", michael@0: "content.foosbug653108 has been set 2"); michael@0: michael@0: gBrowser.selectedBrowser.addEventListener("load", runTests3, true); michael@0: content.location = "data:text/html,test context switch in Scratchpad location 2"; michael@0: }); michael@0: }); michael@0: } michael@0: michael@0: function runTests3() { michael@0: gBrowser.selectedBrowser.removeEventListener("load", runTests3, true); michael@0: // Check that the sandbox is not cached. michael@0: michael@0: sp.setText("typeof foosbug653108;"); michael@0: sp.run().then(function([, , result]) { michael@0: is(result, "undefined", "global variable does not exist"); michael@0: michael@0: tab1 = null; michael@0: tab2 = null; michael@0: sp = null; michael@0: finish(); michael@0: }); michael@0: }