Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(385)

Side by Side Diff: components/rlz/rlz_tracker_unittest.cc

Issue 1229933005: Revert "Componentize chrome/browser/rlz" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « components/rlz/rlz_tracker_mac.cc ('k') | components/rlz/rlz_tracker_win.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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.
4
5 #include "components/rlz/rlz_tracker.h"
6
7 #include "base/memory/ref_counted.h"
8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop/message_loop.h"
10 #include "base/strings/utf_string_conversions.h"
11 #include "base/thread_task_runner_handle.h"
12 #include "base/threading/sequenced_worker_pool.h"
13 #include "base/time/time.h"
14 #include "components/rlz/rlz_tracker_delegate.h"
15 #include "net/url_request/url_request_test_util.h"
16 #include "rlz/test/rlz_test_helpers.h"
17 #include "testing/gtest/include/gtest/gtest.h"
18
19 #if defined(OS_IOS)
20 #include "ui/base/device_form_factor.h"
21 #endif
22
23 using testing::AssertionResult;
24 using testing::AssertionSuccess;
25 using testing::AssertionFailure;
26
27 namespace rlz {
28 namespace {
29
30 class TestRLZTrackerDelegate : public RLZTrackerDelegate {
31 public:
32 TestRLZTrackerDelegate()
33 : worker_pool_(new base::SequencedWorkerPool(1, "TestRLZTracker")),
34 request_context_getter_(new net::TestURLRequestContextGetter(
35 base::ThreadTaskRunnerHandle::Get())) {}
36
37 ~TestRLZTrackerDelegate() override { worker_pool_->Shutdown(); }
38
39 void set_brand(const char* brand) { brand_override_ = brand; }
40
41 void set_reactivation_brand(const char* reactivation_brand) {
42 // TODO(thakis): Reactivation doesn't exist on Mac yet.
43 reactivation_brand_override_ = reactivation_brand;
44 }
45
46 void SimulateOmniboxUsage() {
47 using std::swap;
48 base::Closure callback;
49 swap(callback, on_omnibox_search_callback_);
50 if (!callback.is_null())
51 callback.Run();
52 }
53
54 void SimulateHomepageUsage() {
55 using std::swap;
56 base::Closure callback;
57 swap(callback, on_homepage_search_callback_);
58 if (!callback.is_null())
59 callback.Run();
60 }
61
62 // RLZTrackerDelegate implementation.
63 void Cleanup() override {
64 on_omnibox_search_callback_.Reset();
65 on_homepage_search_callback_.Reset();
66 }
67
68 bool IsOnUIThread() override { return true; }
69
70 base::SequencedWorkerPool* GetBlockingPool() override {
71 return worker_pool_.get();
72 }
73
74 net::URLRequestContextGetter* GetRequestContext() override {
75 return request_context_getter_.get();
76 }
77
78 bool GetBrand(std::string* brand) override {
79 *brand = brand_override_;
80 return true;
81 }
82
83 bool IsBrandOrganic(const std::string& brand) override {
84 return brand.empty() || brand == "GGLS" || brand == "GGRS";
85 }
86
87 bool GetReactivationBrand(std::string* brand) override {
88 *brand = reactivation_brand_override_;
89 return true;
90 }
91
92 bool ShouldEnableZeroDelayForTesting() override { return true; }
93
94 bool GetLanguage(base::string16* language) override { return true; }
95
96 bool GetReferral(base::string16* referral) override { return true; }
97
98 bool ClearReferral() override { return true; }
99
100 void SetOmniboxSearchCallback(const base::Closure& callback) override {
101 DCHECK(!callback.is_null());
102 on_omnibox_search_callback_ = callback;
103 }
104
105 void SetHomepageSearchCallback(const base::Closure& callback) override {
106 DCHECK(!callback.is_null());
107 on_homepage_search_callback_ = callback;
108 }
109
110 private:
111 scoped_refptr<base::SequencedWorkerPool> worker_pool_;
112 scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
113
114 std::string brand_override_;
115 std::string reactivation_brand_override_;
116 base::Closure on_omnibox_search_callback_;
117 base::Closure on_homepage_search_callback_;
118
119 DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate);
120 };
121
122 // Dummy RLZ string for the access points.
123 const char kOmniboxRlzString[] = "test_omnibox";
124 const char kNewOmniboxRlzString[] = "new_omnibox";
125 #if !defined(OS_IOS)
126 const char kHomepageRlzString[] = "test_homepage";
127 const char kNewHomepageRlzString[] = "new_homepage";
128 const char kAppListRlzString[] = "test_applist";
129 const char kNewAppListRlzString[] = "new_applist";
130 #endif // !defined(OS_IOS)
131
132 // Some helper macros to test it a string contains/does not contain a substring.
133
134 AssertionResult CmpHelperSTRC(const char* str_expression,
135 const char* substr_expression,
136 const char* str,
137 const char* substr) {
138 if (nullptr != strstr(str, substr)) {
139 return AssertionSuccess();
140 }
141
142 return AssertionFailure() << "Expected: (" << substr_expression << ") in ("
143 << str_expression << "), actual: '"
144 << substr << "' not in '" << str << "'";
145 }
146
147 AssertionResult CmpHelperSTRNC(const char* str_expression,
148 const char* substr_expression,
149 const char* str,
150 const char* substr) {
151 if (nullptr == strstr(str, substr)) {
152 return AssertionSuccess();
153 }
154
155 return AssertionFailure() << "Expected: (" << substr_expression
156 << ") not in (" << str_expression << "), actual: '"
157 << substr << "' in '" << str << "'";
158 }
159
160 #define EXPECT_STR_CONTAINS(str, substr) \
161 EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
162
163 #define EXPECT_STR_NOT_CONTAIN(str, substr) \
164 EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
165
166 } // namespace
167
168 // Test class for RLZ tracker. Makes some member functions public and
169 // overrides others to make it easier to test.
170 class TestRLZTracker : public RLZTracker {
171 public:
172 using RLZTracker::InitRlzDelayed;
173 using RLZTracker::DelayedInit;
174
175 TestRLZTracker() : assume_not_ui_thread_(true) { set_tracker(this); }
176
177 ~TestRLZTracker() override { set_tracker(nullptr); }
178
179 bool was_ping_sent_for_brand(const std::string& brand) const {
180 return pinged_brands_.count(brand) > 0;
181 }
182
183 void set_assume_not_ui_thread(bool assume_not_ui_thread) {
184 assume_not_ui_thread_ = assume_not_ui_thread;
185 }
186
187 private:
188 void ScheduleDelayedInit(base::TimeDelta delay) override {
189 // If the delay is 0, invoke the delayed init now. Otherwise,
190 // don't schedule anything, it will be manually called during tests.
191 if (delay == base::TimeDelta())
192 DelayedInit();
193 }
194
195 void ScheduleFinancialPing() override { PingNowImpl(); }
196
197 bool ScheduleRecordProductEvent(rlz_lib::Product product,
198 rlz_lib::AccessPoint point,
199 rlz_lib::Event event_id) override {
200 return !assume_not_ui_thread_;
201 }
202
203 bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) override {
204 return !assume_not_ui_thread_;
205 }
206
207 bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) override {
208 return !assume_not_ui_thread_;
209 }
210
211 #if defined(OS_CHROMEOS)
212 bool ScheduleClearRlzState() override { return !assume_not_ui_thread_; }
213 #endif
214
215 bool SendFinancialPing(const std::string& brand,
216 const base::string16& lang,
217 const base::string16& referral) override {
218 // Don't ping the server during tests, just pretend as if we did.
219 EXPECT_FALSE(brand.empty());
220 pinged_brands_.insert(brand);
221
222 // Set new access points RLZ string, like the actual server ping would have
223 // done.
224 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(),
225 kNewOmniboxRlzString);
226 #if !defined(OS_IOS)
227 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(),
228 kNewHomepageRlzString);
229 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(),
230 kNewAppListRlzString);
231 #endif // !defined(OS_IOS)
232 return true;
233 }
234
235 std::set<std::string> pinged_brands_;
236 bool assume_not_ui_thread_;
237
238 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
239 };
240
241 class RlzLibTest : public testing::Test {
242 protected:
243 void SetUp() override;
244 void TearDown() override;
245
246 void SetMainBrand(const char* brand);
247 void SetReactivationBrand(const char* brand);
248
249 void SimulateOmniboxUsage();
250 void SimulateHomepageUsage();
251 void SimulateAppListUsage();
252 void InvokeDelayedInit();
253
254 void ExpectEventRecorded(const char* event_name, bool expected);
255 void ExpectRlzPingSent(bool expected);
256 void ExpectReactivationRlzPingSent(bool expected);
257
258 base::MessageLoop message_loop_;
259 TestRLZTrackerDelegate* delegate_;
260 scoped_ptr<TestRLZTracker> tracker_;
261 RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
262 };
263
264 void RlzLibTest::SetUp() {
265 testing::Test::SetUp();
266 m_rlz_test_helper_.SetUp();
267
268 delegate_ = new TestRLZTrackerDelegate;
269 tracker_.reset(new TestRLZTracker());
270 RLZTracker::SetRlzDelegate(make_scoped_ptr(delegate_));
271
272 // Make sure a non-organic brand code is set in the registry or the RLZTracker
273 // is pretty much a no-op.
274 SetMainBrand("TEST");
275 SetReactivationBrand("");
276 }
277
278 void RlzLibTest::TearDown() {
279 delegate_ = nullptr;
280 tracker_.reset();
281 testing::Test::TearDown();
282 m_rlz_test_helper_.TearDown();
283 }
284
285 void RlzLibTest::SetMainBrand(const char* brand) {
286 delegate_->set_brand(brand);
287 }
288
289 void RlzLibTest::SetReactivationBrand(const char* brand) {
290 delegate_->set_reactivation_brand(brand);
291 }
292
293 void RlzLibTest::SimulateOmniboxUsage() {
294 delegate_->SimulateOmniboxUsage();
295 }
296
297 void RlzLibTest::SimulateHomepageUsage() {
298 delegate_->SimulateHomepageUsage();
299 }
300
301 void RlzLibTest::SimulateAppListUsage() {
302 #if !defined(OS_IOS)
303 RLZTracker::RecordAppListSearch();
304 #endif // !defined(OS_IOS)
305 }
306
307 void RlzLibTest::InvokeDelayedInit() {
308 tracker_->DelayedInit();
309 }
310
311 void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
312 char cgi[rlz_lib::kMaxCgiLength];
313 GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi));
314 if (expected) {
315 EXPECT_STR_CONTAINS(cgi, event_name);
316 } else {
317 EXPECT_STR_NOT_CONTAIN(cgi, event_name);
318 }
319 }
320
321 void RlzLibTest::ExpectRlzPingSent(bool expected) {
322 std::string brand;
323 delegate_->GetBrand(&brand);
324 EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
325 }
326
327 void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
328 std::string brand;
329 delegate_->GetReactivationBrand(&brand);
330 EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
331 }
332
333 // The events that affect the different RLZ scenarios are the following:
334 //
335 // A: the user starts chrome for the first time
336 // B: the user stops chrome
337 // C: the user start a subsequent time
338 // D: the user stops chrome again
339 // I: the RLZTracker::DelayedInit() method is invoked
340 // X: the user performs a search using the omnibox
341 // Y: the user performs a search using the home page
342 // Z: the user performs a search using the app list
343 //
344 // The events A to D happen in chronological order, but the other events
345 // may happen at any point between A-B or C-D, in no particular order.
346 //
347 // The visible results of the scenarios on Win are:
348 //
349 // C1I event is recorded
350 // C2I event is recorded
351 // C7I event is recorded
352 // C1F event is recorded
353 // C2F event is recorded
354 // C7F event is recorded
355 // C1S event is recorded
356 // C2S event is recorded
357 // C7S event is recorded
358 // RLZ ping sent
359 //
360 // On Mac, C5 / C6 / C8 are sent instead of C1 / C2 / C7.
361 // On ChromeOS, CA / CB / CC are sent, respectively.
362 //
363 // On iOS, only the omnibox events are recorded, and the value send depends
364 // on the device form factor (phone or tablet).
365 //
366 // Variations on the above scenarios:
367 //
368 // - if the delay specified to InitRlzDelayed() is negative, then the RLZ
369 // ping should be sent out at the time of event X and not wait for I
370 //
371 // Also want to test that pre-warming the RLZ string cache works correctly.
372
373 #if defined(OS_WIN)
374 const char kOmniboxInstall[] = "C1I";
375 const char kOmniboxSetToGoogle[] = "C1S";
376 const char kOmniboxFirstSearch[] = "C1F";
377
378 const char kHomepageInstall[] = "C2I";
379 const char kHomepageSetToGoogle[] = "C2S";
380 const char kHomepageFirstSearch[] = "C2F";
381
382 const char kAppListInstall[] = "C7I";
383 const char kAppListSetToGoogle[] = "C7S";
384 const char kAppListFirstSearch[] = "C7F";
385 #elif defined(OS_IOS)
386 const char kOmniboxInstallPhone[] = "CDI";
387 const char kOmniboxSetToGooglePhone[] = "CDS";
388 const char kOmniboxFirstSearchPhone[] = "CDF";
389
390 const char kOmniboxInstallTablet[] = "C9I";
391 const char kOmniboxSetToGoogleTablet[] = "C9S";
392 const char kOmniboxFirstSearchTablet[] = "C9F";
393 #elif defined(OS_MACOSX)
394 const char kOmniboxInstall[] = "C5I";
395 const char kOmniboxSetToGoogle[] = "C5S";
396 const char kOmniboxFirstSearch[] = "C5F";
397
398 const char kHomepageInstall[] = "C6I";
399 const char kHomepageSetToGoogle[] = "C6S";
400 const char kHomepageFirstSearch[] = "C6F";
401
402 const char kAppListInstall[] = "C8I";
403 const char kAppListSetToGoogle[] = "C8S";
404 const char kAppListFirstSearch[] = "C8F";
405 #elif defined(OS_CHROMEOS)
406 const char kOmniboxInstall[] = "CAI";
407 const char kOmniboxSetToGoogle[] = "CAS";
408 const char kOmniboxFirstSearch[] = "CAF";
409
410 const char kHomepageInstall[] = "CBI";
411 const char kHomepageSetToGoogle[] = "CBS";
412 const char kHomepageFirstSearch[] = "CBF";
413
414 const char kAppListInstall[] = "CCI";
415 const char kAppListSetToGoogle[] = "CCS";
416 const char kAppListFirstSearch[] = "CCF";
417 #endif
418
419 const char* OmniboxInstall() {
420 #if defined(OS_IOS)
421 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
422 ? kOmniboxInstallTablet
423 : kOmniboxInstallPhone;
424 #else
425 return kOmniboxInstall;
426 #endif
427 }
428
429 const char* OmniboxSetToGoogle() {
430 #if defined(OS_IOS)
431 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
432 ? kOmniboxSetToGoogleTablet
433 : kOmniboxSetToGooglePhone;
434 #else
435 return kOmniboxSetToGoogle;
436 #endif
437 }
438
439 const char* OmniboxFirstSearch() {
440 #if defined(OS_IOS)
441 return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
442 ? kOmniboxFirstSearchTablet
443 : kOmniboxFirstSearchPhone;
444 #else
445 return kOmniboxFirstSearch;
446 #endif
447 }
448
449 const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(20);
450
451 TEST_F(RlzLibTest, RecordProductEvent) {
452 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
453 rlz_lib::FIRST_SEARCH);
454
455 ExpectEventRecorded(OmniboxFirstSearch(), true);
456 }
457
458 TEST_F(RlzLibTest, QuickStopAfterStart) {
459 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, true);
460
461 // Omnibox events.
462 ExpectEventRecorded(OmniboxInstall(), false);
463 ExpectEventRecorded(OmniboxSetToGoogle(), false);
464 ExpectEventRecorded(OmniboxFirstSearch(), false);
465
466 #if !defined(OS_IOS)
467 // Home page events.
468 ExpectEventRecorded(kHomepageInstall, false);
469 ExpectEventRecorded(kHomepageSetToGoogle, false);
470 ExpectEventRecorded(kHomepageFirstSearch, false);
471
472 // App list events.
473 ExpectEventRecorded(kAppListInstall, false);
474 ExpectEventRecorded(kAppListSetToGoogle, false);
475 ExpectEventRecorded(kAppListFirstSearch, false);
476 #endif // !defined(OS_IOS)
477
478 ExpectRlzPingSent(false);
479 }
480
481 TEST_F(RlzLibTest, DelayedInitOnly) {
482 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
483 InvokeDelayedInit();
484
485 // Omnibox events.
486 ExpectEventRecorded(OmniboxInstall(), true);
487 ExpectEventRecorded(OmniboxSetToGoogle(), true);
488 ExpectEventRecorded(OmniboxFirstSearch(), false);
489
490 #if !defined(OS_IOS)
491 // Home page events.
492 ExpectEventRecorded(kHomepageInstall, true);
493 ExpectEventRecorded(kHomepageSetToGoogle, true);
494 ExpectEventRecorded(kHomepageFirstSearch, false);
495
496 // App list events.
497 ExpectEventRecorded(kAppListInstall, true);
498 ExpectEventRecorded(kAppListSetToGoogle, true);
499 ExpectEventRecorded(kAppListFirstSearch, false);
500 #endif // !defined(OS_IOS)
501
502 ExpectRlzPingSent(true);
503 }
504
505 TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) {
506 TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, true);
507 InvokeDelayedInit();
508
509 // Omnibox events.
510 ExpectEventRecorded(OmniboxInstall(), true);
511 ExpectEventRecorded(OmniboxSetToGoogle(), false);
512 ExpectEventRecorded(OmniboxFirstSearch(), false);
513
514 #if !defined(OS_IOS)
515 // Home page events.
516 ExpectEventRecorded(kHomepageInstall, true);
517 ExpectEventRecorded(kHomepageSetToGoogle, true);
518 ExpectEventRecorded(kHomepageFirstSearch, true);
519
520 // App list events.
521 ExpectEventRecorded(kAppListInstall, true);
522 ExpectEventRecorded(kAppListSetToGoogle, false);
523 ExpectEventRecorded(kAppListFirstSearch, false);
524 #endif // !defined(OS_IOS)
525
526 ExpectRlzPingSent(true);
527 }
528
529 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
530 TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, false);
531 InvokeDelayedInit();
532
533 // Omnibox events.
534 ExpectEventRecorded(OmniboxInstall(), true);
535 ExpectEventRecorded(OmniboxSetToGoogle(), true);
536 ExpectEventRecorded(OmniboxFirstSearch(), false);
537
538 #if !defined(OS_IOS)
539 // Home page events.
540 ExpectEventRecorded(kHomepageInstall, true);
541 ExpectEventRecorded(kHomepageSetToGoogle, true);
542 ExpectEventRecorded(kHomepageFirstSearch, false);
543
544 // App list events.
545 ExpectEventRecorded(kAppListInstall, true);
546 ExpectEventRecorded(kAppListSetToGoogle, true);
547 ExpectEventRecorded(kAppListFirstSearch, false);
548 #endif // !defined(OS_IOS)
549
550 ExpectRlzPingSent(true);
551 }
552
553 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) {
554 TestRLZTracker::InitRlzDelayed(false, false, kDelay, false, false, true);
555 InvokeDelayedInit();
556
557 // Omnibox events.
558 ExpectEventRecorded(OmniboxInstall(), true);
559 ExpectEventRecorded(OmniboxSetToGoogle(), false);
560 ExpectEventRecorded(OmniboxFirstSearch(), false);
561
562 #if !defined(OS_IOS)
563 // Home page events.
564 ExpectEventRecorded(kHomepageInstall, true);
565 ExpectEventRecorded(kHomepageSetToGoogle, true);
566 ExpectEventRecorded(kHomepageFirstSearch, true);
567
568 // App list events.
569 ExpectEventRecorded(kAppListInstall, true);
570 ExpectEventRecorded(kAppListSetToGoogle, false);
571 ExpectEventRecorded(kAppListFirstSearch, false);
572 #endif // !defined(OS_IOS)
573
574 ExpectRlzPingSent(true);
575 }
576
577 TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
578 // Set some dummy RLZ strings to simulate that we already ran before and
579 // performed a successful ping to the RLZ server.
580 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
581 #if !defined(OS_IOS)
582 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
583 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
584 #endif // !defined(OS_IOS)
585
586 TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, true);
587 InvokeDelayedInit();
588
589 // Omnibox events.
590 ExpectEventRecorded(OmniboxInstall(), true);
591 ExpectEventRecorded(OmniboxSetToGoogle(), false);
592 ExpectEventRecorded(OmniboxFirstSearch(), false);
593
594 #if !defined(OS_IOS)
595 // Home page events.
596 ExpectEventRecorded(kHomepageInstall, true);
597 ExpectEventRecorded(kHomepageSetToGoogle, false);
598 ExpectEventRecorded(kHomepageFirstSearch, true);
599
600 // App list events.
601 ExpectEventRecorded(kAppListInstall, true);
602 ExpectEventRecorded(kAppListSetToGoogle, false);
603 ExpectEventRecorded(kAppListFirstSearch, false);
604 #endif // !defined(OS_IOS)
605
606 ExpectRlzPingSent(true);
607 }
608
609 TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) {
610 TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, false);
611 InvokeDelayedInit();
612
613 // Omnibox events.
614 ExpectEventRecorded(OmniboxInstall(), true);
615 ExpectEventRecorded(OmniboxSetToGoogle(), false);
616 ExpectEventRecorded(OmniboxFirstSearch(), false);
617
618 #if !defined(OS_IOS)
619 // Home page events.
620 ExpectEventRecorded(kHomepageInstall, true);
621 ExpectEventRecorded(kHomepageSetToGoogle, false);
622 ExpectEventRecorded(kHomepageFirstSearch, false);
623
624 // App list events.
625 ExpectEventRecorded(kAppListInstall, true);
626 ExpectEventRecorded(kAppListSetToGoogle, false);
627 ExpectEventRecorded(kAppListFirstSearch, false);
628 #endif // !defined(OS_IOS)
629
630 ExpectRlzPingSent(true);
631 }
632
633 TEST_F(RlzLibTest, OmniboxUsageOnly) {
634 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
635 SimulateOmniboxUsage();
636
637 // Omnibox events.
638 ExpectEventRecorded(OmniboxInstall(), false);
639 ExpectEventRecorded(OmniboxSetToGoogle(), false);
640 ExpectEventRecorded(OmniboxFirstSearch(), true);
641
642 #if !defined(OS_IOS)
643 // Home page events.
644 ExpectEventRecorded(kHomepageInstall, false);
645 ExpectEventRecorded(kHomepageSetToGoogle, false);
646 ExpectEventRecorded(kHomepageFirstSearch, false);
647
648 // App list events.
649 ExpectEventRecorded(kAppListInstall, false);
650 ExpectEventRecorded(kAppListSetToGoogle, false);
651 ExpectEventRecorded(kAppListFirstSearch, false);
652 #endif // !defined(OS_IOS)
653
654 ExpectRlzPingSent(false);
655 }
656
657 TEST_F(RlzLibTest, HomepageUsageOnly) {
658 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
659 SimulateHomepageUsage();
660
661 // Omnibox events.
662 ExpectEventRecorded(OmniboxInstall(), false);
663 ExpectEventRecorded(OmniboxSetToGoogle(), false);
664 ExpectEventRecorded(OmniboxFirstSearch(), false);
665
666 #if !defined(OS_IOS)
667 // Home page events.
668 ExpectEventRecorded(kHomepageInstall, false);
669 ExpectEventRecorded(kHomepageSetToGoogle, false);
670 ExpectEventRecorded(kHomepageFirstSearch, true);
671
672 // App list events.
673 ExpectEventRecorded(kAppListInstall, false);
674 ExpectEventRecorded(kAppListSetToGoogle, false);
675 ExpectEventRecorded(kAppListFirstSearch, false);
676 #endif // !defined(OS_IOS)
677
678 ExpectRlzPingSent(false);
679 }
680
681 TEST_F(RlzLibTest, AppListUsageOnly) {
682 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
683 SimulateAppListUsage();
684
685 // Omnibox events.
686 ExpectEventRecorded(OmniboxInstall(), false);
687 ExpectEventRecorded(OmniboxSetToGoogle(), false);
688 ExpectEventRecorded(OmniboxFirstSearch(), false);
689
690 #if !defined(OS_IOS)
691 // Home page events.
692 ExpectEventRecorded(kHomepageInstall, false);
693 ExpectEventRecorded(kHomepageSetToGoogle, false);
694 ExpectEventRecorded(kHomepageFirstSearch, false);
695
696 // App list events.
697 ExpectEventRecorded(kAppListInstall, false);
698 ExpectEventRecorded(kAppListSetToGoogle, false);
699 ExpectEventRecorded(kAppListFirstSearch, true);
700 #endif // !defined(OS_IOS)
701
702 ExpectRlzPingSent(false);
703 }
704
705 TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
706 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
707 SimulateOmniboxUsage();
708 SimulateHomepageUsage();
709 SimulateAppListUsage();
710 InvokeDelayedInit();
711
712 // Omnibox events.
713 ExpectEventRecorded(OmniboxInstall(), true);
714 ExpectEventRecorded(OmniboxSetToGoogle(), true);
715 ExpectEventRecorded(OmniboxFirstSearch(), true);
716
717 #if !defined(OS_IOS)
718 // Home page events.
719 ExpectEventRecorded(kHomepageInstall, true);
720 ExpectEventRecorded(kHomepageSetToGoogle, true);
721 ExpectEventRecorded(kHomepageFirstSearch, true);
722
723 // App list events.
724 ExpectEventRecorded(kAppListInstall, true);
725 ExpectEventRecorded(kAppListSetToGoogle, true);
726 ExpectEventRecorded(kAppListFirstSearch, true);
727 #endif // !defined(OS_IOS)
728
729 ExpectRlzPingSent(true);
730 }
731
732 TEST_F(RlzLibTest, UsageAfterDelayedInit) {
733 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
734 InvokeDelayedInit();
735 SimulateOmniboxUsage();
736 SimulateHomepageUsage();
737 SimulateAppListUsage();
738
739 // Omnibox events.
740 ExpectEventRecorded(OmniboxInstall(), true);
741 ExpectEventRecorded(OmniboxSetToGoogle(), true);
742 ExpectEventRecorded(OmniboxFirstSearch(), true);
743
744 #if !defined(OS_IOS)
745 // Home page events.
746 ExpectEventRecorded(kHomepageInstall, true);
747 ExpectEventRecorded(kHomepageSetToGoogle, true);
748 ExpectEventRecorded(kHomepageFirstSearch, true);
749
750 // App list events.
751 ExpectEventRecorded(kAppListInstall, true);
752 ExpectEventRecorded(kAppListSetToGoogle, true);
753 ExpectEventRecorded(kAppListFirstSearch, true);
754 #endif // !defined(OS_IOS)
755
756 ExpectRlzPingSent(true);
757 }
758
759 TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenSendPingImmediately) {
760 TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
761 SimulateOmniboxUsage();
762
763 // Omnibox events.
764 ExpectEventRecorded(OmniboxInstall(), true);
765 ExpectEventRecorded(OmniboxSetToGoogle(), true);
766 ExpectEventRecorded(OmniboxFirstSearch(), true);
767
768 #if !defined(OS_IOS)
769 // Home page events.
770 ExpectEventRecorded(kHomepageInstall, true);
771 ExpectEventRecorded(kHomepageSetToGoogle, true);
772 ExpectEventRecorded(kHomepageFirstSearch, false);
773
774 // App list events.
775 ExpectEventRecorded(kAppListInstall, true);
776 ExpectEventRecorded(kAppListSetToGoogle, true);
777 ExpectEventRecorded(kAppListFirstSearch, false);
778 #endif // !defined(OS_IOS)
779
780 ExpectRlzPingSent(true);
781 }
782
783 TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenSendPingImmediately) {
784 TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
785 SimulateHomepageUsage();
786
787 // Omnibox events.
788 ExpectEventRecorded(OmniboxInstall(), false);
789 ExpectEventRecorded(OmniboxSetToGoogle(), false);
790 ExpectEventRecorded(OmniboxFirstSearch(), false);
791
792 #if !defined(OS_IOS)
793 // Home page events.
794 ExpectEventRecorded(kHomepageInstall, false);
795 ExpectEventRecorded(kHomepageSetToGoogle, false);
796 ExpectEventRecorded(kHomepageFirstSearch, true);
797
798 // App list events.
799 ExpectEventRecorded(kAppListInstall, false);
800 ExpectEventRecorded(kAppListSetToGoogle, false);
801 ExpectEventRecorded(kAppListFirstSearch, false);
802 #endif // !defined(OS_IOS)
803
804 ExpectRlzPingSent(false);
805 }
806
807 TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenSendPingImmediately) {
808 TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, true);
809 SimulateHomepageUsage();
810
811 // Omnibox events.
812 ExpectEventRecorded(OmniboxInstall(), false);
813 ExpectEventRecorded(OmniboxSetToGoogle(), false);
814 ExpectEventRecorded(OmniboxFirstSearch(), false);
815
816 #if !defined(OS_IOS)
817 // Home page events.
818 ExpectEventRecorded(kHomepageInstall, false);
819 ExpectEventRecorded(kHomepageSetToGoogle, false);
820 ExpectEventRecorded(kHomepageFirstSearch, true);
821
822 // App list events.
823 ExpectEventRecorded(kAppListInstall, false);
824 ExpectEventRecorded(kAppListSetToGoogle, false);
825 ExpectEventRecorded(kAppListFirstSearch, false);
826 #endif // !defined(OS_IOS)
827
828 ExpectRlzPingSent(false);
829 }
830
831 TEST_F(RlzLibTest, AppListUsageDoesNotSendPingWhenSendPingImmediately) {
832 TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, false);
833 SimulateAppListUsage();
834
835 // Omnibox events.
836 ExpectEventRecorded(OmniboxInstall(), false);
837 ExpectEventRecorded(OmniboxSetToGoogle(), false);
838 ExpectEventRecorded(OmniboxFirstSearch(), false);
839
840 #if !defined(OS_IOS)
841 // Home page events.
842 ExpectEventRecorded(kHomepageInstall, false);
843 ExpectEventRecorded(kHomepageSetToGoogle, false);
844 ExpectEventRecorded(kHomepageFirstSearch, false);
845
846 // App list events.
847 ExpectEventRecorded(kAppListInstall, false);
848 ExpectEventRecorded(kAppListSetToGoogle, false);
849 ExpectEventRecorded(kAppListFirstSearch, true);
850 #endif // !defined(OS_IOS)
851
852 ExpectRlzPingSent(false);
853 }
854
855 TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) {
856 // Set dummy RLZ string.
857 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
858
859 base::string16 rlz;
860
861 tracker_->set_assume_not_ui_thread(true);
862 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
863 EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
864 }
865
866 TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) {
867 // Set dummy RLZ string.
868 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
869
870 base::string16 rlz;
871
872 tracker_->set_assume_not_ui_thread(false);
873 EXPECT_FALSE(
874 RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
875 }
876
877 TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
878 // Set dummy RLZ string.
879 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
880
881 base::string16 rlz;
882
883 tracker_->set_assume_not_ui_thread(false);
884 EXPECT_FALSE(
885 RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
886
887 tracker_->set_assume_not_ui_thread(true);
888 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
889 EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
890
891 tracker_->set_assume_not_ui_thread(false);
892 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
893 EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
894 }
895
896 TEST_F(RlzLibTest, PingUpdatesRlzCache) {
897 // Set dummy RLZ string.
898 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
899 #if !defined(OS_IOS)
900 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
901 rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
902 #endif // !defined(OS_IOS)
903
904 base::string16 rlz;
905
906 // Prime the cache.
907 tracker_->set_assume_not_ui_thread(true);
908
909 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
910 EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
911 #if !defined(OS_IOS)
912 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
913 RLZTracker::ChromeHomePage(), &rlz));
914 EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
915 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
916 EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
917 #endif // !defined(OS_IOS)
918
919 // Make sure cache is valid.
920 tracker_->set_assume_not_ui_thread(false);
921
922 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
923 EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
924 #if !defined(OS_IOS)
925 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
926 RLZTracker::ChromeHomePage(), &rlz));
927 EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
928 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
929 EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
930 #endif // !defined(OS_IOS)
931
932 // Perform ping.
933 tracker_->set_assume_not_ui_thread(true);
934 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
935 InvokeDelayedInit();
936 ExpectRlzPingSent(true);
937
938 // Make sure cache is now updated.
939 tracker_->set_assume_not_ui_thread(false);
940
941 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
942 EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
943 #if !defined(OS_IOS)
944 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
945 RLZTracker::ChromeHomePage(), &rlz));
946 EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
947 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
948 EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
949 #endif // !defined(OS_IOS)
950 }
951
952 // TODO(thakis): Reactivation doesn't exist on Mac yet.
953 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
954 SetReactivationBrand("REAC");
955
956 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
957 InvokeDelayedInit();
958
959 ExpectRlzPingSent(true);
960 ExpectReactivationRlzPingSent(true);
961 }
962
963 TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) {
964 SetMainBrand("GGLS");
965 SetReactivationBrand("REAC");
966
967 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
968 InvokeDelayedInit();
969
970 ExpectRlzPingSent(false);
971 ExpectReactivationRlzPingSent(true);
972 }
973
974 TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) {
975 SetMainBrand("TEST");
976 SetReactivationBrand("GGLS");
977
978 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
979 InvokeDelayedInit();
980
981 ExpectRlzPingSent(true);
982 ExpectReactivationRlzPingSent(false);
983 }
984
985 TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
986 SetMainBrand("GGLS");
987 SetReactivationBrand("GGRS");
988
989 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
990 InvokeDelayedInit();
991
992 ExpectRlzPingSent(false);
993 ExpectReactivationRlzPingSent(false);
994 }
995
996 #if defined(OS_CHROMEOS)
997 TEST_F(RlzLibTest, ClearRlzState) {
998 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
999 rlz_lib::FIRST_SEARCH);
1000
1001 ExpectEventRecorded(OmniboxFirstSearch(), true);
1002
1003 RLZTracker::ClearRlzState();
1004
1005 ExpectEventRecorded(OmniboxFirstSearch(), false);
1006 }
1007 #endif // defined(OS_CHROMEOS)
1008
1009 } // namespace rlz
OLDNEW
« no previous file with comments | « components/rlz/rlz_tracker_mac.cc ('k') | components/rlz/rlz_tracker_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698