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 <memory> |
8 #include <string> | 8 #include <string> |
9 #include <utility> | 9 #include <utility> |
10 | 10 |
11 #include "base/macros.h" | 11 #include "base/macros.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.h" |
| 13 #include "base/test/scoped_task_environment.h" |
13 #include "base/threading/thread_task_runner_handle.h" | 14 #include "base/threading/thread_task_runner_handle.h" |
14 #include "components/google/core/browser/google_pref_names.h" | 15 #include "components/google/core/browser/google_pref_names.h" |
15 #include "components/google/core/browser/google_url_tracker_client.h" | 16 #include "components/google/core/browser/google_url_tracker_client.h" |
16 #include "components/prefs/pref_registry_simple.h" | 17 #include "components/prefs/pref_registry_simple.h" |
17 #include "components/prefs/pref_service.h" | 18 #include "components/prefs/pref_service.h" |
18 #include "components/prefs/testing_pref_service.h" | 19 #include "components/prefs/testing_pref_service.h" |
19 #include "net/url_request/test_url_fetcher_factory.h" | 20 #include "net/url_request/test_url_fetcher_factory.h" |
20 #include "net/url_request/url_fetcher.h" | 21 #include "net/url_request/url_fetcher.h" |
21 #include "net/url_request/url_request_test_util.h" | 22 #include "net/url_request/url_request_test_util.h" |
22 #include "testing/gtest/include/gtest/gtest.h" | 23 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 102 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
125 void FinishSleep(); | 126 void FinishSleep(); |
126 void NotifyNetworkChanged(); | 127 void NotifyNetworkChanged(); |
127 void set_google_url(const GURL& url) { | 128 void set_google_url(const GURL& url) { |
128 google_url_tracker_->google_url_ = url; | 129 google_url_tracker_->google_url_ = url; |
129 } | 130 } |
130 GURL google_url() const { return google_url_tracker_->google_url(); } | 131 GURL google_url() const { return google_url_tracker_->google_url(); } |
131 bool listener_notified() const { return listener_.notified(); } | 132 bool listener_notified() const { return listener_.notified(); } |
132 void clear_listener_notified() { listener_.clear_notified(); } | 133 void clear_listener_notified() { listener_.clear_notified(); } |
133 | 134 |
134 private: | 135 private: |
135 base::MessageLoop message_loop_; | 136 base::test::ScopedTaskEnvironment scoped_task_environment_; |
136 TestingPrefServiceSimple prefs_; | 137 TestingPrefServiceSimple prefs_; |
137 | 138 |
138 // Creating this allows us to call | 139 // Creating this allows us to call |
139 // net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(). | 140 // net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests(). |
140 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; | 141 std::unique_ptr<net::NetworkChangeNotifier> network_change_notifier_; |
141 net::TestURLFetcherFactory fetcher_factory_; | 142 net::TestURLFetcherFactory fetcher_factory_; |
142 GoogleURLTrackerClient* client_; | 143 GoogleURLTrackerClient* client_; |
143 std::unique_ptr<GoogleURLTracker> google_url_tracker_; | 144 std::unique_ptr<GoogleURLTracker> google_url_tracker_; |
144 TestCallbackListener listener_; | 145 TestCallbackListener listener_; |
145 }; | 146 }; |
(...skipping 200 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
346 EXPECT_TRUE(listener_notified()); | 347 EXPECT_TRUE(listener_notified()); |
347 clear_listener_notified(); | 348 clear_listener_notified(); |
348 | 349 |
349 RequestServerCheck(); | 350 RequestServerCheck(); |
350 // The second request should be ignored. | 351 // The second request should be ignored. |
351 EXPECT_FALSE(GetFetcher()); | 352 EXPECT_FALSE(GetFetcher()); |
352 MockSearchDomainCheckResponse(".google.co.in"); | 353 MockSearchDomainCheckResponse(".google.co.in"); |
353 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 354 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
354 EXPECT_FALSE(listener_notified()); | 355 EXPECT_FALSE(listener_notified()); |
355 } | 356 } |
OLD | NEW |