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