Skip to content

Commit

Permalink
Bug 1461997 - Enable ESLint rule mozilla/require-expected-throws-or-r…
Browse files Browse the repository at this point in the history
…ejects for browser/components. r=Gijs

MozReview-Commit-ID: JXqwIyF6v6k
  • Loading branch information
Standard8 committed May 16, 2018
1 parent 0b47300 commit 49ee521
Show file tree
Hide file tree
Showing 10 changed files with 34 additions and 19 deletions.
1 change: 0 additions & 1 deletion .eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@ module.exports = {
// XXX Bug 1452706. These directories are still being fixed, so turn off
// mozilla/require-expected-throws-or-rejects for now.
"files": [
"browser/components/**",
"browser/extensions/formautofill/test/unit/test_storage_tombstones.js",
"browser/modules/test/browser/**",
"browser/tools/mozscreenshots/browser_boundingbox.js",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -201,7 +201,7 @@ add_task(async function testSecureManifestURLsDenied() {
});

await Assert.rejects(extension.startup(),
null,
/startup failed/,
"Manifest rejected");

SimpleTest.endMonitorConsole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -236,7 +236,7 @@ add_task(async function testPageActionSecurity() {
});

await Assert.rejects(extension.startup(),
null,
/startup failed/,
"Manifest rejected");

SimpleTest.endMonitorConsole();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ async function testThemeWithInvalidProperties(invalidProps) {
});

let extension = ExtensionTestUtils.loadExtension({manifest});
await Assert.rejects(extension.startup(), null, "Theme should fail to load if it contains invalid properties");
await Assert.rejects(extension.startup(),
/startup failed/,
"Theme should fail to load if it contains invalid properties");
}

add_task(async function test_that_theme_with_invalid_properties_fails_to_load() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -298,6 +298,7 @@ function makeURI(aURL) {
add_task(async function setup() {
if (AppConstants.isPlatformAndVersionAtLeast("win", "6.2")) {
Assert.throws(() => getFirstResourceOfType(MigrationUtils.resourceTypes.PASSWORDS),
/failed to find/,
"The migrator doesn't exist for win8+");
return;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -52,8 +52,10 @@ add_task(async function test_checkPreferences() {
// Ensure preferences status.
Assert.ok(!Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));

Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
Assert.throws(() => Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML),
/NS_ERROR_UNEXPECTED/);
Assert.throws(() => Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS),
/NS_ERROR_UNEXPECTED/);
});

add_task(async function test_import() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,8 @@ add_task(async function setup() {
// Ensure preferences status.
Assert.ok(!Services.prefs.getBoolPref(PREF_AUTO_EXPORT_HTML));
Assert.ok(!Services.prefs.getBoolPref(PREF_RESTORE_DEFAULT_BOOKMARKS));
Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML));
Assert.throws(() => Services.prefs.getBoolPref(PREF_IMPORT_BOOKMARKS_HTML),
/NS_ERROR_UNEXPECTED/);
});

add_task(async function test_version_0() {
Expand Down
2 changes: 2 additions & 0 deletions browser/components/sessionstore/test/browser_dying_cache.js
Original file line number Diff line number Diff line change
Expand Up @@ -37,8 +37,10 @@ add_task(async function test() {

// Make sure we're not allowed to modify state data.
Assert.throws(() => ss.setWindowState(win, {}),
/Window is not tracked/,
"we're not allowed to modify state data anymore");
Assert.throws(() => ss.setWindowValue(win, "foo", "baz"),
/Window is not tracked/,
"we're not allowed to modify state data anymore");
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,11 +88,11 @@ add_task(async function testIntervalChanges() {
SessionSaver.runDelayed(0);

// We expect `p1` hits the timeout.
await Assert.rejects(p1, null, "[Test 1A] No state write during idle.");
await Assert.rejects(p1, /Save state timeout/, "[Test 1A] No state write during idle.");

// Test again for better reliability. Same, we expect following promise hits
// the timeout.
await Assert.rejects(promiseSaveState(), null, "[Test 1B] Again: No state write during idle.");
await Assert.rejects(promiseSaveState(), /Save state timeout/, "[Test 1B] Again: No state write during idle.");

// Back to the active mode.
info("Start to test active mode...");
Expand All @@ -101,4 +101,3 @@ add_task(async function testIntervalChanges() {
info("[Test 2] Waiting for sessionstore-state-write-complete during active");
await TestUtils.topicObserved("sessionstore-state-write-complete");
});

27 changes: 18 additions & 9 deletions browser/components/tests/unit/test_distribution.js
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,24 @@ add_task(async function() {
Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.true"), true);
Assert.equal(defaultBranch.getBoolPref("distribution.test.bool.false"), false);

Assert.throws(() => defaultBranch.getCharPref("distribution.test.empty"));
Assert.throws(() => defaultBranch.getIntPref("distribution.test.empty"));
Assert.throws(() => defaultBranch.getBoolPref("distribution.test.empty"));
Assert.throws(() => defaultBranch.getCharPref("distribution.test.empty"),
/NS_ERROR_UNEXPECTED/);
Assert.throws(() => defaultBranch.getIntPref("distribution.test.empty"),
/NS_ERROR_UNEXPECTED/);
Assert.throws(() => defaultBranch.getBoolPref("distribution.test.empty"),
/NS_ERROR_UNEXPECTED/);

Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale"), "en-US");
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.en"), "en");
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.en-US"), "en-US");
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.de"));
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.de"),
/NS_ERROR_UNEXPECTED/);
// This value was never set because of the empty language specific pref
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.reset"));
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.language.reset"),
/NS_ERROR_UNEXPECTED/);
// This value was never set because of the empty locale specific pref
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.locale.reset"));
Assert.throws(() => defaultBranch.getCharPref("distribution.test.pref.locale.reset"),
/NS_ERROR_UNEXPECTED/);
// This value was overridden by a locale specific setting
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Locale Set");
// This value was overridden by a language specific setting
Expand All @@ -126,11 +132,14 @@ add_task(async function() {
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale", Ci.nsIPrefLocalizedString).data, "en-US");
Assert.equal(defaultBranch.getComplexValue("distribution.test.language.en", Ci.nsIPrefLocalizedString).data, "en");
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.en-US", Ci.nsIPrefLocalizedString).data, "en-US");
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString));
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.de", Ci.nsIPrefLocalizedString),
/NS_ERROR_UNEXPECTED/);
// This value was never set because of the empty language specific pref
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString));
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.language.reset", Ci.nsIPrefLocalizedString),
/NS_ERROR_UNEXPECTED/);
// This value was never set because of the empty locale specific pref
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.locale.reset", Ci.nsIPrefLocalizedString));
Assert.throws(() => defaultBranch.getComplexValue("distribution.test.locale.reset", Ci.nsIPrefLocalizedString),
/NS_ERROR_UNEXPECTED/);
// This value was overridden by a locale specific setting
Assert.equal(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Locale Set");
// This value was overridden by a language specific setting
Expand Down

0 comments on commit 49ee521

Please sign in to comment.