Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(118)

Side by Side Diff: ppapi/tests/test_utils.cc

Issue 6899055: PPAPI: Force async callback invocation option. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ppapi/tests/test_utils.h" 5 #include "ppapi/tests/test_utils.h"
6 6
7 #include <stdio.h> 7 #include <stdio.h>
8 8
9 #include "ppapi/c/pp_errors.h" 9 #include "ppapi/c/pp_errors.h"
10 #include "ppapi/cpp/module.h" 10 #include "ppapi/cpp/module.h"
(...skipping 10 matching lines...) Expand all
21 sprintf(error_as_string, "%d", error); 21 sprintf(error_as_string, "%d", error);
22 std::string result = method + std::string(" failed with error: ") + 22 std::string result = method + std::string(" failed with error: ") +
23 error_as_string; 23 error_as_string;
24 if (error == PP_ERROR_NOSPACE) 24 if (error == PP_ERROR_NOSPACE)
25 result += ". Did you run the test with --unlimited-quota-for-files?"; 25 result += ". Did you run the test with --unlimited-quota-for-files?";
26 return result; 26 return result;
27 } 27 }
28 28
29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance) 29 TestCompletionCallback::TestCompletionCallback(PP_Instance instance)
30 : result_(PP_OK_COMPLETIONPENDING), 30 : result_(PP_OK_COMPLETIONPENDING),
31 force_async_(false),
32 post_quit_task_(false),
33 run_count_(0),
34 instance_(instance) {
35 }
36
37 TestCompletionCallback::TestCompletionCallback(PP_Instance instance,
38 bool force_async)
39 : result_(PP_OK_COMPLETIONPENDING),
40 force_async_(force_async),
31 post_quit_task_(false), 41 post_quit_task_(false),
32 run_count_(0), 42 run_count_(0),
33 instance_(instance) { 43 instance_(instance) {
34 } 44 }
35 45
36 int32_t TestCompletionCallback::WaitForResult() { 46 int32_t TestCompletionCallback::WaitForResult() {
37 result_ = PP_OK_COMPLETIONPENDING; // Reset 47 result_ = PP_OK_COMPLETIONPENDING; // Reset
38 post_quit_task_ = true; 48 post_quit_task_ = true;
39 GetTestingInterface()->RunMessageLoop(instance_); 49 GetTestingInterface()->RunMessageLoop(instance_);
40 return result_; 50 return result_;
41 } 51 }
42 52
43 TestCompletionCallback::operator pp::CompletionCallback() const { 53 TestCompletionCallback::operator pp::CompletionCallback() const {
44 return pp::CompletionCallback(&TestCompletionCallback::Handler, 54 pp::CompletionCallback cc(&TestCompletionCallback::Handler,
45 const_cast<TestCompletionCallback*>(this)); 55 const_cast<TestCompletionCallback*>(this));
56 if (!force_async_)
57 cc.set_flags(PP_COMPLETIONCALLBACK_FLAG_NOFORCEASYNC);
58 return cc;
46 } 59 }
47 60
48 // static 61 // static
49 void TestCompletionCallback::Handler(void* user_data, int32_t result) { 62 void TestCompletionCallback::Handler(void* user_data, int32_t result) {
50 TestCompletionCallback* callback = 63 TestCompletionCallback* callback =
51 static_cast<TestCompletionCallback*>(user_data); 64 static_cast<TestCompletionCallback*>(user_data);
52 callback->result_ = result; 65 callback->result_ = result;
53 callback->run_count_++; 66 callback->run_count_++;
54 if (callback->post_quit_task_) { 67 if (callback->post_quit_task_) {
55 callback->post_quit_task_ = false; 68 callback->post_quit_task_ = false;
56 GetTestingInterface()->QuitMessageLoop(callback->instance_); 69 GetTestingInterface()->QuitMessageLoop(callback->instance_);
57 } 70 }
58 } 71 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698