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

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

Issue 10081020: PPAPI: Make blocking completion callbacks work. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: export AssertLockHeld Created 8 years, 6 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
« no previous file with comments | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_url_loader.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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_case.h" 5 #include "ppapi/tests/test_case.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "ppapi/tests/pp_thread.h"
9 #include "ppapi/tests/test_utils.h" 10 #include "ppapi/tests/test_utils.h"
10 #include "ppapi/tests/testing_instance.h" 11 #include "ppapi/tests/testing_instance.h"
11 12
12 TestCase::TestCase(TestingInstance* instance) 13 TestCase::TestCase(TestingInstance* instance)
13 : instance_(instance), 14 : instance_(instance),
14 testing_interface_(NULL), 15 testing_interface_(NULL),
15 callback_type_(PP_REQUIRED) { 16 callback_type_(PP_REQUIRED) {
16 // Get the testing_interface_ if it is available, so that we can do Resource 17 // Get the testing_interface_ if it is available, so that we can do Resource
17 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not 18 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not
18 // available, testing_interface_ will be NULL. Some tests do not require it. 19 // available, testing_interface_ will be NULL. Some tests do not require it.
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
100 } 101 }
101 102
102 return true; 103 return true;
103 } 104 }
104 105
105 bool TestCase::MatchesFilter(const std::string& test_name, 106 bool TestCase::MatchesFilter(const std::string& test_name,
106 const std::string& filter) { 107 const std::string& filter) {
107 return filter.empty() || (test_name == filter); 108 return filter.empty() || (test_name == filter);
108 } 109 }
109 110
110 std::string TestCase::CheckResourcesAndVars() { 111 std::string TestCase::CheckResourcesAndVars(std::string errors) {
111 std::string errors; 112 if (!errors.empty())
113 return errors;
114
112 if (testing_interface_) { 115 if (testing_interface_) {
113 // TODO(dmichael): Fix tests that leak resources and enable the following: 116 // TODO(dmichael): Fix tests that leak resources and enable the following:
114 /* 117 /*
115 uint32_t leaked_resources = 118 uint32_t leaked_resources =
116 testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance()); 119 testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance());
117 if (leaked_resources) { 120 if (leaked_resources) {
118 std::ostringstream output; 121 std::ostringstream output;
119 output << "FAILED: Test leaked " << leaked_resources << " resources.\n"; 122 output << "FAILED: Test leaked " << leaked_resources << " resources.\n";
120 errors += output.str(); 123 errors += output.str();
121 } 124 }
(...skipping 14 matching lines...) Expand all
136 } 139 }
137 for (int i = 0; i < std::min(found_vars, kVarsToPrint); ++i) { 140 for (int i = 0; i < std::min(found_vars, kVarsToPrint); ++i) {
138 pp::Var leaked_var(pp::PASS_REF, vars[i]); 141 pp::Var leaked_var(pp::PASS_REF, vars[i]);
139 if (ignored_leaked_vars_.count(leaked_var.pp_var().value.as_id) == 0) 142 if (ignored_leaked_vars_.count(leaked_var.pp_var().value.as_id) == 0)
140 errors += leaked_var.DebugString() + "<p>"; 143 errors += leaked_var.DebugString() + "<p>";
141 } 144 }
142 } 145 }
143 return errors; 146 return errors;
144 } 147 }
145 148
149 // static
150 void TestCase::QuitMainMessageLoop(PP_Instance instance) {
151 PP_Instance* heap_instance = new PP_Instance(instance);
152 pp::CompletionCallback callback(&DoQuitMainMessageLoop, heap_instance);
153 pp::Module::Get()->core()->CallOnMainThread(0, callback);
154 }
146 155
156 // static
157 void TestCase::DoQuitMainMessageLoop(void* pp_instance, int32_t result) {
158 PP_Instance* instance = static_cast<PP_Instance*>(pp_instance);
159 GetTestingInterface()->QuitMessageLoop(*instance);
160 delete instance;
161 }
162
163 void TestCase::RunOnThreadInternal(void (*thread_func)(void*),
164 void* thread_param,
165 const PPB_Testing_Dev* testing_interface) {
166 PP_ThreadType thread;
167 PP_CreateThread(&thread, thread_func, thread_param);
168 // Run a message loop so pepper calls can be dispatched. The background
169 // thread will set result_ and make us Quit when it's done.
170 testing_interface->RunMessageLoop(instance_->pp_instance());
171 PP_JoinThread(thread);
172 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_url_loader.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698