OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 // | 4 // |
5 | 5 |
6 #include "base/logging.h" | 6 #include "base/logging.h" |
7 #include "base/time.h" | 7 #include "base/time.h" |
8 #include "testing/gtest/include/gtest/gtest.h" | 8 #include "testing/gtest/include/gtest/gtest.h" |
9 #include "chrome/browser/safe_browsing/protocol_manager.h" | 9 #include "chrome/browser/safe_browsing/protocol_manager.h" |
10 | 10 |
11 using base::Time; | 11 using base::Time; |
12 using base::TimeDelta; | 12 using base::TimeDelta; |
13 | 13 |
14 class SafeBrowsingProtocolManagerTest : public testing::Test { | 14 class SafeBrowsingProtocolManagerTest : public testing::Test { |
15 }; | 15 }; |
16 | 16 |
17 // Ensure that we respect section 5 of the SafeBrowsing protocol specification. | 17 // Ensure that we respect section 5 of the SafeBrowsing protocol specification. |
18 TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { | 18 TEST_F(SafeBrowsingProtocolManagerTest, TestBackOffTimes) { |
19 SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); | 19 SafeBrowsingProtocolManager pm(NULL, "", ""); |
20 pm.next_update_sec_ = 1800; | 20 pm.next_update_sec_ = 1800; |
21 DCHECK(pm.back_off_fuzz_ >= 0.0 && pm.back_off_fuzz_ <= 1.0); | 21 DCHECK(pm.back_off_fuzz_ >= 0.0 && pm.back_off_fuzz_ <= 1.0); |
22 | 22 |
23 // No errors received so far. | 23 // No errors received so far. |
24 EXPECT_EQ(pm.GetNextUpdateTime(false), 1800 * 1000); | 24 EXPECT_EQ(pm.GetNextUpdateTime(false), 1800 * 1000); |
25 | 25 |
26 // 1 error. | 26 // 1 error. |
27 EXPECT_EQ(pm.GetNextUpdateTime(true), 60 * 1000); | 27 EXPECT_EQ(pm.GetNextUpdateTime(true), 60 * 1000); |
28 | 28 |
29 // 2 errors. | 29 // 2 errors. |
(...skipping 17 matching lines...) Expand all Loading... |
47 | 47 |
48 // 7 errors. | 48 // 7 errors. |
49 EXPECT_EQ(pm.GetNextUpdateTime(true), 480 * 60 * 1000); | 49 EXPECT_EQ(pm.GetNextUpdateTime(true), 480 * 60 * 1000); |
50 | 50 |
51 // Received a successful response. | 51 // Received a successful response. |
52 EXPECT_EQ(pm.GetNextUpdateTime(false), 1800 * 1000); | 52 EXPECT_EQ(pm.GetNextUpdateTime(false), 1800 * 1000); |
53 } | 53 } |
54 | 54 |
55 // Test string combinations with and without MAC. | 55 // Test string combinations with and without MAC. |
56 TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { | 56 TEST_F(SafeBrowsingProtocolManagerTest, TestChunkStrings) { |
57 SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); | 57 SafeBrowsingProtocolManager pm(NULL, "", ""); |
58 | 58 |
59 // Add and Sub chunks. | 59 // Add and Sub chunks. |
60 SBListChunkRanges phish("goog-phish-shavar"); | 60 SBListChunkRanges phish("goog-phish-shavar"); |
61 phish.adds = "1,4,6,8-20,99"; | 61 phish.adds = "1,4,6,8-20,99"; |
62 phish.subs = "16,32,64-96"; | 62 phish.subs = "16,32,64-96"; |
63 EXPECT_EQ(pm.FormatList(phish, false), | 63 EXPECT_EQ(pm.FormatList(phish, false), |
64 "goog-phish-shavar;a:1,4,6,8-20,99:s:16,32,64-96\n"); | 64 "goog-phish-shavar;a:1,4,6,8-20,99:s:16,32,64-96\n"); |
65 EXPECT_EQ(pm.FormatList(phish, true), | 65 EXPECT_EQ(pm.FormatList(phish, true), |
66 "goog-phish-shavar;a:1,4,6,8-20,99:s:16,32,64-96:mac\n"); | 66 "goog-phish-shavar;a:1,4,6,8-20,99:s:16,32,64-96:mac\n"); |
67 | 67 |
(...skipping 12 matching lines...) Expand all Loading... |
80 "goog-phish-shavar;s:16,32,64-96:mac\n"); | 80 "goog-phish-shavar;s:16,32,64-96:mac\n"); |
81 | 81 |
82 // No chunks of either type. | 82 // No chunks of either type. |
83 phish.adds = ""; | 83 phish.adds = ""; |
84 phish.subs = ""; | 84 phish.subs = ""; |
85 EXPECT_EQ(pm.FormatList(phish, false), "goog-phish-shavar;\n"); | 85 EXPECT_EQ(pm.FormatList(phish, false), "goog-phish-shavar;\n"); |
86 EXPECT_EQ(pm.FormatList(phish, true), "goog-phish-shavar;mac\n"); | 86 EXPECT_EQ(pm.FormatList(phish, true), "goog-phish-shavar;mac\n"); |
87 } | 87 } |
88 | 88 |
89 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { | 89 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { |
90 SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); | 90 SafeBrowsingProtocolManager pm(NULL, "", ""); |
91 | 91 |
92 // No errors or back off time yet. | 92 // No errors or back off time yet. |
93 EXPECT_EQ(pm.gethash_error_count_, 0); | 93 EXPECT_EQ(pm.gethash_error_count_, 0); |
94 EXPECT_TRUE(pm.next_gethash_time_.is_null()); | 94 EXPECT_TRUE(pm.next_gethash_time_.is_null()); |
95 | 95 |
96 Time now = Time::Now(); | 96 Time now = Time::Now(); |
97 | 97 |
98 // 1 error. | 98 // 1 error. |
99 pm.HandleGetHashError(now); | 99 pm.HandleGetHashError(now); |
100 EXPECT_EQ(pm.gethash_error_count_, 1); | 100 EXPECT_EQ(pm.gethash_error_count_, 1); |
(...skipping 29 matching lines...) Expand all Loading... |
130 // 6 errors, reached max backoff. | 130 // 6 errors, reached max backoff. |
131 pm.HandleGetHashError(now); | 131 pm.HandleGetHashError(now); |
132 EXPECT_EQ(pm.gethash_error_count_, 6); | 132 EXPECT_EQ(pm.gethash_error_count_, 6); |
133 EXPECT_TRUE(pm.next_gethash_time_ == now + TimeDelta::FromMinutes(480)); | 133 EXPECT_TRUE(pm.next_gethash_time_ == now + TimeDelta::FromMinutes(480)); |
134 | 134 |
135 // 7 errors. | 135 // 7 errors. |
136 pm.HandleGetHashError(now); | 136 pm.HandleGetHashError(now); |
137 EXPECT_EQ(pm.gethash_error_count_, 7); | 137 EXPECT_EQ(pm.gethash_error_count_, 7); |
138 EXPECT_TRUE(pm.next_gethash_time_== now + TimeDelta::FromMinutes(480)); | 138 EXPECT_TRUE(pm.next_gethash_time_== now + TimeDelta::FromMinutes(480)); |
139 } | 139 } |
OLD | NEW |