зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1406594 - Fix history.search and history.getVisited so that they find hidden items correctly. r=aswan,bsilverberg
I had to add a mochitest because PlacesUtils.history.insertMany cannot create hidden redirects. I also added a support for the "reload" transition while I am here. MozReview-Commit-ID: ECQp6pW2r8v --HG-- extra : rebase_source : d4456d32a57cdadec8ca383a2b09dee29e20b10f
This commit is contained in:
Родитель
982e6cfc6f
Коммит
cac8494c04
|
@ -21,6 +21,7 @@ const TRANSITION_TO_TRANSITION_TYPES_MAP = new Map([
|
|||
["auto_bookmark", nsINavHistoryService.TRANSITION_BOOKMARK],
|
||||
["auto_subframe", nsINavHistoryService.TRANSITION_EMBED],
|
||||
["manual_subframe", nsINavHistoryService.TRANSITION_FRAMED_LINK],
|
||||
["reload", nsINavHistoryService.TRANSITION_RELOAD],
|
||||
]);
|
||||
|
||||
let TRANSITION_TYPE_TO_TRANSITIONS_MAP = new Map();
|
||||
|
@ -189,6 +190,7 @@ this.history = class extends ExtensionAPI {
|
|||
}
|
||||
|
||||
let options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.includeHidden = true;
|
||||
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
||||
options.maxResults = query.maxResults || 100;
|
||||
|
||||
|
@ -208,6 +210,7 @@ this.history = class extends ExtensionAPI {
|
|||
}
|
||||
|
||||
let options = PlacesUtils.history.getNewQueryOptions();
|
||||
options.includeHidden = true;
|
||||
options.sortingMode = options.SORT_BY_DATE_DESCENDING;
|
||||
options.resultType = options.RESULTS_AS_VISIT;
|
||||
|
||||
|
|
|
@ -0,0 +1,10 @@
|
|||
"use strict";
|
||||
|
||||
module.exports = {
|
||||
"extends": "plugin:mozilla/mochitest-test",
|
||||
|
||||
"env": {
|
||||
"browser": true,
|
||||
"webextensions": true,
|
||||
},
|
||||
};
|
|
@ -2,6 +2,8 @@
|
|||
support-files =
|
||||
../../../../../toolkit/components/extensions/test/mochitest/test_ext_all_apis.js
|
||||
../../../../../toolkit/components/extensions/test/mochitest/file_sample.html
|
||||
../../../../../toolkit/components/extensions/test/mochitest/redirection.sjs
|
||||
tags = webextensions
|
||||
|
||||
[test_ext_all_apis.html]
|
||||
[test_ext_history_redirect.html]
|
||||
|
|
|
@ -0,0 +1,87 @@
|
|||
<!DOCTYPE HTML>
|
||||
<html>
|
||||
<head>
|
||||
<title>Test for simple WebExtension</title>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SimpleTest.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/SpawnTask.js"></script>
|
||||
<script type="text/javascript" src="/tests/SimpleTest/ExtensionTestUtils.js"></script>
|
||||
<link rel="stylesheet" type="text/css" href="/tests/SimpleTest/test.css"/>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
<script type="text/javascript">
|
||||
"use strict";
|
||||
|
||||
const REDIRECT_URL = new URL("redirection.sjs", location).href;
|
||||
|
||||
function waitForLoad(win) {
|
||||
return new Promise(resolve => {
|
||||
win.addEventListener("load", function() {
|
||||
resolve();
|
||||
}, {capture: true, once: true});
|
||||
});
|
||||
}
|
||||
|
||||
add_task(async function history_redirect() {
|
||||
function background() {
|
||||
browser.test.onMessage.addListener(async (msg, url) => {
|
||||
switch (msg) {
|
||||
case "delete-all": {
|
||||
let results = await browser.history.deleteAll();
|
||||
browser.test.sendMessage("delete-all-result", results);
|
||||
break;
|
||||
}
|
||||
case "search": {
|
||||
let results = await browser.history.search({text: url, startTime: new Date(0)});
|
||||
browser.test.sendMessage("search-result", results);
|
||||
break;
|
||||
}
|
||||
case "get-visits": {
|
||||
let results = await browser.history.getVisits({url});
|
||||
browser.test.sendMessage("get-visits-result", results);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
browser.test.sendMessage("ready");
|
||||
}
|
||||
|
||||
let extensionData = {
|
||||
manifest: {
|
||||
permissions: [
|
||||
"history",
|
||||
],
|
||||
},
|
||||
background,
|
||||
};
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension(extensionData);
|
||||
|
||||
await Promise.all([extension.startup(), extension.awaitMessage("ready")]);
|
||||
info("extension loaded");
|
||||
|
||||
extension.sendMessage("delete-all");
|
||||
await extension.awaitMessage("delete-all-result");
|
||||
|
||||
let win = window.open(REDIRECT_URL);
|
||||
await waitForLoad(win);
|
||||
|
||||
extension.sendMessage("search", REDIRECT_URL);
|
||||
let results = await extension.awaitMessage("search-result");
|
||||
is(results.length, 1, "search returned expected length of results");
|
||||
|
||||
extension.sendMessage("get-visits", REDIRECT_URL);
|
||||
let visits = await extension.awaitMessage("get-visits-result");
|
||||
is(visits.length, 1, "getVisits returned expected length of visits");
|
||||
|
||||
// cleanup phase
|
||||
win.close();
|
||||
|
||||
await extension.unload();
|
||||
info("extension unloaded");
|
||||
});
|
||||
</script>
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -404,6 +404,83 @@ add_task(async function test_get_visits() {
|
|||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_transition_types() {
|
||||
const VISIT_URL_PREFIX = "http://example.com/";
|
||||
const TRANSITIONS = [
|
||||
["link", Ci.nsINavHistoryService.TRANSITION_LINK],
|
||||
["typed", Ci.nsINavHistoryService.TRANSITION_TYPED],
|
||||
["auto_bookmark", Ci.nsINavHistoryService.TRANSITION_BOOKMARK],
|
||||
// Only session history contains TRANSITION_EMBED visits,
|
||||
// So global history query cannot find them.
|
||||
// ["auto_subframe", Ci.nsINavHistoryService.TRANSITION_EMBED],
|
||||
// Redirects are not correctly tested here because History::UpdatePlaces
|
||||
// will not make redirect entries hidden.
|
||||
["link", Ci.nsINavHistoryService.TRANSITION_REDIRECT_PERMANENT],
|
||||
["link", Ci.nsINavHistoryService.TRANSITION_REDIRECT_TEMPORARY],
|
||||
["link", Ci.nsINavHistoryService.TRANSITION_DOWNLOAD],
|
||||
["manual_subframe", Ci.nsINavHistoryService.TRANSITION_FRAMED_LINK],
|
||||
["reload", Ci.nsINavHistoryService.TRANSITION_RELOAD],
|
||||
];
|
||||
|
||||
// pages/visits to add via History.insertMany
|
||||
let pageInfos = [];
|
||||
let visitDate = new Date(1999, 9, 9, 9, 9).getTime();
|
||||
for (let [, transitionType] of TRANSITIONS) {
|
||||
pageInfos.push({
|
||||
url: VISIT_URL_PREFIX + transitionType + "/",
|
||||
visits: [
|
||||
{transition: transitionType, date: new Date(visitDate -= 1000)},
|
||||
],
|
||||
});
|
||||
}
|
||||
|
||||
function background() {
|
||||
browser.test.onMessage.addListener(async (msg, url) => {
|
||||
switch (msg) {
|
||||
case "search": {
|
||||
let results = await browser.history.search({text: "", startTime: new Date(0)});
|
||||
browser.test.sendMessage("search-result", results);
|
||||
break;
|
||||
}
|
||||
case "get-visits": {
|
||||
let results = await browser.history.getVisits({url});
|
||||
browser.test.sendMessage("get-visits-result", results);
|
||||
break;
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
browser.test.sendMessage("ready");
|
||||
}
|
||||
|
||||
let extension = ExtensionTestUtils.loadExtension({
|
||||
manifest: {
|
||||
permissions: ["history"],
|
||||
},
|
||||
background,
|
||||
});
|
||||
|
||||
await PlacesTestUtils.clearHistory();
|
||||
await extension.startup();
|
||||
await extension.awaitMessage("ready");
|
||||
|
||||
await PlacesUtils.history.insertMany(pageInfos);
|
||||
|
||||
extension.sendMessage("search");
|
||||
let results = await extension.awaitMessage("search-result");
|
||||
equal(results.length, pageInfos.length, "search returned expected length of results");
|
||||
for (let i = 0; i < pageInfos.length; ++i) {
|
||||
equal(results[i].url, pageInfos[i].url, "search returned the expected url");
|
||||
|
||||
extension.sendMessage("get-visits", pageInfos[i].url);
|
||||
let visits = await extension.awaitMessage("get-visits-result");
|
||||
equal(visits.length, 1, "getVisits returned expected length of visits");
|
||||
equal(visits[0].transition, TRANSITIONS[i][0], "getVisits returned the expected transition");
|
||||
}
|
||||
|
||||
await extension.unload();
|
||||
});
|
||||
|
||||
add_task(async function test_on_visited() {
|
||||
const SINGLE_VISIT_URL = "http://example.com/1/";
|
||||
const DOUBLE_VISIT_URL = "http://example.com/2/";
|
||||
|
|
Загрузка…
Ссылка в новой задаче