| 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/test/test_renderer_host.h" |
| 22 #include "rlz/test/rlz_test_helpers.h" | 25 #include "rlz/test/rlz_test_helpers.h" |
| 23 #include "testing/gtest/include/gtest/gtest.h" | 26 #include "testing/gtest/include/gtest/gtest.h" |
| 27 #include "url/gurl.h" |
| 24 | 28 |
| 25 #if defined(OS_WIN) | 29 #if defined(OS_WIN) |
| 26 #include "base/win/registry.h" | 30 #include "base/win/registry.h" |
| 27 #endif | 31 #endif |
| 28 | 32 |
| 29 using content::NavigationEntry; | 33 using content::NavigationEntry; |
| 34 using content::LoadCommittedDetails; |
| 30 using testing::AssertionResult; | 35 using testing::AssertionResult; |
| 31 using testing::AssertionSuccess; | 36 using testing::AssertionSuccess; |
| 32 using testing::AssertionFailure; | 37 using testing::AssertionFailure; |
| 33 | 38 |
| 34 #if defined(OS_WIN) | 39 #if defined(OS_WIN) |
| 35 using base::win::RegKey; | 40 using base::win::RegKey; |
| 36 #endif | 41 #endif |
| 37 | 42 |
| 38 namespace { | 43 namespace { |
| 39 | 44 |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 154 kNewAppListRlzString); | 159 kNewAppListRlzString); |
| 155 return true; | 160 return true; |
| 156 } | 161 } |
| 157 | 162 |
| 158 std::set<std::string> pinged_brands_; | 163 std::set<std::string> pinged_brands_; |
| 159 bool assume_not_ui_thread_; | 164 bool assume_not_ui_thread_; |
| 160 | 165 |
| 161 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); | 166 DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); |
| 162 }; | 167 }; |
| 163 | 168 |
| 164 class RlzLibTest : public RlzLibTestNoMachineState { | 169 class RlzLibTest : public ChromeRenderViewHostTestHarness { |
| 165 protected: | 170 protected: |
| 166 void SetUp() override; | 171 void SetUp() override; |
| 172 void TearDown() override; |
| 167 | 173 |
| 168 void SetMainBrand(const char* brand); | 174 void SetMainBrand(const char* brand); |
| 169 void SetReactivationBrand(const char* brand); | 175 void SetReactivationBrand(const char* brand); |
| 170 #if defined(OS_WIN) | 176 #if defined(OS_WIN) |
| 171 void SetRegistryBrandValue(const wchar_t* name, const char* brand); | 177 void SetRegistryBrandValue(const wchar_t* name, const char* brand); |
| 172 #endif | 178 #endif |
| 173 | 179 |
| 174 void SimulateOmniboxUsage(); | 180 void SimulateOmniboxUsage(); |
| 175 void SimulateHomepageUsage(); | 181 void SimulateHomepageUsage(); |
| 176 void SimulateAppListUsage(); | 182 void SimulateAppListUsage(); |
| 177 void InvokeDelayedInit(); | 183 void InvokeDelayedInit(); |
| 178 | 184 |
| 179 void ExpectEventRecorded(const char* event_name, bool expected); | 185 void ExpectEventRecorded(const char* event_name, bool expected); |
| 180 void ExpectRlzPingSent(bool expected); | 186 void ExpectRlzPingSent(bool expected); |
| 181 void ExpectReactivationRlzPingSent(bool expected); | 187 void ExpectReactivationRlzPingSent(bool expected); |
| 182 | 188 |
| 183 TestRLZTracker tracker_; | 189 TestRLZTracker tracker_; |
| 190 RlzLibTestNoMachineStateHelper m_rlz_test_helper_; |
| 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_; |
| 186 #endif | 193 #endif |
| 187 }; | 194 }; |
| 188 | 195 |
| 189 void RlzLibTest::SetUp() { | 196 void RlzLibTest::SetUp() { |
| 190 RlzLibTestNoMachineState::SetUp(); | 197 ChromeRenderViewHostTestHarness::SetUp(); |
| 198 m_rlz_test_helper_.SetUp(); |
| 191 | 199 |
| 192 // Make sure a non-organic brand code is set in the registry or the RLZTracker | 200 // Make sure a non-organic brand code is set in the registry or the RLZTracker |
| 193 // is pretty much a no-op. | 201 // is pretty much a no-op. |
| 194 SetMainBrand("TEST"); | 202 SetMainBrand("TEST"); |
| 195 SetReactivationBrand(""); | 203 SetReactivationBrand(""); |
| 196 } | 204 } |
| 197 | 205 |
| 206 void RlzLibTest::TearDown() { |
| 207 ChromeRenderViewHostTestHarness::TearDown(); |
| 208 m_rlz_test_helper_.TearDown(); |
| 209 } |
| 210 |
| 198 void RlzLibTest::SetMainBrand(const char* brand) { | 211 void RlzLibTest::SetMainBrand(const char* brand) { |
| 199 #if defined(OS_WIN) | 212 #if defined(OS_WIN) |
| 200 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); | 213 SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
| 201 #elif defined(OS_POSIX) | 214 #elif defined(OS_POSIX) |
| 202 brand_override_.reset(new google_brand::BrandForTesting(brand)); | 215 brand_override_.reset(new google_brand::BrandForTesting(brand)); |
| 203 #endif | 216 #endif |
| 204 std::string check_brand; | 217 std::string check_brand; |
| 205 google_brand::GetBrand(&check_brand); | 218 google_brand::GetBrand(&check_brand); |
| 206 EXPECT_EQ(brand, check_brand); | 219 EXPECT_EQ(brand, check_brand); |
| 207 } | 220 } |
| (...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 243 base::TimeDelta::FromSeconds(0), 0, | 256 base::TimeDelta::FromSeconds(0), 0, |
| 244 base::TimeDelta::FromSeconds(0), | 257 base::TimeDelta::FromSeconds(0), |
| 245 AutocompleteResult()); | 258 AutocompleteResult()); |
| 246 | 259 |
| 247 tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, | 260 tracker_.Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL, |
| 248 content::NotificationService::AllSources(), | 261 content::NotificationService::AllSources(), |
| 249 content::Details<OmniboxLog>(&dummy)); | 262 content::Details<OmniboxLog>(&dummy)); |
| 250 } | 263 } |
| 251 | 264 |
| 252 void RlzLibTest::SimulateHomepageUsage() { | 265 void RlzLibTest::SimulateHomepageUsage() { |
| 253 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 266 GURL home_url = GURL("https://www.google.com/"); |
| 254 entry->SetPageID(0); | 267 GURL search_url = GURL("https://www.google.com/#q=search"); |
| 255 entry->SetTransitionType(ui::PAGE_TRANSITION_HOME_PAGE); | 268 |
| 256 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 269 content::RenderFrameHostTester* rfht = |
| 257 content::NotificationService::AllSources(), | 270 content::RenderFrameHostTester::For(main_rfh()); |
| 258 content::Details<NavigationEntry>(entry.get())); | 271 |
| 272 // Simulate a navigation to homepage first. |
| 273 rfht->SendNavigateWithTransition(0, home_url, ui::PAGE_TRANSITION_HOME_PAGE); |
| 274 // Then simulate a search from homepage. |
| 275 rfht->SendNavigateWithTransition(1, search_url, ui::PAGE_TRANSITION_LINK); |
| 259 } | 276 } |
| 260 | 277 |
| 261 void RlzLibTest::SimulateAppListUsage() { | 278 void RlzLibTest::SimulateAppListUsage() { |
| 262 RLZTracker::RecordAppListSearch(); | 279 RLZTracker::RecordAppListSearch(); |
| 263 } | 280 } |
| 264 | 281 |
| 265 void RlzLibTest::InvokeDelayedInit() { | 282 void RlzLibTest::InvokeDelayedInit() { |
| 266 tracker_.DelayedInit(); | 283 tracker_.DelayedInit(); |
| 267 } | 284 } |
| 268 | 285 |
| (...skipping 549 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 818 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz)); | 835 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz)); |
| 819 EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str()); | 836 EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 820 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( | 837 EXPECT_TRUE(RLZTracker::GetAccessPointRlz( |
| 821 RLZTracker::ChromeHomePage(), &rlz)); | 838 RLZTracker::ChromeHomePage(), &rlz)); |
| 822 EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str()); | 839 EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 823 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz)); | 840 EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz)); |
| 824 EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str()); | 841 EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str()); |
| 825 } | 842 } |
| 826 | 843 |
| 827 TEST_F(RlzLibTest, ObserveHandlesBadArgs) { | 844 TEST_F(RlzLibTest, ObserveHandlesBadArgs) { |
| 828 scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); | 845 scoped_ptr<LoadCommittedDetails> details(new LoadCommittedDetails()); |
| 829 entry->SetPageID(0); | 846 details->entry = NavigationEntry::Create(); |
| 830 entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); | 847 details->entry->SetPageID(0); |
| 831 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 848 details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); |
| 849 |
| 850 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 832 content::NotificationService::AllSources(), | 851 content::NotificationService::AllSources(), |
| 833 content::Details<NavigationEntry>(NULL)); | 852 content::Details<NavigationEntry>(NULL)); |
| 834 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, | 853 tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| 835 content::NotificationService::AllSources(), | 854 content::NotificationService::AllSources(), |
| 836 content::Details<NavigationEntry>(entry.get())); | 855 content::Details<LoadCommittedDetails>(details.get())); |
| 837 } | 856 } |
| 838 | 857 |
| 839 // TODO(thakis): Reactivation doesn't exist on Mac yet. | 858 // TODO(thakis): Reactivation doesn't exist on Mac yet. |
| 840 #if defined(OS_WIN) | 859 #if defined(OS_WIN) |
| 841 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { | 860 TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) { |
| 842 SetReactivationBrand("REAC"); | 861 SetReactivationBrand("REAC"); |
| 843 | 862 |
| 844 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false); | 863 TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, false); |
| 845 InvokeDelayedInit(); | 864 InvokeDelayedInit(); |
| 846 | 865 |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 887 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), | 906 RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(), |
| 888 rlz_lib::FIRST_SEARCH); | 907 rlz_lib::FIRST_SEARCH); |
| 889 | 908 |
| 890 ExpectEventRecorded(kOmniboxFirstSearch, true); | 909 ExpectEventRecorded(kOmniboxFirstSearch, true); |
| 891 | 910 |
| 892 RLZTracker::ClearRlzState(); | 911 RLZTracker::ClearRlzState(); |
| 893 | 912 |
| 894 ExpectEventRecorded(kOmniboxFirstSearch, false); | 913 ExpectEventRecorded(kOmniboxFirstSearch, false); |
| 895 } | 914 } |
| 896 #endif // defined(OS_CHROMEOS) | 915 #endif // defined(OS_CHROMEOS) |
| OLD | NEW |