void TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete) { _PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32), GeneratePrefix(_Fragment("browsing.com/"), 8), GeneratePrefix(_Fragment("gound.com/"), 5), GeneratePrefix(_Fragment("small.com/"), 4) }; RunTestInNewThread([&] () -> void { UniquePtr<LookupCache> cache = SetupLookupCacheV4(array); Completion lookupHash; nsCOMPtr<nsICryptoHash> cryptoHash = do_CreateInstance(NS_CRYPTO_HASH_CONTRACTID); lookupHash.FromPlaintext(aFragment, cryptoHash); bool has, complete; nsresult rv = cache->Has(lookupHash, &has, &complete); EXPECT_EQ(rv, NS_OK); EXPECT_EQ(has, aExpectedHas); EXPECT_EQ(complete, aExpectedComplete); cache->ClearAll(); }); }
void TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete) { _PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32), GeneratePrefix(_Fragment("browsing.com/"), 8), GeneratePrefix(_Fragment("gound.com/"), 5), GeneratePrefix(_Fragment("small.com/"), 4) }; RunTestInNewThread([&] () -> void { UniquePtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array); Completion lookupHash; lookupHash.FromPlaintext(aFragment); bool has, confirmed; uint32_t matchLength; // Freshness is not used in V4 so we just put dummy values here. TableFreshnessMap dummy; nsresult rv = cache->Has(lookupHash, &has, &matchLength, &confirmed); EXPECT_EQ(rv, NS_OK); EXPECT_EQ(has, aExpectedHas); EXPECT_EQ(matchLength == COMPLETE_SIZE, aExpectedComplete); EXPECT_EQ(confirmed, false); cache->ClearAll(); }); }
void TestCache(const Completion aCompletion, bool aExpectedHas, bool aExpectedConfirmed, bool aExpectedInCache, T* aCache = nullptr) { bool has, inCache, confirmed; uint32_t matchLength; if (aCache) { aCache->Has(aCompletion, &has, &matchLength, &confirmed); inCache = aCache->IsInCache(aCompletion.ToUint32()); } else { _PrefixArray array = { GeneratePrefix(_Fragment("cache.notexpired.com/"), 10), GeneratePrefix(_Fragment("cache.expired.com/"), 8), GeneratePrefix(_Fragment("gound.com/"), 5), GeneratePrefix(_Fragment("small.com/"), 4) }; UniquePtr<T> cache = SetupLookupCache<T>(array); // Create an expired entry and a non-expired entry SetupCacheEntry(cache.get(), _Fragment("cache.notexpired.com/")); SetupCacheEntry(cache.get(), _Fragment("cache.expired.com/"), true, true); cache->Has(aCompletion, &has, &matchLength, &confirmed); inCache = cache->IsInCache(aCompletion.ToUint32()); } EXPECT_EQ(has, aExpectedHas); EXPECT_EQ(confirmed, aExpectedConfirmed); EXPECT_EQ(inCache, aExpectedInCache); }