Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(1890)

Unified Diff: chrome/browser/rlz/rlz_unittest.cc

Issue 1229933005: Revert "Componentize chrome/browser/rlz" (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « chrome/browser/rlz/rlz_mac.cc ('k') | chrome/browser/rlz/rlz_win.cc » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/rlz/rlz_unittest.cc
diff --git a/components/rlz/rlz_tracker_unittest.cc b/chrome/browser/rlz/rlz_unittest.cc
similarity index 68%
rename from components/rlz/rlz_tracker_unittest.cc
rename to chrome/browser/rlz/rlz_unittest.cc
index eb33d891b612ffaefd8741d981f8ecde2455d4cc..8aeb09c8186042152a9ce9ecadb248e05dcde288 100644
--- a/components/rlz/rlz_tracker_unittest.cc
+++ b/chrome/browser/rlz/rlz_unittest.cc
@@ -2,132 +2,53 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
-#include "components/rlz/rlz_tracker.h"
+#include "chrome/browser/rlz/rlz.h"
-#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
-#include "base/message_loop/message_loop.h"
#include "base/strings/utf_string_conversions.h"
-#include "base/thread_task_runner_handle.h"
-#include "base/threading/sequenced_worker_pool.h"
#include "base/time/time.h"
-#include "components/rlz/rlz_tracker_delegate.h"
-#include "net/url_request/url_request_test_util.h"
+#include "chrome/browser/chrome_notification_types.h"
+#include "chrome/browser/google/google_brand.h"
+#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 "components/omnibox/browser/autocomplete_controller.h"
+#include "components/omnibox/browser/omnibox_log.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/test/test_renderer_host.h"
#include "rlz/test/rlz_test_helpers.h"
#include "testing/gtest/include/gtest/gtest.h"
+#include "url/gurl.h"
-#if defined(OS_IOS)
-#include "ui/base/device_form_factor.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;
-namespace rlz {
-namespace {
-
-class TestRLZTrackerDelegate : public RLZTrackerDelegate {
- public:
- TestRLZTrackerDelegate()
- : worker_pool_(new base::SequencedWorkerPool(1, "TestRLZTracker")),
- request_context_getter_(new net::TestURLRequestContextGetter(
- base::ThreadTaskRunnerHandle::Get())) {}
-
- ~TestRLZTrackerDelegate() override { worker_pool_->Shutdown(); }
-
- void set_brand(const char* brand) { brand_override_ = brand; }
-
- void set_reactivation_brand(const char* reactivation_brand) {
- // TODO(thakis): Reactivation doesn't exist on Mac yet.
- reactivation_brand_override_ = reactivation_brand;
- }
-
- void SimulateOmniboxUsage() {
- using std::swap;
- base::Closure callback;
- swap(callback, on_omnibox_search_callback_);
- if (!callback.is_null())
- callback.Run();
- }
-
- void SimulateHomepageUsage() {
- using std::swap;
- base::Closure callback;
- swap(callback, on_homepage_search_callback_);
- if (!callback.is_null())
- callback.Run();
- }
-
- // RLZTrackerDelegate implementation.
- void Cleanup() override {
- on_omnibox_search_callback_.Reset();
- on_homepage_search_callback_.Reset();
- }
-
- bool IsOnUIThread() override { return true; }
-
- base::SequencedWorkerPool* GetBlockingPool() override {
- return worker_pool_.get();
- }
-
- net::URLRequestContextGetter* GetRequestContext() override {
- return request_context_getter_.get();
- }
-
- bool GetBrand(std::string* brand) override {
- *brand = brand_override_;
- return true;
- }
-
- bool IsBrandOrganic(const std::string& brand) override {
- return brand.empty() || brand == "GGLS" || brand == "GGRS";
- }
-
- bool GetReactivationBrand(std::string* brand) override {
- *brand = reactivation_brand_override_;
- return true;
- }
-
- bool ShouldEnableZeroDelayForTesting() override { return true; }
-
- bool GetLanguage(base::string16* language) override { return true; }
-
- bool GetReferral(base::string16* referral) override { return true; }
-
- bool ClearReferral() override { return true; }
-
- void SetOmniboxSearchCallback(const base::Closure& callback) override {
- DCHECK(!callback.is_null());
- on_omnibox_search_callback_ = callback;
- }
-
- void SetHomepageSearchCallback(const base::Closure& callback) override {
- DCHECK(!callback.is_null());
- on_homepage_search_callback_ = callback;
- }
-
- private:
- scoped_refptr<base::SequencedWorkerPool> worker_pool_;
- scoped_refptr<net::URLRequestContextGetter> request_context_getter_;
-
- std::string brand_override_;
- std::string reactivation_brand_override_;
- base::Closure on_omnibox_search_callback_;
- base::Closure on_homepage_search_callback_;
+#if defined(OS_WIN)
+using base::win::RegKey;
+#endif
- DISALLOW_COPY_AND_ASSIGN(TestRLZTrackerDelegate);
-};
+namespace {
// Dummy RLZ string for the access points.
const char kOmniboxRlzString[] = "test_omnibox";
-const char kNewOmniboxRlzString[] = "new_omnibox";
-#if !defined(OS_IOS)
const char kHomepageRlzString[] = "test_homepage";
-const char kNewHomepageRlzString[] = "new_homepage";
const char kAppListRlzString[] = "test_applist";
+const char kNewOmniboxRlzString[] = "new_omnibox";
+const char kNewHomepageRlzString[] = "new_homepage";
const char kNewAppListRlzString[] = "new_applist";
-#endif // !defined(OS_IOS)
// Some helper macros to test it a string contains/does not contain a substring.
@@ -135,7 +56,7 @@ AssertionResult CmpHelperSTRC(const char* str_expression,
const char* substr_expression,
const char* str,
const char* substr) {
- if (nullptr != strstr(str, substr)) {
+ if (NULL != strstr(str, substr)) {
return AssertionSuccess();
}
@@ -148,7 +69,7 @@ AssertionResult CmpHelperSTRNC(const char* str_expression,
const char* substr_expression,
const char* str,
const char* substr) {
- if (nullptr == strstr(str, substr)) {
+ if (NULL == strstr(str, substr)) {
return AssertionSuccess();
}
@@ -171,10 +92,15 @@ class TestRLZTracker : public RLZTracker {
public:
using RLZTracker::InitRlzDelayed;
using RLZTracker::DelayedInit;
+ using RLZTracker::Observe;
- TestRLZTracker() : assume_not_ui_thread_(true) { set_tracker(this); }
+ TestRLZTracker() : assume_not_ui_thread_(true) {
+ set_tracker(this);
+ }
- ~TestRLZTracker() override { set_tracker(nullptr); }
+ ~TestRLZTracker() override {
+ set_tracker(NULL);
+ }
bool was_ping_sent_for_brand(const std::string& brand) const {
return pinged_brands_.count(brand) > 0;
@@ -192,11 +118,13 @@ class TestRLZTracker : public RLZTracker {
DelayedInit();
}
- void ScheduleFinancialPing() override { PingNowImpl(); }
+ void ScheduleFinancialPing() override {
+ PingNowImpl();
+ }
bool ScheduleRecordProductEvent(rlz_lib::Product product,
- rlz_lib::AccessPoint point,
- rlz_lib::Event event_id) override {
+ rlz_lib::AccessPoint point,
+ rlz_lib::Event event_id) override {
return !assume_not_ui_thread_;
}
@@ -209,12 +137,14 @@ class TestRLZTracker : public RLZTracker {
}
#if defined(OS_CHROMEOS)
- bool ScheduleClearRlzState() override { return !assume_not_ui_thread_; }
+ bool ScheduleClearRlzState() override {
+ return !assume_not_ui_thread_;
+ }
#endif
bool SendFinancialPing(const std::string& brand,
- const base::string16& lang,
- const base::string16& referral) override {
+ const base::string16& lang,
+ 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);
@@ -223,12 +153,10 @@ class TestRLZTracker : public RLZTracker {
// done.
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(),
kNewOmniboxRlzString);
-#if !defined(OS_IOS)
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(),
kNewHomepageRlzString);
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(),
kNewAppListRlzString);
-#endif // !defined(OS_IOS)
return true;
}
@@ -238,13 +166,16 @@ class TestRLZTracker : public RLZTracker {
DISALLOW_COPY_AND_ASSIGN(TestRLZTracker);
};
-class RlzLibTest : public testing::Test {
+class RlzLibTest : public ChromeRenderViewHostTestHarness {
protected:
void SetUp() override;
void TearDown() override;
void SetMainBrand(const char* brand);
void SetReactivationBrand(const char* brand);
+#if defined(OS_WIN)
+ void SetRegistryBrandValue(const wchar_t* name, const char* brand);
+#endif
void SimulateOmniboxUsage();
void SimulateHomepageUsage();
@@ -255,19 +186,17 @@ class RlzLibTest : public testing::Test {
void ExpectRlzPingSent(bool expected);
void ExpectReactivationRlzPingSent(bool expected);
- base::MessageLoop message_loop_;
- TestRLZTrackerDelegate* delegate_;
scoped_ptr<TestRLZTracker> tracker_;
RlzLibTestNoMachineStateHelper m_rlz_test_helper_;
+#if defined(OS_POSIX)
+ scoped_ptr<google_brand::BrandForTesting> brand_override_;
+#endif
};
void RlzLibTest::SetUp() {
- testing::Test::SetUp();
+ ChromeRenderViewHostTestHarness::SetUp();
m_rlz_test_helper_.SetUp();
-
- delegate_ = new TestRLZTrackerDelegate;
tracker_.reset(new TestRLZTracker());
- RLZTracker::SetRlzDelegate(make_scoped_ptr(delegate_));
// Make sure a non-organic brand code is set in the registry or the RLZTracker
// is pretty much a no-op.
@@ -276,32 +205,86 @@ void RlzLibTest::SetUp() {
}
void RlzLibTest::TearDown() {
- delegate_ = nullptr;
tracker_.reset();
- testing::Test::TearDown();
+ ChromeRenderViewHostTestHarness::TearDown();
m_rlz_test_helper_.TearDown();
}
void RlzLibTest::SetMainBrand(const char* brand) {
- delegate_->set_brand(brand);
+#if defined(OS_WIN)
+ SetRegistryBrandValue(google_update::kRegRLZBrandField, brand);
+#elif defined(OS_POSIX)
+ brand_override_.reset(new google_brand::BrandForTesting(brand));
+#endif
+ std::string check_brand;
+ google_brand::GetBrand(&check_brand);
+ EXPECT_EQ(brand, check_brand);
}
void RlzLibTest::SetReactivationBrand(const char* brand) {
- delegate_->set_reactivation_brand(brand);
+ // TODO(thakis): Reactivation doesn't exist on Mac yet.
+#if defined(OS_WIN)
+ SetRegistryBrandValue(google_update::kRegRLZReactivationBrandField, brand);
+ std::string check_brand;
+ google_brand::GetReactivationBrand(&check_brand);
+ EXPECT_EQ(brand, check_brand);
+#endif
}
+#if defined(OS_WIN)
+void RlzLibTest::SetRegistryBrandValue(const wchar_t* name,
+ const char* brand) {
+ BrowserDistribution* dist = BrowserDistribution::GetDistribution();
+ base::string16 reg_path = dist->GetStateKey();
+ RegKey key(HKEY_CURRENT_USER, reg_path.c_str(), KEY_SET_VALUE);
+ if (*brand == 0) {
+ LONG result = key.DeleteValue(name);
+ ASSERT_TRUE(ERROR_SUCCESS == result || ERROR_FILE_NOT_FOUND == result);
+ } else {
+ base::string16 brand16 = base::ASCIIToUTF16(brand);
+ ASSERT_EQ(ERROR_SUCCESS, key.WriteValue(name, brand16.c_str()));
+ }
+}
+#endif
+
void RlzLibTest::SimulateOmniboxUsage() {
- delegate_->SimulateOmniboxUsage();
+ // Create a dummy OmniboxLog object. The 'is_popup_open' field needs to be
+ // true to trigger record of the first search. All other fields are passed in
+ // with empty or invalid values.
+ AutocompleteResult empty_result;
+ OmniboxLog dummy(base::string16(), false, metrics::OmniboxInputType::INVALID,
+ true, 0, false, -1,
+ metrics::OmniboxEventProto::INVALID_SPEC,
+ base::TimeDelta::FromSeconds(0), 0,
+ base::TimeDelta::FromSeconds(0),
+ AutocompleteResult());
+
+ tracker_->Observe(chrome::NOTIFICATION_OMNIBOX_OPENED_URL,
+ content::NotificationService::AllSources(),
+ content::Details<OmniboxLog>(&dummy));
}
void RlzLibTest::SimulateHomepageUsage() {
- delegate_->SimulateHomepageUsage();
+ GURL home_url = GURL("https://www.google.com/");
+ GURL search_url = GURL("https://www.google.com/#q=search");
+
+ content::RenderFrameHostTester* rfht =
+ content::RenderFrameHostTester::For(main_rfh());
+
+ // Ensure the RenderFrame is initialized before simulating events coming from
+ // it.
+ rfht->InitializeRenderFrameIfNeeded();
+
+ // Simulate a navigation to homepage first.
+ rfht->SendNavigateWithTransition(
+ 0, 0, true, home_url, ui::PAGE_TRANSITION_HOME_PAGE);
+ // Then simulate a search from homepage.
+ rfht->SendNavigateWithTransition(
+ 1, 0, true, search_url, ui::PAGE_TRANSITION_LINK);
}
void RlzLibTest::SimulateAppListUsage() {
-#if !defined(OS_IOS)
RLZTracker::RecordAppListSearch();
-#endif // !defined(OS_IOS)
}
void RlzLibTest::InvokeDelayedInit() {
@@ -320,13 +303,13 @@ void RlzLibTest::ExpectEventRecorded(const char* event_name, bool expected) {
void RlzLibTest::ExpectRlzPingSent(bool expected) {
std::string brand;
- delegate_->GetBrand(&brand);
+ google_brand::GetBrand(&brand);
EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
}
void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
std::string brand;
- delegate_->GetReactivationBrand(&brand);
+ google_brand::GetReactivationBrand(&brand);
EXPECT_EQ(expected, tracker_->was_ping_sent_for_brand(brand.c_str()));
}
@@ -360,9 +343,6 @@ void RlzLibTest::ExpectReactivationRlzPingSent(bool expected) {
// On Mac, C5 / C6 / C8 are sent instead of C1 / C2 / C7.
// On ChromeOS, CA / CB / CC are sent, respectively.
//
-// On iOS, only the omnibox events are recorded, and the value send depends
-// on the device form factor (phone or tablet).
-//
// Variations on the above scenarios:
//
// - if the delay specified to InitRlzDelayed() is negative, then the RLZ
@@ -377,19 +357,11 @@ const char kOmniboxFirstSearch[] = "C1F";
const char kHomepageInstall[] = "C2I";
const char kHomepageSetToGoogle[] = "C2S";
-const char kHomepageFirstSearch[] = "C2F";
+const char kHomepageFirstSeach[] = "C2F";
const char kAppListInstall[] = "C7I";
const char kAppListSetToGoogle[] = "C7S";
const char kAppListFirstSearch[] = "C7F";
-#elif defined(OS_IOS)
-const char kOmniboxInstallPhone[] = "CDI";
-const char kOmniboxSetToGooglePhone[] = "CDS";
-const char kOmniboxFirstSearchPhone[] = "CDF";
-
-const char kOmniboxInstallTablet[] = "C9I";
-const char kOmniboxSetToGoogleTablet[] = "C9S";
-const char kOmniboxFirstSearchTablet[] = "C9F";
#elif defined(OS_MACOSX)
const char kOmniboxInstall[] = "C5I";
const char kOmniboxSetToGoogle[] = "C5S";
@@ -397,7 +369,7 @@ const char kOmniboxFirstSearch[] = "C5F";
const char kHomepageInstall[] = "C6I";
const char kHomepageSetToGoogle[] = "C6S";
-const char kHomepageFirstSearch[] = "C6F";
+const char kHomepageFirstSeach[] = "C6F";
const char kAppListInstall[] = "C8I";
const char kAppListSetToGoogle[] = "C8S";
@@ -409,71 +381,39 @@ const char kOmniboxFirstSearch[] = "CAF";
const char kHomepageInstall[] = "CBI";
const char kHomepageSetToGoogle[] = "CBS";
-const char kHomepageFirstSearch[] = "CBF";
+const char kHomepageFirstSeach[] = "CBF";
const char kAppListInstall[] = "CCI";
const char kAppListSetToGoogle[] = "CCS";
const char kAppListFirstSearch[] = "CCF";
#endif
-const char* OmniboxInstall() {
-#if defined(OS_IOS)
- return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
- ? kOmniboxInstallTablet
- : kOmniboxInstallPhone;
-#else
- return kOmniboxInstall;
-#endif
-}
-
-const char* OmniboxSetToGoogle() {
-#if defined(OS_IOS)
- return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
- ? kOmniboxSetToGoogleTablet
- : kOmniboxSetToGooglePhone;
-#else
- return kOmniboxSetToGoogle;
-#endif
-}
-
-const char* OmniboxFirstSearch() {
-#if defined(OS_IOS)
- return ui::GetDeviceFormFactor() == ui::DEVICE_FORM_FACTOR_TABLET
- ? kOmniboxFirstSearchTablet
- : kOmniboxFirstSearchPhone;
-#else
- return kOmniboxFirstSearch;
-#endif
-}
-
const base::TimeDelta kDelay = base::TimeDelta::FromMilliseconds(20);
TEST_F(RlzLibTest, RecordProductEvent) {
RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
rlz_lib::FIRST_SEARCH);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
}
TEST_F(RlzLibTest, QuickStopAfterStart) {
TestRLZTracker::InitRlzDelayed(true, false, kDelay, true, true, true);
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -483,21 +423,19 @@ TEST_F(RlzLibTest, DelayedInitOnly) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), true);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, true);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, true);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -507,21 +445,19 @@ TEST_F(RlzLibTest, DelayedInitOnlyGoogleAsStartup) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -531,21 +467,19 @@ TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStrings) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), true);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, true);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, true);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -555,21 +489,19 @@ TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRunNoRlzStringsGoogleAsStartup) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -578,30 +510,26 @@ TEST_F(RlzLibTest, DelayedInitOnlyNoFirstRun) {
// Set some dummy RLZ strings to simulate that we already ran before and
// performed a successful ping to the RLZ server.
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
-#if !defined(OS_IOS)
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
-#endif // !defined(OS_IOS)
TestRLZTracker::InitRlzDelayed(false, false, kDelay, true, true, true);
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -611,21 +539,19 @@ TEST_F(RlzLibTest, DelayedInitOnlyNoGoogleDefaultSearchOrHomepageOrStartup) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -635,21 +561,19 @@ TEST_F(RlzLibTest, OmniboxUsageOnly) {
SimulateOmniboxUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -659,21 +583,19 @@ TEST_F(RlzLibTest, HomepageUsageOnly) {
SimulateHomepageUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -683,21 +605,19 @@ TEST_F(RlzLibTest, AppListUsageOnly) {
SimulateAppListUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, true);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -710,21 +630,19 @@ TEST_F(RlzLibTest, UsageBeforeDelayedInit) {
InvokeDelayedInit();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), true);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, true);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, true);
ExpectEventRecorded(kAppListFirstSearch, true);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -737,21 +655,19 @@ TEST_F(RlzLibTest, UsageAfterDelayedInit) {
SimulateAppListUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), true);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, true);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, true);
ExpectEventRecorded(kAppListFirstSearch, true);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -761,21 +677,19 @@ TEST_F(RlzLibTest, OmniboxUsageSendsPingWhenSendPingImmediately) {
SimulateOmniboxUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), true);
- ExpectEventRecorded(OmniboxSetToGoogle(), true);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxInstall, true);
+ ExpectEventRecorded(kOmniboxSetToGoogle, true);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, true);
ExpectEventRecorded(kHomepageSetToGoogle, true);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, true);
ExpectEventRecorded(kAppListSetToGoogle, true);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(true);
}
@@ -785,21 +699,19 @@ TEST_F(RlzLibTest, HomepageUsageDoesNotSendPingWhenSendPingImmediately) {
SimulateHomepageUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -809,21 +721,19 @@ TEST_F(RlzLibTest, StartupUsageDoesNotSendPingWhenSendPingImmediately) {
SimulateHomepageUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, true);
+ ExpectEventRecorded(kHomepageFirstSeach, true);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, false);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -833,21 +743,19 @@ TEST_F(RlzLibTest, AppListUsageDoesNotSendPingWhenSendPingImmediately) {
SimulateAppListUsage();
// Omnibox events.
- ExpectEventRecorded(OmniboxInstall(), false);
- ExpectEventRecorded(OmniboxSetToGoogle(), false);
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxInstall, false);
+ ExpectEventRecorded(kOmniboxSetToGoogle, false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
-#if !defined(OS_IOS)
// Home page events.
ExpectEventRecorded(kHomepageInstall, false);
ExpectEventRecorded(kHomepageSetToGoogle, false);
- ExpectEventRecorded(kHomepageFirstSearch, false);
+ ExpectEventRecorded(kHomepageFirstSeach, false);
// App list events.
ExpectEventRecorded(kAppListInstall, false);
ExpectEventRecorded(kAppListSetToGoogle, false);
ExpectEventRecorded(kAppListFirstSearch, true);
-#endif // !defined(OS_IOS)
ExpectRlzPingSent(false);
}
@@ -896,10 +804,8 @@ TEST_F(RlzLibTest, GetAccessPointRlzIsCached) {
TEST_F(RlzLibTest, PingUpdatesRlzCache) {
// Set dummy RLZ string.
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeOmnibox(), kOmniboxRlzString);
-#if !defined(OS_IOS)
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeHomePage(), kHomepageRlzString);
rlz_lib::SetAccessPointRlz(RLZTracker::ChromeAppList(), kAppListRlzString);
-#endif // !defined(OS_IOS)
base::string16 rlz;
@@ -908,26 +814,22 @@ TEST_F(RlzLibTest, PingUpdatesRlzCache) {
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-#if !defined(OS_IOS)
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
RLZTracker::ChromeHomePage(), &rlz));
EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-#endif // !defined(OS_IOS)
// Make sure cache is valid.
tracker_->set_assume_not_ui_thread(false);
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
EXPECT_STREQ(kOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-#if !defined(OS_IOS)
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
RLZTracker::ChromeHomePage(), &rlz));
EXPECT_STREQ(kHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
EXPECT_STREQ(kAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-#endif // !defined(OS_IOS)
// Perform ping.
tracker_->set_assume_not_ui_thread(true);
@@ -940,16 +842,31 @@ TEST_F(RlzLibTest, PingUpdatesRlzCache) {
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeOmnibox(), &rlz));
EXPECT_STREQ(kNewOmniboxRlzString, base::UTF16ToUTF8(rlz).c_str());
-#if !defined(OS_IOS)
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(
RLZTracker::ChromeHomePage(), &rlz));
EXPECT_STREQ(kNewHomepageRlzString, base::UTF16ToUTF8(rlz).c_str());
EXPECT_TRUE(RLZTracker::GetAccessPointRlz(RLZTracker::ChromeAppList(), &rlz));
EXPECT_STREQ(kNewAppListRlzString, base::UTF16ToUTF8(rlz).c_str());
-#endif // !defined(OS_IOS)
+}
+
+TEST_F(RlzLibTest, ObserveHandlesBadArgs) {
+ scoped_ptr<LoadCommittedDetails> details(new LoadCommittedDetails());
+ scoped_ptr<content::NavigationEntry> entry(
+ content::NavigationEntry::Create());
+ details->entry = entry.get();
+ 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_COMMITTED,
+ content::NotificationService::AllSources(),
+ content::Details<LoadCommittedDetails>(details.get()));
}
// TODO(thakis): Reactivation doesn't exist on Mac yet.
+#if defined(OS_WIN)
TEST_F(RlzLibTest, ReactivationNonOrganicNonOrganic) {
SetReactivationBrand("REAC");
@@ -992,18 +909,17 @@ TEST_F(RlzLibTest, ReactivationOrganicOrganic) {
ExpectRlzPingSent(false);
ExpectReactivationRlzPingSent(false);
}
+#endif // defined(OS_WIN)
#if defined(OS_CHROMEOS)
TEST_F(RlzLibTest, ClearRlzState) {
RLZTracker::RecordProductEvent(rlz_lib::CHROME, RLZTracker::ChromeOmnibox(),
rlz_lib::FIRST_SEARCH);
- ExpectEventRecorded(OmniboxFirstSearch(), true);
+ ExpectEventRecorded(kOmniboxFirstSearch, true);
RLZTracker::ClearRlzState();
- ExpectEventRecorded(OmniboxFirstSearch(), false);
+ ExpectEventRecorded(kOmniboxFirstSearch, false);
}
#endif // defined(OS_CHROMEOS)
-
-} // namespace rlz
« no previous file with comments | « chrome/browser/rlz/rlz_mac.cc ('k') | chrome/browser/rlz/rlz_win.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698