browser_navigation.js (3605B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test the primary browser navigation UI to verify it's connected to the viewport. 7 8 const DUMMY_1_URL = "https://example.com/"; 9 const TEST_URL = `${URL_ROOT_SSL}doc_page_state.html`; 10 const DUMMY_2_URL = "https://example.com/browser/"; 11 const DUMMY_3_URL = "https://example.com/browser/devtools/"; 12 13 addRDMTask( 14 null, 15 async function () { 16 await SpecialPowers.pushPrefEnv({ 17 set: [["browser.navigation.requireUserInteraction", false]], 18 }); 19 20 // Load up a sequence of pages: 21 // 0. DUMMY_1_URL 22 // 1. TEST_URL 23 // 2. DUMMY_2_URL 24 const tab = await addTab(DUMMY_1_URL); 25 const browser = tab.linkedBrowser; 26 await navigateTo(TEST_URL); 27 await navigateTo(DUMMY_2_URL); 28 29 // Check session history state 30 let history = await getSessionHistory(browser); 31 is(history.index - 1, 2, "At page 2 in history"); 32 is(history.entries.length, 3, "3 pages in history"); 33 is(history.entries[0].url, DUMMY_1_URL, "Page 0 URL matches"); 34 is(history.entries[1].url, TEST_URL, "Page 1 URL matches"); 35 is(history.entries[2].url, DUMMY_2_URL, "Page 2 URL matches"); 36 37 // Go back one so we're at the test page 38 await back(browser); 39 40 // Check session history state 41 history = await getSessionHistory(browser); 42 is(history.index - 1, 1, "At page 1 in history"); 43 is(history.entries.length, 3, "3 pages in history"); 44 is(history.entries[0].url, DUMMY_1_URL, "Page 0 URL matches"); 45 is(history.entries[1].url, TEST_URL, "Page 1 URL matches"); 46 is(history.entries[2].url, DUMMY_2_URL, "Page 2 URL matches"); 47 48 const { ui } = await openRDM(tab); 49 await waitForDeviceAndViewportState(ui); 50 51 ok(browser.webNavigation.canGoBack, "Going back is allowed"); 52 ok(browser.webNavigation.canGoForward, "Going forward is allowed"); 53 is(browser.documentURI.spec, TEST_URL, "documentURI matches page 1"); 54 is(browser.contentTitle, "Page State Test", "contentTitle matches page 1"); 55 56 await forward(browser); 57 58 ok(browser.webNavigation.canGoBack, "Going back is allowed"); 59 ok(!browser.webNavigation.canGoForward, "Going forward is not allowed"); 60 is(browser.documentURI.spec, DUMMY_2_URL, "documentURI matches page 2"); 61 is( 62 browser.contentTitle, 63 "mochitest index /browser/", 64 "contentTitle matches page 2" 65 ); 66 67 await back(browser); 68 await back(browser); 69 70 ok(!browser.webNavigation.canGoBack, "Going back is not allowed"); 71 ok(browser.webNavigation.canGoForward, "Going forward is allowed"); 72 is(browser.documentURI.spec, DUMMY_1_URL, "documentURI matches page 0"); 73 is( 74 browser.contentTitle, 75 "mochitest index /", 76 "contentTitle matches page 0" 77 ); 78 79 await navigateTo(DUMMY_3_URL); 80 81 ok(browser.webNavigation.canGoBack, "Going back is allowed"); 82 ok(!browser.webNavigation.canGoForward, "Going forward is not allowed"); 83 is(browser.documentURI.spec, DUMMY_3_URL, "documentURI matches page 3"); 84 is( 85 browser.contentTitle, 86 "mochitest index /browser/devtools/", 87 "contentTitle matches page 3" 88 ); 89 90 await closeRDM(tab); 91 92 // Check session history state 93 history = await getSessionHistory(browser); 94 is(history.index - 1, 1, "At page 1 in history"); 95 is(history.entries.length, 2, "2 pages in history"); 96 is(history.entries[0].url, DUMMY_1_URL, "Page 0 URL matches"); 97 is(history.entries[1].url, DUMMY_3_URL, "Page 1 URL matches"); 98 99 await removeTab(tab); 100 }, 101 { onlyPrefAndTask: true } 102 );