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