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 #include "chrome/browser/rlz/rlz.h" | 5 #include "chrome/browser/rlz/rlz.h" |
6 | 6 |
7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
8 #include "base/memory/scoped_ptr.h" | 8 #include "base/memory/scoped_ptr.h" |
9 #include "base/message_loop.h" | 9 #include "base/message_loop.h" |
10 #include "base/path_service.h" | 10 #include "base/path_service.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/browser/navigation_entry.h" | 21 #include "content/public/browser/navigation_entry.h" |
22 #include "content/public/browser/notification_details.h" | 22 #include "content/public/browser/notification_details.h" |
23 #include "content/public/browser/notification_service.h" | 23 #include "content/public/browser/notification_service.h" |
24 #include "content/public/browser/notification_source.h" | 24 #include "content/public/browser/notification_source.h" |
25 #include "testing/gtest/include/gtest/gtest.h" | 25 #include "testing/gtest/include/gtest/gtest.h" |
26 | 26 |
27 #if defined(OS_WIN) | 27 #if defined(OS_WIN) |
28 #include "base/test/test_reg_util_win.h" | 28 #include "base/test/test_reg_util_win.h" |
29 #include "base/win/registry.h" | 29 #include "base/win/registry.h" |
30 #include "rlz/win/lib/rlz_lib.h" // InitializeTempHivesForTesting | 30 #include "rlz/win/lib/rlz_lib.h" // InitializeTempHivesForTesting |
31 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 31 #elif defined(OS_POSIX) |
32 #include "rlz/lib/rlz_value_store.h" // SetRlzStoreDirectory | 32 #include "rlz/lib/rlz_value_store.h" // SetRlzStoreDirectory |
33 #endif | 33 #endif |
34 #if defined(OS_CHROMEOS) | |
35 #include "rlz/chromeos/lib/rlz_value_store_chromeos.h" | |
36 #endif | |
37 | 34 |
38 using content::NavigationEntry; | 35 using content::NavigationEntry; |
39 using testing::AssertionResult; | 36 using testing::AssertionResult; |
40 using testing::AssertionSuccess; | 37 using testing::AssertionSuccess; |
41 using testing::AssertionFailure; | 38 using testing::AssertionFailure; |
42 | 39 |
43 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
44 using base::win::RegKey; | 41 using base::win::RegKey; |
45 using registry_util::RegistryOverrideManager; | 42 using registry_util::RegistryOverrideManager; |
46 #endif | 43 #endif |
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
92 | 89 |
93 #define EXPECT_STR_NOT_CONTAIN(str, substr) \ | 90 #define EXPECT_STR_NOT_CONTAIN(str, substr) \ |
94 EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr) | 91 EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr) |
95 | 92 |
96 } // namespace | 93 } // namespace |
97 | 94 |
98 // Test class for RLZ tracker. Makes some member functions public and | 95 // Test class for RLZ tracker. Makes some member functions public and |
99 // overrides others to make it easier to test. | 96 // overrides others to make it easier to test. |
100 class TestRLZTracker : public RLZTracker { | 97 class TestRLZTracker : public RLZTracker { |
101 public: | 98 public: |
| 99 using RLZTracker::InitRlzDelayed; |
102 using RLZTracker::DelayedInit; | 100 using RLZTracker::DelayedInit; |
103 using RLZTracker::Observe; | 101 using RLZTracker::Observe; |
104 | 102 |
105 TestRLZTracker() : assume_not_ui_thread_(true) { | 103 TestRLZTracker() : assume_not_ui_thread_(true) { |
106 set_tracker(this); | 104 set_tracker(this); |
107 } | 105 } |
108 | 106 |
109 virtual ~TestRLZTracker() { | 107 virtual ~TestRLZTracker() { |
110 set_tracker(NULL); | 108 set_tracker(NULL); |
111 } | 109 } |
112 | 110 |
113 bool was_ping_sent_for_brand(const std::string& brand) const { | 111 bool was_ping_sent_for_brand(const std::string& brand) const { |
114 return pinged_brands_.count(brand) > 0; | 112 return pinged_brands_.count(brand) > 0; |
115 } | 113 } |
116 | 114 |
117 void set_assume_not_ui_thread(bool assume_not_ui_thread) { | 115 void set_assume_not_ui_thread(bool assume_not_ui_thread) { |
118 assume_not_ui_thread_ = assume_not_ui_thread; | 116 assume_not_ui_thread_ = assume_not_ui_thread; |
119 } | 117 } |
120 | 118 |
121 private: | 119 private: |
122 virtual bool InitWorkers() OVERRIDE { | |
123 return true; | |
124 } | |
125 | |
126 virtual void ScheduleDelayedInit(int delay) OVERRIDE { | 120 virtual void ScheduleDelayedInit(int delay) OVERRIDE { |
127 // If the delay is 0, invoke the delayed init now. Otherwise, | 121 // If the delay is 0, invoke the delayed init now. Otherwise, |
128 // don't schedule anything, it will be manually called during tests. | 122 // don't schedule anything, it will be manually called during tests. |
129 if (delay == 0) | 123 if (delay == 0) |
130 DelayedInit(); | 124 DelayedInit(); |
131 } | 125 } |
132 | 126 |
133 virtual void ScheduleFinancialPing() OVERRIDE { | 127 virtual void ScheduleFinancialPing() OVERRIDE { |
134 PingNowImpl(); | 128 PingNowImpl(); |
135 } | 129 } |
(...skipping 29 matching lines...) Expand all Loading... |
165 } | 159 } |
166 | 160 |
167 std::set<std::string> pinged_brands_; | 161 std::set<std::string> pinged_brands_; |
168 bool assume_not_ui_thread_; | 162 bool assume_not_ui_thread_; |
169 | 163 |
170 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); | 164 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); |
171 }; | 165 }; |
172 | 166 |
173 class RlzLibTest : public testing::Test { | 167 class RlzLibTest : public testing::Test { |
174 public: | 168 public: |
175 #if defined(OS_CHROMEOS) | |
176 RlzLibTest(); | |
177 #endif | |
178 | |
179 virtual void SetUp() OVERRIDE; | 169 virtual void SetUp() OVERRIDE; |
180 virtual void TearDown() OVERRIDE; | 170 virtual void TearDown() OVERRIDE; |
181 | 171 |
182 protected: | 172 protected: |
183 void SetMainBrand(const char* brand); | 173 void SetMainBrand(const char* brand); |
184 void SetReactivationBrand(const char* brand); | 174 void SetReactivationBrand(const char* brand); |
185 #if defined(OS_WIN) | 175 #if defined(OS_WIN) |
186 void SetRegistryBrandValue(const wchar_t* name, const char* brand); | 176 void SetRegistryBrandValue(const wchar_t* name, const char* brand); |
187 #endif | 177 #endif |
188 | 178 |
189 void SimulateOmniboxUsage(); | 179 void SimulateOmniboxUsage(); |
190 void SimulateHomepageUsage(); | 180 void SimulateHomepageUsage(); |
191 void InvokeDelayedInit(); | 181 void InvokeDelayedInit(); |
192 | 182 |
193 void ExpectEventRecorded(const char* event_name, bool expected); | 183 void ExpectEventRecorded(const char* event_name, bool expected); |
194 void ExpectRlzPingSent(bool expected); | 184 void ExpectRlzPingSent(bool expected); |
195 void ExpectReactivationRlzPingSent(bool expected); | 185 void ExpectReactivationRlzPingSent(bool expected); |
196 | 186 |
197 TestRLZTracker tracker_; | 187 TestRLZTracker tracker_; |
198 #if defined(OS_WIN) | 188 #if defined(OS_WIN) |
199 RegistryOverrideManager override_manager_; | 189 RegistryOverrideManager override_manager_; |
200 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 190 #elif defined(OS_POSIX) |
201 base::ScopedTempDir temp_dir_; | 191 base::ScopedTempDir temp_dir_; |
202 scoped_ptr<google_util::BrandForTesting> brand_override_; | 192 scoped_ptr<google_util::BrandForTesting> brand_override_; |
203 #endif | 193 #endif |
204 #if defined(OS_CHROMEOS) | |
205 MessageLoop loop_; | |
206 base::Thread io_thread_; | |
207 #endif | |
208 }; | 194 }; |
209 | 195 |
210 #if defined(OS_CHROMEOS) | |
211 RlzLibTest::RlzLibTest() | |
212 : io_thread_("RlzLibTest-io") { | |
213 } | |
214 #endif | |
215 | |
216 void RlzLibTest::SetUp() { | 196 void RlzLibTest::SetUp() { |
217 testing::Test::SetUp(); | 197 testing::Test::SetUp(); |
218 | 198 |
219 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
220 // Before overriding HKLM for the tests, we need to set it up correctly | 200 // Before overriding HKLM for the tests, we need to set it up correctly |
221 // so that the rlz_lib calls work. This needs to be done before we do the | 201 // so that the rlz_lib calls work. This needs to be done before we do the |
222 // override. | 202 // override. |
223 | 203 |
224 string16 temp_hklm_path = base::StringPrintf( | 204 string16 temp_hklm_path = base::StringPrintf( |
225 L"%ls\\%ls", | 205 L"%ls\\%ls", |
(...skipping 14 matching lines...) Expand all Loading... |
240 ASSERT_EQ(ERROR_SUCCESS, hkcu.Create(HKEY_CURRENT_USER, | 220 ASSERT_EQ(ERROR_SUCCESS, hkcu.Create(HKEY_CURRENT_USER, |
241 temp_hkcu_path.c_str(), | 221 temp_hkcu_path.c_str(), |
242 KEY_READ)); | 222 KEY_READ)); |
243 | 223 |
244 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu); | 224 rlz_lib::InitializeTempHivesForTesting(hklm, hkcu); |
245 | 225 |
246 // Its important to override HKLM before HKCU because of the registry | 226 // Its important to override HKLM before HKCU because of the registry |
247 // initialization performed above. | 227 // initialization performed above. |
248 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, kRlzTempHklm); | 228 override_manager_.OverrideRegistry(HKEY_LOCAL_MACHINE, kRlzTempHklm); |
249 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, kRlzTempHkcu); | 229 override_manager_.OverrideRegistry(HKEY_CURRENT_USER, kRlzTempHkcu); |
250 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 230 #elif defined(OS_POSIX) |
251 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | 231 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
252 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); | 232 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); |
253 #endif | 233 #endif |
254 | 234 |
255 #if defined(OS_CHROMEOS) | |
256 base::Thread::Options options; | |
257 options.message_loop_type = MessageLoop::TYPE_IO; | |
258 ASSERT_TRUE(io_thread_.StartWithOptions(options)); | |
259 rlz_lib::SetIOTaskRunner(io_thread_.message_loop_proxy()); | |
260 rlz_lib::RlzValueStoreChromeOS::ResetForTesting(); | |
261 #endif | |
262 | |
263 // Make sure a non-organic brand code is set in the registry or the RLZTracker | 235 // Make sure a non-organic brand code is set in the registry or the RLZTracker |
264 // is pretty much a no-op. | 236 // is pretty much a no-op. |
265 SetMainBrand("TEST"); | 237 SetMainBrand("TEST"); |
266 SetReactivationBrand(""); | 238 SetReactivationBrand(""); |
267 } | 239 } |
268 | 240 |
269 void RlzLibTest::TearDown() { | 241 void RlzLibTest::TearDown() { |
270 #if defined(OS_MACOSX) || defined(OS_CHROMEOS) | 242 #if defined(OS_POSIX) |
271 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); | 243 rlz_lib::testing::SetRlzStoreDirectory(FilePath()); |
272 #endif | 244 #endif |
273 #if defined(OS_CHROMEOS) | |
274 io_thread_.Stop(); | |
275 #endif // defined(OS_CHROMEOS) | |
276 testing::Test::TearDown(); | 245 testing::Test::TearDown(); |
277 } | 246 } |
278 | 247 |
279 void RlzLibTest::SetMainBrand(const char* brand) { | 248 void RlzLibTest::SetMainBrand(const char* brand) { |
280 #if defined(OS_WIN) | 249 #if defined(OS_WIN) |
281 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); | 250 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
282 #elif defined(OS_MACOSX) || defined(OS_CHROMEOS) | 251 #elif defined(OS_POSIX) |
283 brand_override_.reset(new google_util::BrandForTesting(brand)); | 252 brand_override_.reset(new google_util::BrandForTesting(brand)); |
284 #endif | 253 #endif |
285 std::string check_brand; | 254 std::string check_brand; |
286 google_util::GetBrand(&check_brand); | 255 google_util::GetBrand(&check_brand); |
287 EXPECT_EQ(brand, check_brand); | 256 EXPECT_EQ(brand, check_brand); |
288 } | 257 } |
289 | 258 |
290 void RlzLibTest::SetReactivationBrand(const char* brand) { | 259 void RlzLibTest::SetReactivationBrand(const char* brand) { |
291 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 260 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
292 #if defined(OS_WIN) | 261 #if defined(OS_WIN) |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 #endif | 383 #endif |
415 | 384 |
416 TEST_F(RlzLibTest, RecordProductEvent) { | 385 TEST_F(RlzLibTest, RecordProductEvent) { |
417 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::CHROME_OMNIBOX, | 386 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::CHROME_OMNIBOX, |
418 rlz_lib::FIRST_SEARCH); | 387 rlz_lib::FIRST_SEARCH); |
419 | 388 |
420 ExpectEventRecorded(kOmniboxFirstSearch, true); | 389 ExpectEventRecorded(kOmniboxFirstSearch, true); |
421 } | 390 } |
422 | 391 |
423 TEST_F(RlzLibTest, QuickStopAfterStart) { | 392 TEST_F(RlzLibTest, QuickStopAfterStart) { |
424 RLZTracker::InitRlzDelayed(true, 20, true, true, true); | 393 TestRLZTracker::InitRlzDelayed(true, 20, true, true, true); |
425 | 394 |
426 // Omnibox events. | 395 // Omnibox events. |
427 ExpectEventRecorded(kOmniboxInstall, false); | 396 ExpectEventRecorded(kOmniboxInstall, false); |
428 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 397 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
429 ExpectEventRecorded(kOmniboxFirstSearch, false); | 398 ExpectEventRecorded(kOmniboxFirstSearch, false); |
430 | 399 |
431 // Home page events. | 400 // Home page events. |
432 ExpectEventRecorded(kHomepageInstall, false); | 401 ExpectEventRecorded(kHomepageInstall, false); |
433 ExpectEventRecorded(kHomepageSetToGoogle, false); | 402 ExpectEventRecorded(kHomepageSetToGoogle, false); |
434 ExpectEventRecorded(kHomepageFirstSeach, false); | 403 ExpectEventRecorded(kHomepageFirstSeach, false); |
435 | 404 |
436 ExpectRlzPingSent(false); | 405 ExpectRlzPingSent(false); |
437 } | 406 } |
438 | 407 |
439 TEST_F(RlzLibTest, DelayedInitOnly) { | 408 TEST_F(RlzLibTest, DelayedInitOnly) { |
440 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 409 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
441 InvokeDelayedInit(); | 410 InvokeDelayedInit(); |
442 | 411 |
443 // Omnibox events. | 412 // Omnibox events. |
444 ExpectEventRecorded(kOmniboxInstall, true); | 413 ExpectEventRecorded(kOmniboxInstall, true); |
445 ExpectEventRecorded(kOmniboxSetToGoogle, true); | 414 ExpectEventRecorded(kOmniboxSetToGoogle, true); |
446 ExpectEventRecorded(kOmniboxFirstSearch, false); | 415 ExpectEventRecorded(kOmniboxFirstSearch, false); |
447 | 416 |
448 // Home page events. | 417 // Home page events. |
449 ExpectEventRecorded(kHomepageInstall, true); | 418 ExpectEventRecorded(kHomepageInstall, true); |
450 ExpectEventRecorded(kHomepageSetToGoogle, true); | 419 ExpectEventRecorded(kHomepageSetToGoogle, true); |
451 ExpectEventRecorded(kHomepageFirstSeach, false); | 420 ExpectEventRecorded(kHomepageFirstSeach, false); |
452 | 421 |
453 ExpectRlzPingSent(true); | 422 ExpectRlzPingSent(true); |
454 } | 423 } |
455 | 424 |
456 TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) { | 425 TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) { |
457 RLZTracker::InitRlzDelayed(true, 20, false, false, true); | 426 TestRLZTracker::InitRlzDelayed(true, 20, false, false, true); |
458 InvokeDelayedInit(); | 427 InvokeDelayedInit(); |
459 | 428 |
460 // Omnibox events. | 429 // Omnibox events. |
461 ExpectEventRecorded(kOmniboxInstall, true); | 430 ExpectEventRecorded(kOmniboxInstall, true); |
462 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 431 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
463 ExpectEventRecorded(kOmniboxFirstSearch, false); | 432 ExpectEventRecorded(kOmniboxFirstSearch, false); |
464 | 433 |
465 // Home page events. | 434 // Home page events. |
466 ExpectEventRecorded(kHomepageInstall, true); | 435 ExpectEventRecorded(kHomepageInstall, true); |
467 ExpectEventRecorded(kHomepageSetToGoogle, true); | 436 ExpectEventRecorded(kHomepageSetToGoogle, true); |
468 ExpectEventRecorded(kHomepageFirstSeach, true); | 437 ExpectEventRecorded(kHomepageFirstSeach, true); |
469 | 438 |
470 ExpectRlzPingSent(true); | 439 ExpectRlzPingSent(true); |
471 } | 440 } |
472 | 441 |
473 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) { | 442 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) { |
474 RLZTracker::InitRlzDelayed(false, 20, true, true, false); | 443 TestRLZTracker::InitRlzDelayed(false, 20, true, true, false); |
475 InvokeDelayedInit(); | 444 InvokeDelayedInit(); |
476 | 445 |
477 // Omnibox events. | 446 // Omnibox events. |
478 ExpectEventRecorded(kOmniboxInstall, true); | 447 ExpectEventRecorded(kOmniboxInstall, true); |
479 ExpectEventRecorded(kOmniboxSetToGoogle, true); | 448 ExpectEventRecorded(kOmniboxSetToGoogle, true); |
480 ExpectEventRecorded(kOmniboxFirstSearch, false); | 449 ExpectEventRecorded(kOmniboxFirstSearch, false); |
481 | 450 |
482 // Home page events. | 451 // Home page events. |
483 ExpectEventRecorded(kHomepageInstall, true); | 452 ExpectEventRecorded(kHomepageInstall, true); |
484 ExpectEventRecorded(kHomepageSetToGoogle, true); | 453 ExpectEventRecorded(kHomepageSetToGoogle, true); |
485 ExpectEventRecorded(kHomepageFirstSeach, false); | 454 ExpectEventRecorded(kHomepageFirstSeach, false); |
486 | 455 |
487 ExpectRlzPingSent(true); | 456 ExpectRlzPingSent(true); |
488 } | 457 } |
489 | 458 |
490 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) { | 459 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) { |
491 RLZTracker::InitRlzDelayed(false, 20, false, false, true); | 460 TestRLZTracker::InitRlzDelayed(false, 20, false, false, true); |
492 InvokeDelayedInit(); | 461 InvokeDelayedInit(); |
493 | 462 |
494 // Omnibox events. | 463 // Omnibox events. |
495 ExpectEventRecorded(kOmniboxInstall, true); | 464 ExpectEventRecorded(kOmniboxInstall, true); |
496 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 465 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
497 ExpectEventRecorded(kOmniboxFirstSearch, false); | 466 ExpectEventRecorded(kOmniboxFirstSearch, false); |
498 | 467 |
499 // Home page events. | 468 // Home page events. |
500 ExpectEventRecorded(kHomepageInstall, true); | 469 ExpectEventRecorded(kHomepageInstall, true); |
501 ExpectEventRecorded(kHomepageSetToGoogle, true); | 470 ExpectEventRecorded(kHomepageSetToGoogle, true); |
502 ExpectEventRecorded(kHomepageFirstSeach, true); | 471 ExpectEventRecorded(kHomepageFirstSeach, true); |
503 | 472 |
504 ExpectRlzPingSent(true); | 473 ExpectRlzPingSent(true); |
505 } | 474 } |
506 | 475 |
507 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) { | 476 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) { |
508 // Set some dummy RLZ strings to simulate that we already ran before and | 477 // Set some dummy RLZ strings to simulate that we already ran before and |
509 // performed a successful ping to the RLZ server. | 478 // performed a successful ping to the RLZ server. |
510 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, kOmniboxRlzString); | 479 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, kOmniboxRlzString); |
511 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE, kHomepageRlzString); | 480 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE, kHomepageRlzString); |
512 | 481 |
513 RLZTracker::InitRlzDelayed(false, 20, true, true, true); | 482 TestRLZTracker::InitRlzDelayed(false, 20, true, true, true); |
514 InvokeDelayedInit(); | 483 InvokeDelayedInit(); |
515 | 484 |
516 // Omnibox events. | 485 // Omnibox events. |
517 ExpectEventRecorded(kOmniboxInstall, true); | 486 ExpectEventRecorded(kOmniboxInstall, true); |
518 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 487 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
519 ExpectEventRecorded(kOmniboxFirstSearch, false); | 488 ExpectEventRecorded(kOmniboxFirstSearch, false); |
520 | 489 |
521 // Home page events. | 490 // Home page events. |
522 ExpectEventRecorded(kHomepageInstall, true); | 491 ExpectEventRecorded(kHomepageInstall, true); |
523 ExpectEventRecorded(kHomepageSetToGoogle, false); | 492 ExpectEventRecorded(kHomepageSetToGoogle, false); |
524 ExpectEventRecorded(kHomepageFirstSeach, true); | 493 ExpectEventRecorded(kHomepageFirstSeach, true); |
525 | 494 |
526 ExpectRlzPingSent(true); | 495 ExpectRlzPingSent(true); |
527 } | 496 } |
528 | 497 |
529 TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) { | 498 TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) { |
530 RLZTracker::InitRlzDelayed(true, 20, false, false, false); | 499 TestRLZTracker::InitRlzDelayed(true, 20, false, false, false); |
531 InvokeDelayedInit(); | 500 InvokeDelayedInit(); |
532 | 501 |
533 // Omnibox events. | 502 // Omnibox events. |
534 ExpectEventRecorded(kOmniboxInstall, true); | 503 ExpectEventRecorded(kOmniboxInstall, true); |
535 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 504 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
536 ExpectEventRecorded(kOmniboxFirstSearch, false); | 505 ExpectEventRecorded(kOmniboxFirstSearch, false); |
537 | 506 |
538 // Home page events. | 507 // Home page events. |
539 ExpectEventRecorded(kHomepageInstall, true); | 508 ExpectEventRecorded(kHomepageInstall, true); |
540 ExpectEventRecorded(kHomepageSetToGoogle, false); | 509 ExpectEventRecorded(kHomepageSetToGoogle, false); |
541 ExpectEventRecorded(kHomepageFirstSeach, false); | 510 ExpectEventRecorded(kHomepageFirstSeach, false); |
542 | 511 |
543 ExpectRlzPingSent(true); | 512 ExpectRlzPingSent(true); |
544 } | 513 } |
545 | 514 |
546 TEST_F(RlzLibTest, OmniboxUsageOnly) { | 515 TEST_F(RlzLibTest, OmniboxUsageOnly) { |
547 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 516 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
548 SimulateOmniboxUsage(); | 517 SimulateOmniboxUsage(); |
549 | 518 |
550 // Omnibox events. | 519 // Omnibox events. |
551 ExpectEventRecorded(kOmniboxInstall, false); | 520 ExpectEventRecorded(kOmniboxInstall, false); |
552 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 521 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
553 ExpectEventRecorded(kOmniboxFirstSearch, true); | 522 ExpectEventRecorded(kOmniboxFirstSearch, true); |
554 | 523 |
555 // Home page events. | 524 // Home page events. |
556 ExpectEventRecorded(kHomepageInstall, false); | 525 ExpectEventRecorded(kHomepageInstall, false); |
557 ExpectEventRecorded(kHomepageSetToGoogle, false); | 526 ExpectEventRecorded(kHomepageSetToGoogle, false); |
558 ExpectEventRecorded(kHomepageFirstSeach, false); | 527 ExpectEventRecorded(kHomepageFirstSeach, false); |
559 | 528 |
560 ExpectRlzPingSent(false); | 529 ExpectRlzPingSent(false); |
561 } | 530 } |
562 | 531 |
563 TEST_F(RlzLibTest, HomepageUsageOnly) { | 532 TEST_F(RlzLibTest, HomepageUsageOnly) { |
564 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 533 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
565 SimulateHomepageUsage(); | 534 SimulateHomepageUsage(); |
566 | 535 |
567 // Omnibox events. | 536 // Omnibox events. |
568 ExpectEventRecorded(kOmniboxInstall, false); | 537 ExpectEventRecorded(kOmniboxInstall, false); |
569 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 538 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
570 ExpectEventRecorded(kOmniboxFirstSearch, false); | 539 ExpectEventRecorded(kOmniboxFirstSearch, false); |
571 | 540 |
572 // Home page events. | 541 // Home page events. |
573 ExpectEventRecorded(kHomepageInstall, false); | 542 ExpectEventRecorded(kHomepageInstall, false); |
574 ExpectEventRecorded(kHomepageSetToGoogle, false); | 543 ExpectEventRecorded(kHomepageSetToGoogle, false); |
575 ExpectEventRecorded(kHomepageFirstSeach, true); | 544 ExpectEventRecorded(kHomepageFirstSeach, true); |
576 | 545 |
577 ExpectRlzPingSent(false); | 546 ExpectRlzPingSent(false); |
578 } | 547 } |
579 | 548 |
580 TEST_F(RlzLibTest, UsageBeforeDelayedInit) { | 549 TEST_F(RlzLibTest, UsageBeforeDelayedInit) { |
581 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 550 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
582 SimulateOmniboxUsage(); | 551 SimulateOmniboxUsage(); |
583 SimulateHomepageUsage(); | 552 SimulateHomepageUsage(); |
584 InvokeDelayedInit(); | 553 InvokeDelayedInit(); |
585 | 554 |
586 // Omnibox events. | 555 // Omnibox events. |
587 ExpectEventRecorded(kOmniboxInstall, true); | 556 ExpectEventRecorded(kOmniboxInstall, true); |
588 ExpectEventRecorded(kOmniboxSetToGoogle, true); | 557 ExpectEventRecorded(kOmniboxSetToGoogle, true); |
589 ExpectEventRecorded(kOmniboxFirstSearch, true); | 558 ExpectEventRecorded(kOmniboxFirstSearch, true); |
590 | 559 |
591 // Home page events. | 560 // Home page events. |
592 ExpectEventRecorded(kHomepageInstall, true); | 561 ExpectEventRecorded(kHomepageInstall, true); |
593 ExpectEventRecorded(kHomepageSetToGoogle, true); | 562 ExpectEventRecorded(kHomepageSetToGoogle, true); |
594 ExpectEventRecorded(kHomepageFirstSeach, true); | 563 ExpectEventRecorded(kHomepageFirstSeach, true); |
595 | 564 |
596 ExpectRlzPingSent(true); | 565 ExpectRlzPingSent(true); |
597 } | 566 } |
598 | 567 |
599 TEST_F(RlzLibTest, OmniboxUsageAfterDelayedInit) { | 568 TEST_F(RlzLibTest, OmniboxUsageAfterDelayedInit) { |
600 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 569 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
601 InvokeDelayedInit(); | 570 InvokeDelayedInit(); |
602 SimulateOmniboxUsage(); | 571 SimulateOmniboxUsage(); |
603 SimulateHomepageUsage(); | 572 SimulateHomepageUsage(); |
604 | 573 |
605 // Omnibox events. | 574 // Omnibox events. |
606 ExpectEventRecorded(kOmniboxInstall, true); | 575 ExpectEventRecorded(kOmniboxInstall, true); |
607 ExpectEventRecorded(kOmniboxSetToGoogle, true); | 576 ExpectEventRecorded(kOmniboxSetToGoogle, true); |
608 ExpectEventRecorded(kOmniboxFirstSearch, true); | 577 ExpectEventRecorded(kOmniboxFirstSearch, true); |
609 | 578 |
610 // Home page events. | 579 // Home page events. |
611 ExpectEventRecorded(kHomepageInstall, true); | 580 ExpectEventRecorded(kHomepageInstall, true); |
612 ExpectEventRecorded(kHomepageSetToGoogle, true); | 581 ExpectEventRecorded(kHomepageSetToGoogle, true); |
613 ExpectEventRecorded(kHomepageFirstSeach, true); | 582 ExpectEventRecorded(kHomepageFirstSeach, true); |
614 | 583 |
615 ExpectRlzPingSent(true); | 584 ExpectRlzPingSent(true); |
616 } | 585 } |
617 | 586 |
618 TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenDelayNegative) { | 587 TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenDelayNegative) { |
619 RLZTracker::InitRlzDelayed(true, -20, true, true, false); | 588 TestRLZTracker::InitRlzDelayed(true, -20, true, true, false); |
620 SimulateOmniboxUsage(); | 589 SimulateOmniboxUsage(); |
621 | 590 |
622 // Omnibox events. | 591 // Omnibox events. |
623 ExpectEventRecorded(kOmniboxInstall, true); | 592 ExpectEventRecorded(kOmniboxInstall, true); |
624 ExpectEventRecorded(kOmniboxSetToGoogle, true); | 593 ExpectEventRecorded(kOmniboxSetToGoogle, true); |
625 ExpectEventRecorded(kOmniboxFirstSearch, true); | 594 ExpectEventRecorded(kOmniboxFirstSearch, true); |
626 | 595 |
627 // Home page events. | 596 // Home page events. |
628 ExpectEventRecorded(kHomepageInstall, true); | 597 ExpectEventRecorded(kHomepageInstall, true); |
629 ExpectEventRecorded(kHomepageSetToGoogle, true); | 598 ExpectEventRecorded(kHomepageSetToGoogle, true); |
630 ExpectEventRecorded(kHomepageFirstSeach, false); | 599 ExpectEventRecorded(kHomepageFirstSeach, false); |
631 | 600 |
632 ExpectRlzPingSent(true); | 601 ExpectRlzPingSent(true); |
633 } | 602 } |
634 | 603 |
635 TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenDelayNegative) { | 604 TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenDelayNegative) { |
636 RLZTracker::InitRlzDelayed(true, -20, true, true, false); | 605 TestRLZTracker::InitRlzDelayed(true, -20, true, true, false); |
637 SimulateHomepageUsage(); | 606 SimulateHomepageUsage(); |
638 | 607 |
639 // Omnibox events. | 608 // Omnibox events. |
640 ExpectEventRecorded(kOmniboxInstall, false); | 609 ExpectEventRecorded(kOmniboxInstall, false); |
641 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 610 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
642 ExpectEventRecorded(kOmniboxFirstSearch, false); | 611 ExpectEventRecorded(kOmniboxFirstSearch, false); |
643 | 612 |
644 // Home page events. | 613 // Home page events. |
645 ExpectEventRecorded(kHomepageInstall, false); | 614 ExpectEventRecorded(kHomepageInstall, false); |
646 ExpectEventRecorded(kHomepageSetToGoogle, false); | 615 ExpectEventRecorded(kHomepageSetToGoogle, false); |
647 ExpectEventRecorded(kHomepageFirstSeach, true); | 616 ExpectEventRecorded(kHomepageFirstSeach, true); |
648 | 617 |
649 ExpectRlzPingSent(false); | 618 ExpectRlzPingSent(false); |
650 } | 619 } |
651 | 620 |
652 TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenDelayNegative) { | 621 TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenDelayNegative) { |
653 RLZTracker::InitRlzDelayed(true, -20, true, false, true); | 622 TestRLZTracker::InitRlzDelayed(true, -20, true, false, true); |
654 SimulateHomepageUsage(); | 623 SimulateHomepageUsage(); |
655 | 624 |
656 // Omnibox events. | 625 // Omnibox events. |
657 ExpectEventRecorded(kOmniboxInstall, false); | 626 ExpectEventRecorded(kOmniboxInstall, false); |
658 ExpectEventRecorded(kOmniboxSetToGoogle, false); | 627 ExpectEventRecorded(kOmniboxSetToGoogle, false); |
659 ExpectEventRecorded(kOmniboxFirstSearch, false); | 628 ExpectEventRecorded(kOmniboxFirstSearch, false); |
660 | 629 |
661 // Home page events. | 630 // Home page events. |
662 ExpectEventRecorded(kHomepageInstall, false); | 631 ExpectEventRecorded(kHomepageInstall, false); |
663 ExpectEventRecorded(kHomepageSetToGoogle, false); | 632 ExpectEventRecorded(kHomepageSetToGoogle, false); |
(...skipping 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
725 tracker_.set_assume_not_ui_thread(false); | 694 tracker_.set_assume_not_ui_thread(false); |
726 | 695 |
727 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz)); | 696 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz)); |
728 EXPECT_STREQ(kOmniboxRlzString, UTF16ToUTF8(rlz).c_str()); | 697 EXPECT_STREQ(kOmniboxRlzString, UTF16ToUTF8(rlz).c_str()); |
729 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 698 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
730 RLZTracker::CHROME_HOME_PAGE, &rlz)); | 699 RLZTracker::CHROME_HOME_PAGE, &rlz)); |
731 EXPECT_STREQ(kHomepageRlzString, UTF16ToUTF8(rlz).c_str()); | 700 EXPECT_STREQ(kHomepageRlzString, UTF16ToUTF8(rlz).c_str()); |
732 | 701 |
733 // Perform ping. | 702 // Perform ping. |
734 tracker_.set_assume_not_ui_thread(true); | 703 tracker_.set_assume_not_ui_thread(true); |
735 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 704 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
736 InvokeDelayedInit(); | 705 InvokeDelayedInit(); |
737 ExpectRlzPingSent(true); | 706 ExpectRlzPingSent(true); |
738 | 707 |
739 // Make sure cache is now updated. | 708 // Make sure cache is now updated. |
740 tracker_.set_assume_not_ui_thread(false); | 709 tracker_.set_assume_not_ui_thread(false); |
741 | 710 |
742 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz)); | 711 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX, &rlz)); |
743 EXPECT_STREQ(kNewOmniboxRlzString, UTF16ToUTF8(rlz).c_str()); | 712 EXPECT_STREQ(kNewOmniboxRlzString, UTF16ToUTF8(rlz).c_str()); |
744 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 713 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
745 RLZTracker::CHROME_HOME_PAGE, &rlz)); | 714 RLZTracker::CHROME_HOME_PAGE, &rlz)); |
(...skipping 10 matching lines...) Expand all Loading... |
756 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 725 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, |
757 content::NotificationService::AllSources(), | 726 content::NotificationService::AllSources(), |
758 content::Details<NavigationEntry>(entry.get())); | 727 content::Details<NavigationEntry>(entry.get())); |
759 } | 728 } |
760 | 729 |
761 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 730 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
762 #if defined(OS_WIN) | 731 #if defined(OS_WIN) |
763 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { | 732 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { |
764 SetReactivationBrand("REAC"); | 733 SetReactivationBrand("REAC"); |
765 | 734 |
766 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 735 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
767 InvokeDelayedInit(); | 736 InvokeDelayedInit(); |
768 | 737 |
769 ExpectRlzPingSent(true); | 738 ExpectRlzPingSent(true); |
770 ExpectReactivationRlzPingSent(true); | 739 ExpectReactivationRlzPingSent(true); |
771 } | 740 } |
772 | 741 |
773 TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) { | 742 TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) { |
774 SetMainBrand("GGLS"); | 743 SetMainBrand("GGLS"); |
775 SetReactivationBrand("REAC"); | 744 SetReactivationBrand("REAC"); |
776 | 745 |
777 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 746 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
778 InvokeDelayedInit(); | 747 InvokeDelayedInit(); |
779 | 748 |
780 ExpectRlzPingSent(false); | 749 ExpectRlzPingSent(false); |
781 ExpectReactivationRlzPingSent(true); | 750 ExpectReactivationRlzPingSent(true); |
782 } | 751 } |
783 | 752 |
784 TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) { | 753 TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) { |
785 SetMainBrand("TEST"); | 754 SetMainBrand("TEST"); |
786 SetReactivationBrand("GGLS"); | 755 SetReactivationBrand("GGLS"); |
787 | 756 |
788 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 757 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
789 InvokeDelayedInit(); | 758 InvokeDelayedInit(); |
790 | 759 |
791 ExpectRlzPingSent(true); | 760 ExpectRlzPingSent(true); |
792 ExpectReactivationRlzPingSent(false); | 761 ExpectReactivationRlzPingSent(false); |
793 } | 762 } |
794 | 763 |
795 TEST_F(RlzLibTest, ReactivationOrganicOrganic) { | 764 TEST_F(RlzLibTest, ReactivationOrganicOrganic) { |
796 SetMainBrand("GGLS"); | 765 SetMainBrand("GGLS"); |
797 SetReactivationBrand("GGRS"); | 766 SetReactivationBrand("GGRS"); |
798 | 767 |
799 RLZTracker::InitRlzDelayed(true, 20, true, true, false); | 768 TestRLZTracker::InitRlzDelayed(true, 20, true, true, false); |
800 InvokeDelayedInit(); | 769 InvokeDelayedInit(); |
801 | 770 |
802 ExpectRlzPingSent(false); | 771 ExpectRlzPingSent(false); |
803 ExpectReactivationRlzPingSent(false); | 772 ExpectReactivationRlzPingSent(false); |
804 } | 773 } |
805 #endif // defined(OS_WIN) | 774 #endif // defined(OS_WIN) |
OLD | NEW |