|
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 /* Bug 740948 */ |
|
5 |
|
6 let DEVTOOLS_CHROME_ENABLED = "devtools.chrome.enabled"; |
|
7 let EDITOR_TEXT = [ |
|
8 "var evt = new CustomEvent('foo', { bubbles: true });", |
|
9 "document.body.innerHTML = 'Modified text';", |
|
10 "window.dispatchEvent(evt);" |
|
11 ].join("\n"); |
|
12 |
|
13 function test() |
|
14 { |
|
15 requestLongerTimeout(2); |
|
16 waitForExplicitFinish(); |
|
17 Services.prefs.setBoolPref(DEVTOOLS_CHROME_ENABLED, true); |
|
18 |
|
19 gBrowser.selectedTab = gBrowser.addTab(); |
|
20 gBrowser.selectedBrowser.addEventListener("load", function onLoad() { |
|
21 gBrowser.selectedBrowser.removeEventListener("load", onLoad, true); |
|
22 openScratchpad(runTests); |
|
23 }, true); |
|
24 |
|
25 content.location = "data:text/html,Scratchpad test for bug 740948"; |
|
26 } |
|
27 |
|
28 function runTests() |
|
29 { |
|
30 let sp = gScratchpadWindow.Scratchpad; |
|
31 ok(sp, "Scratchpad object exists in new window"); |
|
32 |
|
33 // Test that Reload And Run command is enabled in the content |
|
34 // context and disabled in the browser context. |
|
35 |
|
36 let reloadAndRun = gScratchpadWindow.document. |
|
37 getElementById("sp-cmd-reloadAndRun"); |
|
38 ok(reloadAndRun, "Reload And Run command exists"); |
|
39 ok(!reloadAndRun.hasAttribute("disabled"), |
|
40 "Reload And Run command is enabled"); |
|
41 |
|
42 sp.setBrowserContext(); |
|
43 ok(reloadAndRun.hasAttribute("disabled"), |
|
44 "Reload And Run command is disabled in the browser context."); |
|
45 |
|
46 // Switch back to the content context and run our predefined |
|
47 // code. This code modifies the body of our document and dispatches |
|
48 // a custom event 'foo'. We listen to that event and check the |
|
49 // body to make sure that the page has been reloaded and Scratchpad |
|
50 // code has been executed. |
|
51 |
|
52 sp.setContentContext(); |
|
53 sp.setText(EDITOR_TEXT); |
|
54 |
|
55 let browser = gBrowser.selectedBrowser; |
|
56 |
|
57 browser.addEventListener("DOMWindowCreated", function onWindowCreated() { |
|
58 browser.removeEventListener("DOMWindowCreated", onWindowCreated, true); |
|
59 |
|
60 browser.contentWindow.addEventListener("foo", function onFoo() { |
|
61 browser.contentWindow.removeEventListener("foo", onFoo, true); |
|
62 |
|
63 is(browser.contentWindow.document.body.innerHTML, "Modified text", |
|
64 "After reloading, HTML is different."); |
|
65 |
|
66 Services.prefs.clearUserPref(DEVTOOLS_CHROME_ENABLED); |
|
67 finish(); |
|
68 }, true); |
|
69 }, true); |
|
70 |
|
71 ok(browser.contentWindow.document.body.innerHTML !== "Modified text", |
|
72 "Before reloading, HTML is intact."); |
|
73 sp.reloadAndRun(); |
|
74 } |
|
75 |