From 43a97878ce14b72f0981164f87f2e35e14151312 Mon Sep 17 00:00:00 2001 From: Daniel Baumann Date: Sun, 7 Apr 2024 11:22:09 +0200 Subject: Adding upstream version 110.0.1. Signed-off-by: Daniel Baumann --- .../components/sessionstore/test/browser_636279.js | 140 +++++++++++++++++++++ 1 file changed, 140 insertions(+) create mode 100644 browser/components/sessionstore/test/browser_636279.js (limited to 'browser/components/sessionstore/test/browser_636279.js') diff --git a/browser/components/sessionstore/test/browser_636279.js b/browser/components/sessionstore/test/browser_636279.js new file mode 100644 index 0000000000..83c21d56c8 --- /dev/null +++ b/browser/components/sessionstore/test/browser_636279.js @@ -0,0 +1,140 @@ +/* Any copyright is dedicated to the Public Domain. + http://creativecommons.org/publicdomain/zero/1.0/ */ + +var stateBackup = ss.getBrowserState(); + +var statePinned = { + windows: [ + { + tabs: [ + { + entries: [ + { url: "http://example.com#1", triggeringPrincipal_base64 }, + ], + pinned: true, + }, + ], + }, + ], +}; + +var state = { + windows: [ + { + tabs: [ + { + entries: [ + { url: "http://example.com#1", triggeringPrincipal_base64 }, + ], + }, + { + entries: [ + { url: "http://example.com#2", triggeringPrincipal_base64 }, + ], + }, + { + entries: [ + { url: "http://example.com#3", triggeringPrincipal_base64 }, + ], + }, + { + entries: [ + { url: "http://example.com#4", triggeringPrincipal_base64 }, + ], + }, + ], + }, + ], +}; + +function test() { + waitForExplicitFinish(); + + registerCleanupFunction(function() { + TabsProgressListener.uninit(); + ss.setBrowserState(stateBackup); + }); + + TabsProgressListener.init(); + + window.addEventListener( + "SSWindowStateReady", + function() { + let firstProgress = true; + + TabsProgressListener.setCallback(function(needsRestore, isRestoring) { + if (firstProgress) { + firstProgress = false; + is(isRestoring, 3, "restoring 3 tabs concurrently"); + } else { + ok(isRestoring <= 3, "restoring max. 2 tabs concurrently"); + } + + if (0 == needsRestore) { + TabsProgressListener.unsetCallback(); + waitForFocus(finish); + } + }); + + ss.setBrowserState(JSON.stringify(state)); + }, + { once: true } + ); + + ss.setBrowserState(JSON.stringify(statePinned)); +} + +function countTabs() { + let needsRestore = 0, + isRestoring = 0; + for (let window of Services.wm.getEnumerator("navigator:browser")) { + if (window.closed) { + continue; + } + + for (let i = 0; i < window.gBrowser.tabs.length; i++) { + let browserState = ss.getInternalObjectState( + window.gBrowser.tabs[i].linkedBrowser + ); + if (browserState == TAB_STATE_RESTORING) { + isRestoring++; + } else if (browserState == TAB_STATE_NEEDS_RESTORE) { + needsRestore++; + } + } + } + + return [needsRestore, isRestoring]; +} + +var TabsProgressListener = { + init() { + Services.obs.addObserver(this, "sessionstore-debug-tab-restored"); + }, + + uninit() { + Services.obs.removeObserver(this, "sessionstore-debug-tab-restored"); + this.unsetCallback(); + }, + + setCallback(callback) { + this.callback = callback; + }, + + unsetCallback() { + delete this.callback; + }, + + observe(browser, topic, data) { + TabsProgressListener.onRestored(browser); + }, + + onRestored(browser) { + if ( + this.callback && + ss.getInternalObjectState(browser) == TAB_STATE_RESTORING + ) { + this.callback.apply(null, countTabs()); + } + }, +}; -- cgit v1.2.3