Bug 1528596 - Devirtualize accesses to nsUrlClassifierUtils, r=dimi
Differential Revision: https://phabricator.services.mozilla.com/D20086
This commit is contained in:
@@ -91,16 +91,10 @@ void ApplyUpdate(TableUpdateArray& updates) {
|
||||
RefPtr<Classifier> classifier = new Classifier();
|
||||
classifier->Open(*file);
|
||||
|
||||
{
|
||||
// Force nsIUrlClassifierUtils loading on main thread
|
||||
// because nsIUrlClassifierDBService will not run in advance
|
||||
// in gtest.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIUrlClassifierUtils> dummy =
|
||||
mozilla::components::UrlClassifierUtils::Service(&rv);
|
||||
Unused << dummy;
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
}
|
||||
// Force nsUrlClassifierUtils loading on main thread
|
||||
// because nsIUrlClassifierDBService will not run in advance
|
||||
// in gtest.
|
||||
nsUrlClassifierUtils::GetInstance();
|
||||
|
||||
SyncApplyUpdates(classifier, updates);
|
||||
}
|
||||
|
||||
@@ -37,8 +37,7 @@ Base64EncodedStringArray MakeBase64EncodedStringArray(nsCString (&aArray)[N]) {
|
||||
} // end of unnamed namespace.
|
||||
|
||||
TEST(UrlClassifierFindFullHash, Request) {
|
||||
nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
|
||||
do_GetService("@mozilla.org/url-classifier/utils;1");
|
||||
nsUrlClassifierUtils* urlUtil = nsUrlClassifierUtils::GetInstance();
|
||||
|
||||
const char* listNames[] = {"test-phish-proto", "test-unwanted-proto"};
|
||||
|
||||
@@ -163,8 +162,8 @@ class MyParseCallback final : public nsIUrlClassifierParseFindFullHashCallback {
|
||||
ASSERT_TRUE(aCompleteHash.Equals(expected.mCompleteHash));
|
||||
|
||||
// Verify aTableNames
|
||||
nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
|
||||
do_GetService("@mozilla.org/url-classifier/utils;1");
|
||||
nsUrlClassifierUtils* urlUtil = nsUrlClassifierUtils::GetInstance();
|
||||
|
||||
nsCString tableNames;
|
||||
nsresult rv =
|
||||
urlUtil->ConvertThreatTypeToListNames(expected.mThreatType, tableNames);
|
||||
@@ -216,8 +215,7 @@ TEST(UrlClassifierFindFullHash, ParseRequest) {
|
||||
nsCOMPtr<nsIUrlClassifierParseFindFullHashCallback> callback =
|
||||
new MyParseCallback(callbackCount);
|
||||
|
||||
nsCOMPtr<nsIUrlClassifierUtils> urlUtil =
|
||||
do_GetService("@mozilla.org/url-classifier/utils;1");
|
||||
nsUrlClassifierUtils* urlUtil = nsUrlClassifierUtils::GetInstance();
|
||||
nsresult rv = urlUtil->ParseFindFullHashResponseV4(
|
||||
nsCString(s.c_str(), s.size()), callback);
|
||||
NS_ENSURE_SUCCESS_VOID(rv);
|
||||
|
||||
@@ -187,16 +187,10 @@ static void testUpdate(TableUpdateArray& tableUpdates,
|
||||
nsCOMPtr<nsIFile> file;
|
||||
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
|
||||
|
||||
{
|
||||
// Force nsIUrlClassifierUtils loading on main thread
|
||||
// because nsIUrlClassifierDBService will not run in advance
|
||||
// in gtest.
|
||||
nsresult rv;
|
||||
nsCOMPtr<nsIUrlClassifierUtils> dummy =
|
||||
components::UrlClassifierUtils::Service(&rv);
|
||||
Unused << dummy;
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
}
|
||||
// Force nsUrlClassifierUtils loading on main thread
|
||||
// because nsIUrlClassifierDBService will not run in advance
|
||||
// in gtest.
|
||||
nsUrlClassifierUtils::GetInstance();
|
||||
|
||||
RefPtr<Classifier> classifier = new Classifier();
|
||||
classifier->Open(*file);
|
||||
|
||||
@@ -76,10 +76,7 @@ TEST(UrlClassifierUtils, Unescape) {
|
||||
|
||||
void TestEncodeHelper(const char* in, const char* expected) {
|
||||
nsCString out, strIn(in), strExp(expected);
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
utils->SpecialEncode(strIn, true, out);
|
||||
nsUrlClassifierUtils::GetInstance()->SpecialEncode(strIn, true, out);
|
||||
CheckEquals(strExp, out);
|
||||
}
|
||||
|
||||
@@ -94,10 +91,8 @@ TEST(UrlClassifierUtils, Enc) {
|
||||
noenc.Append(static_cast<char>(i));
|
||||
}
|
||||
}
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
nsCString out;
|
||||
utils->SpecialEncode(noenc, false, out);
|
||||
nsUrlClassifierUtils::GetInstance()->SpecialEncode(noenc, false, out);
|
||||
CheckEquals(noenc, out);
|
||||
|
||||
// Test that all the chars that we should encode [0,32],37,[127,255] are
|
||||
@@ -112,7 +107,7 @@ TEST(UrlClassifierUtils, Enc) {
|
||||
}
|
||||
|
||||
out.Truncate();
|
||||
utils->SpecialEncode(yesAsString, false, out);
|
||||
nsUrlClassifierUtils::GetInstance()->SpecialEncode(yesAsString, false, out);
|
||||
CheckEquals(yesExpectedString, out);
|
||||
|
||||
TestEncodeHelper("blah//blah", "blah/blah");
|
||||
@@ -120,10 +115,7 @@ TEST(UrlClassifierUtils, Enc) {
|
||||
|
||||
void TestCanonicalizeHelper(const char* in, const char* expected) {
|
||||
nsCString out, strIn(in), strExp(expected);
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
utils->CanonicalizePath(strIn, out);
|
||||
nsUrlClassifierUtils::GetInstance()->CanonicalizePath(strIn, out);
|
||||
CheckEquals(strExp, out);
|
||||
}
|
||||
|
||||
@@ -156,10 +148,7 @@ TEST(UrlClassifierUtils, Canonicalize) {
|
||||
|
||||
void TestParseIPAddressHelper(const char* in, const char* expected) {
|
||||
nsCString out, strIn(in), strExp(expected);
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
utils->ParseIPAddress(strIn, out);
|
||||
nsUrlClassifierUtils::GetInstance()->ParseIPAddress(strIn, out);
|
||||
CheckEquals(strExp, out);
|
||||
}
|
||||
|
||||
@@ -187,10 +176,8 @@ TEST(UrlClassifierUtils, ParseIPAddress) {
|
||||
void TestCanonicalNumHelper(const char* in, uint32_t bytes, bool allowOctal,
|
||||
const char* expected) {
|
||||
nsCString out, strIn(in), strExp(expected);
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
utils->CanonicalNum(strIn, bytes, allowOctal, out);
|
||||
nsUrlClassifierUtils::GetInstance()->CanonicalNum(strIn, bytes, allowOctal,
|
||||
out);
|
||||
CheckEquals(strExp, out);
|
||||
}
|
||||
|
||||
@@ -213,10 +200,7 @@ TEST(UrlClassifierUtils, CanonicalNum) {
|
||||
|
||||
void TestHostnameHelper(const char* in, const char* expected) {
|
||||
nsCString out, strIn(in), strExp(expected);
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
utils->CanonicalizeHostname(strIn, out);
|
||||
nsUrlClassifierUtils::GetInstance()->CanonicalizeHostname(strIn, out);
|
||||
CheckEquals(strExp, out);
|
||||
}
|
||||
|
||||
@@ -249,13 +233,10 @@ TEST(UrlClassifierUtils, LongHostname) {
|
||||
memset(str, 'x', kTestSize);
|
||||
str[kTestSize] = '\0';
|
||||
|
||||
RefPtr<nsUrlClassifierUtils> utils = new nsUrlClassifierUtils;
|
||||
utils->Init();
|
||||
|
||||
nsAutoCString out;
|
||||
nsDependentCString in(str);
|
||||
PRIntervalTime clockStart = PR_IntervalNow();
|
||||
utils->CanonicalizeHostname(in, out);
|
||||
nsUrlClassifierUtils::GetInstance()->CanonicalizeHostname(in, out);
|
||||
PRIntervalTime clockEnd = PR_IntervalNow();
|
||||
|
||||
CheckEquals(in, out);
|
||||
|
||||
Reference in New Issue
Block a user