OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 // A test application for the FinancialPing class. | 5 // A test application for the FinancialPing class. |
6 // | 6 // |
7 // These tests should not be executed on the build server: | 7 // These tests should not be executed on the build server: |
8 // - They modify machine state (registry). | 8 // - They modify machine state (registry). |
9 // | 9 // |
10 // These tests require write access to HKCU and HKLM. | 10 // These tests require write access to HKCU and HKLM. |
11 // | 11 // |
12 // The "GGLA" brand is used to test the normal code flow of the code, and the | 12 // The "GGLA" brand is used to test the normal code flow of the code, and the |
13 // "TEST" brand is used to test the supplementary brand code code flow. In one | 13 // "TEST" brand is used to test the supplementary brand code code flow. In one |
14 // case below, the brand "GOOG" is used because the code wants to use a brand | 14 // case below, the brand "GOOG" is used because the code wants to use a brand |
15 // that is neither of the two mentioned above. | 15 // that is neither of the two mentioned above. |
16 | 16 |
17 #include "rlz/lib/financial_ping.h" | 17 #include "rlz/lib/financial_ping.h" |
18 | 18 |
19 #include "base/basictypes.h" | 19 #include <stdint.h> |
| 20 |
20 #include "base/logging.h" | 21 #include "base/logging.h" |
| 22 #include "base/macros.h" |
21 #include "base/strings/string_util.h" | 23 #include "base/strings/string_util.h" |
22 #include "base/strings/stringprintf.h" | 24 #include "base/strings/stringprintf.h" |
23 #include "base/strings/utf_string_conversions.h" | 25 #include "base/strings/utf_string_conversions.h" |
| 26 #include "build/build_config.h" |
24 #include "rlz/lib/lib_values.h" | 27 #include "rlz/lib/lib_values.h" |
25 #include "rlz/lib/machine_id.h" | 28 #include "rlz/lib/machine_id.h" |
26 #include "rlz/lib/rlz_lib.h" | 29 #include "rlz/lib/rlz_lib.h" |
27 #include "rlz/lib/rlz_value_store.h" | 30 #include "rlz/lib/rlz_value_store.h" |
28 #include "rlz/test/rlz_test_helpers.h" | 31 #include "rlz/test/rlz_test_helpers.h" |
29 #include "testing/gmock/include/gmock/gmock.h" | 32 #include "testing/gmock/include/gmock/gmock.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 33 #include "testing/gtest/include/gtest/gtest.h" |
31 | 34 |
32 #if defined(OS_WIN) | 35 #if defined(OS_WIN) |
33 #include "rlz/win/lib/machine_deal.h" | 36 #include "rlz/win/lib/machine_deal.h" |
34 #else | 37 #else |
35 #include "base/time/time.h" | 38 #include "base/time/time.h" |
36 #endif | 39 #endif |
37 | 40 |
38 namespace { | 41 namespace { |
39 | 42 |
40 // Must match the implementation in file_time.cc. | 43 // Must match the implementation in file_time.cc. |
41 int64 GetSystemTimeAsInt64() { | 44 int64_t GetSystemTimeAsInt64() { |
42 #if defined(OS_WIN) | 45 #if defined(OS_WIN) |
43 FILETIME now_as_file_time; | 46 FILETIME now_as_file_time; |
44 GetSystemTimeAsFileTime(&now_as_file_time); | 47 GetSystemTimeAsFileTime(&now_as_file_time); |
45 LARGE_INTEGER integer; | 48 LARGE_INTEGER integer; |
46 integer.HighPart = now_as_file_time.dwHighDateTime; | 49 integer.HighPart = now_as_file_time.dwHighDateTime; |
47 integer.LowPart = now_as_file_time.dwLowDateTime; | 50 integer.LowPart = now_as_file_time.dwLowDateTime; |
48 return integer.QuadPart; | 51 return integer.QuadPart; |
49 #else | 52 #else |
50 double now_seconds = base::Time::Now().ToDoubleT(); | 53 double now_seconds = base::Time::Now().ToDoubleT(); |
51 return static_cast<int64>(now_seconds * 1000 * 1000 * 10); | 54 return static_cast<int64_t>(now_seconds * 1000 * 1000 * 10); |
52 #endif | 55 #endif |
53 } | 56 } |
54 | 57 |
55 // Ping times in 100-nanosecond intervals. | 58 // Ping times in 100-nanosecond intervals. |
56 const int64 k1MinuteInterval = 60LL * 10000000LL; // 1 minute | 59 const int64_t k1MinuteInterval = 60LL * 10000000LL; // 1 minute |
57 | 60 |
58 } // namespace anonymous | 61 } // namespace anonymous |
59 | 62 |
60 class FinancialPingTest : public RlzLibTestBase { | 63 class FinancialPingTest : public RlzLibTestBase { |
61 }; | 64 }; |
62 | 65 |
63 TEST_F(FinancialPingTest, FormRequest) { | 66 TEST_F(FinancialPingTest, FormRequest) { |
64 std::string brand_string = rlz_lib::SupplementaryBranding::GetBrand(); | 67 std::string brand_string = rlz_lib::SupplementaryBranding::GetBrand(); |
65 const char* brand = brand_string.empty() ? "GGLA" : brand_string.c_str(); | 68 const char* brand = brand_string.empty() ? "GGLA" : brand_string.c_str(); |
66 | 69 |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
171 rlz_lib::AccessPoint points[] = | 174 rlz_lib::AccessPoint points[] = |
172 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, | 175 {rlz_lib::IETB_SEARCH_BOX, rlz_lib::NO_ACCESS_POINT, |
173 rlz_lib::NO_ACCESS_POINT}; | 176 rlz_lib::NO_ACCESS_POINT}; |
174 | 177 |
175 std::string request; | 178 std::string request; |
176 bool ok = rlz_lib::FinancialPing::FormRequest(rlz_lib::TOOLBAR_NOTIFIER, | 179 bool ok = rlz_lib::FinancialPing::FormRequest(rlz_lib::TOOLBAR_NOTIFIER, |
177 points, "swg", "GOOG", NULL, "en", false, &request); | 180 points, "swg", "GOOG", NULL, "en", false, &request); |
178 EXPECT_EQ(rlz_lib::SupplementaryBranding::GetBrand().empty(), ok); | 181 EXPECT_EQ(rlz_lib::SupplementaryBranding::GetBrand().empty(), ok); |
179 } | 182 } |
180 | 183 |
181 | 184 static void SetLastPingTime(int64_t time, rlz_lib::Product product) { |
182 static void SetLastPingTime(int64 time, rlz_lib::Product product) { | |
183 rlz_lib::ScopedRlzValueStoreLock lock; | 185 rlz_lib::ScopedRlzValueStoreLock lock; |
184 rlz_lib::RlzValueStore* store = lock.GetStore(); | 186 rlz_lib::RlzValueStore* store = lock.GetStore(); |
185 ASSERT_TRUE(store); | 187 ASSERT_TRUE(store); |
186 ASSERT_TRUE(store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess)); | 188 ASSERT_TRUE(store->HasAccess(rlz_lib::RlzValueStore::kWriteAccess)); |
187 store->WritePingTime(product, time); | 189 store->WritePingTime(product, time); |
188 } | 190 } |
189 | 191 |
190 TEST_F(FinancialPingTest, IsPingTime) { | 192 TEST_F(FinancialPingTest, IsPingTime) { |
191 int64 now = GetSystemTimeAsInt64(); | 193 int64_t now = GetSystemTimeAsInt64(); |
192 int64 last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval; | 194 int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval; |
193 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); | 195 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); |
194 | 196 |
195 // No events, last ping just over a day ago. | 197 // No events, last ping just over a day ago. |
196 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | 198 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); |
197 EXPECT_FALSE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 199 EXPECT_FALSE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
198 false)); | 200 false)); |
199 | 201 |
200 // Has events, last ping just over a day ago. | 202 // Has events, last ping just over a day ago. |
201 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 203 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
202 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | 204 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); |
(...skipping 30 matching lines...) Expand all Loading... |
233 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 235 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
234 false)); | 236 false)); |
235 } | 237 } |
236 | 238 |
237 TEST_F(FinancialPingTest, BrandingIsPingTime) { | 239 TEST_F(FinancialPingTest, BrandingIsPingTime) { |
238 // Don't run these tests if a supplementary brand is already in place. That | 240 // Don't run these tests if a supplementary brand is already in place. That |
239 // way we can control the branding. | 241 // way we can control the branding. |
240 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) | 242 if (!rlz_lib::SupplementaryBranding::GetBrand().empty()) |
241 return; | 243 return; |
242 | 244 |
243 int64 now = GetSystemTimeAsInt64(); | 245 int64_t now = GetSystemTimeAsInt64(); |
244 int64 last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval; | 246 int64_t last_ping = now - rlz_lib::kEventsPingInterval - k1MinuteInterval; |
245 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); | 247 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); |
246 | 248 |
247 // Has events, last ping just over a day ago. | 249 // Has events, last ping just over a day ago. |
248 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 250 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
249 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | 251 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); |
250 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 252 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
251 false)); | 253 false)); |
252 | 254 |
253 { | 255 { |
254 rlz_lib::SupplementaryBranding branding("TEST"); | 256 rlz_lib::SupplementaryBranding branding("TEST"); |
(...skipping 13 matching lines...) Expand all Loading... |
268 false)); | 270 false)); |
269 | 271 |
270 { | 272 { |
271 rlz_lib::SupplementaryBranding branding("TEST"); | 273 rlz_lib::SupplementaryBranding branding("TEST"); |
272 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 274 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
273 false)); | 275 false)); |
274 } | 276 } |
275 } | 277 } |
276 | 278 |
277 TEST_F(FinancialPingTest, ClearLastPingTime) { | 279 TEST_F(FinancialPingTest, ClearLastPingTime) { |
278 int64 now = GetSystemTimeAsInt64(); | 280 int64_t now = GetSystemTimeAsInt64(); |
279 int64 last_ping = now - rlz_lib::kEventsPingInterval + k1MinuteInterval; | 281 int64_t last_ping = now - rlz_lib::kEventsPingInterval + k1MinuteInterval; |
280 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); | 282 SetLastPingTime(last_ping, rlz_lib::TOOLBAR_NOTIFIER); |
281 | 283 |
282 // Has events, last ping just under a day ago. | 284 // Has events, last ping just under a day ago. |
283 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); | 285 EXPECT_TRUE(rlz_lib::ClearAllProductEvents(rlz_lib::TOOLBAR_NOTIFIER)); |
284 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, | 286 EXPECT_TRUE(rlz_lib::RecordProductEvent(rlz_lib::TOOLBAR_NOTIFIER, |
285 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); | 287 rlz_lib::IE_DEFAULT_SEARCH, rlz_lib::SET_TO_GOOGLE)); |
286 EXPECT_FALSE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 288 EXPECT_FALSE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
287 false)); | 289 false)); |
288 | 290 |
289 EXPECT_TRUE(rlz_lib::FinancialPing::ClearLastPingTime( | 291 EXPECT_TRUE(rlz_lib::FinancialPing::ClearLastPingTime( |
290 rlz_lib::TOOLBAR_NOTIFIER)); | 292 rlz_lib::TOOLBAR_NOTIFIER)); |
291 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, | 293 EXPECT_TRUE(rlz_lib::FinancialPing::IsPingTime(rlz_lib::TOOLBAR_NOTIFIER, |
292 false)); | 294 false)); |
293 } | 295 } |
OLD | NEW |