browser_aboutnewtab_process_selection.js (4353B)
1 const TEST_URL = "http://www.example.com/browser/dom/base/test/dummy.html"; 2 const TEST_URL_2 = "http://example.org/browser/dom/base/test/dummy.html"; 3 const PRELOADED_STATE = "preloaded"; 4 5 var ppmm = Services.ppmm; 6 7 add_task(async function () { 8 // We want to count processes in this test, so let's disable the pre-allocated process manager. 9 await SpecialPowers.pushPrefEnv({ 10 set: [ 11 ["dom.ipc.processPrelaunch.enabled", false], 12 ["dom.ipc.processCount", 10], 13 ["dom.ipc.processCount.webIsolated", 10], 14 ["dom.ipc.keepProcessesAlive.web", 10], 15 ], 16 }); 17 }); 18 19 add_task(async function () { 20 // This test is only relevant in e10s. 21 if (!gMultiProcessBrowser) { 22 return; 23 } 24 25 ppmm.releaseCachedProcesses(); 26 27 // Wait for the preloaded browser to load. 28 await BrowserTestUtils.maybeCreatePreloadedBrowser(gBrowser); 29 30 // Store the number of processes. 31 let expectedChildCount = ppmm.childCount; 32 33 // Open 3 tabs using the preloaded browser. 34 let tabs = []; 35 for (let i = 0; i < 3; i++) { 36 BrowserCommands.openTab(); 37 tabs.unshift(gBrowser.selectedTab); 38 await BrowserTestUtils.maybeCreatePreloadedBrowser(gBrowser); 39 40 // Check that the process count did not change. 41 is( 42 ppmm.childCount, 43 expectedChildCount, 44 "Preloaded browser should not create a new content process." 45 ); 46 } 47 48 // Navigate to a content page from the parent side. 49 // 50 // We should create a new content process. 51 expectedChildCount += 1; 52 BrowserTestUtils.startLoadingURIString(tabs[0].linkedBrowser, TEST_URL); 53 await BrowserTestUtils.browserLoaded(tabs[0].linkedBrowser, false, TEST_URL); 54 is( 55 ppmm.childCount, 56 expectedChildCount, 57 "Navigating away from the preloaded browser (parent side) should create a new content process." 58 ); 59 60 // Navigate to the same content page from the child side. 61 // 62 // We should create a new content process. 63 expectedChildCount += 1; 64 await BrowserTestUtils.switchTab(gBrowser, tabs[1]); 65 await SpecialPowers.spawn(tabs[1].linkedBrowser, [TEST_URL], url => { 66 content.location.href = url; 67 }); 68 await BrowserTestUtils.browserLoaded(tabs[1].linkedBrowser, false, TEST_URL); 69 is( 70 ppmm.childCount, 71 expectedChildCount, 72 "Navigating away from the preloaded browser (child side, same-origin) should create a new content process." 73 ); 74 75 // Navigate to a new content page from the child side. 76 // 77 // We should create a new content process. 78 expectedChildCount += 1; 79 await BrowserTestUtils.switchTab(gBrowser, tabs[2]); 80 await ContentTask.spawn(tabs[2].linkedBrowser, TEST_URL_2, url => { 81 content.location.href = url; 82 }); 83 await BrowserTestUtils.browserLoaded( 84 tabs[2].linkedBrowser, 85 false, 86 TEST_URL_2 87 ); 88 is( 89 ppmm.childCount, 90 expectedChildCount, 91 "Navigating away from the preloaded browser (child side, cross-origin) should create a new content process." 92 ); 93 94 for (let tab of tabs) { 95 BrowserTestUtils.removeTab(tab); 96 } 97 98 // Make sure the preload browser does not keep any of the new processes alive. 99 NewTabPagePreloading.removePreloadedBrowser(window); 100 101 // Since we kept alive all the processes, we can shut down the ones that do 102 // not host any tabs reliably. 103 ppmm.releaseCachedProcesses(); 104 }); 105 106 add_task(async function preloaded_state_attribute() { 107 // Wait for a preloaded browser to exist, use it, and then create another one 108 await BrowserTestUtils.maybeCreatePreloadedBrowser(gBrowser); 109 let preloadedTabState = 110 gBrowser.preloadedBrowser.getAttribute("preloadedState"); 111 is( 112 preloadedTabState, 113 PRELOADED_STATE, 114 "Sanity check that the first preloaded browser has the correct attribute" 115 ); 116 117 BrowserCommands.openTab(); 118 await BrowserTestUtils.maybeCreatePreloadedBrowser(gBrowser); 119 120 // Now check that the tabs have the correct browser attributes set 121 is( 122 gBrowser.selectedBrowser.hasAttribute("preloadedState"), 123 false, 124 "The opened tab consumed the preloaded browser and removed the attribute" 125 ); 126 127 preloadedTabState = gBrowser.preloadedBrowser.getAttribute("preloadedState"); 128 is( 129 preloadedTabState, 130 PRELOADED_STATE, 131 "The preloaded browser has the correct attribute" 132 ); 133 134 // Remove tabs and preloaded browsers 135 BrowserTestUtils.removeTab(gBrowser.selectedTab); 136 NewTabPagePreloading.removePreloadedBrowser(window); 137 });