Chromium Code Reviews| Index: chrome/browser/rlz/rlz_unittest.cc |
| diff --git a/chrome/browser/rlz/rlz_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc |
| index 23e1dc17b38b33eec1aa548a99d794bdd7dc2d44..2dcb4f80bf2c0a8bbcee76b4b0616466f772753d 100644 |
| --- a/chrome/browser/rlz/rlz_unittest.cc |
| +++ b/chrome/browser/rlz/rlz_unittest.cc |
| @@ -14,19 +14,25 @@ |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/installer/util/browser_distribution.h" |
| #include "chrome/installer/util/google_update_constants.h" |
| +#include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| #include "components/metrics/proto/omnibox_event.pb.h" |
| +#include "content/public/browser/navigation_details.h" |
| #include "content/public/browser/navigation_entry.h" |
| #include "content/public/browser/notification_details.h" |
| #include "content/public/browser/notification_service.h" |
| #include "content/public/browser/notification_source.h" |
| +#include "content/public/common/referrer.h" |
| +#include "content/test/test_render_frame_host.h" |
| #include "rlz/test/rlz_test_helpers.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| +#include "url/gurl.h" |
| #if defined(OS_WIN) |
| #include "base/win/registry.h" |
| #endif |
| using content::NavigationEntry; |
| +using content::LoadCommittedDetails; |
| using testing::AssertionResult; |
| using testing::AssertionSuccess; |
| using testing::AssertionFailure; |
| @@ -161,9 +167,10 @@ class TestRLZTracker : public RLZTracker { |
| DISALLOW_COPY_AND_ASSIGN(TestRLZTracker); |
| }; |
| -class RlzLibTest : public RlzLibTestNoMachineState { |
| +class RlzLibTest : public ChromeRenderViewHostTestHarness { |
| protected: |
| virtual void SetUp() OVERRIDE; |
| + virtual void TearDown() OVERRIDE; |
| void SetMainBrand(const char* brand); |
| void SetReactivationBrand(const char* brand); |
| @@ -183,11 +190,27 @@ class RlzLibTest : public RlzLibTestNoMachineState { |
| TestRLZTracker tracker_; |
| #if defined(OS_POSIX) |
| scoped_ptr<google_brand::BrandForTesting> brand_override_; |
| + base::ScopedTempDir temp_dir_; |
| #endif |
| +#if defined(OS_WIN) |
| + registry_util::RegistryOverrideManager override_manager_; |
| +#endif |
| + |
| }; |
| void RlzLibTest::SetUp() { |
| - RlzLibTestNoMachineState::SetUp(); |
| + ChromeRenderViewHostTestHarness::SetUp(); |
| + |
| + // Same with RlzLibTestNoMachineState::SetUp(). |
| +#if defined(OS_WIN) |
| + InitializeRegistryOverridesForTesting(&override_manager_); |
| +#elif defined(OS_MACOSX) |
| + base::mac::ScopedNSAutoreleasePool pool; |
| +#endif // defined(OS_WIN) |
| +#if defined(OS_POSIX) |
| + ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| + rlz_lib::testing::SetRlzStoreDirectory(temp_dir_.path()); |
| +#endif // defined(OS_POSIX) |
| // Make sure a non-organic brand code is set in the registry or the RLZTracker |
| // is pretty much a no-op. |
| @@ -195,6 +218,15 @@ void RlzLibTest::SetUp() { |
| SetReactivationBrand(""); |
| } |
| +void RlzLibTest::TearDown() { |
| + ChromeRenderViewHostTestHarness::TearDown(); |
| + |
| +// Same with RlzLibTestNoMachineState::TearDown(). |
| +#if defined(OS_POSIX) |
| + rlz_lib::testing::SetRlzStoreDirectory(base::FilePath()); |
| +#endif // defined(OS_POSIX) |
| +} |
| + |
| void RlzLibTest::SetMainBrand(const char* brand) { |
| #if defined(OS_WIN) |
| SetRegistryBrandValue(google_update::kRegRLZBrandField, brand); |
| @@ -250,12 +282,16 @@ void RlzLibTest::SimulateOmniboxUsage() { |
| } |
| void RlzLibTest::SimulateHomepageUsage() { |
| - scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
| - entry->SetPageID(0); |
| - entry->SetTransitionType(ui::PAGE_TRANSITION_HOME_PAGE); |
| - tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, |
| - content::NotificationService::AllSources(), |
| - content::Details<NavigationEntry>(entry.get())); |
| + GURL home_url = GURL("https://www.google.com/"); |
| + GURL search_url = GURL("https://www.google.com/#q=search"); |
| + |
| + content::TestRenderFrameHost* trfh = |
| + static_cast<content::TestRenderFrameHost*>(main_rfh()); |
| + |
| + // Simulate a navigation to homepage first. |
| + trfh->SendNavigateWithTransition(0, home_url, ui::PAGE_TRANSITION_HOME_PAGE); |
| + // 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
|
| + trfh->SendNavigateWithTransition(1, search_url, ui::PAGE_TRANSITION_LINK); |
| } |
| void RlzLibTest::SimulateAppListUsage() { |
| @@ -825,15 +861,17 @@ TEST_F(RlzLibTest, PingUpdatesRlzCache) { |
| } |
| TEST_F(RlzLibTest, ObserveHandlesBadArgs) { |
| - scoped_ptr<NavigationEntry> entry(NavigationEntry::Create()); |
| - entry->SetPageID(0); |
| - entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); |
| - tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, |
| + scoped_ptr<LoadCommittedDetails> details(new LoadCommittedDetails()); |
| + details->entry = NavigationEntry::Create(); |
| + details->entry->SetPageID(0); |
| + details->entry->SetTransitionType(ui::PAGE_TRANSITION_LINK); |
| + |
| + tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| content::NotificationService::AllSources(), |
| content::Details<NavigationEntry>(NULL)); |
| - tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_PENDING, |
| + tracker_.Observe(content::NOTIFICATION_NAV_ENTRY_COMMITTED, |
| content::NotificationService::AllSources(), |
| - content::Details<NavigationEntry>(entry.get())); |
| + content::Details<LoadCommittedDetails>(details.get())); |
| } |
| // TODO(thakis): Reactivation doesn't exist on Mac yet. |