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 "chrome/browser/rlz/rlz.h" |
6 | 6 |
7 #include "base/memory/scoped_ptr.h" | 7 #include "base/memory/scoped_ptr.h" |
8 #include "base/strings/utf_string_conversions.h" | 8 #include "base/strings/utf_string_conversions.h" |
9 #include "base/time/time.h" | 9 #include "base/time/time.h" |
10 #include "chrome/browser/autocomplete/autocomplete_controller.h" | 10 #include "chrome/browser/autocomplete/autocomplete_controller.h" |
11 #include "chrome/browser/autocomplete/autocomplete_input.h" | 11 #include "chrome/browser/autocomplete/autocomplete_input.h" |
12 #include "chrome/browser/chrome_notification_types.h" | 12 #include "chrome/browser/chrome_notification_types.h" |
13 #include "chrome/browser/google/google_util.h" | 13 #include "chrome/browser/google/google_brand.h" |
14 #include "chrome/browser/omnibox/omnibox_log.h" | 14 #include "chrome/browser/omnibox/omnibox_log.h" |
15 #include "chrome/browser/profiles/profile.h" | 15 #include "chrome/browser/profiles/profile.h" |
16 #include "chrome/installer/util/browser_distribution.h" | 16 #include "chrome/installer/util/browser_distribution.h" |
17 #include "chrome/installer/util/google_update_constants.h" | 17 #include "chrome/installer/util/google_update_constants.h" |
18 #include "content/public/browser/navigation_entry.h" | 18 #include "content/public/browser/navigation_entry.h" |
19 #include "content/public/browser/notification_details.h" | 19 #include "content/public/browser/notification_details.h" |
20 #include "content/public/browser/notification_service.h" | 20 #include "content/public/browser/notification_service.h" |
21 #include "content/public/browser/notification_source.h" | 21 #include "content/public/browser/notification_source.h" |
22 #include "rlz/test/rlz_test_helpers.h" | 22 #include "rlz/test/rlz_test_helpers.h" |
23 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 151 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
175 void SimulateHomepageUsage(); | 175 void SimulateHomepageUsage(); |
176 void SimulateAppListUsage(); | 176 void SimulateAppListUsage(); |
177 void InvokeDelayedInit(); | 177 void InvokeDelayedInit(); |
178 | 178 |
179 void ExpectEventRecorded(const char* event_name, bool expected); | 179 void ExpectEventRecorded(const char* event_name, bool expected); |
180 void ExpectRlzPingSent(bool expected); | 180 void ExpectRlzPingSent(bool expected); |
181 void ExpectReactivationRlzPingSent(bool expected); | 181 void ExpectReactivationRlzPingSent(bool expected); |
182 | 182 |
183 TestRLZTracker tracker_; | 183 TestRLZTracker tracker_; |
184 #if defined(OS_POSIX) | 184 #if defined(OS_POSIX) |
185 scoped_ptr<google_util::BrandForTesting> brand_override_; | 185 scoped_ptr<google_brand::BrandForTesting> brand_override_; |
186 #endif | 186 #endif |
187 }; | 187 }; |
188 | 188 |
189 void RlzLibTest::SetUp() { | 189 void RlzLibTest::SetUp() { |
190 RlzLibTestNoMachineState::SetUp(); | 190 RlzLibTestNoMachineState::SetUp(); |
191 | 191 |
192 // Make sure a non-organic brand code is set in the registry or the RLZTracker | 192 // Make sure a non-organic brand code is set in the registry or the RLZTracker |
193 // is pretty much a no-op. | 193 // is pretty much a no-op. |
194 SetMainBrand("TEST"); | 194 SetMainBrand("TEST"); |
195 SetReactivationBrand(""); | 195 SetReactivationBrand(""); |
196 } | 196 } |
197 | 197 |
198 void RlzLibTest::SetMainBrand(const char* brand) { | 198 void RlzLibTest::SetMainBrand(const char* brand) { |
199 #if defined(OS_WIN) | 199 #if defined(OS_WIN) |
200 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); | 200 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
201 #elif defined(OS_POSIX) | 201 #elif defined(OS_POSIX) |
202 brand_override_.reset(new google_util::BrandForTesting(brand)); | 202 brand_override_.reset(new google_brand::BrandForTesting(brand)); |
203 #endif | 203 #endif |
204 std::string check_brand; | 204 std::string check_brand; |
205 google_util::GetBrand(&check_brand); | 205 google_brand::GetBrand(&check_brand); |
206 EXPECT_EQ(brand, check_brand); | 206 EXPECT_EQ(brand, check_brand); |
207 } | 207 } |
208 | 208 |
209 void RlzLibTest::SetReactivationBrand(const char* brand) { | 209 void RlzLibTest::SetReactivationBrand(const char* brand) { |
210 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 210 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
211 #if defined(OS_WIN) | 211 #if defined(OS_WIN) |
212 SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand); | 212 SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand); |
213 std::string check_brand; | 213 std::string check_brand; |
214 google_util::GetReactivationBrand(&check_brand); | 214 google_brand::GetReactivationBrand(&check_brand); |
215 EXPECT_EQ(brand, check_brand); | 215 EXPECT_EQ(brand, check_brand); |
216 #endif | 216 #endif |
217 } | 217 } |
218 | 218 |
219 #if defined(OS_WIN) | 219 #if defined(OS_WIN) |
220 void RlzLibTest::SetRegistryBrandValue(const wchar_t* name, | 220 void RlzLibTest::SetRegistryBrandValue(const wchar_t* name, |
221 const char* brand) { | 221 const char* brand) { |
222 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); | 222 BrowserDistribution* dist = BrowserDistribution::GetDistribution(); |
223 base::string16 reg_path = dist->GetStateKey(); | 223 base::string16 reg_path = dist->GetStateKey(); |
224 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE); | 224 RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE); |
(...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
271 GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi)); | 271 GetProductEventsAsCgi(rlz_lib::CHROME, cgi, arraysize(cgi)); |
272 if (expected) { | 272 if (expected) { |
273 EXPECT_STR_CONTAINS(cgi, event_name); | 273 EXPECT_STR_CONTAINS(cgi, event_name); |
274 } else { | 274 } else { |
275 EXPECT_STR_NOT_CONTAIN(cgi, event_name); | 275 EXPECT_STR_NOT_CONTAIN(cgi, event_name); |
276 } | 276 } |
277 } | 277 } |
278 | 278 |
279 void RlzLibTest::ExpectRlzPingSent(bool expected) { | 279 void RlzLibTest::ExpectRlzPingSent(bool expected) { |
280 std::string brand; | 280 std::string brand; |
281 google_util::GetBrand(&brand); | 281 google_brand::GetBrand(&brand); |
282 EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str())); | 282 EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str())); |
283 } | 283 } |
284 | 284 |
285 void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) { | 285 void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) { |
286 std::string brand; | 286 std::string brand; |
287 google_util::GetReactivationBrand(&brand); | 287 google_brand::GetReactivationBrand(&brand); |
288 EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str())); | 288 EXPECT_EQ(expected, tracker_.was_ping_sent_for_brand(brand.c_str())); |
289 } | 289 } |
290 | 290 |
291 // The events that affect the different RLZ scenarios are the following: | 291 // The events that affect the different RLZ scenarios are the following: |
292 // | 292 // |
293 // A: the user starts chrome for the first time | 293 // A: the user starts chrome for the first time |
294 // B: the user stops chrome | 294 // B: the user stops chrome |
295 // C: the user start a subsequent time | 295 // C: the user start a subsequent time |
296 // D: the user stops chrome again | 296 // D: the user stops chrome again |
297 // I: the RLZTracker::DelayedInit() method is invoked | 297 // I: the RLZTracker::DelayedInit() method is invoked |
(...skipping 589 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
887 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), | 887 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), |
888 rlz_lib::FIRST_SEARCH); | 888 rlz_lib::FIRST_SEARCH); |
889 | 889 |
890 ExpectEventRecorded(kOmniboxFirstSearch, true); | 890 ExpectEventRecorded(kOmniboxFirstSearch, true); |
891 | 891 |
892 RLZTracker::ClearRlzState(); | 892 RLZTracker::ClearRlzState(); |
893 | 893 |
894 ExpectEventRecorded(kOmniboxFirstSearch, false); | 894 ExpectEventRecorded(kOmniboxFirstSearch, false); |
895 } | 895 } |
896 #endif // defined(OS_CHROMEOS) | 896 #endif // defined(OS_CHROMEOS) |
OLD | NEW |