michael@0: /* Any copyright is dedicated to the Public Domain. michael@0: http://creativecommons.org/publicdomain/zero/1.0/ */ michael@0: michael@0: /** michael@0: * Tests if the preferences and localization objects work correctly. michael@0: */ michael@0: michael@0: function test() { michael@0: initNetMonitor(SIMPLE_URL).then(([aTab, aDebuggee, aMonitor]) => { michael@0: info("Starting test... "); michael@0: michael@0: ok(aMonitor.panelWin.L10N, michael@0: "Should have a localization object available on the panel window."); michael@0: ok(aMonitor.panelWin.Prefs, michael@0: "Should have a preferences object available on the panel window."); michael@0: michael@0: function testL10N() { michael@0: let { L10N } = aMonitor.panelWin; michael@0: michael@0: ok(L10N.stringBundle, michael@0: "The localization object should have a string bundle available."); michael@0: michael@0: let bundleName = "chrome://browser/locale/devtools/netmonitor.properties"; michael@0: let stringBundle = Services.strings.createBundle(bundleName); michael@0: michael@0: is(L10N.getStr("netmonitor.label"), michael@0: stringBundle.GetStringFromName("netmonitor.label"), michael@0: "The getStr() method didn't return the expected string."); michael@0: michael@0: is(L10N.getFormatStr("networkMenu.totalMS", "foo"), michael@0: stringBundle.formatStringFromName("networkMenu.totalMS", ["foo"], 1), michael@0: "The getFormatStr() method didn't return the expected string."); michael@0: } michael@0: michael@0: function testPrefs() { michael@0: let { Prefs } = aMonitor.panelWin; michael@0: michael@0: is(Prefs.root, "devtools.netmonitor", michael@0: "The preferences object should have a correct root path."); michael@0: michael@0: is(Prefs.networkDetailsWidth, michael@0: Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), michael@0: "Getting a pref should work correctly."); michael@0: michael@0: let previousValue = Prefs.networkDetailsWidth; michael@0: let bogusValue = ~~(Math.random() * 100); michael@0: Prefs.networkDetailsWidth = bogusValue; michael@0: is(Prefs.networkDetailsWidth, michael@0: Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), michael@0: "Getting a pref after it has been modified should work correctly."); michael@0: is(Prefs.networkDetailsWidth, bogusValue, michael@0: "The pref wasn't updated correctly in the preferences object."); michael@0: michael@0: Prefs.networkDetailsWidth = previousValue; michael@0: is(Prefs.networkDetailsWidth, michael@0: Services.prefs.getIntPref("devtools.netmonitor.panes-network-details-width"), michael@0: "Getting a pref after it has been modified again should work correctly."); michael@0: is(Prefs.networkDetailsWidth, previousValue, michael@0: "The pref wasn't updated correctly again in the preferences object."); michael@0: } michael@0: michael@0: testL10N(); michael@0: testPrefs(); michael@0: michael@0: teardown(aMonitor).then(finish); michael@0: }); michael@0: }