15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/rlz/rlz.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
75821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/memory/scoped_ptr.h"
8868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "base/strings/utf_string_conversions.h"
9cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "base/time/time.h"
10cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)#include "chrome/browser/autocomplete/autocomplete_controller.h"
117dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch#include "chrome/browser/chrome_notification_types.h"
1246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "chrome/browser/google/google_brand.h"
13868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "chrome/browser/omnibox/omnibox_log.h"
145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/profiles/profile.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/browser_distribution.h"
165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/installer/util/google_update_constants.h"
176d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)#include "components/metrics/proto/omnibox_event.pb.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/navigation_entry.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_details.h"
202a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "content/public/browser/notification_service.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/notification_source.h"
22f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#include "rlz/test/rlz_test_helpers.h"
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/win/registry.h"
275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using content::NavigationEntry;
305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using testing::AssertionResult;
315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using testing::AssertionSuccess;
325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using testing::AssertionFailure;
335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)using base::win::RegKey;
365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Dummy RLZ string for the access points.
415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kOmniboxRlzString[] = "test_omnibox";
425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kHomepageRlzString[] = "test_homepage";
43c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListRlzString[] = "test_applist";
445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kNewOmniboxRlzString[] = "new_omnibox";
455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)const char kNewHomepageRlzString[] = "new_homepage";
46c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kNewAppListRlzString[] = "new_applist";
475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Some helper macros to test it a string contains/does not contain a substring.
495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AssertionResult CmpHelperSTRC(const char* str_expression,
515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const char* substr_expression,
525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const char* str,
535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                              const char* substr) {
545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (NULL != strstr(str, substr)) {
555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return AssertionSuccess();
565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return AssertionFailure() << "Expected: (" << substr_expression << ") in ("
595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            << str_expression << "), actual: '"
605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            << substr << "' not in '" << str << "'";
615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)AssertionResult CmpHelperSTRNC(const char* str_expression,
645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const char* substr_expression,
655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const char* str,
665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               const char* substr) {
675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (NULL == strstr(str, substr)) {
685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return AssertionSuccess();
695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return AssertionFailure() << "Expected: (" << substr_expression
725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            << ") not in (" << str_expression << "), actual: '"
735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                            << substr << "' in '" << str << "'";
745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_STR_CONTAINS(str, substr) \
775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_PRED_FORMAT2(CmpHelperSTRC, str, substr)
785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#define EXPECT_STR_NOT_CONTAIN(str, substr) \
805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_PRED_FORMAT2(CmpHelperSTRNC, str, substr)
815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
841e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// Test class for RLZ tracker. Makes some member functions public and
851e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)// overrides others to make it easier to test.
861e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)class TestRLZTracker : public RLZTracker {
875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) public:
881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  using RLZTracker::InitRlzDelayed;
891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  using RLZTracker::DelayedInit;
901e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  using RLZTracker::Observe;
911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker() : assume_not_ui_thread_(true) {
931e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    set_tracker(this);
945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
961e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual ~TestRLZTracker() {
971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    set_tracker(NULL);
985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  bool was_ping_sent_for_brand(const std::string& brand) const {
1015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return pinged_brands_.count(brand) > 0;
1025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1041e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  void set_assume_not_ui_thread(bool assume_not_ui_thread) {
1051e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    assume_not_ui_thread_ = assume_not_ui_thread;
1061e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1071e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) private:
1091e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void ScheduleDelayedInit(base::TimeDelta delay) OVERRIDE {
1101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // If the delay is 0, invoke the delayed init now. Otherwise,
1111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    // don't schedule anything, it will be manually called during tests.
1121e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    if (delay == base::TimeDelta())
1131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)      DelayedInit();
1141e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1151e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual void ScheduleFinancialPing() OVERRIDE {
1171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    PingNowImpl();
1181e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool ScheduleRecordProductEvent(rlz_lib::Product product,
1211e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                          rlz_lib::AccessPoint point,
1221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                                          rlz_lib::Event event_id) OVERRIDE {
1231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return !assume_not_ui_thread_;
1241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1251e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) OVERRIDE {
1271e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return !assume_not_ui_thread_;
1281e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1291e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1301e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) OVERRIDE {
1311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return !assume_not_ui_thread_;
1321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#if defined(OS_CHROMEOS)
1351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  virtual bool ScheduleClearRlzState() OVERRIDE {
1361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)    return !assume_not_ui_thread_;
1371e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  }
1381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)#endif
1391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
1405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual bool SendFinancialPing(const std::string& brand,
141a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                 const base::string16& lang,
142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                 const base::string16& referral) OVERRIDE {
1435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Don't ping the server during tests, just pretend as if we did.
1445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_FALSE(brand.empty());
1455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    pinged_brands_.insert(brand);
1465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // Set new access points RLZ string, like the actual server ping would have
1485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    // done.
149cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(),
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               kNewOmniboxRlzString);
151cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(),
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                               kNewHomepageRlzString);
153cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)    rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(),
154c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch                               kNewAppListRlzString);
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    return true;
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::set<std::string> pinged_brands_;
1591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  bool assume_not_ui_thread_;
1605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1611e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
1625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
164f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)class RlzLibTest : public RlzLibTestNoMachineState {
165f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) protected:
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  virtual void SetUp() OVERRIDE;
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetMainBrand(const char* brand);
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetReactivationBrand(const char* brand);
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SetRegistryBrandValue(const wchar_t* name, const char* brand);
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SimulateOmniboxUsage();
1755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void SimulateHomepageUsage();
176c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  void SimulateAppListUsage();
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void InvokeDelayedInit();
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ExpectEventRecorded(const char* event_name, bool expected);
1805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ExpectRlzPingSent(bool expected);
1815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  void ExpectReactivationRlzPingSent(bool expected);
1825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1831e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker tracker_;
184f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)#if defined(OS_POSIX)
18546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<google_brand::BrandForTesting> brand_override_;
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
1875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SetUp() {
190f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles)  RlzLibTestNoMachineState::SetUp();
1915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure a non-organic brand code is set in the registry or the RLZTracker
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // is pretty much a no-op.
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetMainBrand("TEST");
1955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetReactivationBrand("");
1965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SetMainBrand(const char* brand) {
1995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
2005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetRegistryBrandValue(google_update::kRegRLZBrandField, brand);
2012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#elif defined(OS_POSIX)
20246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  brand_override_.reset(new google_brand::BrandForTesting(brand));
2035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string check_brand;
20546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  google_brand::GetBrand(&check_brand);
2065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(brand, check_brand);
2075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SetReactivationBrand(const char* brand) {
2105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // TODO(thakis): Reactivation doesn't exist on Mac yet.
2115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
2125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand);
2135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string check_brand;
21446d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  google_brand::GetReactivationBrand(&check_brand);
2155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(brand, check_brand);
2165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
2205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SetRegistryBrandValue(const wchar_t* name,
2215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                       const char* brand) {
2225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  BrowserDistribution* dist = BrowserDistribution::GetDistribution();
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 reg_path = dist->GetStateKey();
2245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE);
2255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (*brand == 0) {
2265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    LONG result = key.DeleteValue(name);
2275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_TRUE(ERROR_SUCCESS == result || ERROR_FILE_NOT_FOUND == result);
2285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
2295d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)    base::string16 brand16 = base::ASCIIToUTF16(brand);
2305821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(name, brand16.c_str()));
2315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
2345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SimulateOmniboxUsage() {
236cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // Create a dummy OmniboxLog object. The 'is_popup_open' field needs to be
237cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // true to trigger record of the first search. All other fields are passed in
238cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  // with empty or invalid values.
239cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  AutocompleteResult empty_result;
240f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)  OmniboxLog dummy(base::string16(), false, metrics::OmniboxInputType::INVALID,
241cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   true, 0, false, -1,
2426d86b77056ed63eb6871182f42a9fd5f07550f90Torne (Richard Coles)                   metrics::OmniboxEventProto::INVALID_SPEC,
243cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   base::TimeDelta::FromSeconds(0), 0,
244cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   base::TimeDelta::FromSeconds(0),
245cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   AutocompleteResult());
246cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)
2471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
2481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::NotificationService::AllSources(),
249cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)                   content::Details<OmniboxLog>(&dummy));
2505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::SimulateHomepageUsage() {
2535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
2545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  entry->SetPageID(0);
2551320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  entry->SetTransitionType(ui::PAGE_TRANSITION_HOME_PAGE);
2561e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
2571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::NotificationService::AllSources(),
2581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::Details<NavigationEntry>(entry.get()));
2595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
261c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochvoid RlzLibTest::SimulateAppListUsage() {
262c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  RLZTracker::RecordAppListSearch();
263c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
264c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
2655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::InvokeDelayedInit() {
2661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.DelayedInit();
2675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
2705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  char cgi[rlz_lib::kMaxCgiLength];
2715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi));
2725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  if (expected) {
2735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_STR_CONTAINS(cgi, event_name);
2745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  } else {
2755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    EXPECT_STR_NOT_CONTAIN(cgi, event_name);
2765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
2775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::ExpectRlzPingSent(bool expected) {
2805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string brand;
28146d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  google_brand::GetBrand(&brand);
2825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str()));
2835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
2865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  std::string brand;
28746d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  google_brand::GetReactivationBrand(&brand);
2885821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str()));
2895821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
2905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
2915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The events that affect the different RLZ scenarios are the following:
2925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
2935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  A: the user starts chrome for the first time
2945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  B: the user stops chrome
2955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C: the user start a subsequent time
2965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  D: the user stops chrome again
2975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  I: the RLZTracker::DelayedInit() method is invoked
2985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  X: the user performs a search using the omnibox
2995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  Y: the user performs a search using the home page
300c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  Z: the user performs a search using the app list
3015821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// The events A to D happen in chronological order, but the other events
3035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// may happen at any point between A-B or C-D, in no particular order.
3045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)// The visible results of the scenarios on Win are:
3065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C1I event is recorded
3085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C2I event is recorded
309c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  C7I event is recorded
3105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C1F event is recorded
3115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C2F event is recorded
312c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  C7F event is recorded
3135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C1S event is recorded
3145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  C2S event is recorded
315c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  C7S event is recorded
3165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  RLZ ping sent
3175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
318c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  On Mac, C5 / C6 / C8 are sent instead of C1 / C2 / C7.
319c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch//  On ChromeOS, CA / CB / CC are sent, respectively.
3205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Variations on the above scenarios:
3225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//  - if the delay specified to InitRlzDelayed() is negative, then the RLZ
3245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//    ping should be sent out at the time of event X and not wait for I
3255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)//
3265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Also want to test that pre-warming the RLZ string cache works correctly.
3275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_WIN)
3292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxInstall[] = "C1I";
3302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxSetToGoogle[] = "C1S";
3312a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxFirstSearch[] = "C1F";
3322a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageInstall[] = "C2I";
3342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageSetToGoogle[] = "C2S";
3352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageFirstSeach[] = "C2F";
336c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
337c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListInstall[] = "C7I";
338c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListSetToGoogle[] = "C7S";
339c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListFirstSearch[] = "C7F";
3402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#elif defined(OS_MACOSX)
3412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxInstall[] = "C5I";
3422a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxSetToGoogle[] = "C5S";
3432a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxFirstSearch[] = "C5F";
3442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageInstall[] = "C6I";
3462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageSetToGoogle[] = "C6S";
3472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageFirstSeach[] = "C6F";
348c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
349c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListInstall[] = "C8I";
350c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListSetToGoogle[] = "C8S";
351c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListFirstSearch[] = "C8F";
3522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#elif defined(OS_CHROMEOS)
3532a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxInstall[] = "CAI";
3542a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxSetToGoogle[] = "CAS";
3552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kOmniboxFirstSearch[] = "CAF";
3562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageInstall[] = "CBI";
3582a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageSetToGoogle[] = "CBS";
3592a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const char kHomepageFirstSeach[] = "CBF";
360c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
361c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListInstall[] = "CCI";
362c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListSetToGoogle[] = "CCS";
363c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kAppListFirstSearch[] = "CCF";
3645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif
3655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(20);
3672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
3685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, RecordProductEvent) {
369cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
3705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                                 rlz_lib::FIRST_SEARCH);
3715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
3735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, QuickStopAfterStart) {
3761e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, true);
3775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
3792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, false);
3802a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
3812a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
3825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
3842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, false);
3852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
3862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
3875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
388c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
389c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
390c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
391c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
392c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
3935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
3945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
3955821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
3965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnly) {
3971e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
3985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
3995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
4012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
4022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, true);
4032a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
4045821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
4062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
4072a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
4082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
4095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
410c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
411c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
412c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, true);
413c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
414c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
4155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
4165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4175821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) {
4191e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, true);
4205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
4215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
4232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
4242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
4252a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
4265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
4282a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
4292a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
4302a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
4315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
432c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
433c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
434c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
435c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
436c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
4375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
4385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
4411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, false);
4425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
4435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4445821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
4452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
4462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, true);
4472a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
4485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
4502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
4512a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
4522a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
4535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
454c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
455c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
456c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, true);
457c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
458c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
4595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
4605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) {
4631e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(false, false, kDelay, false, false, true);
4645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
4655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
4672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
4682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
4692a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
4705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
4722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
4732a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
4742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
4755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
476c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
477c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
478c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
479c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
480c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
4815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
4825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
4835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
4855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set some dummy RLZ strings to simulate that we already ran before and
4865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // performed a successful ping to the RLZ server.
487cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
488cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
489cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
4905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4911e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, true);
4925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
4935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
4952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
4962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
4972a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
4985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
4995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
5002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
5012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
5022a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
5035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
504c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
505c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
506c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
507c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
508c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
5095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
5105821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) {
5131e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, false, false, false);
5145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
5155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
5172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
5182a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
5192a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
5205821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
5222a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
5232a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
5242a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
5255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
526c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
527c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
528c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
529c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
530c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
5315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
5325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5335821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5345821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, OmniboxUsageOnly) {
5351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
5365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateOmniboxUsage();
5375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
5392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, false);
5402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
5412a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
5425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
5442a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, false);
5452a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
5462a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
5475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
548c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
549c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
550c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
551c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
552c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
5535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
5545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, HomepageUsageOnly) {
5571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
5585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateHomepageUsage();
5595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
5612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, false);
5622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
5632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
5645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
5655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
5662a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, false);
5672a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
5682a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
5695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
570c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
571c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
572c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
573c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
574c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
575c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectRlzPingSent(false);
576c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
577c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
578c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochTEST_F(RlzLibTest, AppListUsageOnly) {
579c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
580c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  SimulateAppListUsage();
581c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
582c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Omnibox events.
583c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxInstall, false);
584c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxSetToGoogle, false);
585c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxFirstSearch, false);
586c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
587c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Home page events.
588c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageInstall, false);
589c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageSetToGoogle, false);
590c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageFirstSeach, false);
591c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
592c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
593c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
594c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
595c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, true);
596c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
5975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
5985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
5995821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6005821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
6011e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
6025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateOmniboxUsage();
6035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateHomepageUsage();
604c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  SimulateAppListUsage();
6055821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
6065821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
6082a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
6092a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, true);
6102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
6115821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
6132a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
6142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
6152a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
6165821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
617c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
618c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
619c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, true);
620c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, true);
621c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
6225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
6235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
625c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochTEST_F(RlzLibTest, UsageAfterDelayedInit) {
6261e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
6275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
6285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateOmniboxUsage();
6295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateHomepageUsage();
630c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  SimulateAppListUsage();
6315821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6325821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
6332a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
6342a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, true);
6352a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
6365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
6382a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
6392a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
6402a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
6415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
642c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
643c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
644c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, true);
645c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, true);
646c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
6475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
6485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6502a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenSendPingImmediately) {
6511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
6525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateOmniboxUsage();
6535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
6552a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, true);
6562a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, true);
6572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
6585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
6602a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, true);
6612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, true);
6622a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, false);
6635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
664c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
665c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, true);
666c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, true);
667c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
668c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
6695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
6705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6722a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenSendPingImmediately) {
6731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, true, false);
6745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateHomepageUsage();
6755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
6772a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, false);
6782a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
6792a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
6805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
6822a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, false);
6832a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
6842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
6855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
686c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
687c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
688c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
689c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
690c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
6915821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
6925821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
6935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenSendPingImmediately) {
6951e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, true);
6965821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SimulateHomepageUsage();
6975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
6985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Omnibox events.
6992a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxInstall, false);
7002a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxSetToGoogle, false);
7012a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
7025821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7035821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Home page events.
7042a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageInstall, false);
7052a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageSetToGoogle, false);
7062a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kHomepageFirstSeach, true);
7075821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
708c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
709c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
710c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
711c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, false);
712c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
713c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectRlzPingSent(false);
714c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch}
715c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
716c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen MurdochTEST_F(RlzLibTest, AppListUsageDoesNotSendPingWhenSendPingImmediately) {
717c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  TestRLZTracker::InitRlzDelayed(true, true, kDelay, true, false, false);
718c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  SimulateAppListUsage();
719c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
720c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Omnibox events.
721c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxInstall, false);
722c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxSetToGoogle, false);
723c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kOmniboxFirstSearch, false);
724c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
725c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // Home page events.
726c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageInstall, false);
727c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageSetToGoogle, false);
728c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kHomepageFirstSeach, false);
729c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
730c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  // App list events.
731c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListInstall, false);
732c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListSetToGoogle, false);
733c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  ExpectEventRecorded(kAppListFirstSearch, true);
734c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch
7355821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
7365821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7381e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RlzLibTest, GetAccessPointRlzOnIoThread) {
7391e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Set dummy RLZ string.
740cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
7411e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
742a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 rlz;
7431e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(true);
745cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
7471e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
7481e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7491e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)TEST_F(RlzLibTest, GetAccessPointRlzNotOnIoThread) {
7501e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  // Set dummy RLZ string.
751cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
7521e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
753a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 rlz;
7541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(false);
756cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_FALSE(
757cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7581e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)}
7591e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
7615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set dummy RLZ string.
762cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
7635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
764a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 rlz;
7651e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(false);
767cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_FALSE(
768cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)      RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7691e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7701e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(true);
771cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7725d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
7731e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
7741e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(false);
775cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7765d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
7775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
7785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, PingUpdatesRlzCache) {
7805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Set dummy RLZ string.
781cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
782cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
783cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
7845821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
785a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 rlz;
7865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7875821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Prime the cache.
7881e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(true);
7894e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
790cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
7915d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
7921e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
793cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        RLZTracker::ChromeHomePage(), &rlz));
7945d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
795cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
796c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
7975821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7985821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure cache is valid.
7991e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(false);
8001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
801cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
8025d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
8031e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
804cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        RLZTracker::ChromeHomePage(), &rlz));
8055d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
806cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
807c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
8085821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8095821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Perform ping.
8101e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(true);
8111e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
8125821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
8135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
8145821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Make sure cache is now updated.
8161e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.set_assume_not_ui_thread(false);
8171e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
818cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
8195d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
8201e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
821cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)        RLZTracker::ChromeHomePage(), &rlz));
8225d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
823cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
824c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch  EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
8255821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8265821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8275821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, ObserveHandlesBadArgs) {
8285821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  scoped_ptr<NavigationEntry> entry(NavigationEntry::Create());
8295821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  entry->SetPageID(0);
8301320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  entry->SetTransitionType(ui::PAGE_TRANSITION_LINK);
8311e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
8321e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::NotificationService::AllSources(),
8331e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::Details<NavigationEntry>(NULL));
8341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING,
8351e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::NotificationService::AllSources(),
8361e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)                   content::Details<NavigationEntry>(entry.get()));
8375821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8385821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8395821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// TODO(thakis): Reactivation doesn't exist on Mac yet.
8405821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#if defined(OS_WIN)
8415821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
8425821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetReactivationBrand("REAC");
8435821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8441e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
8455821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
8465821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8475821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
8485821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectReactivationRlzPingSent(true);
8495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, ReactivationOrganicNonOrganic) {
8525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetMainBrand("GGLS");
8535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetReactivationBrand("REAC");
8545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8551e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
8565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
8575821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
8595821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectReactivationRlzPingSent(true);
8605821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8615821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8625821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, ReactivationNonOrganicOrganic) {
8635821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetMainBrand("TEST");
8645821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetReactivationBrand("GGLS");
8655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8661e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
8675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
8685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(true);
8705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectReactivationRlzPingSent(false);
8715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
8745821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetMainBrand("GGLS");
8755821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  SetReactivationBrand("GGRS");
8765821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8771e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)  TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false);
8785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  InvokeDelayedInit();
8795821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
8805821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectRlzPingSent(false);
8815821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  ExpectReactivationRlzPingSent(false);
8825821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
8835821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#endif  // defined(OS_WIN)
8842a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8852a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#if defined(OS_CHROMEOS)
8862a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)TEST_F(RlzLibTest, ClearRlzState) {
887cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles)  RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
8882a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                 rlz_lib::FIRST_SEARCH);
8891e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles)
8902a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, true);
8912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  RLZTracker::ClearRlzState();
8932a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)
8942a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  ExpectEventRecorded(kOmniboxFirstSearch, false);
8952a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)}
8962a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#endif  // defined(OS_CHROMEOS)
897