browser_movePendingTabToNewWindow.js (3913B)
1 /* Any copyright is dedicated to the Public Domain. 2 * http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 /** 5 * This tests the behaviour of moving pending tabs to a new window. These 6 * pending tabs have yet to be restored and should be restored upon opening 7 * in the new window. This test covers moving a single pending tab at once 8 * as well as multiple tabs at the same time (using tab multiselection). 9 */ 10 add_task(async function test_movePendingTabToNewWindow() { 11 const TEST_URIS = [ 12 "http://www.example.com/1", 13 "http://www.example.com/2", 14 "http://www.example.com/3", 15 "http://www.example.com/4", 16 ]; 17 18 await SpecialPowers.pushPrefEnv({ 19 set: [["browser.sessionstore.restore_on_demand", true]], 20 }); 21 22 let state = { 23 windows: [ 24 { 25 tabs: [ 26 { entries: [{ url: TEST_URIS[0], triggeringPrincipal_base64 }] }, 27 { entries: [{ url: TEST_URIS[1], triggeringPrincipal_base64 }] }, 28 { entries: [{ url: TEST_URIS[2], triggeringPrincipal_base64 }] }, 29 { entries: [{ url: TEST_URIS[3], triggeringPrincipal_base64 }] }, 30 ], 31 selected: 4, 32 }, 33 ], 34 }; 35 36 await promiseBrowserState(state); 37 38 is( 39 gBrowser.visibleTabs.length, 40 4, 41 "Three tabs are visible to start the test" 42 ); 43 44 let tabToSelect = gBrowser.visibleTabs[1]; 45 ok(tabToSelect.hasAttribute("pending"), "Tab should be pending"); 46 47 gBrowser.addRangeToMultiSelectedTabs(gBrowser.selectedTab, tabToSelect); 48 ok(!gBrowser.visibleTabs[0].multiselected, "First tab not multiselected"); 49 ok(gBrowser.visibleTabs[1].multiselected, "Second tab multiselected"); 50 ok(gBrowser.visibleTabs[2].multiselected, "Third tab multiselected"); 51 ok(gBrowser.visibleTabs[3].multiselected, "Fourth tab multiselected"); 52 53 let promiseNewWindow = BrowserTestUtils.waitForNewWindow(); 54 gBrowser.replaceTabsWithWindow(tabToSelect); 55 56 info("Waiting for new window"); 57 let newWindow = await promiseNewWindow; 58 isnot(newWindow, gBrowser.ownerGlobal, "Tab moved to new window"); 59 60 let newWindowTabs = newWindow.gBrowser.visibleTabs; 61 await TestUtils.waitForCondition(() => { 62 return ( 63 newWindowTabs.length == 3 && 64 newWindowTabs[0].linkedBrowser.currentURI.spec == TEST_URIS[1] && 65 newWindowTabs[1].linkedBrowser.currentURI.spec == TEST_URIS[2] && 66 newWindowTabs[2].linkedBrowser.currentURI.spec == TEST_URIS[3] 67 ); 68 }, "Wait for all three tabs to move to new window and load"); 69 70 is(newWindowTabs.length, 3, "Three tabs should be in new window"); 71 is( 72 newWindowTabs[0].linkedBrowser.currentURI.spec, 73 TEST_URIS[1], 74 "Second tab moved" 75 ); 76 is( 77 newWindowTabs[1].linkedBrowser.currentURI.spec, 78 TEST_URIS[2], 79 "Third tab moved" 80 ); 81 is( 82 newWindowTabs[2].linkedBrowser.currentURI.spec, 83 TEST_URIS[3], 84 "Fourth tab moved" 85 ); 86 87 ok( 88 newWindowTabs[0].hasAttribute("pending"), 89 "First tab in new window should still be pending" 90 ); 91 ok( 92 newWindowTabs[1].hasAttribute("pending"), 93 "Second tab in new window should still be pending" 94 ); 95 newWindow.gBrowser.clearMultiSelectedTabs(); 96 ok( 97 newWindowTabs.every(t => !t.multiselected), 98 "No multiselection should be present" 99 ); 100 101 promiseNewWindow = BrowserTestUtils.waitForNewWindow(); 102 newWindow.gBrowser.replaceTabsWithWindow(newWindowTabs[0]); 103 104 info("Waiting for second new window"); 105 let secondNewWindow = await promiseNewWindow; 106 await TestUtils.waitForCondition( 107 () => 108 secondNewWindow.gBrowser.selectedBrowser.currentURI.spec == TEST_URIS[1], 109 "Wait until the URI is updated" 110 ); 111 is( 112 secondNewWindow.gBrowser.visibleTabs.length, 113 1, 114 "Only one tab in second new window" 115 ); 116 is( 117 secondNewWindow.gBrowser.selectedBrowser.currentURI.spec, 118 TEST_URIS[1], 119 "First tab moved" 120 ); 121 122 await BrowserTestUtils.closeWindow(secondNewWindow); 123 await BrowserTestUtils.closeWindow(newWindow); 124 });