|
1 /* Any copyright is dedicated to the Public Domain. |
|
2 http://creativecommons.org/publicdomain/zero/1.0/ */ |
|
3 |
|
4 /** |
|
5 * Tests if the preferences and localization objects work correctly. |
|
6 */ |
|
7 |
|
8 function test() { |
|
9 initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { |
|
10 info("Starting test... "); |
|
11 |
|
12 ok(aMonitor.panelWin.L10N, |
|
13 "Should have a localization object available on the panel window."); |
|
14 ok(aMonitor.panelWin.Prefs, |
|
15 "Should have a preferences object available on the panel window."); |
|
16 |
|
17 function testL10N() { |
|
18 let { L10N } = aMonitor.panelWin; |
|
19 |
|
20 ok(L10N.stringBundle, |
|
21 "The localization object should have a string bundle available."); |
|
22 |
|
23 let bundleName = "chrome://browser/locale/devtools/netmonitor.properties"; |
|
24 let stringBundle = Services.strings.createBundle(bundleName); |
|
25 |
|
26 is(L10N.getStr("netmonitor.label"), |
|
27 stringBundle.GetStringFromName("netmonitor.label"), |
|
28 "The getStr() method didn't return the expected string."); |
|
29 |
|
30 is(L10N.getFormatStr("networkMenu.totalMS", "foo"), |
|
31 stringBundle.formatStringFromName("networkMenu.totalMS", ["foo"], 1), |
|
32 "The getFormatStr() method didn't return the expected string."); |
|
33 } |
|
34 |
|
35 function testPrefs() { |
|
36 let { Prefs } = aMonitor.panelWin; |
|
37 |
|
38 is(Prefs.root, "devtools.netmonitor", |
|
39 "The preferences object should have a correct root path."); |
|
40 |
|
41 is(Prefs.networkDetailsWidth, |
|
42 Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), |
|
43 "Getting a pref should work correctly."); |
|
44 |
|
45 let previousValue = Prefs.networkDetailsWidth; |
|
46 let bogusValue = ~~(Math.random() * 100); |
|
47 Prefs.networkDetailsWidth = bogusValue; |
|
48 is(Prefs.networkDetailsWidth, |
|
49 Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), |
|
50 "Getting a pref after it has been modified should work correctly."); |
|
51 is(Prefs.networkDetailsWidth, bogusValue, |
|
52 "The pref wasn't updated correctly in the preferences object."); |
|
53 |
|
54 Prefs.networkDetailsWidth = previousValue; |
|
55 is(Prefs.networkDetailsWidth, |
|
56 Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), |
|
57 "Getting a pref after it has been modified again should work correctly."); |
|
58 is(Prefs.networkDetailsWidth, previousValue, |
|
59 "The pref wasn't updated correctly again in the preferences object."); |
|
60 } |
|
61 |
|
62 testL10N(); |
|
63 testPrefs(); |
|
64 |
|
65 teardown(aMonitor).then(finish); |
|
66 }); |
|
67 } |