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

Side by Side Diff: chrome/common/chrome_plugin_unittest.cc

Issue 19004: Change URLRequest to use a ref-counted buffer for actual IO.... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 11 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
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 // Tests exercising the Chrome Plugin API. 4 // Tests exercising the Chrome Plugin API.
5 5
6 #include "base/file_util.h" 6 #include "base/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/string_util.h" 8 #include "base/string_util.h"
9 #include "chrome/browser/chrome_plugin_host.h" 9 #include "chrome/browser/chrome_plugin_host.h"
10 #include "chrome/browser/net/url_fetcher.h" 10 #include "chrome/browser/net/url_fetcher.h"
11 #include "chrome/browser/profile.h" 11 #include "chrome/browser/profile.h"
12 #include "chrome/common/chrome_plugin_lib.h" 12 #include "chrome/common/chrome_plugin_lib.h"
13 #include "chrome/test/chrome_plugin/test_chrome_plugin.h" 13 #include "chrome/test/chrome_plugin/test_chrome_plugin.h"
14 #include "net/base/io_buffer.h"
14 #include "net/url_request/url_request_test_job.h" 15 #include "net/url_request/url_request_test_job.h"
15 #include "net/url_request/url_request_unittest.h" 16 #include "net/url_request/url_request_unittest.h"
16 #include "testing/gtest/include/gtest/gtest.h" 17 #include "testing/gtest/include/gtest/gtest.h"
17 18
18 namespace { 19 namespace {
19 20
20 const wchar_t kDocRoot[] = L"chrome/test/data"; 21 const wchar_t kDocRoot[] = L"chrome/test/data";
21 const char kPluginFilename[] = "test_chrome_plugin.dll"; 22 const char kPluginFilename[] = "test_chrome_plugin.dll";
23 const int kResponseBufferSize = 4096;
22 24
23 class ChromePluginTest : public testing::Test, public URLRequest::Delegate { 25 class ChromePluginTest : public testing::Test, public URLRequest::Delegate {
24 public: 26 public:
25 ChromePluginTest() 27 ChromePluginTest()
26 : request_(NULL), 28 : request_(NULL),
29 response_buffer_(new net::IOBuffer(kResponseBufferSize)),
27 plugin_(NULL), 30 plugin_(NULL),
28 expected_payload_(NULL), 31 expected_payload_(NULL),
29 request_context_(new TestURLRequestContext()) { 32 request_context_(new TestURLRequestContext()) {
30 } 33 }
31 34
32 // Loads/unloads the chrome test plugin. 35 // Loads/unloads the chrome test plugin.
33 void LoadPlugin(); 36 void LoadPlugin();
34 void UnloadPlugin(); 37 void UnloadPlugin();
35 38
36 // Runs the test and expects the given payload as a response. If expectation 39 // Runs the test and expects the given payload as a response. If expectation
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
68 71
69 // Flush the message loop to make Purify happy. 72 // Flush the message loop to make Purify happy.
70 message_loop_.RunAllPending(); 73 message_loop_.RunAllPending();
71 } 74 }
72 protected: 75 protected:
73 MessageLoopForIO message_loop_; 76 MessageLoopForIO message_loop_;
74 77
75 // Note: we use URLRequest (instead of URLFetcher) because this allows the 78 // Note: we use URLRequest (instead of URLFetcher) because this allows the
76 // request to be intercepted. 79 // request to be intercepted.
77 scoped_ptr<URLRequest> request_; 80 scoped_ptr<URLRequest> request_;
78 char response_buffer_[4096]; 81 scoped_refptr<net::IOBuffer> response_buffer_;
79 std::string response_data_; 82 std::string response_data_;
80 83
81 ChromePluginLib* plugin_; 84 ChromePluginLib* plugin_;
82 TestFuncParams::PluginFuncs test_funcs_; 85 TestFuncParams::PluginFuncs test_funcs_;
83 const TestResponsePayload* expected_payload_; 86 const TestResponsePayload* expected_payload_;
84 scoped_refptr<URLRequestContext> request_context_; 87 scoped_refptr<URLRequestContext> request_context_;
85 }; 88 };
86 89
87 static void STDCALL CPT_Complete(CPRequest* request, bool success, 90 static void STDCALL CPT_Complete(CPRequest* request, bool success,
88 const std::string& raw_headers, 91 const std::string& raw_headers,
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
148 request_->Start(); 151 request_->Start();
149 152
150 MessageLoop::current()->Run(); 153 MessageLoop::current()->Run();
151 } 154 }
152 155
153 void ChromePluginTest::OnResponseStarted(URLRequest* request) { 156 void ChromePluginTest::OnResponseStarted(URLRequest* request) {
154 DCHECK(request == request_); 157 DCHECK(request == request_);
155 158
156 int bytes_read = 0; 159 int bytes_read = 0;
157 if (request_->status().is_success()) 160 if (request_->status().is_success())
158 request_->Read(response_buffer_, sizeof(response_buffer_), &bytes_read); 161 request_->Read(response_buffer_, kResponseBufferSize, &bytes_read);
159 OnReadCompleted(request_.get(), bytes_read); 162 OnReadCompleted(request_.get(), bytes_read);
160 } 163 }
161 164
162 void ChromePluginTest::OnReadCompleted(URLRequest* request, int bytes_read) { 165 void ChromePluginTest::OnReadCompleted(URLRequest* request, int bytes_read) {
163 DCHECK(request == request_); 166 DCHECK(request == request_);
164 167
165 do { 168 do {
166 if (!request_->status().is_success() || bytes_read <= 0) 169 if (!request_->status().is_success() || bytes_read <= 0)
167 break; 170 break;
168 response_data_.append(response_buffer_, bytes_read); 171 response_data_.append(response_buffer_->data(), bytes_read);
169 } while (request_->Read(response_buffer_, sizeof(response_buffer_), 172 } while (request_->Read(response_buffer_, kResponseBufferSize, &bytes_read));
170 &bytes_read));
171 173
172 if (!request_->status().is_io_pending()) { 174 if (!request_->status().is_io_pending()) {
173 OnURLRequestComplete(); 175 OnURLRequestComplete();
174 } 176 }
175 } 177 }
176 178
177 void ChromePluginTest::OnURLRequestComplete() { 179 void ChromePluginTest::OnURLRequestComplete() {
178 if (expected_payload_) { 180 if (expected_payload_) {
179 EXPECT_TRUE(request_->status().is_success()); 181 EXPECT_TRUE(request_->status().is_success());
180 182
(...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after
277 // Tests that the plugin does not intercept its own requests. 279 // Tests that the plugin does not intercept its own requests.
278 TEST_F(ChromePluginTest, DoesNotInterceptOwnRequest) { 280 TEST_F(ChromePluginTest, DoesNotInterceptOwnRequest) {
279 const TestResponsePayload& payload = kChromeTestPluginPayloads[0]; 281 const TestResponsePayload& payload = kChromeTestPluginPayloads[0];
280 282
281 EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request( 283 EXPECT_EQ(CPERR_SUCCESS, test_funcs_.test_make_request(
282 "GET", GURL(payload.url))); 284 "GET", GURL(payload.url)));
283 285
284 MessageLoop::current()->Run(); 286 MessageLoop::current()->Run();
285 } 287 }
286 288
OLDNEW
« no previous file with comments | « chrome/browser/renderer_host/sync_resource_handler.cc ('k') | chrome/common/net/url_request_intercept_job.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698