|
1 function test() { |
|
2 waitForExplicitFinish(); |
|
3 |
|
4 // XXX This looks a bit odd, but is needed to avoid throwing when removing the |
|
5 // event listeners below. See bug 310955. |
|
6 document.getElementById("sidebar").addEventListener("load", delayedOpenUrl, true); |
|
7 toggleSidebar("viewWebPanelsSidebar", true); |
|
8 } |
|
9 |
|
10 function delayedOpenUrl() { |
|
11 ok(true, "Ran delayedOpenUrl"); |
|
12 setTimeout(openPanelUrl, 100); |
|
13 } |
|
14 |
|
15 function openPanelUrl(event) { |
|
16 ok(!document.getElementById("sidebar-box").hidden, "Sidebar showing"); |
|
17 |
|
18 var sidebar = document.getElementById("sidebar"); |
|
19 var root = sidebar.contentDocument.documentElement; |
|
20 ok(root.nodeName != "parsererror", "Sidebar is well formed"); |
|
21 |
|
22 sidebar.removeEventListener("load", delayedOpenUrl, true); |
|
23 // XXX See comment above |
|
24 sidebar.contentDocument.addEventListener("load", delayedRunTest, true); |
|
25 var url = 'data:text/html,<div%20id="test_bug409481">Content!</div><a id="link" href="http://www.example.com/ctest">Link</a><input id="textbox">'; |
|
26 sidebar.contentWindow.loadWebPanel(url); |
|
27 } |
|
28 |
|
29 function delayedRunTest() { |
|
30 ok(true, "Ran delayedRunTest"); |
|
31 setTimeout(runTest, 100); |
|
32 } |
|
33 |
|
34 function runTest(event) { |
|
35 var sidebar = document.getElementById("sidebar"); |
|
36 sidebar.contentDocument.removeEventListener("load", delayedRunTest, true); |
|
37 |
|
38 var browser = sidebar.contentDocument.getElementById("web-panels-browser"); |
|
39 var div = browser && browser.contentDocument.getElementById("test_bug409481"); |
|
40 ok(div && div.textContent == "Content!", "Sidebar content loaded"); |
|
41 |
|
42 var link = browser && browser.contentDocument.getElementById("link"); |
|
43 sidebar.contentDocument.addEventListener("popupshown", contextMenuOpened, false); |
|
44 |
|
45 EventUtils.synthesizeMouseAtCenter(link, { type: "contextmenu", button: 2 }, browser.contentWindow); |
|
46 } |
|
47 |
|
48 function contextMenuOpened() |
|
49 { |
|
50 var sidebar = document.getElementById("sidebar"); |
|
51 sidebar.contentDocument.removeEventListener("popupshown", contextMenuOpened, false); |
|
52 |
|
53 var copyLinkCommand = sidebar.contentDocument.getElementById("context-copylink"); |
|
54 copyLinkCommand.addEventListener("command", copyLinkCommandExecuted, false); |
|
55 copyLinkCommand.doCommand(); |
|
56 } |
|
57 |
|
58 function copyLinkCommandExecuted(event) |
|
59 { |
|
60 event.target.removeEventListener("command", copyLinkCommandExecuted, false); |
|
61 |
|
62 var sidebar = document.getElementById("sidebar"); |
|
63 var browser = sidebar.contentDocument.getElementById("web-panels-browser"); |
|
64 var textbox = browser && browser.contentDocument.getElementById("textbox"); |
|
65 textbox.focus(); |
|
66 document.commandDispatcher.getControllerForCommand("cmd_paste").doCommand("cmd_paste"); |
|
67 is(textbox.value, "http://www.example.com/ctest", "copy link command"); |
|
68 |
|
69 sidebar.contentDocument.addEventListener("popuphidden", contextMenuClosed, false); |
|
70 event.target.parentNode.hidePopup(); |
|
71 } |
|
72 |
|
73 function contextMenuClosed() |
|
74 { |
|
75 var sidebar = document.getElementById("sidebar"); |
|
76 sidebar.contentDocument.removeEventListener("popuphidden", contextMenuClosed, false); |
|
77 |
|
78 toggleSidebar("viewWebPanelsSidebar"); |
|
79 |
|
80 ok(document.getElementById("sidebar-box").hidden, "Sidebar successfully hidden"); |
|
81 |
|
82 finish(); |
|
83 } |