summaryrefslogtreecommitdiffstats
path: root/mobile/android/tests/browser/chrome/test_session_scroll_position.html
diff options
context:
space:
mode:
authorMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
committerMatt A. Tobin <mattatobin@localhost.localdomain>2018-02-02 04:16:08 -0500
commit5f8de423f190bbb79a62f804151bc24824fa32d8 (patch)
tree10027f336435511475e392454359edea8e25895d /mobile/android/tests/browser/chrome/test_session_scroll_position.html
parent49ee0794b5d912db1f95dce6eb52d781dc210db5 (diff)
downloadUXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.gz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.lz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.tar.xz
UXP-5f8de423f190bbb79a62f804151bc24824fa32d8.zip
Add m-esr52 at 52.6.0
Diffstat (limited to 'mobile/android/tests/browser/chrome/test_session_scroll_position.html')
-rw-r--r--mobile/android/tests/browser/chrome/test_session_scroll_position.html310
1 files changed, 310 insertions, 0 deletions
diff --git a/mobile/android/tests/browser/chrome/test_session_scroll_position.html b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
new file mode 100644
index 000000000..cfbeb5164
--- /dev/null
+++ b/mobile/android/tests/browser/chrome/test_session_scroll_position.html
@@ -0,0 +1,310 @@
+<!DOCTYPE HTML>
+<html>
+<!--
+https://bugzilla.mozilla.org/show_bug.cgi?id=810981
+-->
+<head>
+ <meta charset="utf-8">
+ <title>Test for Bug 810981</title>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SimpleTest.js"></script>
+ <script type="application/javascript" src="chrome://mochikit/content/tests/SimpleTest/SpawnTask.js"></script>
+ <link rel="stylesheet" type="text/css" href="chrome://global/skin"/>
+ <link rel="stylesheet" type="text/css" href="chrome://mochikit/content/tests/SimpleTest/test.css"/>
+ <script type="application/javascript" src="head.js"></script>
+ <script type="application/javascript;version=1.7">
+
+ /** Test for Bug 810981 **/
+
+ "use strict";
+
+ const { classes: Cc, interfaces: Ci, utils: Cu } = Components;
+
+ Cu.import("resource://gre/modules/XPCOMUtils.jsm");
+ Cu.import("resource://gre/modules/Services.jsm");
+ Cu.import("resource://gre/modules/Messaging.jsm");
+ Cu.import("resource://gre/modules/Task.jsm");
+
+ // The chrome window.
+ let chromeWin;
+
+ // Track the tabs where the tests are happening.
+ let tabScroll;
+
+ // Use something with enough content to allow for scrolling.
+ const URL = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article_mobile.html";
+ // Something to test the zoom level scaling on rotation with.
+ const URL_desktop = "http://example.org/chrome/mobile/android/tests/browser/chrome/basic_article.html";
+ // Reader mode URL
+ const URL_reader = "about:reader?url=http%3A%2F%2Fexample.org%2Fchrome%2Fmobile%2Fandroid%2Ftests%2Fbrowser%2Fchrome%2Fbasic_article_mobile.html";
+
+ function dispatchUIEvent(browser, type) {
+ let event = browser.contentDocument.createEvent("UIEvents");
+ event.initUIEvent(type, true, false, browser.contentDocument.defaultView, 0);
+ browser.dispatchEvent(event);
+ }
+
+ function setScrollPosition(browser, x, y) {
+ browser.contentWindow.scrollTo(x, y);
+ dispatchUIEvent(browser, "scroll");
+ }
+
+ function setZoomLevel(browser, zoom) {
+ browser.contentWindow.QueryInterface(
+ Ci.nsIInterfaceRequestor).getInterface(
+ Ci.nsIDOMWindowUtils).setResolutionAndScaleTo(zoom);
+ }
+
+ let ss = Cc["@mozilla.org/browser/sessionstore;1"].getService(Ci.nsISessionStore);
+
+ add_task(function* test_sessionStoreScrollPosition() {
+ const SCROLL_X = 0;
+ const SCROLL_Y = 38;
+
+ chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+ let BrowserApp = chromeWin.BrowserApp;
+
+ // Creates a tab, sets a scroll position and closes the tab.
+ function createAndRemoveTab() {
+ return Task.spawn(function () {
+ // Create a new tab.
+ tabScroll = BrowserApp.addTab(URL);
+ let browser = tabScroll.browser;
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Modify scroll position.
+ setScrollPosition(browser, SCROLL_X, SCROLL_Y);
+ yield promiseTabEvent(browser, "SSTabScrollCaptured");
+
+ // Check that we've actually scrolled.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {};
+ utils.getScrollXY(false, scrollX, scrollY);
+ is(scrollX.value, SCROLL_X, "scrollX set correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY set correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(tabScroll);
+ yield promiseTabEvent(browser, "SSTabCloseProcessed");
+ });
+ }
+
+ yield createAndRemoveTab();
+ let state = ss.getClosedTabs(chromeWin);
+ let [{scrolldata}] = state;
+ is(scrolldata.scroll, SCROLL_X + "," + SCROLL_Y, "stored scroll position is correct");
+
+ // Restore the closed tab.
+ let closedTabData = ss.getClosedTabs(chromeWin)[0];
+ let browser = ss.undoCloseTab(chromeWin, closedTabData);
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Check the scroll position.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {};
+ utils.getScrollXY(false, scrollX, scrollY);
+ is(scrollX.value, SCROLL_X, "scrollX restored correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+ });
+
+ add_task(function* test_sessionStoreScrollPositionReaderMode() {
+ const SCROLL_X = 0;
+ const SCROLL_Y = 44;
+
+ chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+ let BrowserApp = chromeWin.BrowserApp;
+
+ // Creates a tab, sets a scroll position and closes the tab.
+ function createAndRemoveReaderTab() {
+ return Task.spawn(function () {
+ // Create a new tab.
+ tabScroll = BrowserApp.addTab(URL_reader);
+ let browser = tabScroll.browser;
+ yield promiseBrowserEvent(browser, "AboutReaderContentReady");
+
+ // Modify scroll position.
+ setScrollPosition(browser, SCROLL_X, SCROLL_Y);
+ yield promiseTabEvent(browser, "SSTabScrollCaptured");
+
+ // Check that we've actually scrolled.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {};
+ utils.getScrollXY(false, scrollX, scrollY);
+ is(scrollX.value, SCROLL_X, "scrollX set correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY set correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(tabScroll);
+ yield promiseTabEvent(browser, "SSTabCloseProcessed");
+ });
+ }
+
+ yield createAndRemoveReaderTab();
+ let state = ss.getClosedTabs(chromeWin);
+ let [{scrolldata}] = state;
+ is(scrolldata.scroll, SCROLL_X + "," + SCROLL_Y, "stored scroll position is correct");
+
+ // Restore the closed tab.
+ let closedTabData = ss.getClosedTabs(chromeWin)[0];
+ let browser = ss.undoCloseTab(chromeWin, closedTabData);
+ yield promiseBrowserEvent(browser, "AboutReaderContentReady");
+
+ // Check the scroll position.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {};
+ utils.getScrollXY(false, scrollX, scrollY);
+ is(scrollX.value, SCROLL_X, "scrollX restored correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+ });
+
+ add_task(function* test_sessionStoreZoomLevel() {
+ const ZOOM = 4.2;
+ const SCROLL_X = 42;
+ const SCROLL_Y = 42;
+
+ chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+ let BrowserApp = chromeWin.BrowserApp;
+
+ // Creates a tab, sets a scroll position and zoom level and closes the tab.
+ function createAndRemoveTab() {
+ return Task.spawn(function () {
+ // Create a new tab.
+ tabScroll = BrowserApp.addTab(URL);
+ let browser = tabScroll.browser;
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Modify scroll position and zoom level.
+ setZoomLevel(browser, ZOOM);
+ setScrollPosition(browser, SCROLL_X, SCROLL_Y);
+ yield promiseTabEvent(browser, "SSTabScrollCaptured");
+
+ // Check that we've actually scrolled and zoomed.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {}, zoom = {};
+ utils.getResolution(zoom);
+ utils.getScrollXY(false, scrollX, scrollY);
+ ok(fuzzyEquals(zoom.value, ZOOM), "zoom set correctly");
+ is(scrollX.value, SCROLL_X, "scrollX set correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY set correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(tabScroll);
+ yield promiseTabEvent(browser, "SSTabCloseProcessed");
+ });
+ }
+
+ yield createAndRemoveTab();
+ let state = ss.getClosedTabs(chromeWin);
+ let [{scrolldata}] = state;
+ is(scrolldata.scroll, SCROLL_X + "," + SCROLL_Y, "stored scroll position is correct");
+ ok(fuzzyEquals(scrolldata.zoom.resolution, ZOOM), "stored zoom level is correct");
+
+ // Restore the closed tab.
+ let closedTabData = ss.getClosedTabs(chromeWin)[0];
+ let browser = ss.undoCloseTab(chromeWin, closedTabData);
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Check the scroll position and zoom level.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {}, zoom = {};
+ utils.getResolution(zoom);
+ utils.getScrollXY(false, scrollX, scrollY);
+ ok(fuzzyEquals(zoom.value, ZOOM), "zoom restored correctly");
+ is(scrollX.value, SCROLL_X, "scrollX restored correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+ });
+
+ add_task(function* test_sessionStoreZoomLevelRecalc() {
+ const ZOOM = 4.2;
+ const SCROLL_X = 42;
+ const SCROLL_Y = 42;
+
+ chromeWin = Services.wm.getMostRecentWindow("navigator:browser");
+ let BrowserApp = chromeWin.BrowserApp;
+
+ // Creates a tab, sets a scroll position and zoom level and closes the tab.
+ function createAndRemoveTab() {
+ return Task.spawn(function () {
+ // Create a new tab.
+ tabScroll = BrowserApp.addTab(URL_desktop);
+ let browser = tabScroll.browser;
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Modify scroll position and zoom level.
+ setZoomLevel(browser, ZOOM);
+ setScrollPosition(browser, SCROLL_X, SCROLL_Y);
+ yield promiseTabEvent(browser, "SSTabScrollCaptured");
+
+ // Check that we've actually scrolled and zoomed.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {}, zoom = {};
+ utils.getResolution(zoom);
+ utils.getScrollXY(false, scrollX, scrollY);
+ ok(fuzzyEquals(zoom.value, ZOOM), "zoom set correctly");
+ is(scrollX.value, SCROLL_X, "scrollX set correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY set correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(tabScroll);
+ yield promiseTabEvent(browser, "SSTabCloseProcessed");
+ });
+ }
+
+ yield createAndRemoveTab();
+ let state = ss.getClosedTabs(chromeWin);
+ let [{scrolldata}] = state;
+ is(scrolldata.scroll, SCROLL_X + "," + SCROLL_Y, "stored scroll position is correct");
+ ok(fuzzyEquals(scrolldata.zoom.resolution, ZOOM), "stored zoom level is correct");
+
+ // Pretend the zoom level was originally saved on a rotated device.
+ let closedTabData = ss.getClosedTabs(chromeWin)[0];
+ let displayWidth = scrolldata.zoom.displaySize.width;
+ let displayHeight = scrolldata.zoom.displaySize.height;
+ closedTabData.scrolldata.zoom.displaySize.width = displayHeight;
+ closedTabData.scrolldata.zoom.displaySize.height = displayWidth;
+
+ // Restore the closed tab.
+ let browser = ss.undoCloseTab(chromeWin, closedTabData);
+ yield promiseBrowserEvent(browser, "pageshow");
+
+ // Check the scroll position and zoom level.
+ let ifreq = browser.contentWindow.QueryInterface(Ci.nsIInterfaceRequestor);
+ let utils = ifreq.getInterface(Ci.nsIDOMWindowUtils);
+ let scrollX = {}, scrollY = {}, zoom = {};
+ utils.getResolution(zoom);
+ utils.getScrollXY(false, scrollX, scrollY);
+ ok(fuzzyEquals(zoom.value, ZOOM * displayWidth / displayHeight), "recalculated zoom restored correctly");
+ is(scrollX.value, SCROLL_X, "scrollX restored correctly");
+ is(scrollY.value, SCROLL_Y, "scrollY restored correctly");
+
+ // Remove the tab.
+ BrowserApp.closeTab(BrowserApp.getTabForBrowser(browser));
+ });
+
+ </script>
+</head>
+<body>
+<a target="_blank" href="https://bugzilla.mozilla.org/show_bug.cgi?id=810981">Mozilla Bug 810981</a>
+<p id="display"></p>
+<div id="content" style="display: none">
+
+</div>
+<pre id="test">
+</pre>
+</body>
+</html>