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

Unified Diff: chrome/browser/sync/glue/http_bridge_unittest.cc

Issue 258008: Move initialization of ChromeURLRequestContexts to the IO thread. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync again, just in case Created 11 years, 2 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
« no previous file with comments | « chrome/browser/sync/glue/http_bridge.cc ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/browser/sync/glue/http_bridge_unittest.cc
===================================================================
--- chrome/browser/sync/glue/http_bridge_unittest.cc (revision 29872)
+++ chrome/browser/sync/glue/http_bridge_unittest.cc (working copy)
@@ -16,10 +16,22 @@
const wchar_t kDocRoot[] = L"chrome/test/data";
}
+// Lazy getter for TestURLRequestContext instances.
+class TestURLRequestContextGetter : public URLRequestContextGetter {
+ public:
+ virtual URLRequestContext* GetURLRequestContext() {
+ if (!context_)
+ context_ = new TestURLRequestContext;
+ return context_;
+ }
+ private:
+ scoped_refptr<URLRequestContext> context_;
+};
+
class HttpBridgeTest : public testing::Test {
public:
HttpBridgeTest()
- : fake_default_request_context_(NULL),
+ : fake_default_request_context_getter_(NULL),
io_thread_("HttpBridgeTest IO thread") {
}
@@ -30,19 +42,21 @@
}
virtual void TearDown() {
- io_thread_loop()->ReleaseSoon(FROM_HERE, fake_default_request_context_);
+ io_thread_loop()->ReleaseSoon(FROM_HERE,
+ fake_default_request_context_getter_);
io_thread_.Stop();
- fake_default_request_context_ = NULL;
+ fake_default_request_context_getter_ = NULL;
}
HttpBridge* BuildBridge() {
- if (!fake_default_request_context_) {
- fake_default_request_context_ = new TestURLRequestContext();
- fake_default_request_context_->AddRef();
+ if (!fake_default_request_context_getter_) {
+ fake_default_request_context_getter_ = new TestURLRequestContextGetter();
+ fake_default_request_context_getter_->AddRef();
}
HttpBridge* bridge = new HttpBridge(
- new HttpBridge::RequestContext(fake_default_request_context_),
- io_thread_.message_loop());
+ new HttpBridge::RequestContextGetter(
+ fake_default_request_context_getter_),
+ io_thread_loop());
bridge->use_io_loop_for_testing_ = true;
return bridge;
}
@@ -50,14 +64,14 @@
MessageLoop* io_thread_loop() { return io_thread_.message_loop(); }
// Note this is lazy created, so don't call this before your bridge.
- TestURLRequestContext* GetTestRequestContext() {
- return fake_default_request_context_;
+ TestURLRequestContextGetter* GetTestRequestContextGetter() {
+ return fake_default_request_context_getter_;
}
private:
// A make-believe "default" request context, as would be returned by
// Profile::GetDefaultRequestContext(). Created lazily by BuildBridge.
- TestURLRequestContext* fake_default_request_context_;
+ TestURLRequestContextGetter* fake_default_request_context_getter_;
// Separate thread for IO used by the HttpBridge.
base::Thread io_thread_;
@@ -67,9 +81,10 @@
// back with dummy response info.
class ShuntedHttpBridge : public HttpBridge {
public:
- ShuntedHttpBridge(URLRequestContext* baseline_context,
+ ShuntedHttpBridge(URLRequestContextGetter* baseline_context_getter,
MessageLoop* io_loop, HttpBridgeTest* test)
- : HttpBridge(new HttpBridge::RequestContext(baseline_context),
+ : HttpBridge(new HttpBridge::RequestContextGetter(
+ baseline_context_getter),
io_loop), test_(test) { }
protected:
virtual void MakeAsynchronousPost() {
@@ -94,19 +109,22 @@
TEST_F(HttpBridgeTest, TestUsesSameHttpNetworkSession) {
scoped_refptr<HttpBridge> http_bridge(this->BuildBridge());
- EXPECT_TRUE(GetTestRequestContext());
+ EXPECT_TRUE(GetTestRequestContextGetter());
net::HttpNetworkSession* test_session =
- GetTestRequestContext()->http_transaction_factory()->GetSession();
+ GetTestRequestContextGetter()->GetURLRequestContext()->
+ http_transaction_factory()->GetSession();
EXPECT_EQ(test_session,
- http_bridge->GetRequestContext()->
+ http_bridge->GetRequestContextGetter()->
+ GetURLRequestContext()->
http_transaction_factory()->GetSession());
}
// Test the HttpBridge without actually making any network requests.
TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) {
- scoped_refptr<TestURLRequestContext> ctx(new TestURLRequestContext());
+ scoped_refptr<URLRequestContextGetter> ctx_getter(
+ new TestURLRequestContextGetter());
scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge(
- ctx, io_thread_loop(), this));
+ ctx_getter, io_thread_loop(), this));
http_bridge->SetUserAgent("bob");
http_bridge->SetURL("http://www.google.com", 9999);
http_bridge->SetPostPayload("text/plain", 2, " ");
« no previous file with comments | « chrome/browser/sync/glue/http_bridge.cc ('k') | chrome/browser/sync/glue/sync_backend_host.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698