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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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