diff options
author | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 06:08:45 +0000 |
---|---|---|
committer | bbudge@chromium.org <bbudge@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2011-07-21 06:08:45 +0000 |
commit | 86737e7cbdc5deb4620f0c08d3cf088067072b28 (patch) | |
tree | d3bad51ac3e5a912d6e8f1f975649e8625eaeee3 /ppapi/tests | |
parent | 58cfc13b70c28c8debe696675cd65e2321f59918 (diff) | |
download | chromium_src-86737e7cbdc5deb4620f0c08d3cf088067072b28.zip chromium_src-86737e7cbdc5deb4620f0c08d3cf088067072b28.tar.gz chromium_src-86737e7cbdc5deb4620f0c08d3cf088067072b28.tar.bz2 |
Fix crash in PPB_URLLoader_Impl, where didFail invokes a null callback.
Review URL: http://codereview.chromium.org/7371013
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@93345 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_url_loader.cc | 43 | ||||
-rw-r--r-- | ppapi/tests/test_url_loader.h | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc index a2e61ef..fd0cfd5 100644 --- a/ppapi/tests/test_url_loader.cc +++ b/ppapi/tests/test_url_loader.cc @@ -56,6 +56,7 @@ void TestURLLoader::RunTest() { RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile); RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect); RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls); + RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad); } std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io, @@ -442,6 +443,48 @@ std::string TestURLLoader::TestAbortCalls() { PASS(); } +std::string TestURLLoader::TestUntendedLoad() { + pp::URLRequestInfo request(instance_); + request.SetURL("test_url_loader_data/hello.txt"); + request.SetRecordDownloadProgress(true); + TestCompletionCallback callback(instance_->pp_instance(), force_async_); + + pp::URLLoader loader(*instance_); + int32_t rv = loader.Open(request, callback); + if (force_async_ && rv != PP_OK_COMPLETIONPENDING) + return ReportError("URLLoader::Open force_async", rv); + if (rv == PP_OK_COMPLETIONPENDING) + rv = callback.WaitForResult(); + if (rv != PP_OK) + return ReportError("URLLoader::Open", rv); + + // We received the response callback. Yield until the network code has called + // the loader's didReceiveData and didFinishLoading methods before we give it + // another callback function, to make sure the loader works with no callback. + int64_t bytes_received = 0; + int64_t total_bytes_to_be_received = 0; + while (true) { + loader.GetDownloadProgress(&bytes_received, &total_bytes_to_be_received); + if (total_bytes_to_be_received <= 0) + return ReportError("URLLoader::GetDownloadProgress total size", + total_bytes_to_be_received); + if (bytes_received == total_bytes_to_be_received) + break; + pp::Module::Get()->core()->CallOnMainThread(10, callback); + callback.WaitForResult(); + } + + // The loader should now have the data and have finished successfully. + std::string body; + std::string error = ReadEntireResponseBody(&loader, &body); + if (!error.empty()) + return error; + if (body != "hello\n") + return ReportError("Couldn't read data", rv); + + PASS(); +} + // TODO(viettrungluu): Add tests for FollowRedirect, // Get{Upload,Download}Progress, Close (including abort tests if applicable). // TODO(darin): Add a test for GrantUniversalAccess. diff --git a/ppapi/tests/test_url_loader.h b/ppapi/tests/test_url_loader.h index d2deaf6..f162604 100644 --- a/ppapi/tests/test_url_loader.h +++ b/ppapi/tests/test_url_loader.h @@ -45,6 +45,7 @@ class TestURLLoader : public TestCase { std::string TestCrossOriginRequest(); std::string TestAuditURLRedirect(); std::string TestAbortCalls(); + std::string TestUntendedLoad(); const PPB_FileIOTrusted* file_io_trusted_interface_; }; |