forked from mirrors/gecko-dev
***
Bug 1514594: Part 3a - Change ChromeUtils.import to return an exports object; not pollute global. r=mccr8
This changes the behavior of ChromeUtils.import() to return an exports object,
rather than a module global, in all cases except when `null` is passed as a
second argument, and changes the default behavior not to pollute the global
scope with the module's exports. Thus, the following code written for the old
model:
ChromeUtils.import("resource://gre/modules/Services.jsm");
is approximately the same as the following, in the new model:
var {Services} = ChromeUtils.import("resource://gre/modules/Services.jsm");
Since the two behaviors are mutually incompatible, this patch will land with a
scripted rewrite to update all existing callers to use the new model rather
than the old.
***
Bug 1514594: Part 3b - Mass rewrite all JS code to use the new ChromeUtils.import API. rs=Gijs
This was done using the followng script:
https://bitbucket.org/kmaglione/m-c-rewrites/src/tip/processors/cu-import-exports.jsm
***
Bug 1514594: Part 3c - Update ESLint plugin for ChromeUtils.import API changes. r=Standard8
Differential Revision: https://phabricator.services.mozilla.com/D16747
***
Bug 1514594: Part 3d - Remove/fix hundreds of duplicate imports from sync tests. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16748
***
Bug 1514594: Part 3e - Remove no-op ChromeUtils.import() calls. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16749
***
Bug 1514594: Part 3f.1 - Cleanup various test corner cases after mass rewrite. r=Gijs
***
Bug 1514594: Part 3f.2 - Cleanup various non-test corner cases after mass rewrite. r=Gijs
Differential Revision: https://phabricator.services.mozilla.com/D16750
--HG--
extra : rebase_source : 359574ee3064c90f33bf36c2ebe3159a24cc8895
extra : histedit_source : b93c8f42808b1599f9122d7842d2c0b3e656a594%2C64a3a4e3359dc889e2ab2b49461bab9e27fc10a7
169 lines
6.8 KiB
JavaScript
169 lines
6.8 KiB
JavaScript
/* Any copyright is dedicated to the Public Domain.
|
|
* http://creativecommons.org/publicdomain/zero/1.0/ */
|
|
|
|
"use strict";
|
|
|
|
var {SitePermissions} = ChromeUtils.import("resource:///modules/SitePermissions.jsm");
|
|
|
|
async function testClearData(clearSiteData, clearCache) {
|
|
let quotaURI = Services.io.newURI(TEST_QUOTA_USAGE_ORIGIN);
|
|
SitePermissions.set(quotaURI, "persistent-storage", SitePermissions.ALLOW);
|
|
|
|
// Open a test site which saves into appcache.
|
|
await BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_OFFLINE_URL);
|
|
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
|
|
|
// Fill indexedDB with test data.
|
|
// Don't wait for the page to load, to register the content event handler as quickly as possible.
|
|
// If this test goes intermittent, we might have to tell the page to wait longer before
|
|
// firing the event.
|
|
BrowserTestUtils.openNewForegroundTab(gBrowser, TEST_QUOTA_USAGE_URL, false);
|
|
await BrowserTestUtils.waitForContentEvent(
|
|
gBrowser.selectedBrowser, "test-indexedDB-done", false, null, true);
|
|
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
|
|
|
// Register some service workers.
|
|
await loadServiceWorkerTestPage(TEST_SERVICE_WORKER_URL);
|
|
await promiseServiceWorkerRegisteredFor(TEST_SERVICE_WORKER_URL);
|
|
|
|
await openPreferencesViaOpenPreferencesAPI("privacy", { leaveOpen: true });
|
|
|
|
// Test the initial states.
|
|
let cacheUsage = await SiteDataManager.getCacheSize();
|
|
let quotaUsage = await SiteDataTestUtils.getQuotaUsage(TEST_QUOTA_USAGE_ORIGIN);
|
|
let totalUsage = await SiteDataManager.getTotalUsage();
|
|
Assert.greater(cacheUsage, 0, "The cache usage should not be 0");
|
|
Assert.greater(quotaUsage, 0, "The quota usage should not be 0");
|
|
Assert.greater(totalUsage, 0, "The total usage should not be 0");
|
|
|
|
let initialSizeLabelValue = await ContentTask.spawn(gBrowser.selectedBrowser, null, async function() {
|
|
let sizeLabel = content.document.getElementById("totalSiteDataSize");
|
|
return sizeLabel.textContent;
|
|
});
|
|
|
|
let doc = gBrowser.selectedBrowser.contentDocument;
|
|
let clearSiteDataButton = doc.getElementById("clearSiteDataButton");
|
|
|
|
let dialogOpened = promiseLoadSubDialog("chrome://browser/content/preferences/clearSiteData.xul");
|
|
clearSiteDataButton.doCommand();
|
|
let dialogWin = await dialogOpened;
|
|
|
|
// Convert the usage numbers in the same way the UI does it to assert
|
|
// that they're displayed in the dialog.
|
|
let [convertedTotalUsage] = DownloadUtils.convertByteUnits(totalUsage);
|
|
// For cache we just assert that the right unit (KB, probably) is displayed,
|
|
// since we've had cache intermittently changing under our feet.
|
|
let [, convertedCacheUnit] = DownloadUtils.convertByteUnits(cacheUsage);
|
|
|
|
let clearSiteDataCheckbox = dialogWin.document.getElementById("clearSiteData");
|
|
let clearCacheCheckbox = dialogWin.document.getElementById("clearCache");
|
|
// The usage details are filled asynchronously, so we assert that they're present by
|
|
// waiting for them to be filled in.
|
|
await Promise.all([
|
|
TestUtils.waitForCondition(
|
|
() => clearSiteDataCheckbox.label && clearSiteDataCheckbox.label.includes(convertedTotalUsage), "Should show the quota usage"),
|
|
TestUtils.waitForCondition(
|
|
() => clearCacheCheckbox.label && clearCacheCheckbox.label.includes(convertedCacheUnit), "Should show the cache usage"),
|
|
]);
|
|
|
|
// Check the boxes according to our test input.
|
|
clearSiteDataCheckbox.checked = clearSiteData;
|
|
clearCacheCheckbox.checked = clearCache;
|
|
|
|
// Some additional promises/assertions to wait for
|
|
// when deleting site data.
|
|
let acceptPromise;
|
|
let updatePromise;
|
|
let cookiesClearedPromise;
|
|
if (clearSiteData) {
|
|
acceptPromise = BrowserTestUtils.promiseAlertDialogOpen("accept");
|
|
updatePromise = promiseSiteDataManagerSitesUpdated();
|
|
cookiesClearedPromise = promiseCookiesCleared();
|
|
}
|
|
|
|
let dialogClosed = BrowserTestUtils.waitForEvent(dialogWin, "unload");
|
|
|
|
let clearButton = dialogWin.document.getElementById("clearButton");
|
|
if (!clearSiteData && !clearCache) {
|
|
// Simulate user input on one of the checkboxes to trigger the event listener for
|
|
// disabling the clearButton.
|
|
clearCacheCheckbox.doCommand();
|
|
// Check that the clearButton gets disabled by unchecking both options.
|
|
await TestUtils.waitForCondition(() => clearButton.disabled, "Clear button should be disabled");
|
|
let cancelButton = dialogWin.document.getElementById("cancelButton");
|
|
// Cancel, since we can't delete anything.
|
|
cancelButton.click();
|
|
} else {
|
|
// Delete stuff!
|
|
clearButton.click();
|
|
}
|
|
|
|
// For site data we display an extra warning dialog, make sure
|
|
// to accept it.
|
|
if (clearSiteData) {
|
|
await acceptPromise;
|
|
}
|
|
|
|
await dialogClosed;
|
|
|
|
if (clearCache) {
|
|
TestUtils.waitForCondition(async function() {
|
|
let usage = await SiteDataManager.getCacheSize();
|
|
return usage == 0;
|
|
}, "The cache usage should be removed");
|
|
} else {
|
|
Assert.greater(await SiteDataManager.getCacheSize(), 0, "The cache usage should not be 0");
|
|
}
|
|
|
|
if (clearSiteData) {
|
|
await updatePromise;
|
|
await cookiesClearedPromise;
|
|
await promiseServiceWorkersCleared();
|
|
|
|
TestUtils.waitForCondition(async function() {
|
|
let usage = await SiteDataManager.getTotalUsage();
|
|
return usage == 0;
|
|
}, "The total usage should be removed");
|
|
} else {
|
|
quotaUsage = await SiteDataTestUtils.getQuotaUsage(TEST_QUOTA_USAGE_ORIGIN);
|
|
totalUsage = await SiteDataManager.getTotalUsage();
|
|
Assert.greater(quotaUsage, 0, "The quota usage should not be 0");
|
|
Assert.greater(totalUsage, 0, "The total usage should not be 0");
|
|
}
|
|
|
|
if (clearCache || clearSiteData) {
|
|
// Check that the size label in about:preferences updates after we cleared data.
|
|
await ContentTask.spawn(gBrowser.selectedBrowser, {initialSizeLabelValue}, async function(opts) {
|
|
let sizeLabel = content.document.getElementById("totalSiteDataSize");
|
|
await ContentTaskUtils.waitForCondition(
|
|
() => sizeLabel.textContent != opts.initialSizeLabelValue, "Site data size label should have updated.");
|
|
});
|
|
}
|
|
|
|
let desiredPermissionState = clearSiteData ? SitePermissions.UNKNOWN : SitePermissions.ALLOW;
|
|
let permission = SitePermissions.get(quotaURI, "persistent-storage");
|
|
is(permission.state, desiredPermissionState, "Should have the correct permission state.");
|
|
|
|
BrowserTestUtils.removeTab(gBrowser.selectedTab);
|
|
await SiteDataManager.removeAll();
|
|
}
|
|
|
|
// Test opening the "Clear All Data" dialog and cancelling.
|
|
add_task(async function() {
|
|
await testClearData(false, false);
|
|
});
|
|
|
|
// Test opening the "Clear All Data" dialog and removing all site data.
|
|
add_task(async function() {
|
|
await testClearData(true, false);
|
|
});
|
|
|
|
// Test opening the "Clear All Data" dialog and removing all cache.
|
|
add_task(async function() {
|
|
await testClearData(false, true);
|
|
});
|
|
|
|
// Test opening the "Clear All Data" dialog and removing everything.
|
|
add_task(async function() {
|
|
await testClearData(true, true);
|
|
});
|