summaryrefslogtreecommitdiffstats
path: root/ppapi/tests/test_url_loader.cc
diff options
context:
space:
mode:
authordmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-23 14:27:42 +0000
committerdmichael@chromium.org <dmichael@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-06-23 14:27:42 +0000
commitaed965375dec978e7feb8722b1b94250a2a6e039 (patch)
tree9f8ccdf7a3902fa1db54e0c036f7cb9ca96775fb /ppapi/tests/test_url_loader.cc
parent94bd0a2e94c1f07ccc0236a95e57a2e16b94038a (diff)
downloadchromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.zip
chromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.tar.gz
chromium_src-aed965375dec978e7feb8722b1b94250a2a6e039.tar.bz2
PPAPI: Make blocking completion callbacks work.
This also makes scoped_refptr<TrackedCallback> the "new" way to pass completion callbacks in an API. This allows the Enter object to handle checking for blocking callbacks on the main thread to report error, and blocking if on the background thread. This way, interfaces don't have to write any special cases for blocking callbacks. When built with enable_pepper_threading=1 locally, URLLoader tests all pass for blocking completion callbacks. I haven't updated all tests yet. BUG=92909 TEST= Review URL: https://chromiumcodereview.appspot.com/10081020 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@143806 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ppapi/tests/test_url_loader.cc')
-rw-r--r--ppapi/tests/test_url_loader.cc63
1 files changed, 35 insertions, 28 deletions
diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc
index 15ea546..9024491 100644
--- a/ppapi/tests/test_url_loader.cc
+++ b/ppapi/tests/test_url_loader.cc
@@ -33,8 +33,9 @@ namespace {
int32_t WriteEntireBuffer(PP_Instance instance,
pp::FileIO* file_io,
int32_t offset,
- const std::string& data) {
- TestCompletionCallback callback(instance);
+ const std::string& data,
+ CallbackType callback_type) {
+ TestCompletionCallback callback(instance, callback_type);
int32_t write_offset = offset;
const char* buf = data.c_str();
int32_t size = data.size();
@@ -95,29 +96,29 @@ bool TestURLLoader::Init() {
}
void TestURLLoader::RunTests(const std::string& filter) {
- RUN_TEST_FORCEASYNC_AND_NOT(BasicGET, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicFilePOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BasicFileRangePOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(CompoundBodyPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(EmptyDataPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(BinaryDataPOST, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(CustomRequestHeader, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(FailsBogusContentLength, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(StreamToFile, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedSameOriginRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedSameOriginRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedCrossOriginRequest, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedCrossOriginRequest, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedJavascriptURLRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedJavascriptURLRestriction, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntrustedHttpRequests, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(TrustedHttpRequests, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(FollowURLRedirect, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(AuditURLRedirect, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(AbortCalls, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(UntendedLoad, filter);
- RUN_TEST_FORCEASYNC_AND_NOT(PrefetchBufferThreshold, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicGET, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicFilePOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BasicFileRangePOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, CompoundBodyPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, EmptyDataPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, BinaryDataPOST, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, CustomRequestHeader, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, FailsBogusContentLength, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, StreamToFile, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedSameOriginRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedSameOriginRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedCrossOriginRequest, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedCrossOriginRequest, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedJavascriptURLRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedJavascriptURLRestriction, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntrustedHttpRequests, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, TrustedHttpRequests, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, FollowURLRedirect, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, AuditURLRedirect, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, AbortCalls, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, UntendedLoad, filter);
+ RUN_CALLBACK_TEST(TestURLLoader, PrefetchBufferThreshold, filter);
}
std::string TestURLLoader::ReadEntireFile(pp::FileIO* file_io,
@@ -222,7 +223,8 @@ int32_t TestURLLoader::PrepareFileForPost(
return callback.result();
}
- int32_t rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, data);
+ int32_t rv = WriteEntireBuffer(instance_->pp_instance(), &file_io, 0, data,
+ callback_type());
if (rv != PP_OK) {
message->assign("FileIO::Write failed.");
return rv;
@@ -787,8 +789,13 @@ std::string TestURLLoader::TestUntendedLoad() {
total_bytes_to_be_received);
if (bytes_received == total_bytes_to_be_received)
break;
- pp::Module::Get()->core()->CallOnMainThread(10, callback);
- callback.WaitForResult();
+ // TODO(dmichael): This should probably compare pp::MessageLoop::GetCurrent
+ // with GetForMainThread. We only need to yield on the main
+ // thread.
+ if (callback_type() != PP_BLOCKING) {
+ pp::Module::Get()->core()->CallOnMainThread(10, callback);
+ callback.WaitForResult();
+ }
}
// The loader should now have the data and have finished successfully.