browser/base/content/test/social/browser_social_flyout.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/base/content/test/social/browser_social_flyout.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,167 @@
     1.4 +/* This Source Code Form is subject to the terms of the Mozilla Public
     1.5 + * License, v. 2.0. If a copy of the MPL was not distributed with this
     1.6 + * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     1.7 +
     1.8 +function test() {
     1.9 +  waitForExplicitFinish();
    1.10 +
    1.11 +  let manifest = { // normal provider
    1.12 +    name: "provider 1",
    1.13 +    origin: "https://example.com",
    1.14 +    sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
    1.15 +    workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    1.16 +    iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
    1.17 +  };
    1.18 +  runSocialTestWithProvider(manifest, function (finishcb) {
    1.19 +    SocialSidebar.show();
    1.20 +    runSocialTests(tests, undefined, undefined, finishcb);
    1.21 +  });
    1.22 +}
    1.23 +
    1.24 +var tests = {
    1.25 +  testOpenCloseFlyout: function(next) {
    1.26 +    let panel = document.getElementById("social-flyout-panel");
    1.27 +    panel.addEventListener("popupshowing", function onShowing() {
    1.28 +      panel.removeEventListener("popupshowing", onShowing);
    1.29 +      is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
    1.30 +    });
    1.31 +    let port = SocialSidebar.provider.getWorkerPort();
    1.32 +    ok(port, "provider has a port");
    1.33 +    port.onmessage = function (e) {
    1.34 +      let topic = e.data.topic;
    1.35 +      switch (topic) {
    1.36 +        case "got-sidebar-message":
    1.37 +          port.postMessage({topic: "test-flyout-open"});
    1.38 +          break;
    1.39 +        case "got-flyout-visibility":
    1.40 +          if (e.data.result == "hidden") {
    1.41 +            ok(true, "flyout visibility is 'hidden'");
    1.42 +            is(panel.state, "closed", "panel really is closed");
    1.43 +            port.close();
    1.44 +            next();
    1.45 +          } else if (e.data.result == "shown") {
    1.46 +            ok(true, "flyout visibility is 'shown");
    1.47 +            port.postMessage({topic: "test-flyout-close"});
    1.48 +          }
    1.49 +          break;
    1.50 +        case "got-flyout-message":
    1.51 +          ok(e.data.result == "ok", "got flyout message");
    1.52 +          break;
    1.53 +      }
    1.54 +    }
    1.55 +    port.postMessage({topic: "test-init"});
    1.56 +  },
    1.57 +
    1.58 +  testResizeFlyout: function(next) {
    1.59 +    let panel = document.getElementById("social-flyout-panel");
    1.60 +    let port = SocialSidebar.provider.getWorkerPort();
    1.61 +    ok(port, "provider has a port");
    1.62 +    port.onmessage = function (e) {
    1.63 +      let topic = e.data.topic;
    1.64 +      switch (topic) {
    1.65 +        case "test-init-done":
    1.66 +          port.postMessage({topic: "test-flyout-open"});
    1.67 +          break;
    1.68 +        case "got-flyout-visibility":
    1.69 +          if (e.data.result != "shown")
    1.70 +            return;
    1.71 +          // The width of the flyout should be 400px initially
    1.72 +          let iframe = panel.firstChild;
    1.73 +          let body = iframe.contentDocument.body;
    1.74 +          let cs = iframe.contentWindow.getComputedStyle(body);
    1.75 +
    1.76 +          is(cs.width, "400px", "should be 400px wide");
    1.77 +          is(iframe.boxObject.width, 400, "iframe should now be 400px wide");
    1.78 +          is(cs.height, "400px", "should be 400px high");
    1.79 +          is(iframe.boxObject.height, 400, "iframe should now be 400px high");
    1.80 +
    1.81 +          iframe.contentWindow.addEventListener("resize", function _doneHandler() {
    1.82 +            iframe.contentWindow.removeEventListener("resize", _doneHandler, false);
    1.83 +            cs = iframe.contentWindow.getComputedStyle(body);
    1.84 +
    1.85 +            is(cs.width, "500px", "should now be 500px wide");
    1.86 +            is(iframe.boxObject.width, 500, "iframe should now be 500px wide");
    1.87 +            is(cs.height, "500px", "should now be 500px high");
    1.88 +            is(iframe.boxObject.height, 500, "iframe should now be 500px high");
    1.89 +            panel.hidePopup();
    1.90 +            port.close();
    1.91 +            next();
    1.92 +          }, false);
    1.93 +          SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
    1.94 +          break;
    1.95 +      }
    1.96 +    }
    1.97 +    port.postMessage({topic: "test-init"});
    1.98 +  },
    1.99 +
   1.100 +  testCloseSelf: function(next) {
   1.101 +    // window.close is affected by the pref dom.allow_scripts_to_close_windows,
   1.102 +    // which defaults to false, but is set to true by the test harness.
   1.103 +    // so temporarily set it back.
   1.104 +    const ALLOW_SCRIPTS_TO_CLOSE_PREF = "dom.allow_scripts_to_close_windows";
   1.105 +    // note clearUserPref doesn't do what we expect, as the test harness itself
   1.106 +    // changes the pref value - so clearUserPref resets it to false rather than
   1.107 +    // the true setup by the test harness.
   1.108 +    let oldAllowScriptsToClose = Services.prefs.getBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF);
   1.109 +    Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, false);
   1.110 +    let panel = document.getElementById("social-flyout-panel");
   1.111 +    let port = SocialSidebar.provider.getWorkerPort();
   1.112 +    ok(port, "provider has a port");
   1.113 +    port.onmessage = function (e) {
   1.114 +      let topic = e.data.topic;
   1.115 +      switch (topic) {
   1.116 +        case "test-init-done":
   1.117 +          port.postMessage({topic: "test-flyout-open"});
   1.118 +          break;
   1.119 +        case "got-flyout-visibility":
   1.120 +          if (e.data.result != "shown")
   1.121 +            return;
   1.122 +          let iframe = panel.firstChild;
   1.123 +          iframe.contentDocument.addEventListener("SocialTest-DoneCloseSelf", function _doneHandler() {
   1.124 +            iframe.contentDocument.removeEventListener("SocialTest-DoneCloseSelf", _doneHandler, false);
   1.125 +            port.close();
   1.126 +            is(panel.state, "closed", "flyout should have closed itself");
   1.127 +            Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, oldAllowScriptsToClose);
   1.128 +            next();
   1.129 +          }, false);
   1.130 +          is(panel.state, "open", "flyout should be open");
   1.131 +          SocialFlyout.dispatchPanelEvent("socialTest-CloseSelf");
   1.132 +          break;
   1.133 +      }
   1.134 +    }
   1.135 +    port.postMessage({topic: "test-init"});
   1.136 +  },
   1.137 +
   1.138 +  testCloseOnLinkTraversal: function(next) {
   1.139 +
   1.140 +    function onTabOpen(event) {
   1.141 +      gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
   1.142 +      waitForCondition(function() { return panel.state == "closed" }, function() {
   1.143 +        gBrowser.removeTab(event.target);
   1.144 +        next();
   1.145 +      }, "panel should close after tab open");
   1.146 +    }
   1.147 +
   1.148 +    let panel = document.getElementById("social-flyout-panel");
   1.149 +    let port = SocialSidebar.provider.getWorkerPort();
   1.150 +    ok(port, "provider has a port");
   1.151 +    port.onmessage = function (e) {
   1.152 +      let topic = e.data.topic;
   1.153 +      switch (topic) {
   1.154 +        case "test-init-done":
   1.155 +          port.postMessage({topic: "test-flyout-open"});
   1.156 +          break;
   1.157 +        case "got-flyout-visibility":
   1.158 +          if (e.data.result == "shown") {
   1.159 +            // click on our test link
   1.160 +            is(panel.state, "open", "flyout should be open");
   1.161 +            gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
   1.162 +            let iframe = panel.firstChild;
   1.163 +            iframe.contentDocument.getElementById('traversal').click();
   1.164 +          }
   1.165 +          break;
   1.166 +      }
   1.167 +    }
   1.168 +    port.postMessage({topic: "test-init"});
   1.169 +  }
   1.170 +}

mercurial