Chromium Code Reviews| Index: ios/components/io_thread/io_thread_unittest.mm |
| diff --git a/ios/components/io_thread/io_thread_unittest.mm b/ios/components/io_thread/io_thread_unittest.mm |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..423bd3878c1ef0c65bcb8f8ff2806e5ae0df06e8 |
| --- /dev/null |
| +++ b/ios/components/io_thread/io_thread_unittest.mm |
| @@ -0,0 +1,79 @@ |
| +// Copyright 2017 The Chromium Authors. All rights reserved. |
| +// Use of this source code is governed by a BSD-style license that can be |
| +// found in the LICENSE file. |
| + |
| +#include "ios/components/io_thread/io_thread.h" |
| + |
| +#include "base/message_loop/message_loop.h" |
| +#include "base/run_loop.h" |
| +#include "components/prefs/pref_registry_simple.h" |
| +#include "components/prefs/pref_service.h" |
| +#include "components/prefs/pref_service_factory.h" |
| +#include "components/prefs/testing_pref_store.h" |
| +#include "components/proxy_config/pref_proxy_config_tracker_impl.h" |
| +#include "components/ssl_config/ssl_config_service_manager.h" |
| +#include "ios/web/public/test/test_web_thread.h" |
| +#include "net/base/network_delegate_impl.h" |
| +#include "net/test/url_request/url_request_failed_job.h" |
| +#include "net/url_request/url_request_filter.h" |
| +#include "testing/gtest/include/gtest/gtest.h" |
| +#include "testing/gtest_mac.h" |
| +#include "testing/platform_test.h" |
| + |
| +#if !defined(__has_feature) || !__has_feature(objc_arc) |
| +#error "This file requires ARC support." |
| +#endif |
| + |
| +namespace { |
| + |
| +// A concrete implementation of IOThread for testing. |
| +class TestIOThread : public io_thread::IOThread { |
| + public: |
| + TestIOThread(PrefService* local_state, net_log::ChromeNetLog* net_log) |
| + : IOThread(local_state, net_log) {} |
| + ~TestIOThread() override {} |
| + |
| + // Dummy implementations of virtual methods. |
| + std::unique_ptr<net::NetworkDelegate> GetSystemNetworkDelegate() override { |
| + return base::MakeUnique<net::NetworkDelegateImpl>(); |
| + } |
| +}; |
| + |
| +} // namespace |
| + |
| +class IOThreadTest : public PlatformTest { |
| + public: |
| + IOThreadTest() |
| + : loop_(base::MessageLoop::TYPE_IO), |
| + ui_thread_(web::WebThread::UI, &loop_), |
| + io_thread_(web::WebThread::IO, &loop_) { |
| + net::URLRequestFailedJob::AddUrlHandler(); |
| + } |
| + |
| + ~IOThreadTest() override { |
| + net::URLRequestFilter::GetInstance()->ClearHandlers(); |
| + } |
| + |
| + private: |
| + base::MessageLoop loop_; |
| + web::TestWebThread ui_thread_; |
| + web::TestWebThread io_thread_; |
| +}; |
| + |
| +TEST_F(IOThreadTest, AssertSystemUrlRequestContext) { |
|
Eugene But (OOO till 7-30)
2017/05/25 22:05:22
Please add comments describing what is tested here
michaeldo
2017/05/26 07:24:44
Done.
|
| + PrefServiceFactory pref_service_factory; |
| + pref_service_factory.set_user_prefs( |
| + make_scoped_refptr(new TestingPrefStore())); |
| + |
| + scoped_refptr<PrefRegistrySimple> pref_registry = new PrefRegistrySimple; |
| + PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); |
| + ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); |
| + |
| + std::unique_ptr<PrefService> pref_service( |
| + pref_service_factory.Create(pref_registry.get())); |
| + |
| + std::unique_ptr<TestIOThread> test_io_thread( |
| + new TestIOThread(pref_service.get(), nullptr)); |
| + |
| + ASSERT_TRUE(test_io_thread->system_url_request_context_getter()); |
| +} |