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
91
92
93
94
95
96
97
98
99
100
101
102
103
|
"use strict";
const CHECK_DEFAULT_INITIAL = Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser");
add_task(function* clicking_make_default_checks_alwaysCheck_checkbox() {
yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
yield test_with_mock_shellservice({isDefault: false}, function*() {
let setDefaultPane = content.document.getElementById("setDefaultPane");
Assert.equal(setDefaultPane.selectedIndex, "0",
"The 'make default' pane should be visible when not default");
let alwaysCheck = content.document.getElementById("alwaysCheckDefault");
Assert.ok(!alwaysCheck.checked, "Always Check is unchecked by default");
Assert.ok(!Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"),
"alwaysCheck pref should be false by default in test runs");
let setDefaultButton = content.document.getElementById("setDefaultButton");
setDefaultButton.click();
content.window.gMainPane.updateSetDefaultBrowser();
yield ContentTaskUtils.waitForCondition(() => alwaysCheck.checked,
"'Always Check' checkbox should get checked after clicking the 'Set Default' button");
Assert.ok(alwaysCheck.checked,
"Clicking 'Make Default' checks the 'Always Check' checkbox");
Assert.ok(Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"),
"Checking the checkbox should set the pref to true");
Assert.ok(alwaysCheck.disabled,
"'Always Check' checkbox is locked with default browser and alwaysCheck=true");
Assert.equal(setDefaultPane.selectedIndex, "1",
"The 'make default' pane should not be visible when default");
Assert.ok(Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"),
"checkDefaultBrowser pref is now enabled");
});
gBrowser.removeCurrentTab();
Services.prefs.clearUserPref("browser.shell.checkDefaultBrowser");
});
add_task(function* clicking_make_default_checks_alwaysCheck_checkbox() {
Services.prefs.lockPref("browser.shell.checkDefaultBrowser");
yield BrowserTestUtils.openNewForegroundTab(gBrowser, "about:preferences");
yield test_with_mock_shellservice({isDefault: false}, function*() {
let setDefaultPane = content.document.getElementById("setDefaultPane");
Assert.equal(setDefaultPane.selectedIndex, "0",
"The 'make default' pane should be visible when not default");
let alwaysCheck = content.document.getElementById("alwaysCheckDefault");
Assert.ok(alwaysCheck.disabled, "Always Check is disabled when locked");
Assert.ok(alwaysCheck.checked,
"Always Check is checked because defaultPref is true and pref is locked");
Assert.ok(Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"),
"alwaysCheck pref should ship with 'true' by default");
let setDefaultButton = content.document.getElementById("setDefaultButton");
setDefaultButton.click();
content.window.gMainPane.updateSetDefaultBrowser();
yield ContentTaskUtils.waitForCondition(() => setDefaultPane.selectedIndex == "1",
"Browser is now default");
Assert.ok(alwaysCheck.checked,
"'Always Check' is still checked because it's locked");
Assert.ok(alwaysCheck.disabled,
"'Always Check is disabled because it's locked");
Assert.ok(Services.prefs.getBoolPref("browser.shell.checkDefaultBrowser"),
"The pref is locked and so doesn't get changed");
});
Services.prefs.unlockPref("browser.shell.checkDefaultBrowser");
gBrowser.removeCurrentTab();
});
registerCleanupFunction(function() {
Services.prefs.unlockPref("browser.shell.checkDefaultBrowser");
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", CHECK_DEFAULT_INITIAL);
});
function* test_with_mock_shellservice(options, testFn) {
yield ContentTask.spawn(gBrowser.selectedBrowser, options, function*(options) {
let doc = content.document;
let win = doc.defaultView;
win.oldShellService = win.getShellService();
let mockShellService = {
_isDefault: false,
isDefaultBrowser() {
return this._isDefault;
},
setDefaultBrowser() {
this._isDefault = true;
},
};
win.getShellService = function() {
return mockShellService;
}
mockShellService._isDefault = options.isDefault;
win.gMainPane.updateSetDefaultBrowser();
});
yield ContentTask.spawn(gBrowser.selectedBrowser, null, testFn);
Services.prefs.setBoolPref("browser.shell.checkDefaultBrowser", CHECK_DEFAULT_INITIAL);
}
|