Bug 1146193 - Part 2: Add test for tab reorder and duplicate. r=gavin
authorTooru Fujisawa <arai_a@mac.com>
Tue, 24 Mar 2015 06:40:01 +0900
changeset 235708 0bf7f53464d6a587eb5bed4f1027facea3ba206e
parent 235707 f778ed14214557aa9c07aecea6b4ee42e769d8af
child 235709 d71343862e8dbf270231cf5144b339b4bb043c5a
push id57483
push userarai_a@mac.com
push dateThu, 26 Mar 2015 01:13:57 +0000
treeherdermozilla-inbound@0bf7f53464d6 [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersgavin
bugs1146193
milestone39.0a1
first release with
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
last release without
nightly linux32
nightly linux64
nightly mac
nightly win32
nightly win64
Bug 1146193 - Part 2: Add test for tab reorder and duplicate. r=gavin
browser/base/content/test/general/browser.ini
browser/base/content/test/general/browser_tabReorder.js
--- a/browser/base/content/test/general/browser.ini
+++ b/browser/base/content/test/general/browser.ini
@@ -404,16 +404,18 @@ support-files =
 [browser_selectTabAtIndex.js]
 [browser_ssl_error_reports.js]
 [browser_star_hsts.js]
 [browser_subframe_favicons_not_used.js]
 [browser_syncui.js]
 skip-if = e10s # Bug 1137087 - browser_tabopen_reflows.js fails if this was previously run with e10s
 [browser_tabDrop.js]
 skip-if = buildapp == 'mulet' || e10s
+[browser_tabReorder.js]
+skip-if = buildapp == 'mulet'
 [browser_tabMatchesInAwesomebar.js]
 [browser_tabMatchesInAwesomebar_perwindowpb.js]
 skip-if = e10s || os == 'linux' # Bug 1093373, bug 1104755
 [browser_tab_detach_restore.js]
 [browser_tab_drag_drop_perwindow.js]
 skip-if = buildapp == 'mulet'
 [browser_tab_dragdrop.js]
 skip-if = buildapp == 'mulet'
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/general/browser_tabReorder.js
@@ -0,0 +1,82 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+function test() {
+  let initialTabsLength = gBrowser.tabs.length;
+
+  let newTab1 = gBrowser.selectedTab = gBrowser.addTab("about:robots", {skipAnimation: true});
+  let newTab2 = gBrowser.selectedTab = gBrowser.addTab("about:about", {skipAnimation: true});
+  let newTab3 = gBrowser.selectedTab = gBrowser.addTab("about:config", {skipAnimation: true});
+  registerCleanupFunction(function () {
+    while (gBrowser.tabs.length > initialTabsLength) {
+      gBrowser.removeTab(gBrowser.tabs[initialTabsLength]);
+    }
+  });
+
+  is(gBrowser.tabs.length, initialTabsLength + 3, "new tabs are opened");
+  is(gBrowser.tabs[initialTabsLength], newTab1, "newTab1 position is correct");
+  is(gBrowser.tabs[initialTabsLength + 1], newTab2, "newTab2 position is correct");
+  is(gBrowser.tabs[initialTabsLength + 2], newTab3, "newTab3 position is correct");
+
+  let dataTransfer;
+  let trapDrag = function(event) {
+    dataTransfer = event.dataTransfer;
+  };
+  window.addEventListener("dragstart", trapDrag, true);
+  registerCleanupFunction(function () {
+    window.removeEventListener("dragstart", trapDrag, true);
+  });
+
+  let windowUtil = window.QueryInterface(Components.interfaces.nsIInterfaceRequestor).
+                          getInterface(Components.interfaces.nsIDOMWindowUtils);
+  let ds = Components.classes["@mozilla.org/widget/dragservice;1"].
+           getService(Components.interfaces.nsIDragService);
+
+  function dragAndDrop(tab1, tab2, copy) {
+    let ctrlKey = copy;
+    let altKey = copy;
+
+    let rect = tab1.getBoundingClientRect();
+    let x = rect.width / 2;
+    let y = rect.height / 2;
+    let diffX = 10;
+
+    ds.startDragSession();
+    try {
+      EventUtils.synthesizeMouse(tab1, x, y, { type: "mousedown" }, window);
+      EventUtils.synthesizeMouse(tab1, x + diffX, y, { type: "mousemove" }, window);
+
+      dataTransfer.dropEffect = copy ? "copy" : "move";
+
+      let event = window.document.createEvent("DragEvents");
+      event.initDragEvent("dragover", true, true, window, 0,
+                          tab2.boxObject.screenX + x + diffX,
+                          tab2.boxObject.screenY + y,
+                          x + diffX, y, ctrlKey, altKey, false, false, 0, null, dataTransfer);
+      windowUtil.dispatchDOMEventViaPresShell(tab2, event, true);
+
+      event = window.document.createEvent("DragEvents");
+      event.initDragEvent("drop", true, true, window, 0,
+                          tab2.boxObject.screenX + x + diffX,
+                          tab2.boxObject.screenY + y,
+                          x + diffX, y, ctrlKey, altKey, false, false, 0, null, dataTransfer);
+      windowUtil.dispatchDOMEventViaPresShell(tab2, event, true);
+
+      EventUtils.synthesizeMouse(tab2, x + diffX, y, { type: "mouseup" }, window);
+    } finally {
+      ds.endDragSession(true);
+    }
+  }
+
+  dragAndDrop(newTab1, newTab2, false);
+  is(gBrowser.tabs.length, initialTabsLength + 3, "tabs are still there");
+  is(gBrowser.tabs[initialTabsLength], newTab2, "newTab2 and newTab1 are swapped");
+  is(gBrowser.tabs[initialTabsLength + 1], newTab1, "newTab1 and newTab2 are swapped");
+  is(gBrowser.tabs[initialTabsLength + 2], newTab3, "newTab3 stays same place");
+
+  dragAndDrop(newTab2, newTab1, true);
+  is(gBrowser.tabs.length, initialTabsLength + 4, "a tab is duplicated");
+  is(gBrowser.tabs[initialTabsLength], newTab2, "newTab2 stays same place");
+  is(gBrowser.tabs[initialTabsLength + 1], newTab1, "newTab1 stays same place");
+  is(gBrowser.tabs[initialTabsLength + 3], newTab3, "a new tab is inserted before newTab3");
+}