gecko-dev/browser/components/sessionstore/test/browser_607016.js
Rob Wu 4a6f84f91d Bug 1544834 - Replace deprecated generics in test code r=evilpie
- `Array.map` becomes `Array.from`
- Array copying via `Array.slice` becomes `Array.from`.
- `Array.forEach` that did not rely on closures becomes `for`-`of` loops.
- Anything else: `Array.X` becomes `Array.prototype.X`.

Complex cases:

dom/bindings/test/TestInterfaceJS.js and
dom/bindings/test/test_exception_options_from_jsimplemented.html
use `Array.indexOf` to generate an error with a specific error message.
Switched to `Array.prototype.forEach` to generate the same error.

js/src/jit-test/tests/basic/exception-column-number.js
In this test `Array.indexOf()` is used to generate an error. Since the
exact message doesn't matter, I switched to `Array.from()`.

Intentionally not changed:

editor/libeditor/tests/browserscope/lib/richtext/richtext/js/range.js
Did not modify because this is 3rd-party code and the code uses
feature detection as a fall back when Array generics are not used.

testing/talos/talos/tests/dromaeo/lib/mootools.js
Did not modify because mootools adds the `Array.slice` method to the
`Array` object.

Not changed because they check the implementation of Array generics:
js/src/jit-test/tests/basic/arrayNatives.js
js/src/jit-test/tests/basic/bug563243.js
js/src/jit-test/tests/basic/bug618853.js
js/src/jit-test/tests/basic/bug830967.js
js/src/jit-test/tests/jaeger/recompile/bug656753.js
js/src/jit-test/tests/self-hosting/alternate-static-and-instance-array-extras.js
js/src/tests/non262/Array/generics.js
js/src/tests/non262/Array/regress-415540.js
js/src/tests/non262/extensions/regress-355497.js
js/src/tests/non262/extensions/typedarray-set-neutering.js

Depends on D27802

Differential Revision: https://phabricator.services.mozilla.com/D27803

--HG--
extra : moz-landing-system : lando
2019-04-17 19:03:19 +00:00

100 lines
4.4 KiB
JavaScript

"use strict";
var stateBackup = ss.getBrowserState();
add_task(async function() {
/** Bug 607016 - If a tab is never restored, attributes (eg. hidden) aren't updated correctly **/
ignoreAllUncaughtExceptions();
// Set the pref to true so we know exactly how many tabs should be restoring at
// any given time. This guarantees that a finishing load won't start another.
Services.prefs.setBoolPref("browser.sessionstore.restore_on_demand", true);
// Don't restore tabs lazily.
Services.prefs.setBoolPref("browser.sessionstore.restore_tabs_lazily", false);
let state = { windows: [{ tabs: [
{ entries: [{ url: "http://example.org#1", triggeringPrincipal_base64 }], extData: { "uniq": r() } },
{ entries: [{ url: "http://example.org#2", triggeringPrincipal_base64 }], extData: { "uniq": r() } }, // overwriting
{ entries: [{ url: "http://example.org#3", triggeringPrincipal_base64 }], extData: { "uniq": r() } }, // hiding
{ entries: [{ url: "http://example.org#4", triggeringPrincipal_base64 }], extData: { "uniq": r() } }, // adding
{ entries: [{ url: "http://example.org#5", triggeringPrincipal_base64 }], extData: { "uniq": r() } }, // deleting
{ entries: [{ url: "http://example.org#6", triggeringPrincipal_base64 }] }, // creating
], selected: 1 }] };
async function progressCallback() {
let curState = JSON.parse(ss.getBrowserState());
for (let i = 0; i < curState.windows[0].tabs.length; i++) {
let tabState = state.windows[0].tabs[i];
let tabCurState = curState.windows[0].tabs[i];
if (tabState.extData) {
is(tabCurState.extData.uniq, tabState.extData.uniq,
"sanity check that tab has correct extData");
} else {
// We aren't expecting there to be any data on extData, but panorama
// may be setting something, so we need to make sure that if we do have
// data, we just don't have anything for "uniq".
ok(!("extData" in tabCurState) || !("uniq" in tabCurState.extData),
"sanity check that tab doesn't have extData or extData doesn't have 'uniq'");
}
}
// Now we'll set a new unique value on 1 of the tabs
let newUniq = r();
ss.setCustomTabValue(gBrowser.tabs[1], "uniq", newUniq);
let tabState = JSON.parse(ss.getTabState(gBrowser.tabs[1]));
is(tabState.extData.uniq, newUniq,
"(overwriting) new data is stored in extData");
// hide the next tab before closing it
gBrowser.hideTab(gBrowser.tabs[2]);
tabState = JSON.parse(ss.getTabState(gBrowser.tabs[2]));
ok(tabState.hidden, "(hiding) tab data has hidden == true");
// set data that's not in a conflicting key
let stillUniq = r();
ss.setCustomTabValue(gBrowser.tabs[3], "stillUniq", stillUniq);
tabState = JSON.parse(ss.getTabState(gBrowser.tabs[3]));
is(tabState.extData.stillUniq, stillUniq,
"(adding) new data is stored in extData");
// remove the uniq value and make sure it's not there in the closed data
ss.deleteCustomTabValue(gBrowser.tabs[4], "uniq");
tabState = JSON.parse(ss.getTabState(gBrowser.tabs[4]));
// Since Panorama might have put data in, first check if there is extData.
// If there is explicitly check that "uniq" isn't in it. Otherwise, we're ok
if ("extData" in tabState) {
ok(!("uniq" in tabState.extData),
"(deleting) uniq not in existing extData");
} else {
ok(true, "(deleting) no data is stored in extData");
}
// set unique data on the tab that never had any set, make sure that's saved
let newUniq2 = r();
ss.setCustomTabValue(gBrowser.tabs[5], "uniq", newUniq2);
tabState = JSON.parse(ss.getTabState(gBrowser.tabs[5]));
is(tabState.extData.uniq, newUniq2,
"(creating) new data is stored in extData where there was none");
while (gBrowser.tabs.length > 1) {
BrowserTestUtils.removeTab(gBrowser.tabs[1]);
}
}
// Set the test state.
await setBrowserState(state);
// Wait until the selected tab is restored and all others are pending.
await Promise.all(Array.from(gBrowser.tabs, tab => {
return (tab == gBrowser.selectedTab) ?
promiseTabRestored(tab) : promiseTabRestoring(tab);
}));
// Kick off the actual tests.
await progressCallback();
// Cleanup.
Services.prefs.clearUserPref("browser.sessionstore.restore_on_demand");
Services.prefs.clearUserPref("browser.sessionstore.restore_tabs_lazily");
await promiseBrowserState(stateBackup);
});