Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(53)

Unified Diff: ios/chrome/browser/ios_chrome_io_thread_unittest.mm

Issue 2170103002: Notify SystemURLRequestContextGetter before shutdown on iOS. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Added test to gyp. Created 4 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: ios/chrome/browser/ios_chrome_io_thread_unittest.mm
diff --git a/ios/chrome/browser/ios_chrome_io_thread_unittest.mm b/ios/chrome/browser/ios_chrome_io_thread_unittest.mm
new file mode 100644
index 0000000000000000000000000000000000000000..f36dc38abf0a047fe131b775d57beb73ee194ddf
--- /dev/null
+++ b/ios/chrome/browser/ios_chrome_io_thread_unittest.mm
@@ -0,0 +1,80 @@
+// 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/url_request/url_fetcher.h"
+#include "net/url_request/url_fetcher_delegate.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gtest_mac.h"
+#include "testing/platform_test.h"
+
+class IOSChromeIOThreadTest : public PlatformTest {
+ public:
+ IOSChromeIOThreadTest()
+ : loop_(base::MessageLoop::TYPE_IO),
+ ui_thread_(web::WebThread::UI, &loop_),
+ io_thread_(web::WebThread::IO, &loop_){};
+
+ ~IOSChromeIOThreadTest() override {}
+
+ void SetUp() override { DCHECK_CURRENTLY_ON(web::WebThread::UI); }
+
+ void TearDown() override { DCHECK_CURRENTLY_ON(web::WebThread::UI); }
+
+ private:
+ base::MessageLoop loop_;
+ web::TestWebThread ui_thread_;
+ web::TestWebThread io_thread_;
+};
+
+// A delegate interface for users of URLFetcher.
+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.
+ public:
+ TestURLFetcherDelegate() {}
+ ~TestURLFetcherDelegate() override {}
+
+ // net::URLFetcherDelegate implementation.
+ void OnURLFetchComplete(const net::URLFetcher* source) override {}
+};
+
+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());
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.
+ web_thread_delegate->Init();
+
+ // Create and start fetcher.
+ TestURLFetcherDelegate fetcher_delegate;
+ std::unique_ptr<net::URLFetcher> fetcher = net::URLFetcher::Create(
+ GURL("http://example.com"), net::URLFetcher::GET, &fetcher_delegate);
+ fetcher->SetRequestContext(
+ ios_chrome_io_thread->system_url_request_context_getter());
+ fetcher->Start();
+ 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.
+ // Verify that there is no AssertNoUrlRequests triggered during CleanUp.
+ web_thread_delegate->CleanUp();
+}

Powered by Google App Engine
This is Rietveld 408576698