Chromium Code Reviews| 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/chrome_notification_types.h" | 11 #include "chrome/browser/chrome_notification_types.h" |
| 12 #include "chrome/browser/google/google_brand.h" | 12 #include "chrome/browser/google/google_brand.h" |
| 13 #include "chrome/browser/omnibox/omnibox_log.h" | 13 #include "chrome/browser/omnibox/omnibox_log.h" |
| 14 #include "chrome/browser/profiles/profile.h" | 14 #include "chrome/browser/profiles/profile.h" |
| 15 #include "chrome/installer/util/browser_distribution.h" | 15 #include "chrome/installer/util/browser_distribution.h" |
| 16 #include "chrome/installer/util/google_update_constants.h" | 16 #include "chrome/installer/util/google_update_constants.h" |
| 17 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | |
| 17 #include "components/metrics/proto/omnibox_event.pb.h" | 18 #include "components/metrics/proto/omnibox_event.pb.h" |
| 19 #include "content/public/browser/navigation_details.h" | |
| 18 #include "content/public/browser/navigation_entry.h" | 20 #include "content/public/browser/navigation_entry.h" |
| 19 #include "content/public/browser/notification_details.h" | 21 #include "content/public/browser/notification_details.h" |
| 20 #include "content/public/browser/notification_service.h" | 22 #include "content/public/browser/notification_service.h" |
| 21 #include "content/public/browser/notification_source.h" | 23 #include "content/public/browser/notification_source.h" |
| 24 #include "content/public/common/referrer.h" | |
| 25 #include "content/test/test_render_frame_host.h" | |
| 22 #include "rlz/test/rlz_test_helpers.h" | 26 #include "rlz/test/rlz_test_helpers.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
| 28 #include "url/gurl.h" | |
| 24 | 29 |
| 25 #if defined(OS_WIN) | 30 #if defined(OS_WIN) |
| 26 #include "base/win/registry.h" | 31 #include "base/win/registry.h" |
| 27 #endif | 32 #endif |
| 28 | 33 |
| 29 using content::NavigationEntry; | 34 using content::NavigationEntry; |
| 35 using content::LoadCommittedDetails; | |
| 30 using testing::AssertionResult; | 36 using testing::AssertionResult; |
| 31 using testing::AssertionSuccess; | 37 using testing::AssertionSuccess; |
| 32 using testing::AssertionFailure; | 38 using testing::AssertionFailure; |
| 33 | 39 |
| 34 #if defined(OS_WIN) | 40 #if defined(OS_WIN) |
| 35 using base::win::RegKey; | 41 using base::win::RegKey; |
| 36 #endif | 42 #endif |
| 37 | 43 |
| 38 namespace { | 44 namespace { |
| 39 | 45 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 154 kNewAppListRlzString); | 160 kNewAppListRlzString); |
| 155 return true; | 161 return true; |
| 156 } | 162 } |
| 157 | 163 |
| 158 std::set<std::string> pinged_brands_; | 164 std::set<std::string> pinged_brands_; |
| 159 bool assume_not_ui_thread_; | 165 bool assume_not_ui_thread_; |
| 160 | 166 |
| 161 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); | 167 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); |
| 162 }; | 168 }; |
| 163 | 169 |
| 164 class RlzLibTest : public RlzLibTestNoMachineState { | 170 class RlzLibTest : public ChromeRenderViewHostTestHarness { |
| 165 protected: | 171 protected: |
| 166 virtual void SetUp() OVERRIDE; | 172 virtual void SetUp() OVERRIDE; |
| 173 virtual void TearDown() OVERRIDE; | |
| 167 | 174 |
| 168 void SetMainBrand(const char* brand); | 175 void SetMainBrand(const char* brand); |
| 169 void SetReactivationBrand(const char* brand); | 176 void SetReactivationBrand(const char* brand); |
| 170 #if defined(OS_WIN) | 177 #if defined(OS_WIN) |
| 171 void SetRegistryBrandValue(const wchar_t* name, const char* brand); | 178 void SetRegistryBrandValue(const wchar_t* name, const char* brand); |
| 172 #endif | 179 #endif |
| 173 | 180 |
| 174 void SimulateOmniboxUsage(); | 181 void SimulateOmniboxUsage(); |
| 175 void SimulateHomepageUsage(); | 182 void SimulateHomepageUsage(); |
| 176 void SimulateAppListUsage(); | 183 void SimulateAppListUsage(); |
| 177 void InvokeDelayedInit(); | 184 void InvokeDelayedInit(); |
| 178 | 185 |
| 179 void ExpectEventRecorded(const char* event_name, bool expected); | 186 void ExpectEventRecorded(const char* event_name, bool expected); |
| 180 void ExpectRlzPingSent(bool expected); | 187 void ExpectRlzPingSent(bool expected); |
| 181 void ExpectReactivationRlzPingSent(bool expected); | 188 void ExpectReactivationRlzPingSent(bool expected); |
| 182 | 189 |
| 183 TestRLZTracker tracker_; | 190 TestRLZTracker tracker_; |
| 184 #if defined(OS_POSIX) | 191 #if defined(OS_POSIX) |
| 185 scoped_ptr<google_brand::BrandForTesting> brand_override_; | 192 scoped_ptr<google_brand::BrandForTesting> brand_override_; |
| 193 base::ScopedTempDir temp_dir_; | |
| 186 #endif | 194 #endif |
| 195 #if defined(OS_WIN) | |
| 196 registry_util::RegistryOverrideManager override_manager_; | |
| 197 #endif | |
| 198 | |
| 187 }; | 199 }; |
| 188 | 200 |
| 189 void RlzLibTest::SetUp() { | 201 void RlzLibTest::SetUp() { |
| 190 RlzLibTestNoMachineState::SetUp(); | 202 ChromeRenderViewHostTestHarness::SetUp(); |
| 203 | |
| 204 // Same with RlzLibTestNoMachineState::SetUp(). | |
| 205 #if defined(OS_WIN) | |
| 206 InitializeRegistryOverridesForTesting(&override_manager_); | |
| 207 #elif defined(OS_MACOSX) | |
| 208 base::mac::ScopedNSAutoreleasePool pool; | |
| 209 #endif // defined(OS_WIN) | |
| 210 #if defined(OS_POSIX) | |
| 211 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); | |
| 212 rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); | |
| 213 #endif // defined(OS_POSIX) | |
| 191 | 214 |
| 192 // Make sure a non-organic brand code is set in the registry or the RLZTracker | 215 // Make sure a non-organic brand code is set in the registry or the RLZTracker |
| 193 // is pretty much a no-op. | 216 // is pretty much a no-op. |
| 194 SetMainBrand("TEST"); | 217 SetMainBrand("TEST"); |
| 195 SetReactivationBrand(""); | 218 SetReactivationBrand(""); |
| 196 } | 219 } |
| 197 | 220 |
| 221 void RlzLibTest::TearDown() { | |
| 222 ChromeRenderViewHostTestHarness::TearDown(); | |
| 223 | |
| 224 // Same with RlzLibTestNoMachineState::TearDown(). | |
| 225 #if defined(OS_POSIX) | |
| 226 rlz_lib::testing::SetRlzStoreDirectory(base::FilePath()); | |
| 227 #endif // defined(OS_POSIX) | |
| 228 } | |
| 229 | |
| 198 void RlzLibTest::SetMainBrand(const char* brand) { | 230 void RlzLibTest::SetMainBrand(const char* brand) { |
| 199 #if defined(OS_WIN) | 231 #if defined(OS_WIN) |
| 200 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); | 232 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
| 201 #elif defined(OS_POSIX) | 233 #elif defined(OS_POSIX) |
| 202 brand_override_.reset(new google_brand::BrandForTesting(brand)); | 234 brand_override_.reset(new google_brand::BrandForTesting(brand)); |
| 203 #endif | 235 #endif |
| 204 std::string check_brand; | 236 std::string check_brand; |
| 205 google_brand::GetBrand(&check_brand); | 237 google_brand::GetBrand(&check_brand); |
| 206 EXPECT_EQ(brand, check_brand); | 238 EXPECT_EQ(brand, check_brand); |
| 207 } | 239 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 243 base::TimeDelta::FromSeconds(0), 0, | 275 base::TimeDelta::FromSeconds(0), 0, |
| 244 base::TimeDelta::FromSeconds(0), | 276 base::TimeDelta::FromSeconds(0), |
| 245 AutocompleteResult()); | 277 AutocompleteResult()); |
| 246 | 278 |
| 247 tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 279 tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| 248 content::NotificationService::AllSources(), | 280 content::NotificationService::AllSources(), |
| 249 content::Details<OmniboxLog>(&dummy)); | 281 content::Details<OmniboxLog>(&dummy)); |
| 250 } | 282 } |
| 251 | 283 |
| 252 void RlzLibTest::SimulateHomepageUsage() { | 284 void RlzLibTest::SimulateHomepageUsage() { |
| 253 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 285 GURL home_url = GURL("https://www.google.com/"); |
| 254 entry->SetPageID(0); | 286 GURL search_url = GURL("https://www.google.com/#q=search"); |
| 255 entry->SetTransitionType(ui::PAGE_TRANSITION_HOME_PAGE); | 287 |
| 256 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 288 content::TestRenderFrameHost* trfh = |
| 257 content::NotificationService::AllSources(), | 289 static_cast<content::TestRenderFrameHost*>(main_rfh()); |
| 258 content::Details<NavigationEntry>(entry.get())); | 290 |
| 291 // Simulate a navigation to homepage first. | |
| 292 trfh->SendNavigateWithTransition(0, home_url, ui::PAGE_TRANSITION_HOME_PAGE); | |
| 293 // Then simulate a search from homepage. | |
|
Roger Tawa OOO till Jul 10th
2014/09/30 14:43:35
Between the two SendNavigateWithTransition(), woul
yao
2014/09/30 17:10:44
hm.. but kHomepageFirstSeach is defined after this
| |
| 294 trfh->SendNavigateWithTransition(1, search_url, ui::PAGE_TRANSITION_LINK); | |
| 259 } | 295 } |
| 260 | 296 |
| 261 void RlzLibTest::SimulateAppListUsage() { | 297 void RlzLibTest::SimulateAppListUsage() { |
| 262 RLZTracker::RecordAppListSearch(); | 298 RLZTracker::RecordAppListSearch(); |
| 263 } | 299 } |
| 264 | 300 |
| 265 void RlzLibTest::InvokeDelayedInit() { | 301 void RlzLibTest::InvokeDelayedInit() { |
| 266 tracker_.DelayedInit(); | 302 tracker_.DelayedInit(); |
| 267 } | 303 } |
| 268 | 304 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 818 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz)); | 854 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz)); |
| 819 EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str()); | 855 EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 820 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 856 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
| 821 RLZTracker::ChromeHomePage(), &rlz)); | 857 RLZTracker::ChromeHomePage(), &rlz)); |
| 822 EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str()); | 858 EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 823 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz)); | 859 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz)); |
| 824 EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str()); | 860 EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 825 } | 861 } |
| 826 | 862 |
| 827 TEST_F(RlzLibTest, ObserveHandlesBadArgs) { | 863 TEST_F(RlzLibTest, ObserveHandlesBadArgs) { |
| 828 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 864 scoped_ptr<LoadCommittedDetails> details(new LoadCommittedDetails()); |
| 829 entry->SetPageID(0); | 865 details->entry = NavigationEntry::Create(); |
| 830 entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); | 866 details->entry->SetPageID(0); |
| 831 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 867 details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); |
| 868 | |
| 869 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, | |
| 832 content::NotificationService::AllSources(), | 870 content::NotificationService::AllSources(), |
| 833 content::Details<NavigationEntry>(NULL)); | 871 content::Details<NavigationEntry>(NULL)); |
| 834 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 872 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 835 content::NotificationService::AllSources(), | 873 content::NotificationService::AllSources(), |
| 836 content::Details<NavigationEntry>(entry.get())); | 874 content::Details<LoadCommittedDetails>(details.get())); |
| 837 } | 875 } |
| 838 | 876 |
| 839 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 877 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
| 840 #if defined(OS_WIN) | 878 #if defined(OS_WIN) |
| 841 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { | 879 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { |
| 842 SetReactivationBrand("REAC"); | 880 SetReactivationBrand("REAC"); |
| 843 | 881 |
| 844 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false); | 882 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false); |
| 845 InvokeDelayedInit(); | 883 InvokeDelayedInit(); |
| 846 | 884 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 887 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), | 925 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), |
| 888 rlz_lib::FIRST_SEARCH); | 926 rlz_lib::FIRST_SEARCH); |
| 889 | 927 |
| 890 ExpectEventRecorded(kOmniboxFirstSearch, true); | 928 ExpectEventRecorded(kOmniboxFirstSearch, true); |
| 891 | 929 |
| 892 RLZTracker::ClearRlzState(); | 930 RLZTracker::ClearRlzState(); |
| 893 | 931 |
| 894 ExpectEventRecorded(kOmniboxFirstSearch, false); | 932 ExpectEventRecorded(kOmniboxFirstSearch, false); |
| 895 } | 933 } |
| 896 #endif // defined(OS_CHROMEOS) | 934 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |