browser/base/content/test/general/browser_bug409481.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/general/browser_bug409481.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,83 @@
     1.4 +function test() {
     1.5 +  waitForExplicitFinish();
     1.6 +
     1.7 +  // XXX This looks a bit odd, but is needed to avoid throwing when removing the
     1.8 +  // event listeners below. See bug 310955.
     1.9 +  document.getElementById("sidebar").addEventListener("load", delayedOpenUrl, true);
    1.10 +  toggleSidebar("viewWebPanelsSidebar", true);
    1.11 +}
    1.12 +
    1.13 +function delayedOpenUrl() {
    1.14 +  ok(true, "Ran delayedOpenUrl");
    1.15 +  setTimeout(openPanelUrl, 100);
    1.16 +}
    1.17 +
    1.18 +function openPanelUrl(event) {
    1.19 +  ok(!document.getElementById("sidebar-box").hidden, "Sidebar showing");
    1.20 +
    1.21 +  var sidebar = document.getElementById("sidebar");
    1.22 +  var root = sidebar.contentDocument.documentElement;
    1.23 +  ok(root.nodeName != "parsererror", "Sidebar is well formed");
    1.24 +
    1.25 +  sidebar.removeEventListener("load", delayedOpenUrl, true);
    1.26 +  // XXX See comment above
    1.27 +  sidebar.contentDocument.addEventListener("load", delayedRunTest, true);
    1.28 +  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">';
    1.29 +  sidebar.contentWindow.loadWebPanel(url);
    1.30 +}
    1.31 +
    1.32 +function delayedRunTest() {
    1.33 +  ok(true, "Ran delayedRunTest");
    1.34 +  setTimeout(runTest, 100);
    1.35 +}
    1.36 +
    1.37 +function runTest(event) {
    1.38 +  var sidebar = document.getElementById("sidebar");
    1.39 +  sidebar.contentDocument.removeEventListener("load", delayedRunTest, true);
    1.40 +
    1.41 +  var browser = sidebar.contentDocument.getElementById("web-panels-browser");
    1.42 +  var div = browser && browser.contentDocument.getElementById("test_bug409481");
    1.43 +  ok(div && div.textContent == "Content!", "Sidebar content loaded");
    1.44 +
    1.45 +  var link = browser && browser.contentDocument.getElementById("link");
    1.46 +  sidebar.contentDocument.addEventListener("popupshown", contextMenuOpened, false);
    1.47 +
    1.48 +  EventUtils.synthesizeMouseAtCenter(link, { type: "contextmenu", button: 2 }, browser.contentWindow);
    1.49 +}
    1.50 +
    1.51 +function contextMenuOpened()
    1.52 +{
    1.53 +  var sidebar = document.getElementById("sidebar");
    1.54 +  sidebar.contentDocument.removeEventListener("popupshown", contextMenuOpened, false);
    1.55 +
    1.56 +  var copyLinkCommand = sidebar.contentDocument.getElementById("context-copylink");
    1.57 +  copyLinkCommand.addEventListener("command", copyLinkCommandExecuted, false);
    1.58 +  copyLinkCommand.doCommand();
    1.59 +}
    1.60 +
    1.61 +function copyLinkCommandExecuted(event)
    1.62 +{
    1.63 +  event.target.removeEventListener("command", copyLinkCommandExecuted, false);
    1.64 +
    1.65 +  var sidebar = document.getElementById("sidebar");
    1.66 +  var browser = sidebar.contentDocument.getElementById("web-panels-browser");
    1.67 +  var textbox = browser && browser.contentDocument.getElementById("textbox");
    1.68 +  textbox.focus();
    1.69 +  document.commandDispatcher.getControllerForCommand("cmd_paste").doCommand("cmd_paste");
    1.70 +  is(textbox.value, "http://www.example.com/ctest", "copy link command");
    1.71 +
    1.72 +  sidebar.contentDocument.addEventListener("popuphidden", contextMenuClosed, false);
    1.73 +  event.target.parentNode.hidePopup();
    1.74 +}
    1.75 +
    1.76 +function contextMenuClosed()
    1.77 +{
    1.78 +  var sidebar = document.getElementById("sidebar");
    1.79 +  sidebar.contentDocument.removeEventListener("popuphidden", contextMenuClosed, false);
    1.80 +
    1.81 +  toggleSidebar("viewWebPanelsSidebar");
    1.82 +
    1.83 +  ok(document.getElementById("sidebar-box").hidden, "Sidebar successfully hidden");
    1.84 +
    1.85 +  finish();
    1.86 +}

mercurial