1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/scratchpad/test/browser_scratchpad_tab_switch.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,103 @@ 1.4 +/* vim: set ts=2 et sw=2 tw=80: */ 1.5 +/* Any copyright is dedicated to the Public Domain. 1.6 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.7 + 1.8 +let tab1; 1.9 +let tab2; 1.10 +let sp; 1.11 + 1.12 +function test() 1.13 +{ 1.14 + waitForExplicitFinish(); 1.15 + 1.16 + tab1 = gBrowser.addTab(); 1.17 + gBrowser.selectedTab = tab1; 1.18 + gBrowser.selectedBrowser.addEventListener("load", function onLoad1() { 1.19 + gBrowser.selectedBrowser.removeEventListener("load", onLoad1, true); 1.20 + 1.21 + tab2 = gBrowser.addTab(); 1.22 + gBrowser.selectedTab = tab2; 1.23 + gBrowser.selectedBrowser.addEventListener("load", function onLoad2() { 1.24 + gBrowser.selectedBrowser.removeEventListener("load", onLoad2, true); 1.25 + openScratchpad(runTests); 1.26 + }, true); 1.27 + content.location = "data:text/html,test context switch in Scratchpad tab 2"; 1.28 + }, true); 1.29 + 1.30 + content.location = "data:text/html,test context switch in Scratchpad tab 1"; 1.31 +} 1.32 + 1.33 +function runTests() 1.34 +{ 1.35 + sp = gScratchpadWindow.Scratchpad; 1.36 + 1.37 + let contentMenu = gScratchpadWindow.document.getElementById("sp-menu-content"); 1.38 + let browserMenu = gScratchpadWindow.document.getElementById("sp-menu-browser"); 1.39 + let notificationBox = sp.notificationBox; 1.40 + 1.41 + ok(contentMenu, "found #sp-menu-content"); 1.42 + ok(browserMenu, "found #sp-menu-browser"); 1.43 + ok(notificationBox, "found Scratchpad.notificationBox"); 1.44 + 1.45 + sp.setContentContext(); 1.46 + 1.47 + is(sp.executionContext, gScratchpadWindow.SCRATCHPAD_CONTEXT_CONTENT, 1.48 + "executionContext is content"); 1.49 + 1.50 + is(contentMenu.getAttribute("checked"), "true", 1.51 + "content menuitem is checked"); 1.52 + 1.53 + isnot(browserMenu.getAttribute("checked"), "true", 1.54 + "chrome menuitem is not checked"); 1.55 + 1.56 + is(notificationBox.currentNotification, null, 1.57 + "there is no notification currently shown for content context"); 1.58 + 1.59 + sp.setText("window.foosbug653108 = 'aloha';"); 1.60 + 1.61 + ok(!content.wrappedJSObject.foosbug653108, 1.62 + "no content.foosbug653108"); 1.63 + 1.64 + sp.run().then(function() { 1.65 + is(content.wrappedJSObject.foosbug653108, "aloha", 1.66 + "content.foosbug653108 has been set"); 1.67 + 1.68 + gBrowser.tabContainer.addEventListener("TabSelect", runTests2, true); 1.69 + gBrowser.selectedTab = tab1; 1.70 + }); 1.71 +} 1.72 + 1.73 +function runTests2() { 1.74 + gBrowser.tabContainer.removeEventListener("TabSelect", runTests2, true); 1.75 + 1.76 + ok(!window.foosbug653108, "no window.foosbug653108"); 1.77 + 1.78 + sp.setText("window.foosbug653108"); 1.79 + sp.run().then(function([, , result]) { 1.80 + isnot(result, "aloha", "window.foosbug653108 is not aloha"); 1.81 + 1.82 + sp.setText("window.foosbug653108 = 'ahoyhoy';"); 1.83 + sp.run().then(function() { 1.84 + is(content.wrappedJSObject.foosbug653108, "ahoyhoy", 1.85 + "content.foosbug653108 has been set 2"); 1.86 + 1.87 + gBrowser.selectedBrowser.addEventListener("load", runTests3, true); 1.88 + content.location = "data:text/html,test context switch in Scratchpad location 2"; 1.89 + }); 1.90 + }); 1.91 +} 1.92 + 1.93 +function runTests3() { 1.94 + gBrowser.selectedBrowser.removeEventListener("load", runTests3, true); 1.95 + // Check that the sandbox is not cached. 1.96 + 1.97 + sp.setText("typeof foosbug653108;"); 1.98 + sp.run().then(function([, , result]) { 1.99 + is(result, "undefined", "global variable does not exist"); 1.100 + 1.101 + tab1 = null; 1.102 + tab2 = null; 1.103 + sp = null; 1.104 + finish(); 1.105 + }); 1.106 +}