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

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

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