browser_drag_splitview.js (4000B)
1 /* This Source Code Form is subject to the terms of the Mozilla Public 2 * License, v. 2.0. If a copy of the MPL was not distributed with this 3 * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 "use strict"; 6 7 let currentReduceMotionOverride; 8 9 add_setup(() => { 10 currentReduceMotionOverride = gReduceMotionOverride; 11 // Disable tab animations 12 gReduceMotionOverride = true; 13 }); 14 15 add_task(async function test_drag_splitview_tab() { 16 let [tab1, tab2, tab3] = await Promise.all( 17 Array.from({ length: 3 }).map((_, index) => 18 addTab(`data:text/plain,tab${index + 1}`) 19 ) 20 ); 21 22 const startingTab = gBrowser.tabs[0]; 23 let splitview = gBrowser.addTabSplitView([tab2, tab3]); 24 Assert.equal(splitview.tabs.length, 2, "Split view has 2 tabs"); 25 26 Assert.deepEqual( 27 gBrowser.tabs, 28 [startingTab, tab1, tab2, tab3], 29 "confirm tabs' starting order" 30 ); 31 try { 32 info("Drag a splitview tab"); 33 await customDragAndDrop(tab3, tab1, null, waitForTabMove(tab3)); 34 35 Assert.deepEqual( 36 gBrowser.tabs, 37 [startingTab, tab2, tab3, tab1], 38 "Confirm that tab3 and tab2 in a splitview move together before tab1" 39 ); 40 41 info("Drag a tab in between a splitview"); 42 await customDragAndDrop(tab1, tab2, null, waitForTabMove(tab1)); 43 44 Assert.deepEqual( 45 gBrowser.tabs, 46 [startingTab, tab1, tab2, tab3], 47 "Confirm that tab1 cannot be dragged in between splitview tabs" 48 ); 49 50 let group = gBrowser.addTabGroup([tab1, splitview]); 51 Assert.equal(group.tabs.length, 3, "group has 3 tabs"); 52 53 Assert.deepEqual( 54 gBrowser.tabs, 55 [startingTab, tab1, tab2, tab3], 56 "Confirm that splitview tabs can be reordered within a tab group" 57 ); 58 // ensure we drag before tab 1, not after 59 let event = getDragEvent(); 60 info("Drag splitview tabs within a tab group"); 61 await customDragAndDrop(tab2, tab1, null, null, event); 62 63 Assert.deepEqual( 64 gBrowser.tabs, 65 [startingTab, tab2, tab3, tab1], 66 "Confirm that splitview tabs can be reordered within a tab group" 67 ); 68 } finally { 69 BrowserTestUtils.removeTab(tab1); 70 BrowserTestUtils.removeTab(tab2); 71 BrowserTestUtils.removeTab(tab3); 72 } 73 }); 74 75 add_task(async function test_dragging_splitview_second_window() { 76 let win2 = await BrowserTestUtils.openNewBrowserWindow(); 77 let [tab1, tab2] = await Promise.all( 78 Array.from({ length: 2 }).map((_, index) => 79 addTab(`data:text/plain,tab${index + 1}`) 80 ) 81 ); 82 83 let splitview = window.gBrowser.addTabSplitView([tab1, tab2]); 84 Assert.equal(splitview.tabs.length, 2, "Split view has 2 tabs"); 85 86 let secondWindowTab1 = win2.gBrowser.tabs[0]; 87 let secondWindowTab2 = BrowserTestUtils.addTab( 88 win2.gBrowser, 89 "data:text/plain,tab4" 90 ); 91 92 is(win2.gBrowser.tabs.length, 2, "win2 contains 2 tabs"); 93 94 let awaitCloseEvent = BrowserTestUtils.waitForEvent(tab1, "TabClose"); 95 let awaitOpenEvent = BrowserTestUtils.waitForEvent(win2, "TabOpen"); 96 97 let effect = EventUtils.synthesizeDrop( 98 tab1, 99 secondWindowTab1, 100 [[{ type: TAB_DROP_TYPE, data: tab1 }]], 101 null, 102 window, 103 win2 104 ); 105 is(effect, "move", "Tabs should be moved from win1 to win2."); 106 107 let closeEvent = await awaitCloseEvent; 108 let openEvent = await awaitOpenEvent; 109 110 is(openEvent.detail.adoptedTab, tab1, "New tab adopted old tab"); 111 112 is( 113 closeEvent.detail.adoptedBy, 114 openEvent.target, 115 "Old tab adopted by new tab" 116 ); 117 118 is( 119 win2.gBrowser.tabs.length, 120 4, 121 "win2 contains 2 new tabs, for a total of 4" 122 ); 123 124 let [secondWindowTab3, secondWindowTab4] = win2.gBrowser.tabs.slice(1, 3); 125 126 Assert.deepEqual( 127 win2.gBrowser.tabs, 128 [secondWindowTab1, secondWindowTab3, secondWindowTab4, secondWindowTab2], 129 "Two new tabs were inserted in the correct position in the second window" 130 ); 131 132 ok( 133 secondWindowTab3.splitview && secondWindowTab4.splitview, 134 "Two new tabs in second window are splitview tabs" 135 ); 136 137 await BrowserTestUtils.closeWindow(win2); 138 });