OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 // TODO(timsteele): Re-enable ASAP. http://crbug.com/19002 | |
6 #if 0 | |
7 #ifdef CHROME_PERSONALIZATION | 5 #ifdef CHROME_PERSONALIZATION |
8 | 6 |
9 #include "base/thread.h" | 7 #include "base/thread.h" |
10 #include "chrome/browser/sync/glue/http_bridge.h" | 8 #include "chrome/browser/sync/glue/http_bridge.h" |
11 #include "net/url_request/url_request_unittest.h" | 9 #include "net/url_request/url_request_unittest.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 10 #include "testing/gtest/include/gtest/gtest.h" |
13 | 11 |
14 using browser_sync::HttpBridge; | 12 using browser_sync::HttpBridge; |
15 | 13 |
16 namespace { | 14 namespace { |
17 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. | 15 // TODO(timsteele): Should use PathService here. See Chromium Issue 3113. |
18 const char16 kDocRoot[] = L"chrome/test/data"; | 16 const char16 kDocRoot[] = L"chrome/test/data"; |
19 } | 17 } |
20 | 18 |
21 class HttpBridgeTest : public testing::Test { | 19 class HttpBridgeTest : public testing::Test { |
22 public: | 20 public: |
23 HttpBridgeTest() : io_thread_("HttpBridgeTest IO thread") { | 21 HttpBridgeTest() : io_thread_("HttpBridgeTest IO thread"), |
| 22 fake_default_request_context_(NULL) { |
24 } | 23 } |
25 | 24 |
26 virtual void SetUp() { | 25 virtual void SetUp() { |
27 base::Thread::Options options; | 26 base::Thread::Options options; |
28 options.message_loop_type = MessageLoop::TYPE_IO; | 27 options.message_loop_type = MessageLoop::TYPE_IO; |
29 io_thread_.StartWithOptions(options); | 28 io_thread_.StartWithOptions(options); |
30 } | 29 } |
31 | 30 |
32 virtual void TearDown() { | 31 virtual void TearDown() { |
| 32 io_thread_loop()->ReleaseSoon(FROM_HERE, fake_default_request_context_); |
33 io_thread_.Stop(); | 33 io_thread_.Stop(); |
| 34 fake_default_request_context_ = NULL; |
34 } | 35 } |
35 | 36 |
36 HttpBridge* BuildBridge() { | 37 HttpBridge* BuildBridge() { |
37 if (!request_context_) { | 38 if (!fake_default_request_context_) { |
38 request_context_ = new HttpBridge::RequestContext( | 39 fake_default_request_context_ = new TestURLRequestContext(); |
39 new TestURLRequestContext()); | 40 fake_default_request_context_->AddRef(); |
40 } | 41 } |
41 HttpBridge* bridge = new HttpBridge(request_context_, | 42 HttpBridge* bridge = new HttpBridge( |
42 io_thread_.message_loop()); | 43 new HttpBridge::RequestContext(fake_default_request_context_), |
| 44 io_thread_.message_loop()); |
43 bridge->use_io_loop_for_testing_ = true; | 45 bridge->use_io_loop_for_testing_ = true; |
44 return bridge; | 46 return bridge; |
45 } | 47 } |
46 | 48 |
47 MessageLoop* io_thread_loop() { return io_thread_.message_loop(); } | 49 MessageLoop* io_thread_loop() { return io_thread_.message_loop(); } |
48 private: | 50 private: |
| 51 // A make-believe "default" request context, as would be returned by |
| 52 // Profile::GetDefaultRequestContext(). Created lazily by BuildBridge. |
| 53 TestURLRequestContext* fake_default_request_context_; |
| 54 |
49 // Separate thread for IO used by the HttpBridge. | 55 // Separate thread for IO used by the HttpBridge. |
50 scoped_refptr<HttpBridge::RequestContext> request_context_; | |
51 base::Thread io_thread_; | 56 base::Thread io_thread_; |
52 }; | 57 }; |
53 | 58 |
54 // An HttpBridge that doesn't actually make network requests and just calls | 59 // An HttpBridge that doesn't actually make network requests and just calls |
55 // back with dummy response info. | 60 // back with dummy response info. |
56 class ShuntedHttpBridge : public HttpBridge { | 61 class ShuntedHttpBridge : public HttpBridge { |
57 public: | 62 public: |
58 ShuntedHttpBridge(const URLRequestContext* baseline_context, | 63 ShuntedHttpBridge(const URLRequestContext* baseline_context, |
59 MessageLoop* io_loop, HttpBridgeTest* test) | 64 MessageLoop* io_loop, HttpBridgeTest* test) |
60 : HttpBridge(new HttpBridge::RequestContext(baseline_context), | 65 : HttpBridge(new HttpBridge::RequestContext(baseline_context), |
(...skipping 14 matching lines...) Expand all Loading... |
75 cookies.push_back("cookie1"); | 80 cookies.push_back("cookie1"); |
76 std::string response_content = "success!"; | 81 std::string response_content = "success!"; |
77 OnURLFetchComplete(NULL, GURL("www.google.com"), URLRequestStatus(), | 82 OnURLFetchComplete(NULL, GURL("www.google.com"), URLRequestStatus(), |
78 200, cookies, response_content); | 83 200, cookies, response_content); |
79 } | 84 } |
80 HttpBridgeTest* test_; | 85 HttpBridgeTest* test_; |
81 }; | 86 }; |
82 | 87 |
83 // Test the HttpBridge without actually making any network requests. | 88 // Test the HttpBridge without actually making any network requests. |
84 TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) { | 89 TEST_F(HttpBridgeTest, TestMakeSynchronousPostShunted) { |
| 90 scoped_refptr<TestURLRequestContext> ctx(new TestURLRequestContext()); |
85 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge( | 91 scoped_refptr<HttpBridge> http_bridge(new ShuntedHttpBridge( |
86 new TestURLRequestContext(), io_thread_loop(), this)); | 92 ctx, io_thread_loop(), this)); |
87 http_bridge->SetUserAgent("bob"); | 93 http_bridge->SetUserAgent("bob"); |
88 http_bridge->SetURL("http://www.google.com", 9999); | 94 http_bridge->SetURL("http://www.google.com", 9999); |
89 http_bridge->SetPostPayload("text/plain", 2, " "); | 95 http_bridge->SetPostPayload("text/plain", 2, " "); |
90 | 96 |
91 int os_error = 0; | 97 int os_error = 0; |
92 int response_code = 0; | 98 int response_code = 0; |
93 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); | 99 bool success = http_bridge->MakeSynchronousPost(&os_error, &response_code); |
94 EXPECT_TRUE(success); | 100 EXPECT_TRUE(success); |
95 EXPECT_EQ(200, response_code); | 101 EXPECT_EQ(200, response_code); |
96 EXPECT_EQ(0, os_error); | 102 EXPECT_EQ(0, os_error); |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 // seems to be surprising the TestServer, because it isn't echoing the headers | 167 // seems to be surprising the TestServer, because it isn't echoing the headers |
162 // properly. | 168 // properly. |
163 #if FIXED_SYNCER_BACKEND_COOKIE_PARSING | 169 #if FIXED_SYNCER_BACKEND_COOKIE_PARSING |
164 EXPECT_NE(std::string::npos, response.find("Cookie: foo=bar; baz=boo")); | 170 EXPECT_NE(std::string::npos, response.find("Cookie: foo=bar; baz=boo")); |
165 EXPECT_NE(std::string::npos, response.find("User-Agent: bob")); | 171 EXPECT_NE(std::string::npos, response.find("User-Agent: bob")); |
166 #endif | 172 #endif |
167 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); | 173 EXPECT_NE(std::string::npos, response.find(test_payload.c_str())); |
168 } | 174 } |
169 | 175 |
170 #endif // CHROME_PERSONALIZATION | 176 #endif // CHROME_PERSONALIZATION |
171 #endif | |
OLD | NEW |