OLD | NEW |
---|---|
(Empty) | |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | |
2 // Use of this source code is governed by a BSD-style license that can be | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ios/chrome/browser/ios_chrome_io_thread.h" | |
6 | |
7 #include "base/message_loop/message_loop.h" | |
8 #include "base/run_loop.h" | |
9 #include "components/prefs/pref_registry_simple.h" | |
10 #include "components/prefs/pref_service.h" | |
11 #include "components/prefs/pref_service_factory.h" | |
12 #include "components/prefs/testing_pref_store.h" | |
13 #include "components/proxy_config/pref_proxy_config_tracker_impl.h" | |
14 #include "components/ssl_config/ssl_config_service_manager.h" | |
15 #include "ios/web/public/test/test_web_thread.h" | |
16 #include "net/test/url_request/url_request_failed_job.h" | |
17 #include "net/url_request/url_fetcher.h" | |
18 #include "net/url_request/url_fetcher_delegate.h" | |
19 #include "testing/gtest/include/gtest/gtest.h" | |
20 #include "testing/gtest_mac.h" | |
21 #include "testing/platform_test.h" | |
22 | |
23 namespace { | |
24 | |
25 // A delegate interface for users of URLFetcher. | |
26 class TestURLFetcherDelegate : public net::URLFetcherDelegate { | |
27 public: | |
28 TestURLFetcherDelegate() {} | |
29 ~TestURLFetcherDelegate() override {} | |
30 | |
31 // net::URLFetcherDelegate implementation. | |
32 void OnURLFetchComplete(const net::URLFetcher* source) override {} | |
33 }; | |
34 | |
35 } // namespace | |
36 | |
37 class IOSChromeIOThreadTest : public PlatformTest { | |
38 public: | |
39 IOSChromeIOThreadTest() | |
40 : loop_(base::MessageLoop::TYPE_IO), | |
41 ui_thread_(web::WebThread::UI, &loop_), | |
42 io_thread_(web::WebThread::IO, &loop_){}; | |
mmenke
2016/07/27 18:10:43
Semi-colon not needed, need space before open brac
mef
2016/07/27 18:26:52
Done.
| |
43 | |
44 ~IOSChromeIOThreadTest() override {} | |
45 | |
46 void SetUp() override { | |
47 DCHECK_CURRENTLY_ON(web::WebThread::UI); | |
48 net::URLRequestFailedJob::AddUrlHandler(); | |
mmenke
2016/07/27 18:10:43
Oops...Should call net::URLRequestFilter::ClearAll
mef
2016/07/27 18:26:52
Done.
| |
49 } | |
50 | |
51 void TearDown() override { DCHECK_CURRENTLY_ON(web::WebThread::UI); } | |
52 | |
53 private: | |
54 base::MessageLoop loop_; | |
55 web::TestWebThread ui_thread_; | |
56 web::TestWebThread io_thread_; | |
57 }; | |
58 | |
59 TEST_F(IOSChromeIOThreadTest, AssertNoUrlRequests) { | |
60 PrefServiceFactory pref_service_factory; | |
61 pref_service_factory.set_user_prefs( | |
62 make_scoped_refptr(new TestingPrefStore())); | |
63 | |
64 scoped_refptr<PrefRegistrySimple> pref_registry = new PrefRegistrySimple; | |
65 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); | |
66 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); | |
67 | |
68 std::unique_ptr<PrefService> pref_service( | |
69 pref_service_factory.Create(pref_registry.get())); | |
70 | |
71 // Create and init IOSChromeIOThread. | |
72 std::unique_ptr<IOSChromeIOThread> ios_chrome_io_thread( | |
73 new IOSChromeIOThread(pref_service.get(), nullptr)); | |
74 web::WebThreadDelegate* web_thread_delegate = | |
75 static_cast<web::WebThreadDelegate*>(ios_chrome_io_thread.get()); | |
76 web_thread_delegate->Init(); | |
77 | |
78 // Create and start fetcher. | |
79 TestURLFetcherDelegate fetcher_delegate; | |
80 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( | |
81 net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_IO_PENDING), | |
82 net::URLFetcher::GET, &fetcher_delegate); | |
83 fetcher->SetRequestContext( | |
84 ios_chrome_io_thread->system_url_request_context_getter()); | |
85 fetcher->Start(); | |
86 base::RunLoop().RunUntilIdle(); | |
87 // Verify that there is no AssertNoUrlRequests triggered during CleanUp. | |
88 web_thread_delegate->CleanUp(); | |
89 } | |
OLD | NEW |