browser_page_state.js (3038B)
1 /* Any copyright is dedicated to the Public Domain. 2 http://creativecommons.org/publicdomain/zero/1.0/ */ 3 4 "use strict"; 5 6 // Test page state to ensure page is not reloaded and session history is not 7 // modified. 8 9 const DUMMY_1_URL = "https://example.com/"; 10 const TEST_URL = `${URL_ROOT_SSL}doc_page_state.html`; 11 const DUMMY_2_URL = "https://example.com/browser/"; 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 // Click on content to set an altered state that would be lost on reload 49 await BrowserTestUtils.synthesizeMouseAtCenter("body", {}, browser); 50 51 const { ui } = await openRDM(tab); 52 await waitForDeviceAndViewportState(ui); 53 54 // Check color inside the viewport 55 let color = await spawnViewportTask(ui, {}, function () { 56 return content 57 .getComputedStyle(content.document.body) 58 .getPropertyValue("background-color"); 59 }); 60 is( 61 color, 62 "rgb(0, 128, 0)", 63 "Content is still modified from click in viewport" 64 ); 65 66 await closeRDM(tab); 67 68 // Check color back in the browser tab 69 color = await SpecialPowers.spawn(browser, [], async function () { 70 return content 71 .getComputedStyle(content.document.body) 72 .getPropertyValue("background-color"); 73 }); 74 is( 75 color, 76 "rgb(0, 128, 0)", 77 "Content is still modified from click in browser tab" 78 ); 79 80 // Check session history state 81 history = await getSessionHistory(browser); 82 is(history.index - 1, 1, "At page 1 in history"); 83 is(history.entries.length, 3, "3 pages in history"); 84 is(history.entries[0].url, DUMMY_1_URL, "Page 0 URL matches"); 85 is(history.entries[1].url, TEST_URL, "Page 1 URL matches"); 86 is(history.entries[2].url, DUMMY_2_URL, "Page 2 URL matches"); 87 88 await removeTab(tab); 89 }, 90 { onlyPrefAndTask: true } 91 );