Bug 1434229 - Test tab reorder when tabbar is overflown r=dao
authorhemant <hemantsingh1612@gmail.com>
Tue, 24 Apr 2018 12:40:55 +0530
changeset 468831 f8cac1a891b5a7343b4ae359d4a987a58f025cda
parent 468830 5d34206436c6d78140a9d3a9296b90d8f1c37b98
child 468832 fc39571cc03ac7f5fcff5f7ec047638331d09165
push id9165
push userasasaki@mozilla.com
push dateThu, 26 Apr 2018 21:04:54 +0000
treeherdermozilla-beta@064c3804de2e [default view] [failures only]
perfherder[talos] [build metrics] [platform microbench] (compared to previous push)
reviewersdao
bugs1434229
milestone61.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 1434229 - Test tab reorder when tabbar is overflown r=dao MozReview-Commit-ID: FgusKqb0XF6 ***
browser/base/content/test/tabs/browser.ini
browser/base/content/test/tabs/browser_tabReorder_overflow.js
--- a/browser/base/content/test/tabs/browser.ini
+++ b/browser/base/content/test/tabs/browser.ini
@@ -28,14 +28,15 @@ skip-if = !e10s # Pref and test only rel
 support-files = file_new_tab_page.html
 [browser_overflowScroll.js]
 [browser_pinnedTabs.js]
 [browser_pinnedTabs_closeByKeyboard.js]
 [browser_positional_attributes.js]
 [browser_preloadedBrowser_zoom.js]
 [browser_reload_deleted_file.js]
 skip-if = (debug && os == 'mac') || (debug && os == 'linux' && bits == 64) #Bug 1421183, disabled on Linux/OSX for leaked windows
+[browser_tabReorder_overflow.js]
 [browser_tabswitch_updatecommands.js]
 [browser_viewsource_of_data_URI_in_file_process.js]
 [browser_visibleTabs_bookmarkAllTabs.js]
 [browser_visibleTabs_contextMenu.js]
 [browser_open_newtab_start_observer_notification.js]
 [browser_bug_1387976_restore_lazy_tab_browser_muted_state.js]
new file mode 100644
--- /dev/null
+++ b/browser/base/content/test/tabs/browser_tabReorder_overflow.js
@@ -0,0 +1,59 @@
+/* Any copyright is dedicated to the Public Domain.
+ * http://creativecommons.org/publicdomain/zero/1.0/ */
+
+"use strict";
+
+requestLongerTimeout(2);
+
+add_task(async function() {
+  let initialTabsLength = gBrowser.tabs.length;
+
+  let arrowScrollbox = gBrowser.tabContainer.arrowScrollbox;
+  let tabs = gBrowser.tabs;
+  let tabMinWidth = parseInt(getComputedStyle(gBrowser.selectedTab, null).minWidth);
+
+  let rect = ele => ele.getBoundingClientRect();
+  let width = ele => rect(ele).width;
+  let height = ele => rect(ele).height;
+  let left = ele => rect(ele).left;
+  let top = ele => rect(ele).top;
+
+  let tabCountForOverflow = Math.ceil(width(arrowScrollbox) / tabMinWidth);
+
+  let newTab1 = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:robots", {skipAnimation: true});
+  let newTab2 = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:about", {skipAnimation: true});
+  let newTab3 = gBrowser.selectedTab = BrowserTestUtils.addTab(gBrowser, "about:config", {skipAnimation: true});
+
+  while (tabs.length < tabCountForOverflow) {
+    BrowserTestUtils.addTab(gBrowser, "about:blank", { skipAnimation: true });
+  }
+
+  registerCleanupFunction(function() {
+    while (tabs.length > initialTabsLength) {
+      gBrowser.removeTab(gBrowser.tabs[initialTabsLength]);
+    }
+  });
+
+  is(gBrowser.tabs.length, tabCountForOverflow, "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");
+
+  async function dragAndDrop(tab1, tab2) {
+    let event = {
+      clientX: left(tab2) + width(tab2) / 2 + 10,
+      clientY: top(tab2) + height(tab2) / 2,
+    };
+
+    let originalTPos = tab1._tPos;
+    EventUtils.synthesizeDrop(tab1, tab2, null, "move", window, window, event);
+    await BrowserTestUtils.waitForCondition(() => tab1._tPos != originalTPos,
+     "Waiting for tab position to be updated");
+  }
+
+  await dragAndDrop(newTab1, newTab2);
+  is(gBrowser.tabs.length, tabCountForOverflow, "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");
+});