browser/components/tabview/test/browser_tabview_layout.js

changeset 0
6474c204b198
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/browser/components/tabview/test/browser_tabview_layout.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,111 @@
     1.4 +/* Any copyright is dedicated to the Public Domain.
     1.5 +   http://creativecommons.org/publicdomain/zero/1.0/ */
     1.6 +
     1.7 +function test() {
     1.8 +  waitForExplicitFinish();
     1.9 +
    1.10 +  // verify initial state
    1.11 +  ok(!TabView.isVisible(), "Tab View starts hidden");
    1.12 +
    1.13 +  window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.14 +  TabView.toggle();
    1.15 +}
    1.16 +
    1.17 +let originalGroupItem = null;
    1.18 +let originalTab = null;
    1.19 +let contentWindow = null;
    1.20 +
    1.21 +function onTabViewWindowLoaded() {
    1.22 +  window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.23 +  ok(TabView.isVisible(), "Tab View is visible");
    1.24 +
    1.25 +  contentWindow = document.getElementById("tab-view").contentWindow;
    1.26 +
    1.27 +  is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup");
    1.28 +  originalGroupItem = contentWindow.GroupItems.groupItems[0];
    1.29 +  is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group.");
    1.30 +  contentWindow.UI.setActive(originalGroupItem);
    1.31 +
    1.32 +  [originalTab] = gBrowser.visibleTabs;
    1.33 +
    1.34 +  testEmptyGroupItem(contentWindow);
    1.35 +}
    1.36 +
    1.37 +function testEmptyGroupItem(contentWindow) {
    1.38 +  let groupItemCount = contentWindow.GroupItems.groupItems.length;
    1.39 +
    1.40 +  // Preparation
    1.41 +  //
    1.42 +    
    1.43 +  // create empty group item
    1.44 +  let emptyGroupItem = createEmptyGroupItem(contentWindow, 253, 335, 100);
    1.45 +  ok(emptyGroupItem.isEmpty(), "This group is empty");
    1.46 +
    1.47 +  is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
    1.48 +     "The number of groups is increased by 1");
    1.49 +
    1.50 +  // add four blank items
    1.51 +  contentWindow.UI.setActive(emptyGroupItem);
    1.52 +
    1.53 +  let numNewTabs = 4;
    1.54 +  let items = [];
    1.55 +  for(let t=0; t<numNewTabs; t++) {
    1.56 +    let newItem = contentWindow.gBrowser.loadOneTab("about:blank")._tabViewTabItem;
    1.57 +    ok(newItem.container, "Created element "+t+":"+newItem.container);
    1.58 +    items.push(newItem);
    1.59 +  }
    1.60 +
    1.61 +  // Define main test function
    1.62 +  //
    1.63 +
    1.64 +  let mainTestFunc = function() {
    1.65 +    for(let j=0; j<numNewTabs; j++) {
    1.66 +      for(let i=0; i<numNewTabs; i++) {
    1.67 +        if (j!=i) {
    1.68 +          // make sure there is no overlap between j's title and i's box.
    1.69 +          let jitem = items[j];
    1.70 +          let iitem = items[i];
    1.71 +          let $jtitle = contentWindow.iQ(jitem.container).find(".tab-title");
    1.72 +          let jbounds = $jtitle.bounds();
    1.73 +          let ibounds = contentWindow.iQ(iitem.container).bounds();
    1.74 +
    1.75 +          ok(
    1.76 +            (jbounds.top+jbounds.height < ibounds.top) || 
    1.77 +            (jbounds.top > ibounds.top + ibounds.height) ||
    1.78 +            (jbounds.left+jbounds.width < ibounds.left) || 
    1.79 +            (jbounds.left > ibounds.left + ibounds.width),
    1.80 +            "Items do not overlap: "
    1.81 +            +jbounds.left+","+jbounds.top+","+jbounds.width+","+jbounds.height+" ; "
    1.82 +            +ibounds.left+","+ibounds.top+","+ibounds.width+","+ibounds.height);        
    1.83 +        }
    1.84 +      }
    1.85 +    }
    1.86 +
    1.87 +    // Shut down
    1.88 +    emptyGroupItem.addSubscriber("close", function onClose() {
    1.89 +      emptyGroupItem.removeSubscriber("close", onClose);
    1.90 +  
    1.91 +      // check the number of groups.
    1.92 +      is(contentWindow.GroupItems.groupItems.length, --groupItemCount,
    1.93 +         "The number of groups is decreased by 1");
    1.94 +
    1.95 +      let onTabViewHidden = function() {
    1.96 +        window.removeEventListener("tabviewhidden", onTabViewHidden, false);
    1.97 +        // assert that we're no longer in tab view
    1.98 +        ok(!TabView.isVisible(), "Tab View is hidden");
    1.99 +        finish();
   1.100 +      };
   1.101 +      window.addEventListener("tabviewhidden", onTabViewHidden, false);
   1.102 +  
   1.103 +      TabView.toggle();
   1.104 +    });
   1.105 +  
   1.106 +    let closeButton = emptyGroupItem.container.getElementsByClassName("close");
   1.107 +    ok(closeButton[0], "Group close button exists");
   1.108 +  
   1.109 +    // click the close button
   1.110 +    EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow);
   1.111 +  };
   1.112 +
   1.113 +  mainTestFunc();
   1.114 +}

mercurial