browser_NavigationManager_committed.js (2059B)
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 file, 3 * You can obtain one at http://mozilla.org/MPL/2.0/. */ 4 5 const FIRST_URL = "https://example.com/document-builder.sjs?html=first"; 6 const SECOND_URL = "https://example.com/document-builder.sjs?html=second"; 7 8 // Add a simple test for the navigation committed flag. 9 add_task(async function test_committed() { 10 const tab = await addTabAndWaitForNavigated(gBrowser, FIRST_URL); 11 const browser = tab.linkedBrowser; 12 13 const navigationObjects = []; 14 const onEvent = name => { 15 const navigation = navigationManager.getNavigationForBrowsingContext( 16 browser.browsingContext 17 ); 18 navigationObjects.push({ name, committed: navigation.committed }); 19 }; 20 21 const navigationManager = new NavigationManager(); 22 navigationManager.on("navigation-started", onEvent); 23 navigationManager.on("navigation-committed", onEvent); 24 navigationManager.on("navigation-stopped", onEvent); 25 26 navigationManager.startMonitoring(); 27 28 await loadURL(browser, SECOND_URL); 29 await BrowserTestUtils.waitForCondition(() => navigationObjects.length === 3); 30 is( 31 navigationObjects[0].name, 32 "navigation-started", 33 "First event is navigation-started" 34 ); 35 ok( 36 !navigationObjects[0].committed, 37 "Navigation object in navigation-started is not committed yet" 38 ); 39 is( 40 navigationObjects[1].name, 41 "navigation-committed", 42 "Second event is navigation-committed" 43 ); 44 ok( 45 navigationObjects[1].committed, 46 "Navigation object in navigation-committed is committed" 47 ); 48 is( 49 navigationObjects[2].name, 50 "navigation-stopped", 51 "Third event is navigation-stopped" 52 ); 53 ok( 54 navigationObjects[2].committed, 55 "Navigation object in navigation-stopped is committed" 56 ); 57 58 navigationManager.off("navigation-started", onEvent); 59 navigationManager.off("navigation-committed", onEvent); 60 navigationManager.off("navigation-stopped", onEvent); 61 navigationManager.stopMonitoring(); 62 });