Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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/components/io_thread/ios_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/base/network_delegate_impl.h" | |
| 17 #include "net/test/url_request/url_request_failed_job.h" | |
| 18 #include "net/url_request/url_request_filter.h" | |
| 19 #include "testing/gtest/include/gtest/gtest.h" | |
| 20 #include "testing/gtest_mac.h" | |
| 21 #include "testing/platform_test.h" | |
| 22 | |
| 23 #if !defined(__has_feature) || !__has_feature(objc_arc) | |
| 24 #error "This file requires ARC support." | |
| 25 #endif | |
| 26 | |
| 27 namespace { | |
| 28 | |
| 29 // A concrete implementation of IOThread for testing. | |
| 30 class TestIOThread : public io_thread::IOSIOThread { | |
| 31 public: | |
| 32 TestIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log) | |
| 33 : IOSIOThread(local_state, net_log) {} | |
| 34 ~TestIOThread() override {} | |
| 35 | |
| 36 // Dummy implementations of virtual methods. | |
| 37 std::unique_ptr<net::NetworkDelegate> GetSystemNetworkDelegate() override { | |
| 38 return base::MakeUnique<net::NetworkDelegateImpl>(); | |
|
sdefresne
2017/05/29 09:30:41
nit: you should be able to just use "return nullpt
michaeldo
2017/05/30 17:16:24
Done.
| |
| 39 } | |
| 40 std::string GetChannelString() const override { return std::string(); } | |
| 41 }; | |
| 42 | |
| 43 } // namespace | |
| 44 | |
| 45 class IOSIOThreadTest : public PlatformTest { | |
| 46 public: | |
| 47 IOSIOThreadTest() | |
| 48 : loop_(base::MessageLoop::TYPE_IO), | |
| 49 ui_thread_(web::WebThread::UI, &loop_), | |
| 50 io_thread_(web::WebThread::IO, &loop_) { | |
| 51 net::URLRequestFailedJob::AddUrlHandler(); | |
| 52 } | |
| 53 | |
| 54 ~IOSIOThreadTest() override { | |
| 55 net::URLRequestFilter::GetInstance()->ClearHandlers(); | |
| 56 } | |
| 57 | |
| 58 private: | |
| 59 base::MessageLoop loop_; | |
|
sdefresne
2017/05/29 09:30:41
You should be able to remove those three instances
michaeldo
2017/05/30 17:16:24
I'm not positive why, but the bundle object doesn'
| |
| 60 web::TestWebThread ui_thread_; | |
| 61 web::TestWebThread io_thread_; | |
| 62 }; | |
| 63 | |
| 64 // Tests the creation of an IOSIOThread and verifies that it returns a system | |
| 65 // url request context. | |
| 66 TEST_F(IOSIOThreadTest, AssertSystemUrlRequestContext) { | |
| 67 PrefServiceFactory pref_service_factory; | |
| 68 pref_service_factory.set_user_prefs( | |
| 69 make_scoped_refptr(new TestingPrefStore())); | |
| 70 | |
| 71 scoped_refptr<PrefRegistrySimple> pref_registry = new PrefRegistrySimple; | |
| 72 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); | |
| 73 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); | |
| 74 | |
| 75 std::unique_ptr<PrefService> pref_service( | |
| 76 pref_service_factory.Create(pref_registry.get())); | |
| 77 | |
| 78 std::unique_ptr<TestIOThread> test_io_thread( | |
| 79 new TestIOThread(pref_service.get(), nullptr)); | |
| 80 | |
| 81 ASSERT_TRUE(test_io_thread->system_url_request_context_getter()); | |
| 82 } | |
| OLD | NEW |