browser/components/tabview/test/browser_tabview_bug587231.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 let activeTab;
     5 let testTab;
     6 let testGroup;
     7 let contentWindow;
     9 function test() {
    10   waitForExplicitFinish();
    12   // create new tab
    13   testTab = gBrowser.addTab("about:blank");
    15   window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
    16   TabView.toggle();
    17 }
    19 function onTabViewWindowLoaded() {
    20   window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
    21   ok(TabView.isVisible(), "Tab View is visible");
    23   contentWindow = document.getElementById("tab-view").contentWindow;
    25   // create group
    26   let testGroupRect = new contentWindow.Rect(20, 20, 300, 300);
    27   testGroup = new contentWindow.GroupItem([], { bounds: testGroupRect });
    28   ok(testGroup.isEmpty(), "This group is empty");
    30   ok(testTab._tabViewTabItem, "tab item exists");
    32   // place tab in group
    33   let testTabItem = testTab._tabViewTabItem;
    35   if (testTabItem.parent)
    36     testTabItem.parent.remove(testTabItem);
    37   testGroup.add(testTabItem);
    39   ok(testTab._tabViewTabItem, "tab item exists after adding to group");
    41   // record last update time of tab canvas
    42   let initialUpdateTime = testTabItem._lastTabUpdateTime;
    44   // simulate resize
    45   let resizer = contentWindow.iQ('.iq-resizable-handle', testGroup.container)[0];
    46   let offsetX = 100;
    47   let offsetY = 100;
    48   let delay = 500;
    50   let funcChain = new Array();
    51   funcChain.push(function() {
    52     EventUtils.synthesizeMouse(
    53       resizer, 1, 1, { type: "mousedown" }, contentWindow);
    54     setTimeout(funcChain.shift(), delay);
    55   });
    56   // drag
    57   for (let i = 4; i >= 0; i--) {
    58     funcChain.push(function() {
    59       EventUtils.synthesizeMouse(
    60         resizer,  Math.round(offsetX/4),  Math.round(offsetY/4),
    61         { type: "mousemove" }, contentWindow);
    62       setTimeout(funcChain.shift(), delay);
    63     });
    64   }
    65   funcChain.push(function() {
    66     EventUtils.synthesizeMouse(resizer, 0, 0, { type: "mouseup" }, 
    67       contentWindow);    
    68     setTimeout(funcChain.shift(), delay);
    69   });
    70   funcChain.push(function() {
    71     // verify that update time has changed after last update
    72     let lastTime = testTabItem._lastTabUpdateTime;
    73     let hbTiming = contentWindow.TabItems._heartbeatTiming;
    74     ok((lastTime - initialUpdateTime) > hbTiming, "Tab has been updated:"+lastTime+"-"+initialUpdateTime+">"+hbTiming);
    76     // clean up
    77     testGroup.remove(testTab._tabViewTabItem);
    78     testTab._tabViewTabItem.close();
    79     testGroup.close();
    81     let currentTabs = contentWindow.TabItems.getItems();
    82     ok(currentTabs[0], "A tab item exists to make active");
    83     contentWindow.UI.setActive(currentTabs[0]);
    85     window.addEventListener("tabviewhidden", finishTest, false);
    86     TabView.toggle();
    87   });
    88   setTimeout(funcChain.shift(), delay);
    89 }
    91 function finishTest() {
    92   window.removeEventListener("tabviewhidden", finishTest, false);
    93   ok(!TabView.isVisible(), "Tab View is not visible");
    95   finish();  
    96 }

mercurial