Bug 1594786 - Part 2 - WebExt API: Add browser.experiments.app.openClearHistoryDialog call. r=mixedpuppy,adw,rpl

Differential Revision: https://phabricator.services.mozilla.com/D52842

--HG--
extra : moz-landing-system : lando
This commit is contained in:
Harry Twyford 2019-11-22 13:14:15 +00:00
Родитель 7d84bc7ec1
Коммит 6c48a9b98d
4 изменённых файлов: 109 добавлений и 0 удалений

Просмотреть файл

@ -13,6 +13,8 @@ XPCOMUtils.defineLazyModuleGetters(this, {
ProfileAge: "resource://gre/modules/ProfileAge.jsm",
Services: "resource://gre/modules/Services.jsm",
ResetProfile: "resource://gre/modules/ResetProfile.jsm",
PrivateBrowsingUtils: "resource://gre/modules/PrivateBrowsingUtils.jsm",
Sanitizer: "resource:///modules/Sanitizer.jsm",
});
XPCOMUtils.defineLazyServiceGetter(
@ -138,6 +140,16 @@ this.experiments_urlbar = class extends ExtensionAPI {
"browser.urlbar.openViewOnFocus"
),
openClearHistoryDialog() {
let window = BrowserWindowTracker.getTopWindow();
// The behaviour of the Clear Recent History dialog in PBM does
// not have the expected effect (bug 463607).
if (PrivateBrowsingUtils.isWindowPrivate(window)) {
return;
}
Sanitizer.showUI(window);
},
restartBrowser() {
// Notify all windows that an application quit has been requested.
let cancelQuit = Cc[

Просмотреть файл

@ -13,5 +13,6 @@ support-files =
[browser_ext_urlbar_isBrowserShowingNotification.js]
[browser_ext_urlbar_isBrowserUpdateReadyToInstall.js]
[browser_ext_urlbar_lastBrowserUpdateDate.js]
[browser_ext_urlbar_openClearHistoryDialog.js]
[browser_ext_urlbar_openViewOnFocus.js]
[browser_ext_urlbar_resetBrowser.js]

Просмотреть файл

@ -0,0 +1,88 @@
/* Any copyright is dedicated to the Public Domain.
* http://creativecommons.org/publicdomain/zero/1.0/ */
/* global browser */
// This tests the browser.experiments.urlbar.openClearHistoryDialog
// WebExtension Experiment API.
"use strict";
add_task(async function normalMode() {
await checkExtension();
});
add_task(async function privateBrowsingMode() {
const privateWindow = await BrowserTestUtils.openNewBrowserWindow({
private: true,
});
await checkExtension(/* isPrivate */ true);
await BrowserTestUtils.closeWindow(privateWindow);
});
async function checkExtension(isPrivate = false) {
let ext = await loadExtension(async () => {
browser.test.onMessage.addListener(async () => {
// Testing without user input. We expect the call to fail.
await browser.test.assertRejects(
browser.experiments.urlbar.openClearHistoryDialog(),
"experiments.urlbar.openClearHistoryDialog may only be called from a user input handler",
"browser.experiments.urlbar.openClearHistoryDialog should fail when called from outside a user input handler."
);
// Testing with user input.
browser.test.withHandlingUserInput(() => {
browser.experiments.urlbar.openClearHistoryDialog();
});
});
});
let dialogPromise = new Promise((resolve, reject) => {
function onOpen(subj, topic, data) {
if (topic == "domwindowopened" && subj instanceof Ci.nsIDOMWindow) {
subj.addEventListener(
"load",
function() {
if (
subj.document.documentURI ==
"chrome://browser/content/sanitize.xul"
) {
Services.ww.unregisterNotification(onOpen);
Assert.ok(true, "Observed Clear Recent History window open");
// On macOS the Clear Recent History dialog gets opened as an
// app-modal window, so its opener is null.
is(
subj.opener,
AppConstants.platform == "macosx" ? null : window,
"openClearHistoryDialog opened a sanitizer window."
);
subj.close();
resolve();
}
},
{ once: true }
);
}
}
Services.ww.registerNotification(onOpen);
if (isPrivate) {
// eslint-disable-next-line mozilla/no-arbitrary-setTimeout
setTimeout(() => {
Services.ww.unregisterNotification(onOpen);
reject("No window opened.");
}, 500);
}
});
ext.sendMessage("begin-test");
if (isPrivate) {
await dialogPromise.catch(() => {
Assert.ok(true, "Promise should have timed out in PBM.");
});
} else {
await dialogPromise;
Assert.ok(true, "Clear history browser dialog was shown.");
}
await ext.unload();
}

Просмотреть файл

@ -34,6 +34,14 @@
"description": "Returns the date of the last browser update. If there's no update history, then the date the profile was first used is returned instead. The return value is milliseconds since 1 January 1970 UTC (i.e., suitable for passing to <code>new Date()</code>).",
"parameters": []
},
{
"name": "openClearHistoryDialog",
"type": "function",
"async": true,
"description": "Shows the 'Clear Recent History' dialog unless the user is in Private Browsing Mode.",
"parameters": [],
"requireUserInput": true
},
{
"name": "restartBrowser",
"type": "function",