| 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 |
| (...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 79 EXPECT_EQ(pm.FormatList(phish, true), | 79 EXPECT_EQ(pm.FormatList(phish, true), |
| 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 // Flakey, see http://code.google.com/p/chromium/issues/detail?id=1880 | 89 TEST_F(SafeBrowsingProtocolManagerTest, TestGetHashBackOffTimes) { |
| 90 TEST_F(SafeBrowsingProtocolManagerTest, DISABLED_TestGetHashBackOffTimes) { | |
| 91 SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); | 90 SafeBrowsingProtocolManager pm(NULL, NULL, "", ""); |
| 92 | 91 |
| 93 // No errors or back off time yet. | 92 // No errors or back off time yet. |
| 94 EXPECT_EQ(pm.gethash_error_count_, 0); | 93 EXPECT_EQ(pm.gethash_error_count_, 0); |
| 95 EXPECT_TRUE(pm.next_gethash_time_.is_null()); | 94 EXPECT_TRUE(pm.next_gethash_time_.is_null()); |
| 96 | 95 |
| 97 Time now = Time::Now(); | 96 Time now = Time::Now(); |
| 98 | 97 |
| 99 // 1 error. | 98 // 1 error. |
| 100 pm.HandleGetHashError(); | 99 pm.HandleGetHashError(now); |
| 101 EXPECT_EQ(pm.gethash_error_count_, 1); | 100 EXPECT_EQ(pm.gethash_error_count_, 1); |
| 102 TimeDelta margin = TimeDelta::FromSeconds(5); // Fudge factor. | 101 TimeDelta margin = TimeDelta::FromSeconds(5); // Fudge factor. |
| 103 Time future = now + TimeDelta::FromMinutes(1); | 102 Time future = now + TimeDelta::FromMinutes(1); |
| 104 EXPECT_TRUE(pm.next_gethash_time_ >= future - margin && | 103 EXPECT_TRUE(pm.next_gethash_time_ >= future - margin && |
| 105 pm.next_gethash_time_ <= future + margin); | 104 pm.next_gethash_time_ <= future + margin); |
| 106 | 105 |
| 107 // 2 errors. | 106 // 2 errors. |
| 108 pm.HandleGetHashError(); | 107 pm.HandleGetHashError(now); |
| 109 EXPECT_EQ(pm.gethash_error_count_, 2); | 108 EXPECT_EQ(pm.gethash_error_count_, 2); |
| 110 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(30)); | 109 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(30)); |
| 111 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(60)); | 110 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(60)); |
| 112 | 111 |
| 113 // 3 errors. | 112 // 3 errors. |
| 114 pm.HandleGetHashError(); | 113 pm.HandleGetHashError(now); |
| 115 EXPECT_EQ(pm.gethash_error_count_, 3); | 114 EXPECT_EQ(pm.gethash_error_count_, 3); |
| 116 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(60)); | 115 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(60)); |
| 117 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(120)); | 116 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(120)); |
| 118 | 117 |
| 119 // 4 errors. | 118 // 4 errors. |
| 120 pm.HandleGetHashError(); | 119 pm.HandleGetHashError(now); |
| 121 EXPECT_EQ(pm.gethash_error_count_, 4); | 120 EXPECT_EQ(pm.gethash_error_count_, 4); |
| 122 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(120)); | 121 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(120)); |
| 123 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(240)); | 122 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(240)); |
| 124 | 123 |
| 125 // 5 errors. | 124 // 5 errors. |
| 126 pm.HandleGetHashError(); | 125 pm.HandleGetHashError(now); |
| 127 EXPECT_EQ(pm.gethash_error_count_, 5); | 126 EXPECT_EQ(pm.gethash_error_count_, 5); |
| 128 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(240)); | 127 EXPECT_TRUE(pm.next_gethash_time_ >= now + TimeDelta::FromMinutes(240)); |
| 129 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(480)); | 128 EXPECT_TRUE(pm.next_gethash_time_ <= now + TimeDelta::FromMinutes(480)); |
| 130 | 129 |
| 131 // 6 errors, reached max backoff. | 130 // 6 errors, reached max backoff. |
| 132 pm.HandleGetHashError(); | 131 pm.HandleGetHashError(now); |
| 133 EXPECT_EQ(pm.gethash_error_count_, 6); | 132 EXPECT_EQ(pm.gethash_error_count_, 6); |
| 134 EXPECT_TRUE(pm.next_gethash_time_ == now + TimeDelta::FromMinutes(480)); | 133 EXPECT_TRUE(pm.next_gethash_time_ == now + TimeDelta::FromMinutes(480)); |
| 135 | 134 |
| 136 // 7 errors. | 135 // 7 errors. |
| 137 pm.HandleGetHashError(); | 136 pm.HandleGetHashError(now); |
| 138 EXPECT_EQ(pm.gethash_error_count_, 7); | 137 EXPECT_EQ(pm.gethash_error_count_, 7); |
| 139 EXPECT_TRUE(pm.next_gethash_time_== now + TimeDelta::FromMinutes(480)); | 138 EXPECT_TRUE(pm.next_gethash_time_== now + TimeDelta::FromMinutes(480)); |
| 140 } | 139 } |
| OLD | NEW |