File: browser_tabview_layout.js

package info (click to toggle)
iceweasel 31.6.0esr-1
  • links: PTS, VCS
  • area: main
  • in suites: jessie-kfreebsd
  • size: 1,368,576 kB
  • sloc: cpp: 3,692,968; ansic: 1,797,194; python: 193,401; java: 180,622; asm: 133,557; xml: 89,288; sh: 71,748; perl: 22,087; makefile: 21,687; objc: 4,014; yacc: 1,995; pascal: 1,292; lex: 950; exp: 449; lisp: 228; awk: 211; php: 113; sed: 43; csh: 31; ada: 16; ruby: 3
file content (111 lines) | stat: -rw-r--r-- 3,687 bytes parent folder | download | duplicates (15)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
/* Any copyright is dedicated to the Public Domain.
   http://creativecommons.org/publicdomain/zero/1.0/ */

function test() {
  waitForExplicitFinish();

  // verify initial state
  ok(!TabView.isVisible(), "Tab View starts hidden");

  window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
  TabView.toggle();
}

let originalGroupItem = null;
let originalTab = null;
let contentWindow = null;

function onTabViewWindowLoaded() {
  window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
  ok(TabView.isVisible(), "Tab View is visible");

  contentWindow = document.getElementById("tab-view").contentWindow;

  is(contentWindow.GroupItems.groupItems.length, 1, "There is one group item on startup");
  originalGroupItem = contentWindow.GroupItems.groupItems[0];
  is(originalGroupItem.getChildren().length, 1, "There should be one Tab Item in that group.");
  contentWindow.UI.setActive(originalGroupItem);

  [originalTab] = gBrowser.visibleTabs;

  testEmptyGroupItem(contentWindow);
}

function testEmptyGroupItem(contentWindow) {
  let groupItemCount = contentWindow.GroupItems.groupItems.length;

  // Preparation
  //
    
  // create empty group item
  let emptyGroupItem = createEmptyGroupItem(contentWindow, 253, 335, 100);
  ok(emptyGroupItem.isEmpty(), "This group is empty");

  is(contentWindow.GroupItems.groupItems.length, ++groupItemCount,
     "The number of groups is increased by 1");

  // add four blank items
  contentWindow.UI.setActive(emptyGroupItem);

  let numNewTabs = 4;
  let items = [];
  for(let t=0; t<numNewTabs; t++) {
    let newItem = contentWindow.gBrowser.loadOneTab("about:blank")._tabViewTabItem;
    ok(newItem.container, "Created element "+t+":"+newItem.container);
    items.push(newItem);
  }

  // Define main test function
  //

  let mainTestFunc = function() {
    for(let j=0; j<numNewTabs; j++) {
      for(let i=0; i<numNewTabs; i++) {
        if (j!=i) {
          // make sure there is no overlap between j's title and i's box.
          let jitem = items[j];
          let iitem = items[i];
          let $jtitle = contentWindow.iQ(jitem.container).find(".tab-title");
          let jbounds = $jtitle.bounds();
          let ibounds = contentWindow.iQ(iitem.container).bounds();

          ok(
            (jbounds.top+jbounds.height < ibounds.top) || 
            (jbounds.top > ibounds.top + ibounds.height) ||
            (jbounds.left+jbounds.width < ibounds.left) || 
            (jbounds.left > ibounds.left + ibounds.width),
            "Items do not overlap: "
            +jbounds.left+","+jbounds.top+","+jbounds.width+","+jbounds.height+" ; "
            +ibounds.left+","+ibounds.top+","+ibounds.width+","+ibounds.height);        
        }
      }
    }

    // Shut down
    emptyGroupItem.addSubscriber("close", function onClose() {
      emptyGroupItem.removeSubscriber("close", onClose);
  
      // check the number of groups.
      is(contentWindow.GroupItems.groupItems.length, --groupItemCount,
         "The number of groups is decreased by 1");

      let onTabViewHidden = function() {
        window.removeEventListener("tabviewhidden", onTabViewHidden, false);
        // assert that we're no longer in tab view
        ok(!TabView.isVisible(), "Tab View is hidden");
        finish();
      };
      window.addEventListener("tabviewhidden", onTabViewHidden, false);
  
      TabView.toggle();
    });
  
    let closeButton = emptyGroupItem.container.getElementsByClassName("close");
    ok(closeButton[0], "Group close button exists");
  
    // click the close button
    EventUtils.synthesizeMouse(closeButton[0], 1, 1, {}, contentWindow);
  };

  mainTestFunc();
}