| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 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 "components/google/core/browser/google_url_tracker.h" | 5 #include "components/google/core/browser/google_url_tracker.h" |
| 6 | 6 |
| 7 #include <memory> |
| 7 #include <string> | 8 #include <string> |
| 8 #include <utility> | 9 #include <utility> |
| 9 | 10 |
| 10 #include "base/macros.h" | 11 #include "base/macros.h" |
| 11 #include "base/memory/scoped_ptr.h" | |
| 12 #include "base/thread_task_runner_handle.h" | 12 #include "base/thread_task_runner_handle.h" |
| 13 #include "components/google/core/browser/google_pref_names.h" | 13 #include "components/google/core/browser/google_pref_names.h" |
| 14 #include "components/google/core/browser/google_url_tracker_client.h" | 14 #include "components/google/core/browser/google_url_tracker_client.h" |
| 15 #include "components/prefs/pref_registry_simple.h" | 15 #include "components/prefs/pref_registry_simple.h" |
| 16 #include "components/prefs/pref_service.h" | 16 #include "components/prefs/pref_service.h" |
| 17 #include "components/prefs/testing_pref_service.h" | 17 #include "components/prefs/testing_pref_service.h" |
| 18 #include "net/url_request/test_url_fetcher_factory.h" | 18 #include "net/url_request/test_url_fetcher_factory.h" |
| 19 #include "net/url_request/url_fetcher.h" | 19 #include "net/url_request/url_fetcher.h" |
| 20 #include "net/url_request/url_request_test_util.h" | 20 #include "net/url_request/url_request_test_util.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 10 matching lines...) Expand all Loading... |
| 32 bool HasRegisteredCallback(); | 32 bool HasRegisteredCallback(); |
| 33 void RegisterCallback(GoogleURLTracker* google_url_tracker); | 33 void RegisterCallback(GoogleURLTracker* google_url_tracker); |
| 34 | 34 |
| 35 bool notified() const { return notified_; } | 35 bool notified() const { return notified_; } |
| 36 void clear_notified() { notified_ = false; } | 36 void clear_notified() { notified_ = false; } |
| 37 | 37 |
| 38 private: | 38 private: |
| 39 void OnGoogleURLUpdated(); | 39 void OnGoogleURLUpdated(); |
| 40 | 40 |
| 41 bool notified_; | 41 bool notified_; |
| 42 scoped_ptr<GoogleURLTracker::Subscription> google_url_updated_subscription_; | 42 std::unique_ptr<GoogleURLTracker::Subscription> |
| 43 google_url_updated_subscription_; |
| 43 }; | 44 }; |
| 44 | 45 |
| 45 TestCallbackListener::TestCallbackListener() : notified_(false) { | 46 TestCallbackListener::TestCallbackListener() : notified_(false) { |
| 46 } | 47 } |
| 47 | 48 |
| 48 TestCallbackListener::~TestCallbackListener() { | 49 TestCallbackListener::~TestCallbackListener() { |
| 49 } | 50 } |
| 50 | 51 |
| 51 void TestCallbackListener::OnGoogleURLUpdated() { | 52 void TestCallbackListener::OnGoogleURLUpdated() { |
| 52 notified_ = true; | 53 notified_ = true; |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 128 GURL google_url() const { return google_url_tracker_->google_url(); } | 129 GURL google_url() const { return google_url_tracker_->google_url(); } |
| 129 bool listener_notified() const { return listener_.notified(); } | 130 bool listener_notified() const { return listener_.notified(); } |
| 130 void clear_listener_notified() { listener_.clear_notified(); } | 131 void clear_listener_notified() { listener_.clear_notified(); } |
| 131 | 132 |
| 132 private: | 133 private: |
| 133 base::MessageLoop message_loop_; | 134 base::MessageLoop message_loop_; |
| 134 TestingPrefServiceSimple prefs_; | 135 TestingPrefServiceSimple prefs_; |
| 135 | 136 |
| 136 // Creating this allows us to call | 137 // Creating this allows us to call |
| 137 // net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(). | 138 // net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(). |
| 138 scoped_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 139 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
| 139 net::TestURLFetcherFactory fetcher_factory_; | 140 net::TestURLFetcherFactory fetcher_factory_; |
| 140 GoogleURLTrackerClient* client_; | 141 GoogleURLTrackerClient* client_; |
| 141 scoped_ptr<GoogleURLTracker> google_url_tracker_; | 142 std::unique_ptr<GoogleURLTracker> google_url_tracker_; |
| 142 TestCallbackListener listener_; | 143 TestCallbackListener listener_; |
| 143 }; | 144 }; |
| 144 | 145 |
| 145 GoogleURLTrackerTest::GoogleURLTrackerTest() { | 146 GoogleURLTrackerTest::GoogleURLTrackerTest() { |
| 146 prefs_.registry()->RegisterStringPref( | 147 prefs_.registry()->RegisterStringPref( |
| 147 prefs::kLastKnownGoogleURL, | 148 prefs::kLastKnownGoogleURL, |
| 148 GoogleURLTracker::kDefaultGoogleHomepage); | 149 GoogleURLTracker::kDefaultGoogleHomepage); |
| 149 } | 150 } |
| 150 | 151 |
| 151 GoogleURLTrackerTest::~GoogleURLTrackerTest() { | 152 GoogleURLTrackerTest::~GoogleURLTrackerTest() { |
| 152 } | 153 } |
| 153 | 154 |
| 154 void GoogleURLTrackerTest::SetUp() { | 155 void GoogleURLTrackerTest::SetUp() { |
| 155 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); | 156 network_change_notifier_.reset(net::NetworkChangeNotifier::CreateMock()); |
| 156 // Ownership is passed to google_url_tracker_, but a weak pointer is kept; | 157 // Ownership is passed to google_url_tracker_, but a weak pointer is kept; |
| 157 // this is safe since GoogleURLTracker keeps the client for its lifetime. | 158 // this is safe since GoogleURLTracker keeps the client for its lifetime. |
| 158 client_ = new TestGoogleURLTrackerClient(&prefs_); | 159 client_ = new TestGoogleURLTrackerClient(&prefs_); |
| 159 scoped_ptr<GoogleURLTrackerClient> client(client_); | 160 std::unique_ptr<GoogleURLTrackerClient> client(client_); |
| 160 google_url_tracker_.reset(new GoogleURLTracker( | 161 google_url_tracker_.reset(new GoogleURLTracker( |
| 161 std::move(client), GoogleURLTracker::UNIT_TEST_MODE)); | 162 std::move(client), GoogleURLTracker::UNIT_TEST_MODE)); |
| 162 } | 163 } |
| 163 | 164 |
| 164 void GoogleURLTrackerTest::TearDown() { | 165 void GoogleURLTrackerTest::TearDown() { |
| 165 google_url_tracker_->Shutdown(); | 166 google_url_tracker_->Shutdown(); |
| 166 } | 167 } |
| 167 | 168 |
| 168 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { | 169 net::TestURLFetcher* GoogleURLTrackerTest::GetFetcher() { |
| 169 // This will return the last fetcher created. If no fetchers have been | 170 // This will return the last fetcher created. If no fetchers have been |
| (...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 344 EXPECT_TRUE(listener_notified()); | 345 EXPECT_TRUE(listener_notified()); |
| 345 clear_listener_notified(); | 346 clear_listener_notified(); |
| 346 | 347 |
| 347 RequestServerCheck(); | 348 RequestServerCheck(); |
| 348 // The second request should be ignored. | 349 // The second request should be ignored. |
| 349 EXPECT_FALSE(GetFetcher()); | 350 EXPECT_FALSE(GetFetcher()); |
| 350 MockSearchDomainCheckResponse(".google.co.in"); | 351 MockSearchDomainCheckResponse(".google.co.in"); |
| 351 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 352 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
| 352 EXPECT_FALSE(listener_notified()); | 353 EXPECT_FALSE(listener_notified()); |
| 353 } | 354 } |
| OLD | NEW |