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
This commit is contained in:
dlee 2019-09-05 07:34:41 +00:00
Родитель 44ad3cfc99
Коммит da8b128c32
4 изменённых файлов: 29 добавлений и 7 удалений

Просмотреть файл

@ -212,6 +212,20 @@ static nsresult BuildCache(LookupCacheV4* cache,
return cache->Build(map);
}
template <typename T>
RefPtr<T> SetupLookupCache(const _PrefixArray& aPrefixArray,
nsCOMPtr<nsIFile>& aFile) {
RefPtr<T> 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 <typename T>
RefPtr<T> SetupLookupCache(const _PrefixArray& aPrefixArray) {
nsCOMPtr<nsIFile> file;

Просмотреть файл

@ -69,6 +69,10 @@ void CheckContent(LookupCacheV4* aCache, PrefixStringMap& aExpected);
template <typename T>
RefPtr<T> SetupLookupCache(const _PrefixArray& aPrefixArray);
template <typename T>
RefPtr<T> SetupLookupCache(const _PrefixArray& aPrefixArray,
nsCOMPtr<nsIFile>& aFile);
/**
* Retrieve Classifer class
*/

Просмотреть файл

@ -12,8 +12,12 @@ static void TestHasPrefix(const nsCString& aURL, bool aExpectedHas,
CreatePrefixFromURL("gound.com/", 5),
CreatePrefixFromURL("small.com/", 4)};
nsCOMPtr<nsIFile> file;
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(file));
file->AppendNative(GTEST_SAFEBROWSING_DIR);
RunTestInNewThread([&]() -> void {
RefPtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array);
RefPtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array, file);
Completion lookupHash;
lookupHash.FromPlaintext(aURL);

Просмотреть файл

@ -62,10 +62,10 @@ static void VerifyPrivateStorePath(T* target, const nsCString& aTableName,
TEST(UrlClassifierPerProviderDirectory, LookupCache)
{
RunTestInNewThread([]() -> void {
nsCOMPtr<nsIFile> rootDir;
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir));
nsCOMPtr<nsIFile> 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<nsIFile> rootDir;
NS_GetSpecialDirectory(NS_APP_USER_PROFILE_50_DIR, getter_AddRefs(rootDir));
nsCOMPtr<nsIFile> 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.
{