Chromium Code Reviews| 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/url_request/url_fetcher.h" | |
| 17 #include "net/url_request/url_fetcher_delegate.h" | |
| 18 #include "testing/gtest/include/gtest/gtest.h" | |
| 19 #include "testing/gtest_mac.h" | |
| 20 #include "testing/platform_test.h" | |
| 21 | |
| 22 class IOSChromeIOThreadTest : public PlatformTest { | |
| 23 public: | |
| 24 IOSChromeIOThreadTest() | |
| 25 : loop_(base::MessageLoop::TYPE_IO), | |
| 26 ui_thread_(web::WebThread::UI, &loop_), | |
| 27 io_thread_(web::WebThread::IO, &loop_){}; | |
| 28 | |
| 29 ~IOSChromeIOThreadTest() override {} | |
| 30 | |
| 31 void SetUp() override { DCHECK_CURRENTLY_ON(web::WebThread::UI); } | |
| 32 | |
| 33 void TearDown() override { DCHECK_CURRENTLY_ON(web::WebThread::UI); } | |
| 34 | |
| 35 private: | |
| 36 base::MessageLoop loop_; | |
| 37 web::TestWebThread ui_thread_; | |
| 38 web::TestWebThread io_thread_; | |
| 39 }; | |
| 40 | |
| 41 // A delegate interface for users of URLFetcher. | |
| 42 class TestURLFetcherDelegate : public net::URLFetcherDelegate { | |
|
mmenke
2016/07/27 17:23:45
This should be in an anonymous namespace (I'd put
mef
2016/07/27 18:04:27
Done.
| |
| 43 public: | |
| 44 TestURLFetcherDelegate() {} | |
| 45 ~TestURLFetcherDelegate() override {} | |
| 46 | |
| 47 // net::URLFetcherDelegate implementation. | |
| 48 void OnURLFetchComplete(const net::URLFetcher* source) override {} | |
| 49 }; | |
| 50 | |
| 51 TEST_F(IOSChromeIOThreadTest, AssertNoUrlRequests) { | |
| 52 PrefServiceFactory pref_service_factory; | |
| 53 pref_service_factory.set_user_prefs( | |
| 54 make_scoped_refptr(new TestingPrefStore())); | |
| 55 | |
| 56 scoped_refptr<PrefRegistrySimple> pref_registry = new PrefRegistrySimple; | |
| 57 PrefProxyConfigTrackerImpl::RegisterPrefs(pref_registry.get()); | |
| 58 ssl_config::SSLConfigServiceManager::RegisterPrefs(pref_registry.get()); | |
| 59 | |
| 60 std::unique_ptr<PrefService> pref_service( | |
| 61 pref_service_factory.Create(pref_registry.get())); | |
| 62 | |
| 63 // Create and init IOSChromeIOThread. | |
| 64 std::unique_ptr<IOSChromeIOThread> ios_chrome_io_thread( | |
| 65 new IOSChromeIOThread(pref_service.get(), nullptr)); | |
| 66 web::WebThreadDelegate* web_thread_delegate = | |
| 67 static_cast<web::WebThreadDelegate*>(ios_chrome_io_thread.get()); | |
|
mmenke
2016/07/27 17:23:45
This is weird. I guess it's needed because IOSChr
mef
2016/07/27 18:04:27
Exactly.
| |
| 68 web_thread_delegate->Init(); | |
| 69 | |
| 70 // Create and start fetcher. | |
| 71 TestURLFetcherDelegate fetcher_delegate; | |
| 72 std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create( | |
| 73 GURL("http://example.com"), net::URLFetcher::GET, &fetcher_delegate); | |
| 74 fetcher->SetRequestContext( | |
| 75 ios_chrome_io_thread->system_url_request_context_getter()); | |
| 76 fetcher->Start(); | |
| 77 base::RunLoop().RunUntilIdle(); | |
|
mmenke
2016/07/27 17:23:46
What guarantee do we have that the fetcher wont co
mef
2016/07/27 18:04:27
Done.
| |
| 78 // Verify that there is no AssertNoUrlRequests triggered during CleanUp. | |
| 79 web_thread_delegate->CleanUp(); | |
| 80 } | |
| OLD | NEW |