| Index: chrome/browser/extensions/api/web_request/web_request_api_unittest.cc
|
| diff --git a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc
|
| index 661b880094a32bf919b0daeb6865b198e2da45c5..fb1d05f3ed312894d46270b30c0446c720784243 100644
|
| --- a/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc
|
| +++ b/chrome/browser/extensions/api/web_request/web_request_api_unittest.cc
|
| @@ -11,6 +11,7 @@
|
| #include "base/files/file_path.h"
|
| #include "base/json/json_reader.h"
|
| #include "base/json/json_string_value_serializer.h"
|
| +#include "base/memory/scoped_ptr.h"
|
| #include "base/memory/weak_ptr.h"
|
| #include "base/message_loop/message_loop.h"
|
| #include "base/path_service.h"
|
| @@ -238,8 +239,8 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| GURL redirect_url("about:redirected");
|
| GURL not_chosen_redirect_url("about:not_chosen");
|
|
|
| - net::URLRequest request(
|
| - GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, NULL));
|
| {
|
| // onBeforeRequest will be dispatched twice initially. The second response -
|
| // the redirect - should win, since it has a later |install_time|. The
|
| @@ -254,7 +255,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension1_id, kEventName, kEventName + "/1",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| // Extension2 response. Arrives second, and chosen because of install_time.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -263,7 +264,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension2_id, kEventName, kEventName + "/2",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| // Extension2 response to the redirected URL. Arrives first, and chosen.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -271,7 +272,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension2_id, kEventName, kEventName + "/2",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| // Extension1 response to the redirected URL. Arrives second, and ignored.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -279,22 +280,22 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension1_id, kEventName, kEventName + "/1",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| - request.Start();
|
| + request->Start();
|
| base::MessageLoop::current()->Run();
|
|
|
| - EXPECT_TRUE(!request.is_pending());
|
| - EXPECT_EQ(net::URLRequestStatus::SUCCESS, request.status().status());
|
| - EXPECT_EQ(0, request.status().error());
|
| - EXPECT_EQ(redirect_url, request.url());
|
| - EXPECT_EQ(2U, request.url_chain().size());
|
| + EXPECT_TRUE(!request->is_pending());
|
| + EXPECT_EQ(net::URLRequestStatus::SUCCESS, request->status().status());
|
| + EXPECT_EQ(0, request->status().error());
|
| + EXPECT_EQ(redirect_url, request->url());
|
| + EXPECT_EQ(2U, request->url_chain().size());
|
| EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
|
| }
|
|
|
| // Now test the same thing but the extensions answer in reverse order.
|
| - net::URLRequest request2(
|
| - GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| + scoped_ptr<net::URLRequest> request2(context_->CreateRequest(
|
| + GURL("about:blank"), net::DEFAULT_PRIORITY, &delegate_, NULL));
|
| {
|
| ExtensionWebRequestEventRouter::EventResponse* response = NULL;
|
|
|
| @@ -305,7 +306,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension2_id, kEventName, kEventName + "/2",
|
| - request2.identifier(), response));
|
| + request2->identifier(), response));
|
|
|
| // Extension1 response. Arrives second, but ignored due to install_time.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -314,7 +315,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension1_id, kEventName, kEventName + "/1",
|
| - request2.identifier(), response));
|
| + request2->identifier(), response));
|
|
|
| // Extension2 response to the redirected URL. Arrives first, and chosen.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -322,7 +323,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension2_id, kEventName, kEventName + "/2",
|
| - request2.identifier(), response));
|
| + request2->identifier(), response));
|
|
|
| // Extension1 response to the redirected URL. Arrives second, and ignored.
|
| response = new ExtensionWebRequestEventRouter::EventResponse(
|
| @@ -330,16 +331,16 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceRedirect) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension1_id, kEventName, kEventName + "/1",
|
| - request2.identifier(), response));
|
| + request2->identifier(), response));
|
|
|
| - request2.Start();
|
| + request2->Start();
|
| base::MessageLoop::current()->Run();
|
|
|
| - EXPECT_TRUE(!request2.is_pending());
|
| - EXPECT_EQ(net::URLRequestStatus::SUCCESS, request2.status().status());
|
| - EXPECT_EQ(0, request2.status().error());
|
| - EXPECT_EQ(redirect_url, request2.url());
|
| - EXPECT_EQ(2U, request2.url_chain().size());
|
| + EXPECT_TRUE(!request2->is_pending());
|
| + EXPECT_EQ(net::URLRequestStatus::SUCCESS, request2->status().status());
|
| + EXPECT_EQ(0, request2->status().error());
|
| + EXPECT_EQ(redirect_url, request2->url());
|
| + EXPECT_EQ(2U, request2->url_chain().size());
|
| EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
|
| }
|
|
|
| @@ -367,8 +368,8 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) {
|
| ipc_sender_factory.GetWeakPtr());
|
|
|
| GURL request_url("about:blank");
|
| - net::URLRequest request(
|
| - request_url, net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + request_url, net::DEFAULT_PRIORITY, &delegate_, NULL));
|
|
|
| // onBeforeRequest will be dispatched twice. The second response -
|
| // the redirect - would win, since it has a later |install_time|, but
|
| @@ -384,7 +385,7 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension1_id, kEventName, kEventName + "/1",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| // Extension2 response. Arrives second, but has higher precedence
|
| // due to its later install_time.
|
| @@ -394,17 +395,17 @@ TEST_F(ExtensionWebRequestTest, BlockingEventPrecedenceCancel) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension2_id, kEventName, kEventName + "/2",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| - request.Start();
|
| + request->Start();
|
|
|
| base::MessageLoop::current()->Run();
|
|
|
| - EXPECT_TRUE(!request.is_pending());
|
| - EXPECT_EQ(net::URLRequestStatus::FAILED, request.status().status());
|
| - EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, request.status().error());
|
| - EXPECT_EQ(request_url, request.url());
|
| - EXPECT_EQ(1U, request.url_chain().size());
|
| + EXPECT_TRUE(!request->is_pending());
|
| + EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
|
| + EXPECT_EQ(net::ERR_BLOCKED_BY_CLIENT, request->status().error());
|
| + EXPECT_EQ(request_url, request->url());
|
| + EXPECT_EQ(1U, request->url_chain().size());
|
| EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
|
|
|
| ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
|
| @@ -435,8 +436,8 @@ TEST_F(ExtensionWebRequestTest, SimulateChancelWhileBlocked) {
|
| filter, 0, -1, -1, ipc_sender_factory.GetWeakPtr());
|
|
|
| GURL request_url("about:blank");
|
| - net::URLRequest request(
|
| - request_url, net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + request_url, net::DEFAULT_PRIORITY, &delegate_, NULL));
|
|
|
| ExtensionWebRequestEventRouter::EventResponse* response = NULL;
|
|
|
| @@ -449,7 +450,7 @@ TEST_F(ExtensionWebRequestTest, SimulateChancelWhileBlocked) {
|
| ipc_sender_.PushTask(
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, extension_id, kEventName, kEventName + "/1",
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
|
|
| // Extension response for OnErrorOccurred: Terminate the message loop.
|
| ipc_sender_.PushTask(
|
| @@ -457,16 +458,16 @@ TEST_F(ExtensionWebRequestTest, SimulateChancelWhileBlocked) {
|
| base::Unretained(base::MessageLoop::current()),
|
| FROM_HERE, base::MessageLoop::QuitClosure()));
|
|
|
| - request.Start();
|
| - // request.Start() will have submitted OnBeforeRequest by the time we cancel.
|
| - request.Cancel();
|
| + request->Start();
|
| + // request->Start() will have submitted OnBeforeRequest by the time we cancel.
|
| + request->Cancel();
|
| base::MessageLoop::current()->Run();
|
|
|
| - EXPECT_TRUE(!request.is_pending());
|
| - EXPECT_EQ(net::URLRequestStatus::CANCELED, request.status().status());
|
| - EXPECT_EQ(net::ERR_ABORTED, request.status().error());
|
| - EXPECT_EQ(request_url, request.url());
|
| - EXPECT_EQ(1U, request.url_chain().size());
|
| + EXPECT_TRUE(!request->is_pending());
|
| + EXPECT_EQ(net::URLRequestStatus::CANCELED, request->status().status());
|
| + EXPECT_EQ(net::ERR_ABORTED, request->status().error());
|
| + EXPECT_EQ(request_url, request->url());
|
| + EXPECT_EQ(1U, request->url_chain().size());
|
| EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
|
|
|
| ExtensionWebRequestEventRouter::GetInstance()->RemoveEventListener(
|
| @@ -499,13 +500,14 @@ void ExtensionWebRequestTest::FireURLRequestWithData(
|
| const std::vector<char>& bytes_2) {
|
| // The request URL can be arbitrary but must have an HTTP or HTTPS scheme.
|
| GURL request_url("http://www.example.com");
|
| - net::URLRequest request(
|
| - request_url, net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| - request.set_method(method);
|
| - if (content_type != NULL)
|
| - request.SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType,
|
| - content_type,
|
| - true /* overwrite */);
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + request_url, net::DEFAULT_PRIORITY, &delegate_, NULL));
|
| + request->set_method(method);
|
| + if (content_type != NULL) {
|
| + request->SetExtraRequestHeaderByName(net::HttpRequestHeaders::kContentType,
|
| + content_type,
|
| + true /* overwrite */);
|
| + }
|
| ScopedVector<net::UploadElementReader> element_readers;
|
| element_readers.push_back(new net::UploadBytesElementReader(
|
| &(bytes_1[0]), bytes_1.size()));
|
| @@ -517,10 +519,10 @@ void ExtensionWebRequestTest::FireURLRequestWithData(
|
| base::Time()));
|
| element_readers.push_back(
|
| new net::UploadBytesElementReader(&(bytes_2[0]), bytes_2.size()));
|
| - request.set_upload(make_scoped_ptr(
|
| + request->set_upload(make_scoped_ptr(
|
| new net::UploadDataStream(element_readers.Pass(), 0)));
|
| ipc_sender_.PushTask(base::Bind(&base::DoNothing));
|
| - request.Start();
|
| + request->Start();
|
| }
|
|
|
| TEST_F(ExtensionWebRequestTest, AccessRequestBodyData) {
|
| @@ -713,11 +715,11 @@ TEST_F(ExtensionWebRequestTest, NoAccessRequestBodyData) {
|
| const GURL request_url("http://www.example.com");
|
|
|
| for (size_t i = 0; i < arraysize(kMethods); ++i) {
|
| - net::URLRequest request(
|
| - request_url, net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| - request.set_method(kMethods[i]);
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + request_url, net::DEFAULT_PRIORITY, &delegate_, NULL));
|
| + request->set_method(kMethods[i]);
|
| ipc_sender_.PushTask(base::Bind(&base::DoNothing));
|
| - request.Start();
|
| + request->Start();
|
| }
|
|
|
| // We inspect the result in the message list of |ipc_sender_| later.
|
| @@ -833,8 +835,8 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
|
| ipc_sender_factory.GetWeakPtr());
|
|
|
| GURL request_url("http://doesnotexist/does_not_exist.html");
|
| - net::URLRequest request(
|
| - request_url, net::DEFAULT_PRIORITY, &delegate_, context_.get());
|
| + scoped_ptr<net::URLRequest> request(context_->CreateRequest(
|
| + request_url, net::DEFAULT_PRIORITY, &delegate_, NULL));
|
|
|
| // Initialize headers available before extensions are notified of the
|
| // onBeforeSendHeaders event.
|
| @@ -842,7 +844,7 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
|
| net::HttpRequestHeaders before_headers;
|
| for (int i = 0; i < test.before_size; ++i)
|
| before_headers.SetHeader(test.before[i].name, test.before[i].value);
|
| - request.SetExtraRequestHeaders(before_headers);
|
| + request->SetExtraRequestHeaders(before_headers);
|
|
|
| // Gather the modifications to the headers for the respective extensions.
|
| // We assume here that all modifications of one extension are listed
|
| @@ -855,7 +857,7 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
|
| mod.extension_id == 1 ? extension1_id : extension2_id,
|
| base::Time::FromDoubleT(mod.extension_id));
|
| response->request_headers.reset(new net::HttpRequestHeaders());
|
| - response->request_headers->MergeFrom(request.extra_request_headers());
|
| + response->request_headers->MergeFrom(request->extra_request_headers());
|
| }
|
|
|
| switch (mod.type) {
|
| @@ -875,7 +877,7 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
|
| base::Bind(&EventHandledOnIOThread,
|
| &profile_, mod.extension_id == 1 ? extension1_id : extension2_id,
|
| kEventName, kEventName + (mod.extension_id == 1 ? "/1" : "/2"),
|
| - request.identifier(), response));
|
| + request->identifier(), response));
|
| response = NULL;
|
| }
|
| }
|
| @@ -884,19 +886,19 @@ TEST_P(ExtensionWebRequestHeaderModificationTest, TestModifications) {
|
| ipc_sender_.PushTask(base::Bind(&base::DoNothing));
|
|
|
| // Note that we mess up the headers slightly:
|
| - // request.Start() will first add additional headers (e.g. the User-Agent)
|
| + // request->Start() will first add additional headers (e.g. the User-Agent)
|
| // and then send an event to the extension. When we have prepared our
|
| // answers to the onBeforeSendHeaders events above, these headers did not
|
| // exists and are therefore not listed in the responses. This makes
|
| // them seem deleted.
|
| - request.Start();
|
| + request->Start();
|
| base::MessageLoop::current()->Run();
|
|
|
| - EXPECT_TRUE(!request.is_pending());
|
| + EXPECT_TRUE(!request->is_pending());
|
| // This cannot succeed as we send the request to a server that does not exist.
|
| - EXPECT_EQ(net::URLRequestStatus::FAILED, request.status().status());
|
| - EXPECT_EQ(request_url, request.url());
|
| - EXPECT_EQ(1U, request.url_chain().size());
|
| + EXPECT_EQ(net::URLRequestStatus::FAILED, request->status().status());
|
| + EXPECT_EQ(request_url, request->url());
|
| + EXPECT_EQ(1U, request->url_chain().size());
|
| EXPECT_EQ(0U, ipc_sender_.GetNumTasks());
|
|
|
| // Calculate the expected headers.
|
|
|