Bug 1461997 - Enable ESLint rule mozilla/require-expected-throws-or-rejects for browser/components. r?Gijs
MozReview-Commit-ID: JXqwIyF6v6k
--- a/.eslintrc.js
+++ b/.eslintrc.js
@@ -47,17 +47,16 @@ module.exports = {
],
"rules": {
"mozilla/no-define-cc-etc": "off",
}
}, {
// 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",
"devtools/client/inspector/extensions/test/head_devtools_inspector_sidebar.js",
"services/**",
"storage/test/unit/**",
"testing/marionette/test/unit/**",
"toolkit/components/**",
--- a/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js
+++ b/browser/components/extensions/test/browser/browser_ext_browserAction_pageAction_icon_permissions.js
@@ -196,16 +196,16 @@ add_task(async function testSecureManife
manifest: {
[api]: {
"default_icon": url,
},
},
});
await Assert.rejects(extension.startup(),
- null,
+ /startup failed/,
"Manifest rejected");
SimpleTest.endMonitorConsole();
await waitForConsole;
}
}
});
--- a/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
+++ b/browser/components/extensions/test/browser/browser_ext_pageAction_popup.js
@@ -231,17 +231,17 @@ add_task(async function testPageActionSe
let extension = ExtensionTestUtils.loadExtension({
manifest: {
[api]: {"default_popup": URL},
},
});
await Assert.rejects(extension.startup(),
- null,
+ /startup failed/,
"Manifest rejected");
SimpleTest.endMonitorConsole();
await waitForConsole;
}
});
add_task(forceGC);
--- a/browser/components/extensions/test/browser/browser_ext_themes_validation.js
+++ b/browser/components/extensions/test/browser/browser_ext_themes_validation.js
@@ -28,17 +28,19 @@ async function testThemeWithInvalidPrope
manifest[prop] = {"keyword": "test"};
break;
default:
manifest[prop] = {};
}
});
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() {
let invalidProps = ["page_action", "browser_action", "background", "permissions", "omnibox", "commands"];
for (let prop in invalidProps) {
await testThemeWithInvalidProperties([prop]);
}
await testThemeWithInvalidProperties(invalidProps);
--- a/browser/components/migration/tests/unit/test_IE7_passwords.js
+++ b/browser/components/migration/tests/unit/test_IE7_passwords.js
@@ -293,16 +293,17 @@ function getFirstResourceOfType(type) {
function makeURI(aURL) {
return Services.io.newURI(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;
}
// create the path to Storage2 in the registry if it doest exist.
createRegistryPath(LOGINS_KEY);
Storage2Key = Cc["@mozilla.org/windows-registry-key;1"].
createInstance(nsIWindowsRegKey);
Storage2Key.open(nsIWindowsRegKey.ROOT_KEY_CURRENT_USER, LOGINS_KEY,
--- a/browser/components/places/tests/unit/test_browserGlue_prefs.js
+++ b/browser/components/places/tests/unit/test_browserGlue_prefs.js
@@ -47,18 +47,20 @@ add_task(async function test_checkPrefer
let promiseComplete = promiseTopicObserved("places-browser-init-complete");
Assert.equal(PlacesUtils.history.databaseStatus,
PlacesUtils.history.DATABASE_STATUS_CREATE);
await promiseComplete;
// 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() {
info("Import from bookmarks.html if importBookmarksHTML is true.");
await PlacesUtils.bookmarks.eraseEverything();
// Sanity check: we should not have any bookmark on the toolbar.
--- a/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js
+++ b/browser/components/places/tests/unit/test_browserGlue_smartBookmarks.js
@@ -44,17 +44,18 @@ add_task(async function setup() {
let promiseComplete = promiseTopicObserved("places-browser-init-complete");
Assert.equal(PlacesUtils.history.databaseStatus,
PlacesUtils.history.DATABASE_STATUS_CREATE);
await promiseComplete;
// 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() {
info("All smart bookmarks are created if smart bookmarks version is 0.");
// Sanity check: we should have default bookmark.
Assert.ok(await PlacesUtils.bookmarks.fetch({
parentGuid: PlacesUtils.bookmarks.toolbarGuid,
--- a/browser/components/sessionstore/test/browser_dying_cache.js
+++ b/browser/components/sessionstore/test/browser_dying_cache.js
@@ -32,18 +32,20 @@ add_task(async function test() {
// SessionStore should no longer track our window
// but it should still report the same state.
ok(!("__SSi" in win), "sessionstore does no longer track our window");
checkWindowState(win);
// 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");
});
function checkWindowState(window) {
let {windows: [{tabs}]} = JSON.parse(ss.getWindowState(window));
is(tabs.length, 1, "the window has a single tab");
is(tabs[0].entries[0].url, "about:mozilla", "the tab is about:mozilla");
--- a/browser/components/sessionstore/test/browser_not_collect_when_idle.js
+++ b/browser/components/sessionstore/test/browser_not_collect_when_idle.js
@@ -83,22 +83,21 @@ add_task(async function testIntervalChan
let p1 = promiseSaveState();
// Schedule a state write, which is expeced to be postponed after about
// `browser.sessionstore.interval.idle` ms, since the idle flag was just set.
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...");
idleService._fireObservers("active");
info("[Test 2] Waiting for sessionstore-state-write-complete during active");
await TestUtils.topicObserved("sessionstore-state-write-complete");
});
-
--- a/browser/components/tests/unit/test_distribution.js
+++ b/browser/components/tests/unit/test_distribution.js
@@ -99,43 +99,52 @@ add_task(async function() {
Assert.equal(defaultBranch.getStringPref("distribution.about"), "Tèƨƭ δïƨƭřïβúƭïôñ ƒïℓè");
Assert.equal(defaultBranch.getCharPref("distribution.test.string"), "Test String");
Assert.equal(defaultBranch.getCharPref("distribution.test.string.noquotes"), "Test String");
Assert.equal(defaultBranch.getIntPref("distribution.test.int"), 777);
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
Assert.equal(defaultBranch.getCharPref("distribution.test.pref.language.set"), "Language Set");
// Language should not override locale
Assert.notEqual(defaultBranch.getCharPref("distribution.test.pref.locale.set"), "Language Set");
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
Assert.equal(defaultBranch.getComplexValue("distribution.test.language.set", Ci.nsIPrefLocalizedString).data, "Language Set");
// Language should not override locale
Assert.notEqual(defaultBranch.getComplexValue("distribution.test.locale.set", Ci.nsIPrefLocalizedString).data, "Language Set");
do_test_pending();