/src/mozilla-central/toolkit/components/url-classifier/tests/gtest/TestLookupCacheV4.cpp
Line | Count | Source (jump to first uncovered line) |
1 | | /* This Source Code Form is subject to the terms of the Mozilla Public |
2 | | * License, v. 2.0. If a copy of the MPL was not distributed with this |
3 | | * file, You can obtain one at http://mozilla.org/MPL/2.0/. */ |
4 | | |
5 | | #include "Common.h" |
6 | | |
7 | | void |
8 | | TestHasPrefix(const _Fragment& aFragment, bool aExpectedHas, bool aExpectedComplete) |
9 | 0 | { |
10 | 0 | _PrefixArray array = { GeneratePrefix(_Fragment("bravo.com/"), 32), |
11 | 0 | GeneratePrefix(_Fragment("browsing.com/"), 8), |
12 | 0 | GeneratePrefix(_Fragment("gound.com/"), 5), |
13 | 0 | GeneratePrefix(_Fragment("small.com/"), 4) |
14 | 0 | }; |
15 | 0 |
|
16 | 0 | RunTestInNewThread([&] () -> void { |
17 | 0 | RefPtr<LookupCache> cache = SetupLookupCache<LookupCacheV4>(array); |
18 | 0 |
|
19 | 0 | Completion lookupHash; |
20 | 0 | lookupHash.FromPlaintext(aFragment); |
21 | 0 |
|
22 | 0 | bool has, confirmed; |
23 | 0 | uint32_t matchLength; |
24 | 0 | // Freshness is not used in V4 so we just put dummy values here. |
25 | 0 | TableFreshnessMap dummy; |
26 | 0 | nsresult rv = |
27 | 0 | cache->Has(lookupHash, &has, &matchLength, &confirmed); |
28 | 0 |
|
29 | 0 | EXPECT_EQ(rv, NS_OK); |
30 | 0 | EXPECT_EQ(has, aExpectedHas); |
31 | 0 | EXPECT_EQ(matchLength == COMPLETE_SIZE, aExpectedComplete); |
32 | 0 | EXPECT_EQ(confirmed, false); |
33 | 0 |
|
34 | 0 | cache->ClearAll(); |
35 | 0 | }); |
36 | 0 |
|
37 | 0 | } |
38 | | |
39 | | TEST(UrlClassifierLookupCacheV4, HasComplete) |
40 | 0 | { |
41 | 0 | TestHasPrefix(_Fragment("bravo.com/"), true, true); |
42 | 0 | } |
43 | | |
44 | | TEST(UrlClassifierLookupCacheV4, HasPrefix) |
45 | 0 | { |
46 | 0 | TestHasPrefix(_Fragment("browsing.com/"), true, false); |
47 | 0 | } |
48 | | |
49 | | TEST(UrlClassifierLookupCacheV4, Nomatch) |
50 | 0 | { |
51 | 0 | TestHasPrefix(_Fragment("nomatch.com/"), false, false); |
52 | 0 | } |