browser/components/tabview/test/browser_tabview_bug591706.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_bug591706.js	Wed Dec 31 06:09:35 2014 +0100
     1.3 @@ -0,0 +1,107 @@
     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 +  window.addEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.11 +  if (TabView.isVisible())
    1.12 +    onTabViewWindowLoaded();
    1.13 +  else
    1.14 +    TabView.show();
    1.15 +}
    1.16 +
    1.17 +function onTabViewWindowLoaded() {
    1.18 +  window.removeEventListener("tabviewshown", onTabViewWindowLoaded, false);
    1.19 +
    1.20 +  ok(TabView.isVisible(), "Tab View is visible");
    1.21 +
    1.22 +  let contentWindow = document.getElementById("tab-view").contentWindow;
    1.23 +  let [originalTab] = gBrowser.visibleTabs;
    1.24 +
    1.25 +  // Create a first tab and orphan it
    1.26 +  let firstTab = gBrowser.loadOneTab("about:blank#1", {inBackground: true});
    1.27 +  let firstTabItem = firstTab._tabViewTabItem;
    1.28 +  let currentGroup = contentWindow.GroupItems.getActiveGroupItem();
    1.29 +  ok(currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was made in the current group");
    1.30 +  contentWindow.GroupItems.getActiveGroupItem().remove(firstTabItem);
    1.31 +  ok(!currentGroup.getChildren().some(function(child) child == firstTabItem),"The first tab was orphaned");
    1.32 +
    1.33 +  // Create a group and make it active
    1.34 +  let box = new contentWindow.Rect(10, 10, 300, 300);
    1.35 +  let group = new contentWindow.GroupItem([], { bounds: box });
    1.36 +  ok(group.isEmpty(), "This group is empty");
    1.37 +  contentWindow.UI.setActive(group);
    1.38 +  
    1.39 +  // Create a second tab in this new group
    1.40 +  let secondTab = gBrowser.loadOneTab("about:blank#2", {inBackground: true});
    1.41 +  let secondTabItem = secondTab._tabViewTabItem;
    1.42 +  ok(group.getChildren().some(function(child) child == secondTabItem),"The second tab was made in our new group");
    1.43 +  is(group.getChildren().length, 1, "Only one tab in the first group");
    1.44 +  isnot(firstTab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The two tabs must have different locations");
    1.45 +
    1.46 +  // Add the first tab to the group *programmatically*, without specifying a dropPos
    1.47 +  group.add(firstTabItem);
    1.48 +  is(group.getChildren().length, 2, "Two tabs in the group");
    1.49 +
    1.50 +  is(group.getChildren()[0].tab.linkedBrowser.currentURI.spec, secondTab.linkedBrowser.currentURI.spec, "The second tab was there first");
    1.51 +  is(group.getChildren()[1].tab.linkedBrowser.currentURI.spec, firstTab.linkedBrowser.currentURI.spec, "The first tab was just added and went to the end of the line");
    1.52 +
    1.53 +  group.addSubscriber("close", function onClose() {
    1.54 +    group.removeSubscriber("close", onClose);
    1.55 +
    1.56 +    ok(group.isEmpty(), "The group is empty again");
    1.57 +
    1.58 +    is(contentWindow.GroupItems.getActiveGroupItem(), currentGroup, "There is an active group");
    1.59 +    is(gBrowser.tabs.length, 1, "There is only one tab left");
    1.60 +    is(gBrowser.visibleTabs.length, 1, "There is also only one visible tab");
    1.61 +
    1.62 +    let onTabViewHidden = function() {
    1.63 +      window.removeEventListener("tabviewhidden", onTabViewHidden, false);
    1.64 +      finish();
    1.65 +    };
    1.66 +    window.addEventListener("tabviewhidden", onTabViewHidden, false);
    1.67 +    gBrowser.selectedTab = originalTab;
    1.68 +
    1.69 +    TabView.hide();
    1.70 +  });
    1.71 +
    1.72 +  // Get rid of the group and its children
    1.73 +  group.closeAll();
    1.74 +  // close undo group
    1.75 +  let closeButton = group.$undoContainer.find(".close");
    1.76 +  EventUtils.sendMouseEvent(
    1.77 +    { type: "click" }, closeButton[0], contentWindow);
    1.78 +}
    1.79 +
    1.80 +function simulateDragDrop(srcElement, offsetX, offsetY, contentWindow) {
    1.81 +  // enter drag mode
    1.82 +  let dataTransfer;
    1.83 +
    1.84 +  EventUtils.synthesizeMouse(
    1.85 +    srcElement, 1, 1, { type: "mousedown" }, contentWindow);
    1.86 +  event = contentWindow.document.createEvent("DragEvents");
    1.87 +  event.initDragEvent(
    1.88 +    "dragenter", true, true, contentWindow, 0, 0, 0, 0, 0,
    1.89 +    false, false, false, false, 1, null, dataTransfer);
    1.90 +  srcElement.dispatchEvent(event);
    1.91 +
    1.92 +  // drag over
    1.93 +  for (let i = 4; i >= 0; i--)
    1.94 +    EventUtils.synthesizeMouse(
    1.95 +      srcElement,  Math.round(offsetX/5),  Math.round(offsetY/4),
    1.96 +      { type: "mousemove" }, contentWindow);
    1.97 +  event = contentWindow.document.createEvent("DragEvents");
    1.98 +  event.initDragEvent(
    1.99 +    "dragover", true, true, contentWindow, 0, 0, 0, 0, 0,
   1.100 +    false, false, false, false, 0, null, dataTransfer);
   1.101 +  srcElement.dispatchEvent(event);
   1.102 +
   1.103 +  // drop
   1.104 +  EventUtils.synthesizeMouse(srcElement, 0, 0, { type: "mouseup" }, contentWindow);
   1.105 +  event = contentWindow.document.createEvent("DragEvents");
   1.106 +  event.initDragEvent(
   1.107 +    "drop", true, true, contentWindow, 0, 0, 0, 0, 0,
   1.108 +    false, false, false, false, 0, null, dataTransfer);
   1.109 +  srcElement.dispatchEvent(event);
   1.110 +}

mercurial