michael@0: function test() {
michael@0: waitForExplicitFinish();
michael@0:
michael@0: // XXX This looks a bit odd, but is needed to avoid throwing when removing the
michael@0: // event listeners below. See bug 310955.
michael@0: document.getElementById("sidebar").addEventListener("load", delayedOpenUrl, true);
michael@0: toggleSidebar("viewWebPanelsSidebar", true);
michael@0: }
michael@0:
michael@0: function delayedOpenUrl() {
michael@0: ok(true, "Ran delayedOpenUrl");
michael@0: setTimeout(openPanelUrl, 100);
michael@0: }
michael@0:
michael@0: function openPanelUrl(event) {
michael@0: ok(!document.getElementById("sidebar-box").hidden, "Sidebar showing");
michael@0:
michael@0: var sidebar = document.getElementById("sidebar");
michael@0: var root = sidebar.contentDocument.documentElement;
michael@0: ok(root.nodeName != "parsererror", "Sidebar is well formed");
michael@0:
michael@0: sidebar.removeEventListener("load", delayedOpenUrl, true);
michael@0: // XXX See comment above
michael@0: sidebar.contentDocument.addEventListener("load", delayedRunTest, true);
michael@0: var url = 'data:text/html,
Content!
Link';
michael@0: sidebar.contentWindow.loadWebPanel(url);
michael@0: }
michael@0:
michael@0: function delayedRunTest() {
michael@0: ok(true, "Ran delayedRunTest");
michael@0: setTimeout(runTest, 100);
michael@0: }
michael@0:
michael@0: function runTest(event) {
michael@0: var sidebar = document.getElementById("sidebar");
michael@0: sidebar.contentDocument.removeEventListener("load", delayedRunTest, true);
michael@0:
michael@0: var browser = sidebar.contentDocument.getElementById("web-panels-browser");
michael@0: var div = browser && browser.contentDocument.getElementById("test_bug409481");
michael@0: ok(div && div.textContent == "Content!", "Sidebar content loaded");
michael@0:
michael@0: var link = browser && browser.contentDocument.getElementById("link");
michael@0: sidebar.contentDocument.addEventListener("popupshown", contextMenuOpened, false);
michael@0:
michael@0: EventUtils.synthesizeMouseAtCenter(link, { type: "contextmenu", button: 2 }, browser.contentWindow);
michael@0: }
michael@0:
michael@0: function contextMenuOpened()
michael@0: {
michael@0: var sidebar = document.getElementById("sidebar");
michael@0: sidebar.contentDocument.removeEventListener("popupshown", contextMenuOpened, false);
michael@0:
michael@0: var copyLinkCommand = sidebar.contentDocument.getElementById("context-copylink");
michael@0: copyLinkCommand.addEventListener("command", copyLinkCommandExecuted, false);
michael@0: copyLinkCommand.doCommand();
michael@0: }
michael@0:
michael@0: function copyLinkCommandExecuted(event)
michael@0: {
michael@0: event.target.removeEventListener("command", copyLinkCommandExecuted, false);
michael@0:
michael@0: var sidebar = document.getElementById("sidebar");
michael@0: var browser = sidebar.contentDocument.getElementById("web-panels-browser");
michael@0: var textbox = browser && browser.contentDocument.getElementById("textbox");
michael@0: textbox.focus();
michael@0: document.commandDispatcher.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
michael@0: is(textbox.value, "http://www.example.com/ctest", "copy link command");
michael@0:
michael@0: sidebar.contentDocument.addEventListener("popuphidden", contextMenuClosed, false);
michael@0: event.target.parentNode.hidePopup();
michael@0: }
michael@0:
michael@0: function contextMenuClosed()
michael@0: {
michael@0: var sidebar = document.getElementById("sidebar");
michael@0: sidebar.contentDocument.removeEventListener("popuphidden", contextMenuClosed, false);
michael@0:
michael@0: toggleSidebar("viewWebPanelsSidebar");
michael@0:
michael@0: ok(document.getElementById("sidebar-box").hidden, "Sidebar successfully hidden");
michael@0:
michael@0: finish();
michael@0: }