browser/components/tabview/test/browser_tabview_bug610242.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 /* Any copyright is dedicated to the Public Domain.
     2    http://creativecommons.org/publicdomain/zero/1.0/ */
     4 function test() {
     5   waitForExplicitFinish();
     7   newWindowWithTabView(onTabViewWindowLoaded);
     8 }
    10 function onTabViewWindowLoaded(win) {
    11   win.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
    13   ok(win.TabView.isVisible(), "Tab View is visible");
    15   let contentWindow = win.document.getElementById("tab-view").contentWindow;
    16   let [originalTab] = win.gBrowser.visibleTabs;
    18   let currentGroup = contentWindow.GroupItems.getActiveGroupItem();
    20   // Create a group and make it active
    21   let box = new contentWindow.Rect(100, 100, 370, 370);
    22   let group = new contentWindow.GroupItem([], { bounds: box });
    23   ok(group.isEmpty(), "This group is empty");
    24   contentWindow.UI.setActive(group);
    25   is(contentWindow.GroupItems.getActiveGroupItem(), group, "new group is active");
    27   // Create a bunch of tabs in the group
    28   let bg = {inBackground: true};
    29   let datatext = win.gBrowser.loadOneTab("data:text/plain,bug610242", bg);
    30   let datahtml = win.gBrowser.loadOneTab("data:text/html,<h1>hi!</h1>", bg);
    31   let mozilla  = win.gBrowser.loadOneTab("about:mozilla", bg);
    32   let synclog   = win.gBrowser.loadOneTab("about:sync-log", bg);
    33   let html     = win.gBrowser.loadOneTab("http://example.com", bg);
    34   let png      = win.gBrowser.loadOneTab("http://mochi.test:8888/browser/browser/base/content/test/general/moz.png", bg);
    35   let svg      = win.gBrowser.loadOneTab("http://mochi.test:8888/browser/browser/base/content/test/general/title_test.svg", bg);
    37   ok(!group.shouldStack(group._children.length), "Group should not stack.");
    39   // PREPARE FINISH:
    40   group.addSubscriber("close", function onClose() {
    41     group.removeSubscriber("close", onClose);
    43     ok(group.isEmpty(), "The group is empty again");
    45     contentWindow.UI.setActive(currentGroup);
    46     isnot(contentWindow.GroupItems.getActiveGroupItem(), null, "There is an active group");
    47     is(win.gBrowser.tabs.length, 1, "There is only one tab left");
    48     is(win.gBrowser.visibleTabs.length, 1, "There is also only one visible tab");
    50     whenTabViewIsHidden(function() {
    51       win.close();
    52       ok(win.closed, "new window is closed");
    53       finish();
    54     }, win);
    55     win.gBrowser.selectedTab = originalTab;
    57     win.TabView.hide();
    58   });
    60   function check(tab, label, visible) {
    61     let display = contentWindow.getComputedStyle(tab._tabViewTabItem.$fav[0], null).getPropertyValue("display");
    62     if (visible) {
    63       is(display, "block", label + " has favicon");
    64     } else {
    65       is(display, "none", label + " has no favicon");
    66     }
    67   }
    69   afterAllTabsLoaded(function() {
    70     let children = group.getChildren();
    71     let len = children.length;
    72     let iconUpdateCounter = 0;
    74     children.forEach(function(tabItem) {
    75       tabItem.addSubscriber("iconUpdated", function onIconUpdated() {
    76         tabItem.removeSubscriber("iconUpdated", onIconUpdated);
    78         if (++iconUpdateCounter == len) {
    79           check(datatext, "datatext", false);
    80           check(datahtml, "datahtml", false);
    81           check(mozilla, "about:mozilla", false);
    82           check(synclog, "about:sync-log", true);
    83           check(html, "html", true);
    84           check(png, "png", false);
    85           check(svg, "svg", true);
    87           // Get rid of the group and its children
    88           // The group close will trigger a finish().
    89           closeGroupItem(group);
    90         }
    91       });
    92     });
    94     afterAllTabItemsUpdated(function () {}, win);
    95   }, win);
    96 }

mercurial