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

Wed, 31 Dec 2014 06:09:35 +0100

author
Michael Schloh von Bennewitz <michael@schloh.com>
date
Wed, 31 Dec 2014 06:09:35 +0100
changeset 0
6474c204b198
permissions
-rw-r--r--

Cloned upstream origin tor-browser at tor-browser-31.3.0esr-4.5-1-build1
revision ID fc1c9ff7c1b2defdbc039f12214767608f46423f for hacking purpose.

     1 /* This Source Code Form is subject to the terms of the Mozilla Public
     2  * License, v. 2.0. If a copy of the MPL was not distributed with this
     3  * file, You can obtain one at http://mozilla.org/MPL/2.0/. */
     5 function test() {
     6   waitForExplicitFinish();
     8   let manifest = { // normal provider
     9     name: "provider 1",
    10     origin: "https://example.com",
    11     sidebarURL: "https://example.com/browser/browser/base/content/test/social/social_sidebar.html",
    12     workerURL: "https://example.com/browser/browser/base/content/test/social/social_worker.js",
    13     iconURL: "https://example.com/browser/browser/base/content/test/general/moz.png"
    14   };
    15   runSocialTestWithProvider(manifest, function (finishcb) {
    16     SocialSidebar.show();
    17     runSocialTests(tests, undefined, undefined, finishcb);
    18   });
    19 }
    21 var tests = {
    22   testOpenCloseFlyout: function(next) {
    23     let panel = document.getElementById("social-flyout-panel");
    24     panel.addEventListener("popupshowing", function onShowing() {
    25       panel.removeEventListener("popupshowing", onShowing);
    26       is(panel.firstChild.contentDocument.readyState, "complete", "panel is loaded prior to showing");
    27     });
    28     let port = SocialSidebar.provider.getWorkerPort();
    29     ok(port, "provider has a port");
    30     port.onmessage = function (e) {
    31       let topic = e.data.topic;
    32       switch (topic) {
    33         case "got-sidebar-message":
    34           port.postMessage({topic: "test-flyout-open"});
    35           break;
    36         case "got-flyout-visibility":
    37           if (e.data.result == "hidden") {
    38             ok(true, "flyout visibility is 'hidden'");
    39             is(panel.state, "closed", "panel really is closed");
    40             port.close();
    41             next();
    42           } else if (e.data.result == "shown") {
    43             ok(true, "flyout visibility is 'shown");
    44             port.postMessage({topic: "test-flyout-close"});
    45           }
    46           break;
    47         case "got-flyout-message":
    48           ok(e.data.result == "ok", "got flyout message");
    49           break;
    50       }
    51     }
    52     port.postMessage({topic: "test-init"});
    53   },
    55   testResizeFlyout: function(next) {
    56     let panel = document.getElementById("social-flyout-panel");
    57     let port = SocialSidebar.provider.getWorkerPort();
    58     ok(port, "provider has a port");
    59     port.onmessage = function (e) {
    60       let topic = e.data.topic;
    61       switch (topic) {
    62         case "test-init-done":
    63           port.postMessage({topic: "test-flyout-open"});
    64           break;
    65         case "got-flyout-visibility":
    66           if (e.data.result != "shown")
    67             return;
    68           // The width of the flyout should be 400px initially
    69           let iframe = panel.firstChild;
    70           let body = iframe.contentDocument.body;
    71           let cs = iframe.contentWindow.getComputedStyle(body);
    73           is(cs.width, "400px", "should be 400px wide");
    74           is(iframe.boxObject.width, 400, "iframe should now be 400px wide");
    75           is(cs.height, "400px", "should be 400px high");
    76           is(iframe.boxObject.height, 400, "iframe should now be 400px high");
    78           iframe.contentWindow.addEventListener("resize", function _doneHandler() {
    79             iframe.contentWindow.removeEventListener("resize", _doneHandler, false);
    80             cs = iframe.contentWindow.getComputedStyle(body);
    82             is(cs.width, "500px", "should now be 500px wide");
    83             is(iframe.boxObject.width, 500, "iframe should now be 500px wide");
    84             is(cs.height, "500px", "should now be 500px high");
    85             is(iframe.boxObject.height, 500, "iframe should now be 500px high");
    86             panel.hidePopup();
    87             port.close();
    88             next();
    89           }, false);
    90           SocialFlyout.dispatchPanelEvent("socialTest-MakeWider");
    91           break;
    92       }
    93     }
    94     port.postMessage({topic: "test-init"});
    95   },
    97   testCloseSelf: function(next) {
    98     // window.close is affected by the pref dom.allow_scripts_to_close_windows,
    99     // which defaults to false, but is set to true by the test harness.
   100     // so temporarily set it back.
   101     const ALLOW_SCRIPTS_TO_CLOSE_PREF = "dom.allow_scripts_to_close_windows";
   102     // note clearUserPref doesn't do what we expect, as the test harness itself
   103     // changes the pref value - so clearUserPref resets it to false rather than
   104     // the true setup by the test harness.
   105     let oldAllowScriptsToClose = Services.prefs.getBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF);
   106     Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, false);
   107     let panel = document.getElementById("social-flyout-panel");
   108     let port = SocialSidebar.provider.getWorkerPort();
   109     ok(port, "provider has a port");
   110     port.onmessage = function (e) {
   111       let topic = e.data.topic;
   112       switch (topic) {
   113         case "test-init-done":
   114           port.postMessage({topic: "test-flyout-open"});
   115           break;
   116         case "got-flyout-visibility":
   117           if (e.data.result != "shown")
   118             return;
   119           let iframe = panel.firstChild;
   120           iframe.contentDocument.addEventListener("SocialTest-DoneCloseSelf", function _doneHandler() {
   121             iframe.contentDocument.removeEventListener("SocialTest-DoneCloseSelf", _doneHandler, false);
   122             port.close();
   123             is(panel.state, "closed", "flyout should have closed itself");
   124             Services.prefs.setBoolPref(ALLOW_SCRIPTS_TO_CLOSE_PREF, oldAllowScriptsToClose);
   125             next();
   126           }, false);
   127           is(panel.state, "open", "flyout should be open");
   128           SocialFlyout.dispatchPanelEvent("socialTest-CloseSelf");
   129           break;
   130       }
   131     }
   132     port.postMessage({topic: "test-init"});
   133   },
   135   testCloseOnLinkTraversal: function(next) {
   137     function onTabOpen(event) {
   138       gBrowser.tabContainer.removeEventListener("TabOpen", onTabOpen, true);
   139       waitForCondition(function() { return panel.state == "closed" }, function() {
   140         gBrowser.removeTab(event.target);
   141         next();
   142       }, "panel should close after tab open");
   143     }
   145     let panel = document.getElementById("social-flyout-panel");
   146     let port = SocialSidebar.provider.getWorkerPort();
   147     ok(port, "provider has a port");
   148     port.onmessage = function (e) {
   149       let topic = e.data.topic;
   150       switch (topic) {
   151         case "test-init-done":
   152           port.postMessage({topic: "test-flyout-open"});
   153           break;
   154         case "got-flyout-visibility":
   155           if (e.data.result == "shown") {
   156             // click on our test link
   157             is(panel.state, "open", "flyout should be open");
   158             gBrowser.tabContainer.addEventListener("TabOpen", onTabOpen, true);
   159             let iframe = panel.firstChild;
   160             iframe.contentDocument.getElementById('traversal').click();
   161           }
   162           break;
   163       }
   164     }
   165     port.postMessage({topic: "test-init"});
   166   }
   167 }

mercurial