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/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
13 #include "components/google/core/browser/google_pref_names.h" | 14 #include "components/google/core/browser/google_pref_names.h" |
14 #include "components/google/core/browser/google_url_tracker_client.h" | 15 #include "components/google/core/browser/google_url_tracker_client.h" |
15 #include "components/prefs/pref_registry_simple.h" | 16 #include "components/prefs/pref_registry_simple.h" |
16 #include "components/prefs/pref_service.h" | 17 #include "components/prefs/pref_service.h" |
17 #include "components/prefs/testing_pref_service.h" | 18 #include "components/prefs/testing_pref_service.h" |
18 #include "net/url_request/test_url_fetcher_factory.h" | 19 #include "net/url_request/test_url_fetcher_factory.h" |
19 #include "net/url_request/url_fetcher.h" | 20 #include "net/url_request/url_fetcher.h" |
20 #include "net/url_request/url_request_test_util.h" | 21 #include "net/url_request/url_request_test_util.h" |
21 #include "testing/gtest/include/gtest/gtest.h" | 22 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 194 |
194 void GoogleURLTrackerTest::FinishSleep() { | 195 void GoogleURLTrackerTest::FinishSleep() { |
195 google_url_tracker_->FinishSleep(); | 196 google_url_tracker_->FinishSleep(); |
196 } | 197 } |
197 | 198 |
198 void GoogleURLTrackerTest::NotifyNetworkChanged() { | 199 void GoogleURLTrackerTest::NotifyNetworkChanged() { |
199 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( | 200 net::NetworkChangeNotifier::NotifyObserversOfNetworkChangeForTests( |
200 net::NetworkChangeNotifier::CONNECTION_UNKNOWN); | 201 net::NetworkChangeNotifier::CONNECTION_UNKNOWN); |
201 // For thread safety, the NCN queues tasks to do the actual notifications, so | 202 // For thread safety, the NCN queues tasks to do the actual notifications, so |
202 // we need to spin the message loop so the tracker will actually be notified. | 203 // we need to spin the message loop so the tracker will actually be notified. |
203 base::MessageLoop::current()->RunUntilIdle(); | 204 base::RunLoop().RunUntilIdle(); |
204 } | 205 } |
205 | 206 |
206 // Tests ---------------------------------------------------------------------- | 207 // Tests ---------------------------------------------------------------------- |
207 | 208 |
208 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { | 209 TEST_F(GoogleURLTrackerTest, DontFetchWhenNoOneRequestsCheck) { |
209 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); | 210 EXPECT_EQ(GURL(GoogleURLTracker::kDefaultGoogleHomepage), google_url()); |
210 FinishSleep(); | 211 FinishSleep(); |
211 // No one called RequestServerCheck() so nothing should have happened. | 212 // No one called RequestServerCheck() so nothing should have happened. |
212 EXPECT_FALSE(GetFetcher()); | 213 EXPECT_FALSE(GetFetcher()); |
213 MockSearchDomainCheckResponse(".google.co.uk"); | 214 MockSearchDomainCheckResponse(".google.co.uk"); |
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
345 EXPECT_TRUE(listener_notified()); | 346 EXPECT_TRUE(listener_notified()); |
346 clear_listener_notified(); | 347 clear_listener_notified(); |
347 | 348 |
348 RequestServerCheck(); | 349 RequestServerCheck(); |
349 // The second request should be ignored. | 350 // The second request should be ignored. |
350 EXPECT_FALSE(GetFetcher()); | 351 EXPECT_FALSE(GetFetcher()); |
351 MockSearchDomainCheckResponse(".google.co.in"); | 352 MockSearchDomainCheckResponse(".google.co.in"); |
352 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); | 353 EXPECT_EQ(GURL("https://www.google.co.uk/"), google_url()); |
353 EXPECT_FALSE(listener_notified()); | 354 EXPECT_FALSE(listener_notified()); |
354 } | 355 } |
OLD | NEW |