Commit 6c48a9b9 authored by Harry Twyford's avatar Harry Twyford
Browse files

Bug 1594786 - Part 2 - WebExt API: Add...

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
parent 7d84bc7e
......@@ -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]
/* 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",
......
Supports Markdown
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment