Bug 1265818 - Part 4 - Test that scroll positions for previous session history entries are restored on Desktop. r?mikedeboer
This extends the existing the existing scroll position test by navigating to a second page and then checking that after closing and restoring that tab, the scroll position is restored not only for the current history entry, but after going back as well.
MozReview-Commit-ID: Ddig1Mfo5rz
--- a/browser/components/sessionstore/test/browser.ini
+++ b/browser/components/sessionstore/test/browser.ini
@@ -26,16 +26,17 @@ support-files =
browser_frame_history_c1.html
browser_frame_history_c2.html
browser_form_restore_events_sample.html
browser_formdata_format_sample.html
browser_pageStyle_sample.html
browser_pageStyle_sample_nested.html
browser_sessionHistory_slow.sjs
browser_scrollPositions_sample.html
+ browser_scrollPositions_sample2.html
browser_scrollPositions_sample_frameset.html
browser_scrollPositions_readerModeArticle.html
browser_sessionStorage.html
browser_248970_b_sample.html
browser_339445_sample.html
browser_423132_sample.html
browser_447951_sample.html
browser_454908_sample.html
--- a/browser/components/sessionstore/test/browser_scrollPositions.js
+++ b/browser/components/sessionstore/test/browser_scrollPositions.js
@@ -1,15 +1,16 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
const BASE = "http://example.com/browser/browser/components/sessionstore/test/"
const URL = BASE + "browser_scrollPositions_sample.html";
+const URL2 = BASE + "browser_scrollPositions_sample2.html";
const URL_FRAMESET = BASE + "browser_scrollPositions_sample_frameset.html";
// Randomized set of scroll positions we will use in this test.
const SCROLL_X = Math.round(100 * (1 + Math.random()));
const SCROLL_Y = Math.round(200 * (1 + Math.random()));
const SCROLL_STR = SCROLL_X + "," + SCROLL_Y;
const SCROLL2_X = Math.round(300 * (1 + Math.random()));
@@ -103,28 +104,38 @@ add_task(function* test_scroll_nested()
// Cleanup.
yield promiseRemoveTab(tab);
yield promiseRemoveTab(tab2);
});
/**
* Test that scroll positions persist after restoring background tabs in
* a restored window (bug 1228518).
+ * Also test that scroll positions for previous session history entries
+ * are preserved as well (bug 1265818).
*/
add_task(function* test_scroll_background_tabs() {
pushPrefs(["browser.sessionstore.restore_on_demand", true]);
let newWin = yield BrowserTestUtils.openNewBrowserWindow();
let tab = newWin.gBrowser.addTab(URL);
let browser = tab.linkedBrowser;
yield BrowserTestUtils.browserLoaded(browser);
// Scroll down a little.
yield sendMessage(browser, "ss-test:setScrollPosition", {x: SCROLL_X, y: SCROLL_Y});
- yield checkScroll(tab, {scroll: SCROLL_STR}, "scroll is fine");
+ yield checkScroll(tab, {scroll: SCROLL_STR}, "scroll on first page is fine");
+
+ // Navigate to a different page and scroll there as well.
+ browser.loadURI(URL2);
+ yield BrowserTestUtils.browserLoaded(browser);
+
+ // Scroll down a little.
+ yield sendMessage(browser, "ss-test:setScrollPosition", {x: SCROLL2_X, y: SCROLL2_Y});
+ yield checkScroll(tab, {scroll: SCROLL2_STR}, "scroll on second page is fine");
// Close the window
yield BrowserTestUtils.closeWindow(newWin);
yield forceSaveState();
// Now restore the window
newWin = ss.undoCloseWindow(0);
@@ -144,12 +155,22 @@ add_task(function* test_scroll_backgroun
// Ensure there are no pending queued messages in the child.
yield TabStateFlusher.flush(browser);
// Now check to see if the background tab remembers where it
// should be scrolled to.
newWin.gBrowser.selectedTab = tab;
yield promiseTabRestored(tab);
- yield checkScroll(tab, {scroll: SCROLL_STR}, "scroll is still fine");
+ yield checkScroll(tab, {scroll: SCROLL2_STR}, "scroll is still fine");
+
+ // Now go back in history and check that the scroll position
+ // is restored there as well.
+ is(browser.canGoBack, true, "can go back");
+ browser.goBack();
+
+ yield BrowserTestUtils.browserLoaded(browser);
+ yield TabStateFlusher.flush(browser);
+
+ yield checkScroll(tab, {scroll: SCROLL_STR}, "scroll is still fine after navigating back");
yield BrowserTestUtils.closeWindow(newWin);
});
new file mode 100644
--- /dev/null
+++ b/browser/components/sessionstore/test/browser_scrollPositions_sample2.html
@@ -0,0 +1,8 @@
+<!DOCTYPE html>
+<html lang="en">
+ <head>
+ <meta charset="utf-8">
+ <title>browser_scrollPositions_sample.html</title>
+ </head>
+ <body style='width: 100000px; height: 100000px;'>top</body>
+</html>