diff options
author | jam <jam@chromium.org> | 2015-02-19 12:29:17 -0800 |
---|---|---|
committer | Commit bot <commit-bot@chromium.org> | 2015-02-19 20:30:08 +0000 |
commit | 4a1511ef45627b827c47a34a65aee06028d71d3a (patch) | |
tree | 6275b4ab73944c411a306039dc73342ce5556d5b /content/child/resource_dispatcher_unittest.cc | |
parent | ac1a3823f82e90136e7800d6f77a08534f9afbd1 (diff) | |
download | chromium_src-4a1511ef45627b827c47a34a65aee06028d71d3a.zip chromium_src-4a1511ef45627b827c47a34a65aee06028d71d3a.tar.gz chromium_src-4a1511ef45627b827c47a34a65aee06028d71d3a.tar.bz2 |
Remove ResourceLoaderBridge interface.
We don't need it anymore since WebURLLoaderImpl is in content.
This is based on https://codereview.chromium.org/226273005.
BUG=338338
Review URL: https://codereview.chromium.org/938933002
Cr-Commit-Position: refs/heads/master@{#317126}
Diffstat (limited to 'content/child/resource_dispatcher_unittest.cc')
-rw-r--r-- | content/child/resource_dispatcher_unittest.cc | 167 |
1 files changed, 86 insertions, 81 deletions
diff --git a/content/child/resource_dispatcher_unittest.cc b/content/child/resource_dispatcher_unittest.cc index 46ce695..e0938d1 100644 --- a/content/child/resource_dispatcher_unittest.cc +++ b/content/child/resource_dispatcher_unittest.cc @@ -15,7 +15,6 @@ #include "content/child/request_extra_data.h" #include "content/child/request_info.h" #include "content/child/resource_dispatcher.h" -#include "content/child/resource_loader_bridge.h" #include "content/common/appcache_interfaces.h" #include "content/common/resource_messages.h" #include "content/common/service_worker/service_worker_types.h" @@ -41,7 +40,7 @@ static const char kTestRedirectHeaders[] = // to the reference data. class TestRequestPeer : public RequestPeer { public: - TestRequestPeer(ResourceLoaderBridge* bridge) + TestRequestPeer(ResourceDispatcher* dispatcher) : follow_redirects_(true), defer_on_redirect_(false), seen_redirects_(0), @@ -50,16 +49,19 @@ class TestRequestPeer : public RequestPeer { total_encoded_data_length_(0), total_downloaded_data_length_(0), complete_(false), - bridge_(bridge) { + dispatcher_(dispatcher), + request_id_(0) { } + void set_request_id(int request_id) { request_id_ = request_id; } + void OnUploadProgress(uint64 position, uint64 size) override {} bool OnReceivedRedirect(const net::RedirectInfo& redirect_info, const ResourceResponseInfo& info) override { ++seen_redirects_; if (defer_on_redirect_) - bridge_->SetDefersLoading(true); + dispatcher_->SetDefersLoading(request_id_, true); return follow_redirects_; } @@ -67,7 +69,7 @@ class TestRequestPeer : public RequestPeer { EXPECT_FALSE(received_response_); received_response_ = true; if (cancel_on_receive_response_) - bridge_->Cancel(); + dispatcher_->Cancel(request_id_); } void OnDownloadedData(int len, int encoded_data_length) override { @@ -144,7 +146,8 @@ class TestRequestPeer : public RequestPeer { bool complete_; - ResourceLoaderBridge* bridge_; + ResourceDispatcher* dispatcher_; + int request_id_; DISALLOW_COPY_AND_ASSIGN(TestRequestPeer); }; @@ -306,37 +309,28 @@ class ResourceDispatcherTest : public testing::Test, public IPC::Sender { ResourceMsg_RequestComplete(request_id, request_complete_data))); } - ResourceLoaderBridge* CreateBridge() { - return CreateBridgeInternal(false); - } + RequestInfo* CreateRequestInfo(bool download_to_file) { + RequestInfo* request_info = new RequestInfo(); + request_info->method = "GET"; + request_info->url = GURL(kTestPageUrl); + request_info->first_party_for_cookies = GURL(kTestPageUrl); + request_info->referrer = Referrer(); + request_info->headers = std::string(); + request_info->load_flags = 0; + request_info->requestor_pid = 0; + request_info->request_type = RESOURCE_TYPE_SUB_RESOURCE; + request_info->appcache_host_id = kAppCacheNoHostId; + request_info->should_reset_appcache = false; + request_info->routing_id = 0; + request_info->download_to_file = download_to_file; + RequestExtraData extra_data; - ResourceLoaderBridge* CreateBridgeForDownloadToFile() { - return CreateBridgeInternal(true); + return request_info; } ResourceDispatcher* dispatcher() { return &dispatcher_; } private: - ResourceLoaderBridge* CreateBridgeInternal(bool download_to_file) { - RequestInfo request_info; - request_info.method = "GET"; - request_info.url = GURL(kTestPageUrl); - request_info.first_party_for_cookies = GURL(kTestPageUrl); - request_info.referrer = Referrer(); - request_info.headers = std::string(); - request_info.load_flags = 0; - request_info.requestor_pid = 0; - request_info.request_type = RESOURCE_TYPE_SUB_RESOURCE; - request_info.appcache_host_id = kAppCacheNoHostId; - request_info.should_reset_appcache = false; - request_info.routing_id = 0; - request_info.download_to_file = download_to_file; - RequestExtraData extra_data; - request_info.extra_data = &extra_data; - - return dispatcher_.CreateBridge(request_info); - } - // Map of request IDs to shared memory. std::map<int, base::SharedMemory*> shared_memory_map_; @@ -352,10 +346,11 @@ TEST_F(ResourceDispatcherTest, RoundTrip) { const size_t kFirstReceiveSize = 2; ASSERT_LT(kFirstReceiveSize, strlen(kTestPageContents)); - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -383,14 +378,18 @@ TEST_F(ResourceDispatcherTest, RoundTrip) { TEST_F(ResourceDispatcherTest, MultipleRequests) { const char kTestPageContents2[] = "Not kTestPageContents"; - scoped_ptr<ResourceLoaderBridge> bridge1(CreateBridge()); - TestRequestPeer peer1(bridge1.get()); - scoped_ptr<ResourceLoaderBridge> bridge2(CreateBridge()); - TestRequestPeer peer2(bridge2.get()); + scoped_ptr<RequestInfo> request_info1(CreateRequestInfo(false)); + TestRequestPeer peer1(dispatcher()); + int request_id1 = dispatcher()->StartAsync( + *request_info1.get(), NULL, &peer1); + peer1.set_request_id(request_id1); + scoped_ptr<RequestInfo> request_info2(CreateRequestInfo(false)); + TestRequestPeer peer2(dispatcher()); + int request_id2 = dispatcher()->StartAsync( + *request_info1.get(), NULL, &peer2); + peer2.set_request_id(request_id2); - EXPECT_TRUE(bridge1->Start(&peer1)); int id1 = ConsumeRequestResource(); - EXPECT_TRUE(bridge2->Start(&peer2)); int id2 = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -423,15 +422,16 @@ TEST_F(ResourceDispatcherTest, MultipleRequests) { // Tests that the cancel method prevents other messages from being received. TEST_F(ResourceDispatcherTest, Cancel) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); // Cancel the request. - bridge->Cancel(); + dispatcher()->Cancel(request_id); ConsumeCancelRequest(id); // Any future messages related to the request should be ignored. @@ -448,11 +448,12 @@ TEST_F(ResourceDispatcherTest, Cancel) { // Tests that calling cancel during a callback works as expected. TEST_F(ResourceDispatcherTest, CancelDuringCallback) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); peer.set_cancel_on_receive_response(true); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -473,10 +474,11 @@ TEST_F(ResourceDispatcherTest, CancelDuringCallback) { // Checks that redirects work as expected. TEST_F(ResourceDispatcherTest, Redirect) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); NotifyReceivedRedirect(id); @@ -504,11 +506,12 @@ TEST_F(ResourceDispatcherTest, Redirect) { // Tests that that cancelling during a redirect method prevents other messages // from being received. TEST_F(ResourceDispatcherTest, CancelDuringRedirect) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); peer.set_follow_redirects(false); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -534,14 +537,15 @@ TEST_F(ResourceDispatcherTest, CancelDuringRedirect) { // Checks that deferring a request delays messages until it's resumed. TEST_F(ResourceDispatcherTest, Defer) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); - bridge->SetDefersLoading(true); + dispatcher()->SetDefersLoading(request_id, true); NotifyReceivedResponse(id); NotifySetDataBuffer(id, strlen(kTestPageContents)); NotifyDataReceived(id, kTestPageContents); @@ -555,7 +559,7 @@ TEST_F(ResourceDispatcherTest, Defer) { EXPECT_EQ(0, peer.seen_redirects()); // Resuming the request should asynchronously unleash the deferred messages. - bridge->SetDefersLoading(false); + dispatcher()->SetDefersLoading(request_id, false); base::RunLoop().RunUntilIdle(); ConsumeDataReceived_ACK(id); @@ -568,11 +572,12 @@ TEST_F(ResourceDispatcherTest, Defer) { // Checks that deferring a request during a redirect delays messages until it's // resumed. TEST_F(ResourceDispatcherTest, DeferOnRedirect) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); peer.set_defer_on_redirect(true); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -592,7 +597,7 @@ TEST_F(ResourceDispatcherTest, DeferOnRedirect) { EXPECT_EQ(1, peer.seen_redirects()); // Resuming the request should asynchronously unleash the deferred messages. - bridge->SetDefersLoading(false); + dispatcher()->SetDefersLoading(request_id, false); base::RunLoop().RunUntilIdle(); ConsumeFollowRedirect(id); @@ -607,16 +612,17 @@ TEST_F(ResourceDispatcherTest, DeferOnRedirect) { // Checks that a deferred request that's cancelled doesn't receive any messages. TEST_F(ResourceDispatcherTest, CancelDeferredRequest) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); - bridge->SetDefersLoading(true); + dispatcher()->SetDefersLoading(request_id, true); NotifyReceivedRedirect(id); - bridge->Cancel(); + dispatcher()->Cancel(request_id); ConsumeCancelRequest(id); NotifyRequestComplete(id, 0); @@ -630,12 +636,13 @@ TEST_F(ResourceDispatcherTest, CancelDeferredRequest) { } TEST_F(ResourceDispatcherTest, DownloadToFile) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridgeForDownloadToFile()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(true)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); const int kDownloadedIncrement = 100; const int kEncodedIncrement = 50; - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -660,7 +667,7 @@ TEST_F(ResourceDispatcherTest, DownloadToFile) { EXPECT_TRUE(peer.complete()); EXPECT_EQ(0u, queued_messages()); - bridge.reset(); + dispatcher()->RemovePendingRequest(request_id); ConsumeReleaseDownloadedFile(id); EXPECT_EQ(0u, queued_messages()); EXPECT_EQ(expected_total_downloaded_length, @@ -670,10 +677,11 @@ TEST_F(ResourceDispatcherTest, DownloadToFile) { // Make sure that when a download to file is cancelled, the file is destroyed. TEST_F(ResourceDispatcherTest, CancelDownloadToFile) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridgeForDownloadToFile()); - TestRequestPeer peer(bridge.get()); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(true)); + TestRequestPeer peer(dispatcher()); + int request_id = dispatcher()->StartAsync(*request_info.get(), NULL, &peer); + peer.set_request_id(request_id); - EXPECT_TRUE(bridge->Start(&peer)); int id = ConsumeRequestResource(); EXPECT_EQ(0u, queued_messages()); @@ -682,13 +690,9 @@ TEST_F(ResourceDispatcherTest, CancelDownloadToFile) { EXPECT_TRUE(peer.received_response()); // Cancelling the request deletes the file. - bridge->Cancel(); + dispatcher()->Cancel(request_id); ConsumeCancelRequest(id); ConsumeReleaseDownloadedFile(id); - - // Deleting the bridge shouldn't send another message to delete the file. - bridge.reset(); - EXPECT_EQ(0u, queued_messages()); } TEST_F(ResourceDispatcherTest, Cookies) { @@ -708,8 +712,9 @@ class TimeConversionTest : public ResourceDispatcherTest, } void PerformTest(const ResourceResponseHead& response_head) { - scoped_ptr<ResourceLoaderBridge> bridge(CreateBridge()); - bridge->Start(this); + scoped_ptr<RequestInfo> request_info(CreateRequestInfo(false)); + TestRequestPeer peer(dispatcher()); + dispatcher()->StartAsync(*request_info.get(), NULL, &peer); dispatcher()->OnMessageReceived( ResourceMsg_ReceivedResponse(0, response_head)); |