1.1 --- /dev/null Thu Jan 01 00:00:00 1970 +0000 1.2 +++ b/browser/devtools/netmonitor/test/browser_net_prefs-and-l10n.js Wed Dec 31 06:09:35 2014 +0100 1.3 @@ -0,0 +1,67 @@ 1.4 +/* Any copyright is dedicated to the Public Domain. 1.5 + http://creativecommons.org/publicdomain/zero/1.0/ */ 1.6 + 1.7 +/** 1.8 + * Tests if the preferences and localization objects work correctly. 1.9 + */ 1.10 + 1.11 +function test() { 1.12 + initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { 1.13 + info("Starting test... "); 1.14 + 1.15 + ok(aMonitor.panelWin.L10N, 1.16 + "Should have a localization object available on the panel window."); 1.17 + ok(aMonitor.panelWin.Prefs, 1.18 + "Should have a preferences object available on the panel window."); 1.19 + 1.20 + function testL10N() { 1.21 + let { L10N } = aMonitor.panelWin; 1.22 + 1.23 + ok(L10N.stringBundle, 1.24 + "The localization object should have a string bundle available."); 1.25 + 1.26 + let bundleName = "chrome://browser/locale/devtools/netmonitor.properties"; 1.27 + let stringBundle = Services.strings.createBundle(bundleName); 1.28 + 1.29 + is(L10N.getStr("netmonitor.label"), 1.30 + stringBundle.GetStringFromName("netmonitor.label"), 1.31 + "The getStr() method didn't return the expected string."); 1.32 + 1.33 + is(L10N.getFormatStr("networkMenu.totalMS", "foo"), 1.34 + stringBundle.formatStringFromName("networkMenu.totalMS", ["foo"], 1), 1.35 + "The getFormatStr() method didn't return the expected string."); 1.36 + } 1.37 + 1.38 + function testPrefs() { 1.39 + let { Prefs } = aMonitor.panelWin; 1.40 + 1.41 + is(Prefs.root, "devtools.netmonitor", 1.42 + "The preferences object should have a correct root path."); 1.43 + 1.44 + is(Prefs.networkDetailsWidth, 1.45 + Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), 1.46 + "Getting a pref should work correctly."); 1.47 + 1.48 + let previousValue = Prefs.networkDetailsWidth; 1.49 + let bogusValue = ~~(Math.random() * 100); 1.50 + Prefs.networkDetailsWidth = bogusValue; 1.51 + is(Prefs.networkDetailsWidth, 1.52 + Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), 1.53 + "Getting a pref after it has been modified should work correctly."); 1.54 + is(Prefs.networkDetailsWidth, bogusValue, 1.55 + "The pref wasn't updated correctly in the preferences object."); 1.56 + 1.57 + Prefs.networkDetailsWidth = previousValue; 1.58 + is(Prefs.networkDetailsWidth, 1.59 + Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), 1.60 + "Getting a pref after it has been modified again should work correctly."); 1.61 + is(Prefs.networkDetailsWidth, previousValue, 1.62 + "The pref wasn't updated correctly again in the preferences object."); 1.63 + } 1.64 + 1.65 + testL10N(); 1.66 + testPrefs(); 1.67 + 1.68 + teardown(aMonitor).then(finish); 1.69 + }); 1.70 +}