1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
/* Any copyright is dedicated to the Public Domain.
http://creativecommons.org/publicdomain/zero/1.0/ */
"use strict";
ChromeUtils.defineESModuleGetters(this, {
ShoppingUtils: "resource:///modules/ShoppingUtils.sys.mjs",
});
const ACTIVE_PREF = "browser.shopping.experience2023.active";
const AUTO_OPEN_ENABLED_PREF =
"browser.shopping.experience2023.autoOpen.enabled";
const AUTO_OPEN_USER_ENABLED_PREF =
"browser.shopping.experience2023.autoOpen.userEnabled";
const PRODUCT_PAGE = "https://example.com/product/B09TJGHL5F";
const productURI = Services.io.newURI(PRODUCT_PAGE);
async function trigger_auto_open_flow(expectedActivePrefValue) {
// Set the active pref to false, which triggers ShoppingUtils.onActiveUpdate.
Services.prefs.setBoolPref(ACTIVE_PREF, false);
// Call onLocationChange with a product URL, triggering auto-open to flip the
// active pref back to true, if the auto-open conditions are satisfied.
ShoppingUtils.onLocationChange(productURI, 0);
// Wait a turn for the change to propagate...
await TestUtils.waitForTick();
// Finally, assert the active pref has the expected state.
Assert.equal(
expectedActivePrefValue,
Services.prefs.getBoolPref(ACTIVE_PREF, false)
);
}
add_task(async function test_auto_open() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.optedIn", 1],
["browser.shopping.experience2023.autoOpen.enabled", true],
["browser.shopping.experience2023.autoOpen.userEnabled", true],
],
});
await trigger_auto_open_flow(true);
await SpecialPowers.popPrefEnv();
});
add_task(async function test_auto_open_disabled() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.optedIn", 1],
["browser.shopping.experience2023.autoOpen.enabled", false],
["browser.shopping.experience2023.autoOpen.userEnabled", true],
],
});
await trigger_auto_open_flow(false);
await SpecialPowers.popPrefEnv();
});
add_task(async function test_auto_open_user_disabled() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.optedIn", 1],
["browser.shopping.experience2023.autoOpen.enabled", true],
["browser.shopping.experience2023.autoOpen.userEnabled", false],
],
});
await trigger_auto_open_flow(false);
await SpecialPowers.popPrefEnv();
});
add_task(async function test_auto_open_not_opted_in() {
await SpecialPowers.pushPrefEnv({
set: [
["browser.shopping.experience2023.optedIn", 0],
["browser.shopping.experience2023.autoOpen.enabled", true],
["browser.shopping.experience2023.autoOpen.userEnabled", true],
],
});
await trigger_auto_open_flow(false);
await SpecialPowers.popPrefEnv();
});
|