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

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

Issue 9403039: PPAPI: Really force-free NPObjects on Instance destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 9 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/testing_instance.h ('k') | webkit/plugins/ppapi/host_var_tracker.h » ('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) 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/testing_instance.h" 5 #include "ppapi/tests/testing_instance.h"
6 6
7 #include <algorithm> 7 #include <algorithm>
8 #include <cstring> 8 #include <cstring>
9 #include <sstream> 9 #include <sstream>
10 #include <vector> 10 #include <vector>
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
95 current_case_->DidChangeView(view); 95 current_case_->DidChangeView(view);
96 } 96 }
97 97
98 bool TestingInstance::HandleInputEvent(const pp::InputEvent& event) { 98 bool TestingInstance::HandleInputEvent(const pp::InputEvent& event) {
99 if (current_case_) 99 if (current_case_)
100 return current_case_->HandleInputEvent(event); 100 return current_case_->HandleInputEvent(event);
101 return false; 101 return false;
102 } 102 }
103 103
104 void TestingInstance::EvalScript(const std::string& script) { 104 void TestingInstance::EvalScript(const std::string& script) {
105 std::string message("TESTING_MESSAGE:EvalScript:"); 105 SendTestCommand("EvalScript", script);
106 message.append(script);
107 PostMessage(pp::Var(message));
108 } 106 }
109 107
110 void TestingInstance::SetCookie(const std::string& name, 108 void TestingInstance::SetCookie(const std::string& name,
111 const std::string& value) { 109 const std::string& value) {
112 std::string message("TESTING_MESSAGE:SetCookie:"); 110 SendTestCommand("SetCookie", name + "=" + value);
113 message.append(name); 111 }
114 message.append("="); 112
115 message.append(value); 113 void TestingInstance::AddPostCondition(const std::string& script) {
116 PostMessage(pp::Var(message)); 114 SendTestCommand("AddPostCondition", script);
117 } 115 }
118 116
119 void TestingInstance::LogTest(const std::string& test_name, 117 void TestingInstance::LogTest(const std::string& test_name,
120 const std::string& error_message) { 118 const std::string& error_message) {
121 // Tell the browser we're still working. 119 // Tell the browser we're still working.
122 ReportProgress(kProgressSignal); 120 ReportProgress(kProgressSignal);
123 121
124 std::string html; 122 std::string html;
125 html.append("<div class=\"test_line\"><span class=\"test_name\">"); 123 html.append("<div class=\"test_line\"><span class=\"test_name\">");
126 html.append(test_name); 124 html.append(test_name);
(...skipping 16 matching lines...) Expand all
143 void TestingInstance::AppendError(const std::string& message) { 141 void TestingInstance::AppendError(const std::string& message) {
144 if (!errors_.empty()) 142 if (!errors_.empty())
145 errors_.append(", "); 143 errors_.append(", ");
146 errors_.append(message); 144 errors_.append(message);
147 } 145 }
148 146
149 void TestingInstance::ExecuteTests(int32_t unused) { 147 void TestingInstance::ExecuteTests(int32_t unused) {
150 ReportProgress(kProgressSignal); 148 ReportProgress(kProgressSignal);
151 149
152 // Clear the console. 150 // Clear the console.
153 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole")); 151 SendTestCommand("ClearConsole");
154 152
155 if (!errors_.empty()) { 153 if (!errors_.empty()) {
156 // Catch initialization errors and output the current error string to 154 // Catch initialization errors and output the current error string to
157 // the console. 155 // the console.
158 LogError("Plugin initialization failed: " + errors_); 156 LogError("Plugin initialization failed: " + errors_);
159 } else if (!current_case_) { 157 } else if (!current_case_) {
160 LogAvailableTests(); 158 LogAvailableTests();
161 errors_.append("FAIL: Only listed tests"); 159 errors_.append("FAIL: Only listed tests");
162 } else { 160 } else {
163 current_case_->RunTests(test_filter_); 161 current_case_->RunTests(test_filter_);
164 // Automated PyAuto tests rely on finding the exact strings below. 162 // Automated PyAuto tests rely on finding the exact strings below.
165 LogHTML(errors_.empty() ? 163 LogHTML(errors_.empty() ?
166 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : 164 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." :
167 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); 165 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed.");
168 } 166 }
169 167
170 // Declare we're done by setting a cookie to either "PASS" or the errors. 168 // Declare we're done by setting a cookie to either "PASS" or the errors.
171 ReportProgress(errors_.empty() ? "PASS" : errors_); 169 ReportProgress(errors_.empty() ? "PASS" : errors_);
172 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests")); 170 SendTestCommand("DidExecuteTests");
171 // Note, DidExecuteTests unloads the plugin. We can't really do anthing after
172 // this point.
173 } 173 }
174 174
175 TestCase* TestingInstance::CaseForTestName(const std::string& name) { 175 TestCase* TestingInstance::CaseForTestName(const std::string& name) {
176 std::string case_name = name.substr(0, name.find_first_of('_')); 176 std::string case_name = name.substr(0, name.find_first_of('_'));
177 TestCaseFactory* iter = TestCaseFactory::head_; 177 TestCaseFactory* iter = TestCaseFactory::head_;
178 while (iter != NULL) { 178 while (iter != NULL) {
179 if (case_name == iter->name_) 179 if (case_name == iter->name_)
180 return iter->method_(this); 180 return iter->method_(this);
181 iter = iter->next_; 181 iter = iter->next_;
182 } 182 }
183 return NULL; 183 return NULL;
184 } 184 }
185 185
186 std::string TestingInstance::FilterForTestName(const std::string& name) { 186 std::string TestingInstance::FilterForTestName(const std::string& name) {
187 size_t delim = name.find_first_of('_'); 187 size_t delim = name.find_first_of('_');
188 if (delim != std::string::npos) 188 if (delim != std::string::npos)
189 return name.substr(delim+1); 189 return name.substr(delim+1);
190 return ""; 190 return "";
191 } 191 }
192 192
193 void TestingInstance::SendTestCommand(const std::string& command) {
194 std::string msg("TESTING_MESSAGE:");
195 msg += command;
196 PostMessage(pp::Var(msg));
197 }
198
199 void TestingInstance::SendTestCommand(const std::string& command,
200 const std::string& params) {
201 SendTestCommand(command + ":" + params);
202 }
203
204
193 void TestingInstance::LogAvailableTests() { 205 void TestingInstance::LogAvailableTests() {
194 // Print out a listing of all tests. 206 // Print out a listing of all tests.
195 std::vector<std::string> test_cases; 207 std::vector<std::string> test_cases;
196 TestCaseFactory* iter = TestCaseFactory::head_; 208 TestCaseFactory* iter = TestCaseFactory::head_;
197 while (iter != NULL) { 209 while (iter != NULL) {
198 test_cases.push_back(iter->name_); 210 test_cases.push_back(iter->name_);
199 iter = iter->next_; 211 iter = iter->next_;
200 } 212 }
201 std::sort(test_cases.begin(), test_cases.end()); 213 std::sort(test_cases.begin(), test_cases.end());
202 214
(...skipping 16 matching lines...) Expand all
219 231
220 void TestingInstance::LogError(const std::string& text) { 232 void TestingInstance::LogError(const std::string& text) {
221 std::string html; 233 std::string html;
222 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); 234 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">");
223 html.append(text); 235 html.append(text);
224 html.append("</span>"); 236 html.append("</span>");
225 LogHTML(html); 237 LogHTML(html);
226 } 238 }
227 239
228 void TestingInstance::LogHTML(const std::string& html) { 240 void TestingInstance::LogHTML(const std::string& html) {
229 std::string message("TESTING_MESSAGE:LogHTML:"); 241 SendTestCommand("LogHTML", html);
230 message.append(html);
231 PostMessage(pp::Var(message));
232 } 242 }
233 243
234 void TestingInstance::ReportProgress(const std::string& progress_value) { 244 void TestingInstance::ReportProgress(const std::string& progress_value) {
235 // Use streams since nacl doesn't compile base yet (for StringPrintf). 245 // Use streams since nacl doesn't compile base yet (for StringPrintf).
236 std::ostringstream cookie_name; 246 std::ostringstream cookie_name;
237 cookie_name << "PPAPI_PROGRESS_" << progress_cookie_number_; 247 cookie_name << "PPAPI_PROGRESS_" << progress_cookie_number_;
238 SetCookie(cookie_name.str(), progress_value); 248 SetCookie(cookie_name.str(), progress_value);
239 progress_cookie_number_++; 249 progress_cookie_number_++;
240 } 250 }
241 251
242 class Module : public pp::Module { 252 class Module : public pp::Module {
243 public: 253 public:
244 Module() : pp::Module() {} 254 Module() : pp::Module() {}
245 virtual ~Module() {} 255 virtual ~Module() {}
246 256
247 virtual pp::Instance* CreateInstance(PP_Instance instance) { 257 virtual pp::Instance* CreateInstance(PP_Instance instance) {
248 return new TestingInstance(instance); 258 return new TestingInstance(instance);
249 } 259 }
250 }; 260 };
251 261
252 namespace pp { 262 namespace pp {
253 263
254 Module* CreateModule() { 264 Module* CreateModule() {
255 return new ::Module(); 265 return new ::Module();
256 } 266 }
257 267
258 } // namespace pp 268 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/tests/testing_instance.h ('k') | webkit/plugins/ppapi/host_var_tracker.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698