forked from chromium/chromium
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathios_chrome_io_thread_unittest.mm
87 lines (73 loc) · 3.07 KB
/
ios_chrome_io_thread_unittest.mm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
// Copyright 2016 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/chrome/browser/ios_chrome_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/test/url_request/url_request_failed_job.h"
#include "net/url_request/url_fetcher.h"
#include "net/url_request/url_fetcher_delegate.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"
namespace {
// A delegate interface for users of URLFetcher.
class TestURLFetcherDelegate : public net::URLFetcherDelegate {
public:
TestURLFetcherDelegate() {}
~TestURLFetcherDelegate() override {}
// net::URLFetcherDelegate implementation.
void OnURLFetchComplete(const net::URLFetcher* source) override {}
};
} // namespace
class IOSChromeIOThreadTest : public PlatformTest {
public:
IOSChromeIOThreadTest()
: loop_(base::MessageLoop::TYPE_IO),
ui_thread_(web::WebThread::UI, &loop_),
io_thread_(web::WebThread::IO, &loop_) {
net::URLRequestFailedJob::AddUrlHandler();
}
~IOSChromeIOThreadTest() override {
net::URLRequestFilter::GetInstance()->ClearHandlers();
}
private:
base::MessageLoop loop_;
web::TestWebThread ui_thread_;
web::TestWebThread io_thread_;
};
TEST_F(IOSChromeIOThreadTest, AssertNoUrlRequests) {
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()));
// Create and init IOSChromeIOThread.
std::unique_ptr<IOSChromeIOThread> ios_chrome_io_thread(
new IOSChromeIOThread(pref_service.get(), nullptr));
web::WebThreadDelegate* web_thread_delegate =
static_cast<web::WebThreadDelegate*>(ios_chrome_io_thread.get());
web_thread_delegate->Init();
// Create and start fetcher.
TestURLFetcherDelegate fetcher_delegate;
std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
net::URLRequestFailedJob::GetMockHttpUrl(net::ERR_IO_PENDING),
net::URLFetcher::GET, &fetcher_delegate);
fetcher->SetRequestContext(
ios_chrome_io_thread->system_url_request_context_getter());
fetcher->Start();
base::RunLoop().RunUntilIdle();
// Verify that there is no AssertNoUrlRequests triggered during CleanUp.
web_thread_delegate->CleanUp();
}