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
3 // found in the LICENSE file.
5 #include "chrome/browser/rlz/rlz.h"
7 #include "base/memory/scoped_ptr.h"
8 #include "base/strings/utf_string_conversions.h"
9 #include "chrome/browser/chrome_notification_types.h"
10 #include "chrome/browser/google/google_util.h"
11 #include "chrome/browser/omnibox/omnibox_log.h"
12 #include "chrome/browser/profiles/profile.h"
13 #include "chrome/installer/util/browser_distribution.h"
14 #include "chrome/installer/util/google_update_constants.h"
15 #include "content/public/browser/navigation_entry.h"
16 #include "content/public/browser/notification_details.h"
17 #include "content/public/browser/notification_service.h"
18 #include "content/public/browser/notification_source.h"
19 #include "rlz/test/rlz_test_helpers.h"
20 #include "testing/gtest/include/gtest/gtest.h"
23 #include "base/win/registry.h"
26 using content::NavigationEntry
;
27 using testing::AssertionResult
;
28 using testing::AssertionSuccess
;
29 using testing::AssertionFailure
;
32 using base::win::RegKey
;
37 // Dummy RLZ string for the access points.
38 const char kOmniboxRlzString
[] = "test_omnibox";
39 const char kHomepageRlzString
[] = "test_homepage";
40 const char kNewOmniboxRlzString
[] = "new_omnibox";
41 const char kNewHomepageRlzString
[] = "new_homepage";
43 // Some helper macros to test it a string contains/does not contain a substring.
45 AssertionResult
CmpHelperSTRC(const char* str_expression
,
46 const char* substr_expression
,
49 if (NULL
!= strstr(str
, substr
)) {
50 return AssertionSuccess();
53 return AssertionFailure() << "Expected: (" << substr_expression
<< ") in ("
54 << str_expression
<< "), actual: '"
55 << substr
<< "' not in '" << str
<< "'";
58 AssertionResult
CmpHelperSTRNC(const char* str_expression
,
59 const char* substr_expression
,
62 if (NULL
== strstr(str
, substr
)) {
63 return AssertionSuccess();
66 return AssertionFailure() << "Expected: (" << substr_expression
67 << ") not in (" << str_expression
<< "), actual: '"
68 << substr
<< "' in '" << str
<< "'";
71 #define EXPECT_STR_CONTAINS(str, substr) \
72 EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
74 #define EXPECT_STR_NOT_CONTAIN(str, substr) \
75 EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
79 // Test class for RLZ tracker. Makes some member functions public and
80 // overrides others to make it easier to test.
81 class TestRLZTracker
: public RLZTracker
{
83 using RLZTracker::InitRlzDelayed
;
84 using RLZTracker::DelayedInit
;
85 using RLZTracker::Observe
;
87 TestRLZTracker() : assume_not_ui_thread_(true) {
91 virtual ~TestRLZTracker() {
95 bool was_ping_sent_for_brand(const std::string
& brand
) const {
96 return pinged_brands_
.count(brand
) > 0;
99 void set_assume_not_ui_thread(bool assume_not_ui_thread
) {
100 assume_not_ui_thread_
= assume_not_ui_thread
;
104 virtual void ScheduleDelayedInit(base::TimeDelta delay
) OVERRIDE
{
105 // If the delay is 0, invoke the delayed init now. Otherwise,
106 // don't schedule anything, it will be manually called during tests.
107 if (delay
== base::TimeDelta())
111 virtual void ScheduleFinancialPing() OVERRIDE
{
115 virtual bool ScheduleRecordProductEvent(rlz_lib::Product product
,
116 rlz_lib::AccessPoint point
,
117 rlz_lib::Event event_id
) OVERRIDE
{
118 return !assume_not_ui_thread_
;
121 virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point
) OVERRIDE
{
122 return !assume_not_ui_thread_
;
125 virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point
) OVERRIDE
{
126 return !assume_not_ui_thread_
;
129 #if defined(OS_CHROMEOS)
130 virtual bool ScheduleClearRlzState() OVERRIDE
{
131 return !assume_not_ui_thread_
;
135 virtual bool SendFinancialPing(const std::string
& brand
,
136 const string16
& lang
,
137 const string16
& referral
) OVERRIDE
{
138 // Don't ping the server during tests, just pretend as if we did.
139 EXPECT_FALSE(brand
.empty());
140 pinged_brands_
.insert(brand
);
142 // Set new access points RLZ string, like the actual server ping would have
144 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
,
145 kNewOmniboxRlzString
);
146 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE
,
147 kNewHomepageRlzString
);
151 std::set
<std::string
> pinged_brands_
;
152 bool assume_not_ui_thread_
;
154 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker
);
157 class RlzLibTest
: public RlzLibTestNoMachineState
{
159 virtual void SetUp() OVERRIDE
;
161 void SetMainBrand(const char* brand
);
162 void SetReactivationBrand(const char* brand
);
164 void SetRegistryBrandValue(const wchar_t* name
, const char* brand
);
167 void SimulateOmniboxUsage();
168 void SimulateHomepageUsage();
169 void InvokeDelayedInit();
171 void ExpectEventRecorded(const char* event_name
, bool expected
);
172 void ExpectRlzPingSent(bool expected
);
173 void ExpectReactivationRlzPingSent(bool expected
);
175 TestRLZTracker tracker_
;
176 #if defined(OS_POSIX)
177 scoped_ptr
<google_util::BrandForTesting
> brand_override_
;
181 void RlzLibTest::SetUp() {
182 RlzLibTestNoMachineState::SetUp();
184 // Make sure a non-organic brand code is set in the registry or the RLZTracker
185 // is pretty much a no-op.
186 SetMainBrand("TEST");
187 SetReactivationBrand("");
190 void RlzLibTest::SetMainBrand(const char* brand
) {
192 SetRegistryBrandValue(google_update::kRegRLZBrandField
, brand
);
193 #elif defined(OS_POSIX)
194 brand_override_
.reset(new google_util::BrandForTesting(brand
));
196 std::string check_brand
;
197 google_util::GetBrand(&check_brand
);
198 EXPECT_EQ(brand
, check_brand
);
201 void RlzLibTest::SetReactivationBrand(const char* brand
) {
202 // TODO(thakis): Reactivation doesn't exist on Mac yet.
204 SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField
, brand
);
205 std::string check_brand
;
206 google_util::GetReactivationBrand(&check_brand
);
207 EXPECT_EQ(brand
, check_brand
);
212 void RlzLibTest::SetRegistryBrandValue(const wchar_t* name
,
214 BrowserDistribution
* dist
= BrowserDistribution::GetDistribution();
215 string16 reg_path
= dist
->GetStateKey();
216 RegKey
key(HKEY_CURRENT_USER
, reg_path
.c_str(), KEY_SET_VALUE
);
218 LONG result
= key
.DeleteValue(name
);
219 ASSERT_TRUE(ERROR_SUCCESS
== result
|| ERROR_FILE_NOT_FOUND
== result
);
221 string16 brand16
= ASCIIToUTF16(brand
);
222 ASSERT_EQ(ERROR_SUCCESS
, key
.WriteValue(name
, brand16
.c_str()));
227 void RlzLibTest::SimulateOmniboxUsage() {
228 tracker_
.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL
,
229 content::NotificationService::AllSources(),
230 content::Details
<OmniboxLog
>(NULL
));
233 void RlzLibTest::SimulateHomepageUsage() {
234 scoped_ptr
<NavigationEntry
> entry(NavigationEntry::Create());
236 entry
->SetTransitionType(content::PAGE_TRANSITION_HOME_PAGE
);
237 tracker_
.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING
,
238 content::NotificationService::AllSources(),
239 content::Details
<NavigationEntry
>(entry
.get()));
242 void RlzLibTest::InvokeDelayedInit() {
243 tracker_
.DelayedInit();
246 void RlzLibTest::ExpectEventRecorded(const char* event_name
, bool expected
) {
247 char cgi
[rlz_lib::kMaxCgiLength
];
248 GetProductEventsAsCgi(rlz_lib::CHROME
, cgi
, arraysize(cgi
));
250 EXPECT_STR_CONTAINS(cgi
, event_name
);
252 EXPECT_STR_NOT_CONTAIN(cgi
, event_name
);
256 void RlzLibTest::ExpectRlzPingSent(bool expected
) {
258 google_util::GetBrand(&brand
);
259 EXPECT_EQ(expected
, tracker_
.was_ping_sent_for_brand(brand
.c_str()));
262 void RlzLibTest::ExpectReactivationRlzPingSent(bool expected
) {
264 google_util::GetReactivationBrand(&brand
);
265 EXPECT_EQ(expected
, tracker_
.was_ping_sent_for_brand(brand
.c_str()));
268 // The events that affect the different RLZ scenarios are the following:
270 // A: the user starts chrome for the first time
271 // B: the user stops chrome
272 // C: the user start a subsequent time
273 // D: the user stops chrome again
274 // I: the RLZTracker::DelayedInit() method is invoked
275 // X: the user performs a search using the omnibox
276 // Y: the user performs a search using the home page
278 // The events A to D happen in chronological order, but the other events
279 // may happen at any point between A-B or C-D, in no particular order.
281 // The visible results of the scenarios on Win are:
283 // C1I event is recorded
284 // C2I event is recorded
285 // C1F event is recorded
286 // C2F event is recorded
287 // C1S event is recorded
288 // C2S event is recorded
291 // On Mac, C5 / C6 are sent instead of C1 / C2.
292 // On ChromeOS, CA / CB are sent, respectively.
294 // Variations on the above scenarios:
296 // - if the delay specified to InitRlzDelayed() is negative, then the RLZ
297 // ping should be sent out at the time of event X and not wait for I
299 // Also want to test that pre-warming the RLZ string cache works correctly.
302 const char kOmniboxInstall
[] = "C1I";
303 const char kOmniboxSetToGoogle
[] = "C1S";
304 const char kOmniboxFirstSearch
[] = "C1F";
306 const char kHomepageInstall
[] = "C2I";
307 const char kHomepageSetToGoogle
[] = "C2S";
308 const char kHomepageFirstSeach
[] = "C2F";
309 #elif defined(OS_MACOSX)
310 const char kOmniboxInstall
[] = "C5I";
311 const char kOmniboxSetToGoogle
[] = "C5S";
312 const char kOmniboxFirstSearch
[] = "C5F";
314 const char kHomepageInstall
[] = "C6I";
315 const char kHomepageSetToGoogle
[] = "C6S";
316 const char kHomepageFirstSeach
[] = "C6F";
317 #elif defined(OS_CHROMEOS)
318 const char kOmniboxInstall
[] = "CAI";
319 const char kOmniboxSetToGoogle
[] = "CAS";
320 const char kOmniboxFirstSearch
[] = "CAF";
322 const char kHomepageInstall
[] = "CBI";
323 const char kHomepageSetToGoogle
[] = "CBS";
324 const char kHomepageFirstSeach
[] = "CBF";
327 const base::TimeDelta kDelay
= base::TimeDelta::FromMilliseconds(20);
329 TEST_F(RlzLibTest
, RecordProductEvent
) {
330 RLZTracker::RecordProductEvent(rlz_lib::CHROME
, RLZTracker::CHROME_OMNIBOX
,
331 rlz_lib::FIRST_SEARCH
);
333 ExpectEventRecorded(kOmniboxFirstSearch
, true);
336 TEST_F(RlzLibTest
, QuickStopAfterStart
) {
337 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, true);
340 ExpectEventRecorded(kOmniboxInstall
, false);
341 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
342 ExpectEventRecorded(kOmniboxFirstSearch
, false);
345 ExpectEventRecorded(kHomepageInstall
, false);
346 ExpectEventRecorded(kHomepageSetToGoogle
, false);
347 ExpectEventRecorded(kHomepageFirstSeach
, false);
349 ExpectRlzPingSent(false);
352 TEST_F(RlzLibTest
, DelayedInitOnly
) {
353 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
357 ExpectEventRecorded(kOmniboxInstall
, true);
358 ExpectEventRecorded(kOmniboxSetToGoogle
, true);
359 ExpectEventRecorded(kOmniboxFirstSearch
, false);
362 ExpectEventRecorded(kHomepageInstall
, true);
363 ExpectEventRecorded(kHomepageSetToGoogle
, true);
364 ExpectEventRecorded(kHomepageFirstSeach
, false);
366 ExpectRlzPingSent(true);
369 TEST_F(RlzLibTest
, DelayedInitOnlyGoogleAsStartup
) {
370 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, false, false, true);
374 ExpectEventRecorded(kOmniboxInstall
, true);
375 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
376 ExpectEventRecorded(kOmniboxFirstSearch
, false);
379 ExpectEventRecorded(kHomepageInstall
, true);
380 ExpectEventRecorded(kHomepageSetToGoogle
, true);
381 ExpectEventRecorded(kHomepageFirstSeach
, true);
383 ExpectRlzPingSent(true);
386 TEST_F(RlzLibTest
, DelayedInitOnlyNoFirstRunNoRlzStrings
) {
387 TestRLZTracker::InitRlzDelayed(false, false, kDelay
, true, true, false);
391 ExpectEventRecorded(kOmniboxInstall
, true);
392 ExpectEventRecorded(kOmniboxSetToGoogle
, true);
393 ExpectEventRecorded(kOmniboxFirstSearch
, false);
396 ExpectEventRecorded(kHomepageInstall
, true);
397 ExpectEventRecorded(kHomepageSetToGoogle
, true);
398 ExpectEventRecorded(kHomepageFirstSeach
, false);
400 ExpectRlzPingSent(true);
403 TEST_F(RlzLibTest
, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup
) {
404 TestRLZTracker::InitRlzDelayed(false, false, kDelay
, false, false, true);
408 ExpectEventRecorded(kOmniboxInstall
, true);
409 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
410 ExpectEventRecorded(kOmniboxFirstSearch
, false);
413 ExpectEventRecorded(kHomepageInstall
, true);
414 ExpectEventRecorded(kHomepageSetToGoogle
, true);
415 ExpectEventRecorded(kHomepageFirstSeach
, true);
417 ExpectRlzPingSent(true);
420 TEST_F(RlzLibTest
, DelayedInitOnlyNoFirstRun
) {
421 // Set some dummy RLZ strings to simulate that we already ran before and
422 // performed a successful ping to the RLZ server.
423 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, kOmniboxRlzString
);
424 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE
, kHomepageRlzString
);
426 TestRLZTracker::InitRlzDelayed(false, false, kDelay
, true, true, true);
430 ExpectEventRecorded(kOmniboxInstall
, true);
431 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
432 ExpectEventRecorded(kOmniboxFirstSearch
, false);
435 ExpectEventRecorded(kHomepageInstall
, true);
436 ExpectEventRecorded(kHomepageSetToGoogle
, false);
437 ExpectEventRecorded(kHomepageFirstSeach
, true);
439 ExpectRlzPingSent(true);
442 TEST_F(RlzLibTest
, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup
) {
443 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, false, false, false);
447 ExpectEventRecorded(kOmniboxInstall
, true);
448 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
449 ExpectEventRecorded(kOmniboxFirstSearch
, false);
452 ExpectEventRecorded(kHomepageInstall
, true);
453 ExpectEventRecorded(kHomepageSetToGoogle
, false);
454 ExpectEventRecorded(kHomepageFirstSeach
, false);
456 ExpectRlzPingSent(true);
459 TEST_F(RlzLibTest
, OmniboxUsageOnly
) {
460 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
461 SimulateOmniboxUsage();
464 ExpectEventRecorded(kOmniboxInstall
, false);
465 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
466 ExpectEventRecorded(kOmniboxFirstSearch
, true);
469 ExpectEventRecorded(kHomepageInstall
, false);
470 ExpectEventRecorded(kHomepageSetToGoogle
, false);
471 ExpectEventRecorded(kHomepageFirstSeach
, false);
473 ExpectRlzPingSent(false);
476 TEST_F(RlzLibTest
, HomepageUsageOnly
) {
477 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
478 SimulateHomepageUsage();
481 ExpectEventRecorded(kOmniboxInstall
, false);
482 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
483 ExpectEventRecorded(kOmniboxFirstSearch
, false);
486 ExpectEventRecorded(kHomepageInstall
, false);
487 ExpectEventRecorded(kHomepageSetToGoogle
, false);
488 ExpectEventRecorded(kHomepageFirstSeach
, true);
490 ExpectRlzPingSent(false);
493 TEST_F(RlzLibTest
, UsageBeforeDelayedInit
) {
494 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
495 SimulateOmniboxUsage();
496 SimulateHomepageUsage();
500 ExpectEventRecorded(kOmniboxInstall
, true);
501 ExpectEventRecorded(kOmniboxSetToGoogle
, true);
502 ExpectEventRecorded(kOmniboxFirstSearch
, true);
505 ExpectEventRecorded(kHomepageInstall
, true);
506 ExpectEventRecorded(kHomepageSetToGoogle
, true);
507 ExpectEventRecorded(kHomepageFirstSeach
, true);
509 ExpectRlzPingSent(true);
512 TEST_F(RlzLibTest
, OmniboxUsageAfterDelayedInit
) {
513 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
515 SimulateOmniboxUsage();
516 SimulateHomepageUsage();
519 ExpectEventRecorded(kOmniboxInstall
, true);
520 ExpectEventRecorded(kOmniboxSetToGoogle
, true);
521 ExpectEventRecorded(kOmniboxFirstSearch
, true);
524 ExpectEventRecorded(kHomepageInstall
, true);
525 ExpectEventRecorded(kHomepageSetToGoogle
, true);
526 ExpectEventRecorded(kHomepageFirstSeach
, true);
528 ExpectRlzPingSent(true);
531 TEST_F(RlzLibTest
, OmniboxUsageSendsPingWhenSendPingImmediately
) {
532 TestRLZTracker::InitRlzDelayed(true, true, kDelay
, true, true, false);
533 SimulateOmniboxUsage();
536 ExpectEventRecorded(kOmniboxInstall
, true);
537 ExpectEventRecorded(kOmniboxSetToGoogle
, true);
538 ExpectEventRecorded(kOmniboxFirstSearch
, true);
541 ExpectEventRecorded(kHomepageInstall
, true);
542 ExpectEventRecorded(kHomepageSetToGoogle
, true);
543 ExpectEventRecorded(kHomepageFirstSeach
, false);
545 ExpectRlzPingSent(true);
548 TEST_F(RlzLibTest
, HomepageUsageDoesNotSendPingWhenSendPingImmediately
) {
549 TestRLZTracker::InitRlzDelayed(true, true, kDelay
, true, true, false);
550 SimulateHomepageUsage();
553 ExpectEventRecorded(kOmniboxInstall
, false);
554 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
555 ExpectEventRecorded(kOmniboxFirstSearch
, false);
558 ExpectEventRecorded(kHomepageInstall
, false);
559 ExpectEventRecorded(kHomepageSetToGoogle
, false);
560 ExpectEventRecorded(kHomepageFirstSeach
, true);
562 ExpectRlzPingSent(false);
565 TEST_F(RlzLibTest
, StartupUsageDoesNotSendPingWhenSendPingImmediately
) {
566 TestRLZTracker::InitRlzDelayed(true, true, kDelay
, true, false, true);
567 SimulateHomepageUsage();
570 ExpectEventRecorded(kOmniboxInstall
, false);
571 ExpectEventRecorded(kOmniboxSetToGoogle
, false);
572 ExpectEventRecorded(kOmniboxFirstSearch
, false);
575 ExpectEventRecorded(kHomepageInstall
, false);
576 ExpectEventRecorded(kHomepageSetToGoogle
, false);
577 ExpectEventRecorded(kHomepageFirstSeach
, true);
579 ExpectRlzPingSent(false);
582 TEST_F(RlzLibTest
, GetAccessPointRlzOnIoThread
) {
583 // Set dummy RLZ string.
584 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, kOmniboxRlzString
);
588 tracker_
.set_assume_not_ui_thread(true);
589 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
590 EXPECT_STREQ(kOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
593 TEST_F(RlzLibTest
, GetAccessPointRlzNotOnIoThread
) {
594 // Set dummy RLZ string.
595 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, kOmniboxRlzString
);
599 tracker_
.set_assume_not_ui_thread(false);
600 EXPECT_FALSE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
603 TEST_F(RlzLibTest
, GetAccessPointRlzIsCached
) {
604 // Set dummy RLZ string.
605 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, kOmniboxRlzString
);
609 tracker_
.set_assume_not_ui_thread(false);
610 EXPECT_FALSE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
612 tracker_
.set_assume_not_ui_thread(true);
613 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
614 EXPECT_STREQ(kOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
616 tracker_
.set_assume_not_ui_thread(false);
617 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
618 EXPECT_STREQ(kOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
621 TEST_F(RlzLibTest
, PingUpdatesRlzCache
) {
622 // Set dummy RLZ string.
623 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, kOmniboxRlzString
);
624 rlz_lib::SetAccessPointRlz(RLZTracker::CHROME_HOME_PAGE
, kHomepageRlzString
);
629 tracker_
.set_assume_not_ui_thread(true);
631 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
632 EXPECT_STREQ(kOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
633 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
634 RLZTracker::CHROME_HOME_PAGE
, &rlz
));
635 EXPECT_STREQ(kHomepageRlzString
, UTF16ToUTF8(rlz
).c_str());
637 // Make sure cache is valid.
638 tracker_
.set_assume_not_ui_thread(false);
640 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
641 EXPECT_STREQ(kOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
642 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
643 RLZTracker::CHROME_HOME_PAGE
, &rlz
));
644 EXPECT_STREQ(kHomepageRlzString
, UTF16ToUTF8(rlz
).c_str());
647 tracker_
.set_assume_not_ui_thread(true);
648 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
650 ExpectRlzPingSent(true);
652 // Make sure cache is now updated.
653 tracker_
.set_assume_not_ui_thread(false);
655 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::CHROME_OMNIBOX
, &rlz
));
656 EXPECT_STREQ(kNewOmniboxRlzString
, UTF16ToUTF8(rlz
).c_str());
657 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
658 RLZTracker::CHROME_HOME_PAGE
, &rlz
));
659 EXPECT_STREQ(kNewHomepageRlzString
, UTF16ToUTF8(rlz
).c_str());
662 TEST_F(RlzLibTest
, ObserveHandlesBadArgs
) {
663 scoped_ptr
<NavigationEntry
> entry(NavigationEntry::Create());
665 entry
->SetTransitionType(content::PAGE_TRANSITION_LINK
);
666 tracker_
.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING
,
667 content::NotificationService::AllSources(),
668 content::Details
<NavigationEntry
>(NULL
));
669 tracker_
.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING
,
670 content::NotificationService::AllSources(),
671 content::Details
<NavigationEntry
>(entry
.get()));
674 // TODO(thakis): Reactivation doesn't exist on Mac yet.
676 TEST_F(RlzLibTest
, ReactivationNonOrganicNonOrganic
) {
677 SetReactivationBrand("REAC");
679 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
682 ExpectRlzPingSent(true);
683 ExpectReactivationRlzPingSent(true);
686 TEST_F(RlzLibTest
, ReactivationOrganicNonOrganic
) {
687 SetMainBrand("GGLS");
688 SetReactivationBrand("REAC");
690 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
693 ExpectRlzPingSent(false);
694 ExpectReactivationRlzPingSent(true);
697 TEST_F(RlzLibTest
, ReactivationNonOrganicOrganic
) {
698 SetMainBrand("TEST");
699 SetReactivationBrand("GGLS");
701 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
704 ExpectRlzPingSent(true);
705 ExpectReactivationRlzPingSent(false);
708 TEST_F(RlzLibTest
, ReactivationOrganicOrganic
) {
709 SetMainBrand("GGLS");
710 SetReactivationBrand("GGRS");
712 TestRLZTracker::InitRlzDelayed(true, false, kDelay
, true, true, false);
715 ExpectRlzPingSent(false);
716 ExpectReactivationRlzPingSent(false);
718 #endif // defined(OS_WIN)
720 #if defined(OS_CHROMEOS)
721 TEST_F(RlzLibTest
, ClearRlzState
) {
722 RLZTracker::RecordProductEvent(rlz_lib::CHROME
, RLZTracker::CHROME_OMNIBOX
,
723 rlz_lib::FIRST_SEARCH
);
725 ExpectEventRecorded(kOmniboxFirstSearch
, true);
727 RLZTracker::ClearRlzState();
729 ExpectEventRecorded(kOmniboxFirstSearch
, false);
731 #endif // defined(OS_CHROMEOS)