Bug 1894911 - Resolve ESLint warnings about no-case-declarations in toolkit/components/places. r=dao,places-reviewers

Differential Revision: https://phabricator.services.mozilla.com/D211208
This commit is contained in:
Moritz Beier 2024-05-23 11:52:29 +00:00
parent 0e9f98bc02
commit f78a5220cc
8 changed files with 32 additions and 16 deletions

View file

@ -405,7 +405,7 @@ function translateTreeTypes(node) {
}
switch (node.type) {
case PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER:
case PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER: {
node.type = PlacesUtils.bookmarks.TYPE_FOLDER;
// Older type mobile folders have a random guid with an annotation. We need
@ -424,6 +424,7 @@ function translateTreeTypes(node) {
// queries later.
folderIdToGuidMap[node.id] = node.guid;
break;
}
case PlacesUtils.TYPE_X_MOZ_PLACE:
node.type = PlacesUtils.bookmarks.TYPE_BOOKMARK;
break;

View file

@ -1379,7 +1379,7 @@ export function PlacesDBUtilsIdleMaintenance() {}
PlacesDBUtilsIdleMaintenance.prototype = {
observe(subject, topic) {
switch (topic) {
case "idle-daily":
case "idle-daily": {
// Once a week run places.sqlite maintenance tasks.
let lastMaintenance = Services.prefs.getIntPref(
"places.database.lastMaintenance",
@ -1390,6 +1390,7 @@ PlacesDBUtilsIdleMaintenance.prototype = {
PlacesDBUtils.maintenanceOnIdle();
}
break;
}
default:
throw new Error("Trying to handle an unknown category.");
}

View file

@ -272,11 +272,12 @@ export class PlacesQuery {
switch (this.cachedHistoryOptions.sortBy) {
case "date":
return this.getStartOfDayTimestamp(visit.date);
case "site":
case "site": {
const { protocol } = new URL(visit.url);
return protocol === "http:" || protocol === "https:"
? lazy.BrowserUtils.formatURIStringForDisplay(visit.url)
: "";
}
}
return null;
}

View file

@ -1618,7 +1618,7 @@ export var PlacesUtils = {
}
switch (type) {
case PlacesUtils.bookmarks.TYPE_BOOKMARK:
case PlacesUtils.bookmarks.TYPE_BOOKMARK: {
item.type = PlacesUtils.TYPE_X_MOZ_PLACE;
// If this throws due to an invalid url, the item will be skipped.
try {
@ -1635,6 +1635,7 @@ export var PlacesUtils = {
item.postData = entry.postData;
}
break;
}
case PlacesUtils.bookmarks.TYPE_FOLDER:
item.type = PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER;
// Mark root folders.
@ -1840,11 +1841,12 @@ export var PlacesUtils = {
data = new TextEncoder().encode(data);
hasher.update(data, data.length);
switch (format) {
case "hex":
case "hex": {
let hash = hasher.finish(false);
return Array.from(hash, (c, i) =>
hash.charCodeAt(i).toString(16).padStart(2, "0")
).join("");
}
case "base64":
default:
return hasher.finish(true);
@ -1874,11 +1876,12 @@ export var PlacesUtils = {
hasher.update(data, data.length);
}
switch (format) {
case "hex":
case "hex": {
let hash = hasher.finish(false);
return Array.from(hash, (c, i) =>
hash.charCodeAt(i).toString(16).padStart(2, "0")
).join("");
}
case "base64url":
return hasher.finish(true).replaceAll("+", "-").replaceAll("/", "_");
case "base64":

View file

@ -13,7 +13,7 @@ var bookmarksObserver = {
Assert.equal(events.length, 1);
let event = events[0];
switch (event.type) {
case "bookmark-added":
case "bookmark-added": {
bookmarksObserver._itemAddedId = event.id;
bookmarksObserver._itemAddedParent = event.parentId;
bookmarksObserver._itemAddedIndex = event.index;
@ -35,6 +35,7 @@ var bookmarksObserver = {
Assert.equal(stmt.row.guid, event.guid);
stmt.finalize();
break;
}
case "bookmark-removed":
bookmarksObserver._itemRemovedId = event.id;
bookmarksObserver._itemRemovedFolder = event.parentId;

View file

@ -366,13 +366,14 @@ function checkItem(aExpected, aNode) {
case "url":
Assert.equal(aNode.uri, aExpected.url);
break;
case "icon":
case "icon": {
let { data } = await getFaviconDataForPage(aExpected.url);
let base64Icon =
"data:image/png;base64," +
base64EncodeString(String.fromCharCode.apply(String, data));
Assert.ok(base64Icon == aExpected.icon);
break;
}
case "keyword": {
let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
Assert.equal(entry.keyword, aExpected.keyword);
@ -383,7 +384,7 @@ function checkItem(aExpected, aNode) {
Assert.equal(entry.postData, aExpected.postData);
break;
}
case "charset":
case "charset": {
let pageInfo = await PlacesUtils.history.fetch(aNode.uri, {
includeAnnotations: true,
});
@ -392,10 +393,11 @@ function checkItem(aExpected, aNode) {
aExpected.charset
);
break;
}
case "feedUrl":
// No more supported.
break;
case "children":
case "children": {
let folder = aNode.QueryInterface(
Ci.nsINavHistoryContainerResultNode
);
@ -409,6 +411,7 @@ function checkItem(aExpected, aNode) {
folder.containerOpen = false;
break;
}
default:
throw new Error("Unknown property");
}

View file

@ -312,13 +312,14 @@ async function checkItem(aExpected, aNode) {
case "url":
Assert.equal(aNode.uri, aExpected.url);
break;
case "icon":
case "icon": {
let { data } = await getFaviconDataForPage(aExpected.url);
let base64Icon =
"data:image/png;base64," +
base64EncodeString(String.fromCharCode.apply(String, data));
Assert.equal(base64Icon, aExpected.icon);
break;
}
case "keyword": {
let entry = await PlacesUtils.keywords.fetch({ url: aNode.uri });
Assert.equal(entry.keyword, aExpected.keyword);
@ -332,7 +333,7 @@ async function checkItem(aExpected, aNode) {
Assert.equal(entry.postData, aExpected.postData);
break;
}
case "charset":
case "charset": {
let pageInfo = await PlacesUtils.history.fetch(aNode.uri, {
includeAnnotations: true,
});
@ -341,7 +342,8 @@ async function checkItem(aExpected, aNode) {
aExpected.charset
);
break;
case "children":
}
case "children": {
let folder = aNode.QueryInterface(Ci.nsINavHistoryContainerResultNode);
Assert.equal(folder.hasChildren, !!aExpected.children.length);
folder.containerOpen = true;
@ -353,7 +355,8 @@ async function checkItem(aExpected, aNode) {
folder.containerOpen = false;
break;
case "tags":
}
case "tags": {
let uri = Services.io.newURI(aNode.uri);
Assert.deepEqual(
PlacesUtils.tagging.getTagsForURI(uri),
@ -361,6 +364,7 @@ async function checkItem(aExpected, aNode) {
"should have the expected tags"
);
break;
}
default:
throw new Error("Unknown property");
}

View file

@ -55,7 +55,7 @@ async function compareToNode(aItem, aNode, aIsRootItem, aExcludedGuids = []) {
let nodesCount = 1;
switch (aNode.type) {
case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER:
case Ci.nsINavHistoryResultNode.RESULT_TYPE_FOLDER: {
Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE_CONTAINER);
Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_FOLDER);
compare_prop("title", "title", true);
@ -101,12 +101,13 @@ async function compareToNode(aItem, aNode, aIsRootItem, aExcludedGuids = []) {
check_unset("root");
}
break;
}
case Ci.nsINavHistoryResultNode.RESULT_TYPE_SEPARATOR:
Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE_SEPARATOR);
Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_SEPARATOR);
check_unset(...BOOKMARK_ONLY_PROPS, ...FOLDER_ONLY_PROPS);
break;
default:
default: {
Assert.equal(aItem.type, PlacesUtils.TYPE_X_MOZ_PLACE);
Assert.equal(aItem.typeCode, PlacesUtils.bookmarks.TYPE_BOOKMARK);
compare_prop("uri");
@ -152,6 +153,7 @@ async function compareToNode(aItem, aNode, aIsRootItem, aExcludedGuids = []) {
} else {
Assert.equal(null, aNode.title);
}
}
}
if (aIsRootItem) {