| Index: content/browser/renderer_host/resource_dispatcher_host_unittest.cc
|
| ===================================================================
|
| --- content/browser/renderer_host/resource_dispatcher_host_unittest.cc (revision 142991)
|
| +++ content/browser/renderer_host/resource_dispatcher_host_unittest.cc (working copy)
|
| @@ -11,6 +11,8 @@
|
| #include "base/memory/scoped_vector.h"
|
| #include "base/message_loop.h"
|
| #include "base/process_util.h"
|
| +#include "base/string_number_conversions.h"
|
| +#include "base/string_split.h"
|
| #include "content/browser/browser_thread_impl.h"
|
| #include "content/browser/child_process_security_policy_impl.h"
|
| #include "content/browser/renderer_host/resource_dispatcher_host_impl.h"
|
| @@ -29,6 +31,7 @@
|
| #include "net/http/http_util.h"
|
| #include "net/url_request/url_request.h"
|
| #include "net/url_request/url_request_job.h"
|
| +#include "net/url_request/url_request_simple_job.h"
|
| #include "net/url_request/url_request_test_job.h"
|
| #include "testing/gtest/include/gtest/gtest.h"
|
| #include "webkit/appcache/appcache_interfaces.h"
|
| @@ -113,6 +116,7 @@
|
| typedef std::vector< std::vector<IPC::Message> > ClassifiedMessages;
|
| void GetClassifiedMessages(ClassifiedMessages* msgs);
|
|
|
| + private:
|
| std::vector<IPC::Message> messages_;
|
| };
|
|
|
| @@ -288,8 +292,46 @@
|
| virtual bool NextReadAsync() OVERRIDE { return true; }
|
| };
|
|
|
| +class URLRequestBigJob : public net::URLRequestSimpleJob {
|
| + public:
|
| + URLRequestBigJob(net::URLRequest* request)
|
| + : net::URLRequestSimpleJob(request) {
|
| + }
|
|
|
| + virtual bool GetData(std::string* mime_type,
|
| + std::string* charset,
|
| + std::string* data) const {
|
| + *mime_type = "text/plain";
|
| + *charset = "UTF-8";
|
|
|
| + std::string text;
|
| + int count;
|
| + if (!ParseURL(request_->url(), &text, &count))
|
| + return false;
|
| +
|
| + data->reserve(text.size() * count);
|
| + for (int i = 0; i < count; ++i)
|
| + data->append(text);
|
| +
|
| + return true;
|
| + }
|
| +
|
| + private:
|
| + virtual ~URLRequestBigJob() {}
|
| +
|
| + // big-job:substring,N
|
| + static bool ParseURL(const GURL& url, std::string* text, int* count) {
|
| + std::vector<std::string> parts;
|
| + base::SplitString(url.path(), ',', &parts);
|
| +
|
| + if (parts.size() != 2)
|
| + return false;
|
| +
|
| + *text = parts[0];
|
| + return base::StringToInt(parts[1], count);
|
| + }
|
| +};
|
| +
|
| // Associated with an URLRequest to determine if the URLRequest gets deleted.
|
| class TestUserData : public base::SupportsUserData::Data {
|
| public:
|
| @@ -446,13 +488,17 @@
|
|
|
| void CompleteStartRequest(int request_id);
|
|
|
| - void EnsureTestSchemeIsAllowed() {
|
| + void EnsureSchemeIsAllowed(const std::string& scheme) {
|
| ChildProcessSecurityPolicyImpl* policy =
|
| ChildProcessSecurityPolicyImpl::GetInstance();
|
| - if (!policy->IsWebSafeScheme("test"))
|
| - policy->RegisterWebSafeScheme("test");
|
| + if (!policy->IsWebSafeScheme(scheme))
|
| + policy->RegisterWebSafeScheme(scheme);
|
| }
|
|
|
| + void EnsureTestSchemeIsAllowed() {
|
| + EnsureSchemeIsAllowed("test");
|
| + }
|
| +
|
| // Sets a particular response for any request from now on. To switch back to
|
| // the default bahavior, pass an empty |headers|. |headers| should be raw-
|
| // formatted (NULLs instead of EOLs).
|
| @@ -473,6 +519,7 @@
|
| scheme_ = scheme;
|
| old_factory_ = net::URLRequest::Deprecated::RegisterProtocolFactory(
|
| scheme_, &ResourceDispatcherHostTest::Factory);
|
| + EnsureSchemeIsAllowed(scheme);
|
| }
|
|
|
| // Our own net::URLRequestJob factory.
|
| @@ -483,6 +530,8 @@
|
| return new URLRequestTestDelayedStartJob(request);
|
| } else if (delay_complete_) {
|
| return new URLRequestTestDelayedCompletionJob(request);
|
| + } else if (scheme == "big-job") {
|
| + return new URLRequestBigJob(request);
|
| } else {
|
| return new net::URLRequestTestJob(request);
|
| }
|
| @@ -1432,4 +1481,48 @@
|
| EXPECT_EQ(net::ERR_UNKNOWN_URL_SCHEME, status.error());
|
| }
|
|
|
| +TEST_F(ResourceDispatcherHostTest, DelayedDataReceivedACK) {
|
| + EXPECT_EQ(0, host_.pending_requests());
|
| +
|
| + HandleScheme("big-job");
|
| + MakeTestRequest(0, 1, GURL("big-job:0123456789,1000000"));
|
| +
|
| + // Sort all the messages we saw by request.
|
| + ResourceIPCAccumulator::ClassifiedMessages msgs;
|
| + accum_.GetClassifiedMessages(&msgs);
|
| +
|
| + // We expect 1x ReceivedResponse + Nx ReceivedData messages.
|
| + EXPECT_EQ(ResourceMsg_ReceivedResponse::ID, msgs[0][0].type());
|
| + for (size_t i = 1; i < msgs[0].size(); ++i)
|
| + EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
|
| +
|
| + // NOTE: If we fail the above checks then it means that we probably didn't
|
| + // load a big enough response to trigger the delay mechanism we are trying to
|
| + // test!
|
| +
|
| + msgs[0].erase(msgs[0].begin());
|
| +
|
| + // ACK all DataReceived messages until we find a RequestComplete message.
|
| + bool complete = false;
|
| + while (!complete) {
|
| + for (size_t i = 0; i < msgs[0].size(); ++i) {
|
| + if (msgs[0][i].type() == ResourceMsg_RequestComplete::ID) {
|
| + complete = true;
|
| + break;
|
| + }
|
| +
|
| + EXPECT_EQ(ResourceMsg_DataReceived::ID, msgs[0][i].type());
|
| +
|
| + ResourceHostMsg_DataReceived_ACK msg(0, 1);
|
| + bool msg_was_ok;
|
| + host_.OnMessageReceived(msg, filter_.get(), &msg_was_ok);
|
| + }
|
| +
|
| + MessageLoop::current()->RunAllPending();
|
| +
|
| + msgs.clear();
|
| + accum_.GetClassifiedMessages(&msgs);
|
| + }
|
| +}
|
| +
|
| } // namespace content
|
|
|