зеркало из https://github.com/mozilla/gecko-dev.git
Bug 1540247 - Expose MozURL::Init to JS for QuotaManager tests r=ttung,asuth
Differential Revision: https://phabricator.services.mozilla.com/D39207 --HG-- extra : moz-landing-system : lando
This commit is contained in:
Родитель
8d8b904439
Коммит
fc1e20f375
|
@ -17,6 +17,7 @@
|
|||
#include "mozilla/ipc/BackgroundParent.h"
|
||||
#include "mozilla/ipc/BackgroundUtils.h"
|
||||
#include "mozilla/ipc/PBackgroundChild.h"
|
||||
#include "mozilla/net/MozURL.h"
|
||||
#include "nsIIdleService.h"
|
||||
#include "nsIObserverService.h"
|
||||
#include "nsIScriptSecurityManager.h"
|
||||
|
@ -788,6 +789,24 @@ QuotaManagerService::ListInitializedOrigins(nsIQuotaCallback* aCallback,
|
|||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::IsValidMozURL(const nsACString& aSpec,
|
||||
bool* const _retval) {
|
||||
// it should also be okay to call it on the worker thread, but there is no any
|
||||
// request for that so far
|
||||
MOZ_ASSERT(NS_IsMainThread());
|
||||
MOZ_ASSERT(_retval);
|
||||
|
||||
RefPtr<net::MozURL> url;
|
||||
const bool valid =
|
||||
NS_SUCCEEDED(net::MozURL::Init(getter_AddRefs(url), aSpec));
|
||||
MOZ_ASSERT(valid == static_cast<bool>(url));
|
||||
|
||||
*_retval = valid;
|
||||
|
||||
return NS_OK;
|
||||
}
|
||||
|
||||
NS_IMETHODIMP
|
||||
QuotaManagerService::Observe(nsISupports* aSubject, const char* aTopic,
|
||||
const char16_t* aData) {
|
||||
|
|
|
@ -224,6 +224,15 @@ interface nsIQuotaManagerService : nsISupports
|
|||
[must_use] nsIQuotaRequest
|
||||
persist(in nsIPrincipal aPrincipal);
|
||||
|
||||
/**
|
||||
* Check if given spec is a valid MozURL.
|
||||
*
|
||||
* @param aSpec
|
||||
* A URL spec to check.
|
||||
*/
|
||||
[must_use] boolean
|
||||
isValidMozURL(in ACString aSpec);
|
||||
|
||||
/**
|
||||
* Given an origin, asynchronously calculate its group quota usage and quota
|
||||
* limit. An origin's group is the set of all origins that share the same
|
||||
|
|
|
@ -212,6 +212,10 @@ function listInitializedOrigins(callback) {
|
|||
return request;
|
||||
}
|
||||
|
||||
function isValidMozURL(spec) {
|
||||
return SpecialPowers._getQuotaManager().isValidMozURL(spec);
|
||||
}
|
||||
|
||||
function installPackage(packageName) {
|
||||
let directoryService = Cc["@mozilla.org/file/directory_service;1"].getService(
|
||||
Ci.nsIProperties
|
||||
|
|
|
@ -0,0 +1,30 @@
|
|||
/**
|
||||
* Any copyright is dedicated to the Public Domain.
|
||||
* http://creativecommons.org/publicdomain/zero/1.0/
|
||||
*/
|
||||
|
||||
// For comprehensive test cases of MozURL::Init, refer to
|
||||
// netwerk/test/gtest/TestMozURL.cpp, this is just testing whether the
|
||||
// validation result is correctly exposed to JS.
|
||||
//
|
||||
// This test doesn't have to be an async function because there are no async
|
||||
// operations inside the test. However, it's currently needed due to our
|
||||
// infrastructure for xpcshell tests.
|
||||
async function testSteps() {
|
||||
// TODO add more appropriate test cases?
|
||||
const validURLs = ["about:blank", "https://foo.github.io"];
|
||||
const invalidURLs = ["", "xxx"];
|
||||
|
||||
info("Testing valid URLs");
|
||||
|
||||
for (let validURL of validURLs) {
|
||||
ok(isValidMozURL(validURL), "Should be considered valid: " + validURL);
|
||||
}
|
||||
|
||||
for (let invalidURL of invalidURLs) {
|
||||
ok(
|
||||
!isValidMozURL(invalidURL),
|
||||
"Should be considered invalid: " + invalidURL
|
||||
);
|
||||
}
|
||||
}
|
|
@ -9,21 +9,22 @@
|
|||
// test verifies that as well.
|
||||
|
||||
async function testSteps() {
|
||||
const obsoleteOriginPaths = [
|
||||
"storage/default/chrome+++content+browser.xul/",
|
||||
"storage/default/moz-safe-about+++home/",
|
||||
// XXX Bug 1540247 will expose MozURL::Init to js so that we could test the
|
||||
// failure cases of that. The below directory is expected to fail now, but
|
||||
// we expect it to pass once the rust-url issue is fixed. Thus, only test it
|
||||
// manually.
|
||||
// "storage/default/https+++smaug----.github.io/",
|
||||
// Deprecated client
|
||||
"storage/default/https+++example.com/asmjs/",
|
||||
"storage/default/about+home+1",
|
||||
"storage/default/about+home+1+q",
|
||||
// about:reader?url=xxx before bug 1422456
|
||||
"storage/default/about+reader+url=https%3A%2F%2Fexample.com",
|
||||
];
|
||||
const obsoleteOriginPaths =
|
||||
[
|
||||
"storage/default/chrome+++content+browser.xul/",
|
||||
"storage/default/moz-safe-about+++home/",
|
||||
// Deprecated client
|
||||
"storage/default/https+++example.com/asmjs/",
|
||||
"storage/default/about+home+1",
|
||||
"storage/default/about+home+1+q",
|
||||
// about:reader?url=xxx before bug 1422456
|
||||
"storage/default/about+reader+url=https%3A%2F%2Fexample.com",
|
||||
] +
|
||||
// XXX The below directory is expected to fail now, but
|
||||
// we expect it to pass once the rust-url issue is fixed.
|
||||
isValidMozURL("https://smaug----.github.io")
|
||||
? ["storage/default/https+++smaug----.github.io/"]
|
||||
: [];
|
||||
const obsoleteFilePath =
|
||||
"storage/default/https+++example.com/idb/UUID123.tmp";
|
||||
const invalidOriginPath = "storage/default/invalid+++example.com/";
|
||||
|
|
|
@ -38,6 +38,7 @@ support-files =
|
|||
[test_groupMismatch.js]
|
||||
[test_idbSubdirUpgrade.js]
|
||||
[test_initTemporaryStorage.js]
|
||||
[test_isValidMozURL.js]
|
||||
[test_listInitializedOrigins.js]
|
||||
[test_localStorageArchive1upgrade.js]
|
||||
[test_localStorageArchive4upgrade.js]
|
||||
|
|
Загрузка…
Ссылка в новой задаче