| Index: ppapi/tests/test_url_loader.cc
|
| diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
|
| index 90244912681fc7c77d24b1746db811fa62ff8205..e818ea4274d072913b2474b98d967275ff37955c 100644
|
| --- a/ppapi/tests/test_url_loader.cc
|
| +++ b/ppapi/tests/test_url_loader.cc
|
| @@ -97,6 +97,7 @@ bool TestURLLoader::Init() {
|
|
|
| void TestURLLoader::RunTests(const std::string& filter) {
|
| RUN_CALLBACK_TEST(TestURLLoader, BasicGET, filter);
|
| + RUN_CALLBACK_TEST(TestURLLoader, BasicGET_ToArray, filter);
|
| RUN_CALLBACK_TEST(TestURLLoader, BasicPOST, filter);
|
| RUN_CALLBACK_TEST(TestURLLoader, BasicFilePOST, filter);
|
| RUN_CALLBACK_TEST(TestURLLoader, BasicFileRangePOST, filter);
|
| @@ -158,6 +159,26 @@ std::string TestURLLoader::ReadEntireResponseBody(pp::URLLoader* loader,
|
| PASS();
|
| }
|
|
|
| +std::string TestURLLoader::ReadEntireResponseBodyToArray(pp::URLLoader* loader,
|
| + std::string* body) {
|
| + TestCompletionCallbackWithOutput< std::vector<char> > callback(
|
| + instance_->pp_instance(), callback_type());
|
| +
|
| + for (;;) {
|
| + // Read just a little bit so that multiple reads are needed.
|
| + callback.WaitForResult(loader->ReadResponseBody(2, callback));
|
| + int32_t rv = callback.result();
|
| + if (rv < 0)
|
| + return ReportError("URLLoader::ReadResponseBody", rv);
|
| + if (rv == 0)
|
| + break;
|
| + assert(rv == static_cast<int32_t>(callback.output().size()));
|
| + body->append(callback.output().begin(), callback.output().end());
|
| + }
|
| +
|
| + PASS();
|
| +}
|
| +
|
| std::string TestURLLoader::LoadAndCompareBody(
|
| const pp::URLRequestInfo& request,
|
| const std::string& expected_body) {
|
| @@ -188,6 +209,38 @@ std::string TestURLLoader::LoadAndCompareBody(
|
| PASS();
|
| }
|
|
|
| +// Exact the same test of LoadAndCompareBody, but for ReadResponseBodyToArray.
|
| +std::string TestURLLoader::LoadAndCompareBody_ToArray(
|
| + const pp::URLRequestInfo& request,
|
| + const std::string& expected_body) {
|
| + TestCompletionCallback callback(instance_->pp_instance(), callback_type());
|
| +
|
| + pp::URLLoader loader(instance_);
|
| + callback.WaitForResult(loader.Open(request, callback));
|
| + CHECK_CALLBACK_BEHAVIOR(callback);
|
| + ASSERT_EQ(PP_OK, callback.result());
|
| +
|
| + pp::URLResponseInfo response_info(loader.GetResponseInfo());
|
| + if (response_info.is_null())
|
| + return "URLLoader::GetResponseInfo returned null";
|
| + int32_t status_code = response_info.GetStatusCode();
|
| + if (status_code != 200)
|
| + return "Unexpected HTTP status code";
|
| +
|
| + std::string body;
|
| + std::string error = ReadEntireResponseBodyToArray(&loader, &body);
|
| + if (!error.empty())
|
| + return error;
|
| +
|
| + if (body.size() != expected_body.size())
|
| + return "URLLoader::ReadResponseBodyToArray returned unexpected content "
|
| + "length";
|
| + if (body != expected_body)
|
| + return "URLLoader::ReadResponseBodyToArray returned unexpected content";
|
| +
|
| + PASS();
|
| +}
|
| +
|
| int32_t TestURLLoader::OpenFileSystem(pp::FileSystem* file_system,
|
| std::string* message) {
|
| TestCompletionCallback callback(instance_->pp_instance(), callback_type());
|
| @@ -307,6 +360,13 @@ std::string TestURLLoader::TestBasicGET() {
|
| return LoadAndCompareBody(request, "hello\n");
|
| }
|
|
|
| +// A variance of BasicGET but use ReadResponseBodyToArray internally.
|
| +std::string TestURLLoader::TestBasicGET_ToArray() {
|
| + pp::URLRequestInfo request(instance_);
|
| + request.SetURL("test_url_loader_data/hello.txt");
|
| + return LoadAndCompareBody_ToArray(request, "hello\n");
|
| +}
|
| +
|
| std::string TestURLLoader::TestBasicPOST() {
|
| pp::URLRequestInfo request(instance_);
|
| request.SetURL("/echo");
|
|
|