Skip to content
This repository has been archived by the owner on Aug 4, 2022. It is now read-only.

Commit

Permalink
Bug 1329013 - Enable no-lone-blocks rule for eslint and remove the se…
Browse files Browse the repository at this point in the history
…ven unnecessary blocks that it found. r=mossop

MozReview-Commit-ID: 9DJGO4en378
  • Loading branch information
msujaws committed Jan 5, 2017
1 parent 67616b7 commit 33512ad
Show file tree
Hide file tree
Showing 4 changed files with 200 additions and 211 deletions.
3 changes: 3 additions & 0 deletions toolkit/.eslintrc.js
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,9 @@ module.exports = {
// No labels
"no-labels": "error",

// Disallow unnecessary nested blocks
"no-lone-blocks": "error",

// If an if block ends with a return no need for an else block
"no-else-return": "error",

Expand Down
120 changes: 57 additions & 63 deletions toolkit/components/contentprefs/tests/unit/test_stringGroups.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,85 +17,79 @@ function run_test() {
var stringURI = "www.example.com"; // typeof = "string"
var stringObjectURI = new String("www.example.com"); // typeof = "object"

{
// First check that all the methods work or don't work.
function simple_test_methods(aGroup, shouldThrow) {
var prefName = "test.pref.0";
var prefValue = Math.floor(Math.random() * 100);

if (shouldThrow) {
do_check_thrown(function() { cps.getPref(aGroup, prefName); });
do_check_thrown(function() { cps.setPref(aGroup, prefName, prefValue); });
do_check_thrown(function() { cps.hasPref(aGroup, prefName); });
do_check_thrown(function() { cps.removePref(aGroup, prefName); });
do_check_thrown(function() { cps.getPrefs(aGroup); });
} else {
do_check_eq(cps.setPref(aGroup, prefName, prefValue), undefined);
do_check_true(cps.hasPref(aGroup, prefName));
do_check_eq(cps.getPref(aGroup, prefName), prefValue);
do_check_eq(cps.removePref(aGroup, prefName), undefined);
do_check_false(cps.hasPref(aGroup, prefName));
}
// First check that all the methods work or don't work.
function simple_test_methods(aGroup, shouldThrow) {
var prefName = "test.pref.0";
var prefValue = Math.floor(Math.random() * 100);

if (shouldThrow) {
do_check_thrown(function() { cps.getPref(aGroup, prefName); });
do_check_thrown(function() { cps.setPref(aGroup, prefName, prefValue); });
do_check_thrown(function() { cps.hasPref(aGroup, prefName); });
do_check_thrown(function() { cps.removePref(aGroup, prefName); });
do_check_thrown(function() { cps.getPrefs(aGroup); });
} else {
do_check_eq(cps.setPref(aGroup, prefName, prefValue), undefined);
do_check_true(cps.hasPref(aGroup, prefName));
do_check_eq(cps.getPref(aGroup, prefName), prefValue);
do_check_eq(cps.removePref(aGroup, prefName), undefined);
do_check_false(cps.hasPref(aGroup, prefName));
}

simple_test_methods(cps, true); // arbitrary nsISupports object, should throw too
simple_test_methods(anObject, true);
simple_test_methods(uri, false);
simple_test_methods(stringURI, false);
simple_test_methods(stringObjectURI, false);
}

{
// Now we'll check that each argument produces the same result.
function complex_test_methods(aGroup) {
var prefName = "test.pref.1";
var prefValue = Math.floor(Math.random() * 100);
simple_test_methods(cps, true); // arbitrary nsISupports object, should throw too
simple_test_methods(anObject, true);
simple_test_methods(uri, false);
simple_test_methods(stringURI, false);
simple_test_methods(stringObjectURI, false);

do_check_eq(cps.setPref(aGroup, prefName, prefValue), undefined);
// Now we'll check that each argument produces the same result.
function complex_test_methods(aGroup) {
var prefName = "test.pref.1";
var prefValue = Math.floor(Math.random() * 100);

do_check_true(cps.hasPref(uri, prefName));
do_check_true(cps.hasPref(stringURI, prefName));
do_check_true(cps.hasPref(stringObjectURI, prefName));
do_check_eq(cps.setPref(aGroup, prefName, prefValue), undefined);

do_check_eq(cps.getPref(uri, prefName), prefValue);
do_check_eq(cps.getPref(stringURI, prefName), prefValue);
do_check_eq(cps.getPref(stringObjectURI, prefName), prefValue);
do_check_true(cps.hasPref(uri, prefName));
do_check_true(cps.hasPref(stringURI, prefName));
do_check_true(cps.hasPref(stringObjectURI, prefName));

do_check_eq(cps.removePref(aGroup, prefName), undefined);
do_check_eq(cps.getPref(uri, prefName), prefValue);
do_check_eq(cps.getPref(stringURI, prefName), prefValue);
do_check_eq(cps.getPref(stringObjectURI, prefName), prefValue);

do_check_false(cps.hasPref(uri, prefName));
do_check_false(cps.hasPref(stringURI, prefName));
do_check_false(cps.hasPref(stringObjectURI, prefName));
}
do_check_eq(cps.removePref(aGroup, prefName), undefined);

complex_test_methods(uri);
complex_test_methods(stringURI);
complex_test_methods(stringObjectURI);
do_check_false(cps.hasPref(uri, prefName));
do_check_false(cps.hasPref(stringURI, prefName));
do_check_false(cps.hasPref(stringObjectURI, prefName));
}

{
// test getPrefs returns the same prefs
do_check_eq(cps.setPref(stringObjectURI, "test.5", 5), undefined);
do_check_eq(cps.setPref(stringURI, "test.2", 2), undefined);
do_check_eq(cps.setPref(uri, "test.1", 1), undefined);
complex_test_methods(uri);
complex_test_methods(stringURI);
complex_test_methods(stringObjectURI);

enumerateAndCheck(cps.getPrefs(uri), 8, ["test.1", "test.2", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 8, ["test.1", "test.2", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 8, ["test.1", "test.2", "test.5"]);
// test getPrefs returns the same prefs
do_check_eq(cps.setPref(stringObjectURI, "test.5", 5), undefined);
do_check_eq(cps.setPref(stringURI, "test.2", 2), undefined);
do_check_eq(cps.setPref(uri, "test.1", 1), undefined);

do_check_eq(cps.setPref(uri, "test.4", 4), undefined);
do_check_eq(cps.setPref(stringObjectURI, "test.0", 0), undefined);
enumerateAndCheck(cps.getPrefs(uri), 8, ["test.1", "test.2", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 8, ["test.1", "test.2", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 8, ["test.1", "test.2", "test.5"]);

enumerateAndCheck(cps.getPrefs(uri), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);
do_check_eq(cps.setPref(uri, "test.4", 4), undefined);
do_check_eq(cps.setPref(stringObjectURI, "test.0", 0), undefined);

do_check_eq(cps.setPref(stringURI, "test.3", 3), undefined);
enumerateAndCheck(cps.getPrefs(uri), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 12, ["test.0", "test.1", "test.2", "test.4", "test.5"]);

enumerateAndCheck(cps.getPrefs(uri), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
}
do_check_eq(cps.setPref(stringURI, "test.3", 3), undefined);

enumerateAndCheck(cps.getPrefs(uri), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringURI), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
enumerateAndCheck(cps.getPrefs(stringObjectURI), 15, ["test.0", "test.1", "test.2", "test.3", "test.4", "test.5"]);
}

function do_check_thrown(aCallback) {
Expand Down
44 changes: 19 additions & 25 deletions toolkit/components/places/tests/unit/test_sync_utils.js
Original file line number Diff line number Diff line change
Expand Up @@ -1219,24 +1219,20 @@ add_task(function* test_insert_tag_query() {
}

do_print("Use the public tagging API to ensure we added the tag correctly");
{
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "https://mozilla.org",
title: "Mozilla",
});
PlacesUtils.tagging.tagURI(uri("https://mozilla.org"), ["taggy"]);
assertURLHasTags("https://mozilla.org/", ["taggy"],
"Should set tags using the tagging API");
}
yield PlacesUtils.bookmarks.insert({
parentGuid: PlacesUtils.bookmarks.menuGuid,
type: PlacesUtils.bookmarks.TYPE_BOOKMARK,
url: "https://mozilla.org",
title: "Mozilla",
});
PlacesUtils.tagging.tagURI(uri("https://mozilla.org"), ["taggy"]);
assertURLHasTags("https://mozilla.org/", ["taggy"],
"Should set tags using the tagging API");

do_print("Removing the tag should clean up the tag folder");
{
PlacesUtils.tagging.untagURI(uri("https://mozilla.org"), null);
deepEqual(PlacesUtils.tagging.allTags, [],
"Should remove tag folder once last item is untagged");
}
PlacesUtils.tagging.untagURI(uri("https://mozilla.org"), null);
deepEqual(PlacesUtils.tagging.allTags, [],
"Should remove tag folder once last item is untagged");

yield PlacesUtils.bookmarks.eraseEverything();
yield PlacesSyncUtils.bookmarks.reset();
Expand Down Expand Up @@ -1269,15 +1265,13 @@ add_task(function* test_insert_orphans() {
}

do_print("Insert the grandparent");
{
yield PlacesSyncUtils.bookmarks.insert({
kind: "folder",
parentSyncId: "menu",
syncId: grandParentGuid,
});
equal(PlacesUtils.annotations.getItemAnnotation(childId, SYNC_PARENT_ANNO),
parentGuid, "Child should still have orphan anno");
}
yield PlacesSyncUtils.bookmarks.insert({
kind: "folder",
parentSyncId: "menu",
syncId: grandParentGuid,
});
equal(PlacesUtils.annotations.getItemAnnotation(childId, SYNC_PARENT_ANNO),
parentGuid, "Child should still have orphan anno");

do_print("Insert the missing parent");
{
Expand Down
Loading

0 comments on commit 33512ad

Please sign in to comment.