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