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 --- .../xpcshell/test_ASRouterTargeting_snapshot.js | 54 ++++++++++++++++++++++ 1 file changed, 54 insertions(+) create mode 100644 browser/components/newtab/test/xpcshell/test_ASRouterTargeting_snapshot.js (limited to 'browser/components/newtab/test/xpcshell/test_ASRouterTargeting_snapshot.js') diff --git a/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_snapshot.js b/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_snapshot.js new file mode 100644 index 0000000000..26d91cb417 --- /dev/null +++ b/browser/components/newtab/test/xpcshell/test_ASRouterTargeting_snapshot.js @@ -0,0 +1,54 @@ +/* Any copyright is dedicated to the Public Domain. + * http://creativecommons.org/publicdomain/zero/1.0/ + */ + +"use strict"; + +const { ASRouterTargeting } = ChromeUtils.import( + "resource://activity-stream/lib/ASRouterTargeting.jsm" +); + +add_task(async function should_ignore_rejections() { + let target = { + get foo() { + return new Promise(resolve => resolve(1)); + }, + + get bar() { + return new Promise((resolve, reject) => reject(new Error("unspecified"))); + }, + }; + + let snapshot = await ASRouterTargeting.getEnvironmentSnapshot(target); + deepEqual(snapshot, { environment: { foo: 1 }, version: 1 }); +}); + +add_task(async function should_ignore_rejections() { + // The order that `ASRouterTargeting.getEnvironmentSnapshot` + // enumerates the target object matters here, but it's guaranteed to + // be consistent by the `for ... in` ordering: see + // https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/for...in#description. + let target = { + get foo() { + return new Promise(resolve => resolve(1)); + }, + + get bar() { + return new Promise(resolve => { + // Pretend that we're about to shut down. + Services.startup.advanceShutdownPhase( + Services.startup.SHUTDOWN_PHASE_APPSHUTDOWN + ); + resolve(2); + }); + }, + + get baz() { + return new Promise(resolve => resolve(3)); + }, + }; + + let snapshot = await ASRouterTargeting.getEnvironmentSnapshot(target); + // `baz` is dropped since we're shutting down by the time it's processed. + deepEqual(snapshot, { environment: { foo: 1, bar: 2 }, version: 1 }); +}); -- cgit v1.2.3