| Index: chrome/browser/rlz/rlz_unittest.cc
|
| diff --git a/chrome/browser/rlz/rlz_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc
|
| index 6a2f26ec762bd11c8a0a583cff2bb7e157028901..2a8c89e3eb379d527011af8a21d22000925dacb7 100644
|
| --- a/chrome/browser/rlz/rlz_unittest.cc
|
| +++ b/chrome/browser/rlz/rlz_unittest.cc
|
| @@ -14,19 +14,24 @@
|
| #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/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;
|
| @@ -106,40 +111,40 @@ class TestRLZTracker : public RLZTracker {
|
| }
|
|
|
| private:
|
| - virtual void ScheduleDelayedInit(base::TimeDelta delay) override {
|
| + virtual void ScheduleDelayedInit(base::TimeDelta delay) OVERRIDE {
|
| // If the delay is 0, invoke the delayed init now. Otherwise,
|
| // don't schedule anything, it will be manually called during tests.
|
| if (delay == base::TimeDelta())
|
| DelayedInit();
|
| }
|
|
|
| - virtual void ScheduleFinancialPing() override {
|
| + virtual void ScheduleFinancialPing() OVERRIDE {
|
| PingNowImpl();
|
| }
|
|
|
| virtual bool ScheduleRecordProductEvent(rlz_lib::Product product,
|
| rlz_lib::AccessPoint point,
|
| - rlz_lib::Event event_id) override {
|
| + rlz_lib::Event event_id) OVERRIDE {
|
| return !assume_not_ui_thread_;
|
| }
|
|
|
| - virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) override {
|
| + virtual bool ScheduleGetAccessPointRlz(rlz_lib::AccessPoint point) OVERRIDE {
|
| return !assume_not_ui_thread_;
|
| }
|
|
|
| - virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) override {
|
| + virtual bool ScheduleRecordFirstSearch(rlz_lib::AccessPoint point) OVERRIDE {
|
| return !assume_not_ui_thread_;
|
| }
|
|
|
| #if defined(OS_CHROMEOS)
|
| - virtual bool ScheduleClearRlzState() override {
|
| + virtual bool ScheduleClearRlzState() OVERRIDE {
|
| return !assume_not_ui_thread_;
|
| }
|
| #endif
|
|
|
| virtual bool SendFinancialPing(const std::string& brand,
|
| const base::string16& lang,
|
| - const base::string16& referral) override {
|
| + const base::string16& referral) OVERRIDE {
|
| // Don't ping the server during tests, just pretend as if we did.
|
| EXPECT_FALSE(brand.empty());
|
| pinged_brands_.insert(brand);
|
| @@ -161,9 +166,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 SetUp() OVERRIDE;
|
| + virtual void TearDown() OVERRIDE;
|
|
|
| void SetMainBrand(const char* brand);
|
| void SetReactivationBrand(const char* brand);
|
| @@ -181,13 +187,12 @@ class RlzLibTest : public RlzLibTestNoMachineState {
|
| void ExpectReactivationRlzPingSent(bool expected);
|
|
|
| TestRLZTracker tracker_;
|
| -#if defined(OS_POSIX)
|
| - scoped_ptr<google_brand::BrandForTesting> brand_override_;
|
| -#endif
|
| + RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
|
| };
|
|
|
| void RlzLibTest::SetUp() {
|
| - RlzLibTestNoMachineState::SetUp();
|
| + ChromeRenderViewHostTestHarness::SetUp();
|
| + m_rlz_test_helper_.SetUp();
|
|
|
| // Make sure a non-organic brand code is set in the registry or the RLZTracker
|
| // is pretty much a no-op.
|
| @@ -195,6 +200,11 @@ void RlzLibTest::SetUp() {
|
| SetReactivationBrand("");
|
| }
|
|
|
| +void RlzLibTest::TearDown() {
|
| + ChromeRenderViewHostTestHarness::TearDown();
|
| + m_rlz_test_helper_.TearDown();
|
| +}
|
| +
|
| void RlzLibTest::SetMainBrand(const char* brand) {
|
| #if defined(OS_WIN)
|
| SetRegistryBrandValue(google_update::kRegRLZBrandField, brand);
|
| @@ -250,12 +260,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.
|
| + trfh->SendNavigateWithTransition(1, search_url, ui::PAGE_TRANSITION_LINK);
|
| }
|
|
|
| void RlzLibTest::SimulateAppListUsage() {
|
| @@ -825,15 +839,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.
|
|
|