From da8b128c32637278e8659122766e6c2afb7391c4 Mon Sep 17 00:00:00 2001 From: dlee Date: Thu, 5 Sep 2019 07:34:41 +0000 Subject: [PATCH] Bug 1576292 - Avoid using directory service off-main-thread in URL Classifier gtest. r=gcp Differential Revision: https://phabricator.services.mozilla.com/D44728 --HG-- extra : moz-landing-system : lando --- .../url-classifier/tests/gtest/Common.cpp | 14 ++++++++++++++ .../components/url-classifier/tests/gtest/Common.h | 4 ++++ .../tests/gtest/TestLookupCacheV4.cpp | 6 +++++- .../tests/gtest/TestPerProviderDirectory.cpp | 12 ++++++------ 4 files changed, 29 insertions(+), 7 deletions(-) diff --git a/toolkit/components/url-classifier/tests/gtest/Common.cpp b/toolkit/components/url-classifier/tests/gtest/Common.cpp index 5682819047f3..381f5a68575a 100644 --- a/toolkit/components/url-classifier/tests/gtest/Common.cpp +++ b/toolkit/components/url-classifier/tests/gtest/Common.cpp @@ -212,6 +212,20 @@ static nsresult BuildCache(LookupCacheV4* cache, return cache->Build(map); } +template +RefPtr SetupLookupCache(const _PrefixArray& aPrefixArray, + nsCOMPtr& aFile) { + RefPtr cache = new T(GTEST_TABLE_V4, EmptyCString(), aFile); + + nsresult rv = cache->Init(); + EXPECT_EQ(rv, NS_OK); + + rv = BuildCache(cache, aPrefixArray); + EXPECT_EQ(rv, NS_OK); + + return cache; +} + template RefPtr SetupLookupCache(const _PrefixArray& aPrefixArray) { nsCOMPtr file; diff --git a/toolkit/components/url-classifier/tests/gtest/Common.h b/toolkit/components/url-classifier/tests/gtest/Common.h index c83d9536b436..10ad4e268a3a 100644 --- a/toolkit/components/url-classifier/tests/gtest/Common.h +++ b/toolkit/components/url-classifier/tests/gtest/Common.h @@ -69,6 +69,10 @@ void CheckContent(LookupCacheV4* aCache, PrefixStringMap& aExpected); template RefPtr SetupLookupCache(const _PrefixArray& aPrefixArray); +template +RefPtr SetupLookupCache(const _PrefixArray& aPrefixArray, + nsCOMPtr& aFile); + /** * Retrieve Classifer class */ diff --git a/toolkit/components/url-classifier/tests/gtest/TestLookupCacheV4.cpp b/toolkit/components/url-classifier/tests/gtest/TestLookupCacheV4.cpp index c7ebdc4e6c61..639c81809f95 100644 --- a/toolkit/components/url-classifier/tests/gtest/TestLookupCacheV4.cpp +++ b/toolkit/components/url-classifier/tests/gtest/TestLookupCacheV4.cpp @@ -12,8 +12,12 @@ static void TestHasPrefix(const nsCString& aURL, bool aExpectedHas, CreatePrefixFromURL("gound.com/", 5), CreatePrefixFromURL("small.com/", 4)}; + nsCOMPtr file; + NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file)); + file->AppendNative(GTEST_SAFEBROWSING_DIR); + RunTestInNewThread([&]() -> void { - RefPtr cache = SetupLookupCache(array); + RefPtr cache = SetupLookupCache(array, file); Completion lookupHash; lookupHash.FromPlaintext(aURL); diff --git a/toolkit/components/url-classifier/tests/gtest/TestPerProviderDirectory.cpp b/toolkit/components/url-classifier/tests/gtest/TestPerProviderDirectory.cpp index 6e2378bc427c..045b3e5b5af8 100644 --- a/toolkit/components/url-classifier/tests/gtest/TestPerProviderDirectory.cpp +++ b/toolkit/components/url-classifier/tests/gtest/TestPerProviderDirectory.cpp @@ -62,10 +62,10 @@ static void VerifyPrivateStorePath(T* target, const nsCString& aTableName, TEST(UrlClassifierPerProviderDirectory, LookupCache) { - RunTestInNewThread([]() -> void { - nsCOMPtr rootDir; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir)); + nsCOMPtr rootDir; + NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir)); + RunTestInNewThread([&]() -> void { // For V2 tables (NOT ending with '-proto'), root directory should be // used as the private store. { @@ -96,10 +96,10 @@ TEST(UrlClassifierPerProviderDirectory, LookupCache) TEST(UrlClassifierPerProviderDirectory, HashStore) { - RunTestInNewThread([]() -> void { - nsCOMPtr rootDir; - NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir)); + nsCOMPtr rootDir; + NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir)); + RunTestInNewThread([&]() -> void { // For V2 tables (NOT ending with '-proto'), root directory should be // used as the private store. {