|
| 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 |
| 3 | +# file, You can obtain one at http://mozilla.org/MPL/2.0/. |
| 4 | + |
| 5 | +import os |
| 6 | +import sys |
| 7 | + |
| 8 | +# add this directory to the path |
| 9 | +sys.path.append(os.path.dirname(__file__)) |
| 10 | + |
| 11 | +from session_store_test_case import SessionStoreTestCase |
| 12 | + |
| 13 | + |
| 14 | +def inline(title): |
| 15 | + return "data:text/html;charset=utf-8,<html><head><title>{}</title></head><body></body></html>".format( |
| 16 | + title |
| 17 | + ) |
| 18 | + |
| 19 | + |
| 20 | +class TestSessionRestoreManually(SessionStoreTestCase): |
| 21 | + """ |
| 22 | + Test that window attributes for each window are restored |
| 23 | + correctly (with manual session restore) in a new session. |
| 24 | + """ |
| 25 | + |
| 26 | + def setUp(self): |
| 27 | + super(TestSessionRestoreManually, self).setUp( |
| 28 | + startup_page=1, |
| 29 | + include_private=False, |
| 30 | + restore_on_demand=True, |
| 31 | + test_windows=set( |
| 32 | + [ |
| 33 | + # Window 1 |
| 34 | + ( |
| 35 | + inline("lorem ipsom"), |
| 36 | + inline("dolor"), |
| 37 | + ), |
| 38 | + # Window 2 |
| 39 | + (inline("sit"),), |
| 40 | + ] |
| 41 | + ), |
| 42 | + ) |
| 43 | + |
| 44 | + def test_restore(self): |
| 45 | + self.marionette.execute_script( |
| 46 | + """ |
| 47 | + Services.prefs.setBoolPref("browser.sessionstore.persist_closed_tabs_between_sessions", true); |
| 48 | + """ |
| 49 | + ) |
| 50 | + |
| 51 | + self.wait_for_windows( |
| 52 | + self.all_windows, "Not all requested windows have been opened" |
| 53 | + ) |
| 54 | + |
| 55 | + self.assertEqual( |
| 56 | + len(self.marionette.chrome_window_handles), |
| 57 | + 2, |
| 58 | + msg="Should have 3 windows open.", |
| 59 | + ) |
| 60 | + self.marionette.execute_script( |
| 61 | + """ |
| 62 | + const lazy = {}; |
| 63 | + ChromeUtils.defineESModuleGetters(lazy, { |
| 64 | + SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", |
| 65 | + }); |
| 66 | + function getAllBrowserWindows() { |
| 67 | + return Array.from(Services.wm.getEnumerator("navigator:browser")); |
| 68 | + } |
| 69 | + let windows = getAllBrowserWindows(); |
| 70 | + windows[1].resizeTo(500, 500) |
| 71 | + """ |
| 72 | + ) |
| 73 | + |
| 74 | + self.marionette.quit() |
| 75 | + self.marionette.start_session() |
| 76 | + self.marionette.set_context("chrome") |
| 77 | + |
| 78 | + # restore the previous session |
| 79 | + self.marionette.execute_script( |
| 80 | + """ |
| 81 | + const lazy = {}; |
| 82 | + ChromeUtils.defineESModuleGetters(lazy, { |
| 83 | + SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", |
| 84 | + }); |
| 85 | + function observeClosedObjectsChange() { |
| 86 | + return new Promise(resolve => { |
| 87 | + function observe(subject, topic, data) { |
| 88 | + if (topic == "sessionstore-closed-objects-changed") { |
| 89 | + Services.obs.removeObserver(this, "sessionstore-closed-objects-changed"); |
| 90 | + resolve('observed closed objects changed'); |
| 91 | + }; |
| 92 | + } |
| 93 | + Services.obs.addObserver(observe, "sessionstore-closed-objects-changed"); |
| 94 | + }); |
| 95 | + }; |
| 96 | +
|
| 97 | + async function checkForWindowHeight() { |
| 98 | + let closedWindowsObserver = observeClosedObjectsChange(); |
| 99 | + lazy.SessionStore.restoreLastSession(); |
| 100 | + await closedWindowsObserver; |
| 101 | + } |
| 102 | + checkForWindowHeight(); |
| 103 | + """ |
| 104 | + ) |
| 105 | + |
| 106 | + self.assertEqual( |
| 107 | + len(self.marionette.chrome_window_handles), |
| 108 | + 2, |
| 109 | + msg="Windows from last session have been restored.", |
| 110 | + ) |
| 111 | + |
| 112 | + self.assertEqual( |
| 113 | + self.marionette.execute_script( |
| 114 | + """ |
| 115 | + const lazy = {}; |
| 116 | + ChromeUtils.defineESModuleGetters(lazy, { |
| 117 | + SessionStore: "resource:///modules/sessionstore/SessionStore.sys.mjs", |
| 118 | + }); |
| 119 | + let state = SessionStore.getCurrentState() |
| 120 | + return state.windows[1]["height"] |
| 121 | + """ |
| 122 | + ), |
| 123 | + 500, |
| 124 | + "Second window has been restored to the correct height.", |
| 125 | + ) |
0 commit comments