OLD | NEW |
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/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 <iomanip> |
9 #include <sstream> | 10 #include <sstream> |
10 #include <vector> | 11 #include <vector> |
11 | 12 |
| 13 #include "ppapi/cpp/core.h" |
12 #include "ppapi/cpp/module.h" | 14 #include "ppapi/cpp/module.h" |
13 #include "ppapi/cpp/var.h" | 15 #include "ppapi/cpp/var.h" |
14 #include "ppapi/cpp/view.h" | 16 #include "ppapi/cpp/view.h" |
15 #include "ppapi/tests/test_case.h" | 17 #include "ppapi/tests/test_case.h" |
16 | 18 |
17 TestCaseFactory* TestCaseFactory::head_ = NULL; | 19 TestCaseFactory* TestCaseFactory::head_ = NULL; |
18 | 20 |
19 // Cookie value we use to signal "we're still working." See the comment above | 21 // Cookie value we use to signal "we're still working." See the comment above |
20 // the class declaration for how this works. | 22 // the class declaration for how this works. |
21 static const char kProgressSignal[] = "..."; | 23 static const char kProgressSignal[] = "..."; |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
59 } else if (std::strcmp(argn[i], "ssl_server_port") == 0) { | 61 } else if (std::strcmp(argn[i], "ssl_server_port") == 0) { |
60 ssl_server_port_ = atoi(argv[i]); | 62 ssl_server_port_ = atoi(argv[i]); |
61 } | 63 } |
62 } | 64 } |
63 // Create the proper test case from the argument. | 65 // Create the proper test case from the argument. |
64 for (uint32_t i = 0; i < argc; i++) { | 66 for (uint32_t i = 0; i < argc; i++) { |
65 if (std::strcmp(argn[i], "testcase") == 0) { | 67 if (std::strcmp(argn[i], "testcase") == 0) { |
66 if (argv[i][0] == '\0') | 68 if (argv[i][0] == '\0') |
67 break; | 69 break; |
68 current_case_ = CaseForTestName(argv[i]); | 70 current_case_ = CaseForTestName(argv[i]); |
69 test_filter_ = FilterForTestName(argv[i]); | 71 test_filter_ = argv[i]; |
70 if (!current_case_) | 72 if (!current_case_) |
71 errors_.append(std::string("Unknown test case ") + argv[i]); | 73 errors_.append(std::string("Unknown test case ") + argv[i]); |
72 else if (!current_case_->Init()) | 74 else if (!current_case_->Init()) |
73 errors_.append(" Test case could not initialize."); | 75 errors_.append(" Test case could not initialize."); |
74 return true; | 76 return true; |
75 } | 77 } |
76 } | 78 } |
77 | 79 |
78 // In DidChangeView, we'll dump out a list of all available tests. | 80 // In DidChangeView, we'll dump out a list of all available tests. |
79 return true; | 81 return true; |
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
113 void TestingInstance::EvalScript(const std::string& script) { | 115 void TestingInstance::EvalScript(const std::string& script) { |
114 SendTestCommand("EvalScript", script); | 116 SendTestCommand("EvalScript", script); |
115 } | 117 } |
116 | 118 |
117 void TestingInstance::SetCookie(const std::string& name, | 119 void TestingInstance::SetCookie(const std::string& name, |
118 const std::string& value) { | 120 const std::string& value) { |
119 SendTestCommand("SetCookie", name + "=" + value); | 121 SendTestCommand("SetCookie", name + "=" + value); |
120 } | 122 } |
121 | 123 |
122 void TestingInstance::LogTest(const std::string& test_name, | 124 void TestingInstance::LogTest(const std::string& test_name, |
123 const std::string& error_message) { | 125 const std::string& error_message, |
| 126 PP_TimeTicks start_time) { |
| 127 // Compute the time to run the test and save it in a string for logging: |
| 128 PP_TimeTicks end_time(pp::Module::Get()->core()->GetTimeTicks()); |
| 129 std::ostringstream number_stream; |
| 130 PP_TimeTicks elapsed_time(end_time - start_time); |
| 131 number_stream << std::fixed << std::setprecision(3) << elapsed_time; |
| 132 std::string time_string(number_stream.str()); |
| 133 |
124 // Tell the browser we're still working. | 134 // Tell the browser we're still working. |
125 ReportProgress(kProgressSignal); | 135 ReportProgress(kProgressSignal); |
126 | 136 |
127 number_tests_executed_++; | 137 number_tests_executed_++; |
128 | 138 |
129 std::string html; | 139 std::string html; |
130 html.append("<div class=\"test_line\"><span class=\"test_name\">"); | 140 html.append("<div class=\"test_line\"><span class=\"test_name\">"); |
131 html.append(test_name); | 141 html.append(test_name); |
132 html.append("</span> "); | 142 html.append("</span> "); |
133 if (error_message.empty()) { | 143 if (error_message.empty()) { |
134 html.append("<span class=\"pass\">PASS</span>"); | 144 html.append("<span class=\"pass\">PASS</span>"); |
135 } else { | 145 } else { |
136 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); | 146 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); |
137 html.append(error_message); | 147 html.append(error_message); |
138 html.append("</span>"); | 148 html.append("</span>"); |
139 | 149 |
140 if (!errors_.empty()) | 150 if (!errors_.empty()) |
141 errors_.append(", "); // Separator for different error messages. | 151 errors_.append(", "); // Separator for different error messages. |
142 errors_.append(test_name + " FAIL: " + error_message); | 152 errors_.append(test_name + " FAIL: " + error_message); |
143 } | 153 } |
| 154 html.append(" <span class=\"time\">("); |
| 155 html.append(time_string); |
| 156 html.append("s)</span>"); |
| 157 |
144 html.append("</div>"); | 158 html.append("</div>"); |
145 LogHTML(html); | 159 LogHTML(html); |
146 } | 160 } |
147 | 161 |
148 void TestingInstance::AppendError(const std::string& message) { | 162 void TestingInstance::AppendError(const std::string& message) { |
149 if (!errors_.empty()) | 163 if (!errors_.empty()) |
150 errors_.append(", "); | 164 errors_.append(", "); |
151 errors_.append(message); | 165 errors_.append(message); |
152 } | 166 } |
153 | 167 |
(...skipping 11 matching lines...) Expand all Loading... |
165 LogAvailableTests(); | 179 LogAvailableTests(); |
166 errors_.append("FAIL: Only listed tests"); | 180 errors_.append("FAIL: Only listed tests"); |
167 } else { | 181 } else { |
168 current_case_->RunTests(test_filter_); | 182 current_case_->RunTests(test_filter_); |
169 | 183 |
170 if (number_tests_executed_ == 0) { | 184 if (number_tests_executed_ == 0) { |
171 errors_.append("No tests executed. The test filter might be too " | 185 errors_.append("No tests executed. The test filter might be too " |
172 "restrictive: '" + test_filter_ + "'."); | 186 "restrictive: '" + test_filter_ + "'."); |
173 LogError(errors_); | 187 LogError(errors_); |
174 } | 188 } |
175 else { | 189 if (current_case_->skipped_tests().size()) { |
176 // Automated PyAuto tests rely on finding the exact strings below. | 190 // TODO(dmichael): Convert all TestCases to run all tests in one fixture, |
177 LogHTML(errors_.empty() ? | 191 // and enable this check. Currently, a lot of our tests |
178 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : | 192 // run 1 test per fixture, which is slow. |
179 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); | 193 /* |
| 194 errors_.append("Some tests were not listed and thus were not run. Make " |
| 195 "sure all tests are passed in the test_case URL (even if " |
| 196 "they are marked DISABLED_). Forgotten tests: "); |
| 197 std::set<std::string>::const_iterator iter = |
| 198 current_case_->skipped_tests().begin(); |
| 199 for (; iter != current_case_->skipped_tests().end(); ++iter) { |
| 200 errors_.append(*iter); |
| 201 errors_.append(" "); |
| 202 } |
| 203 LogError(errors_); |
| 204 */ |
| 205 } |
| 206 if (current_case_->remaining_tests().size()) { |
| 207 errors_.append("Some listed tests were not found in the TestCase. Check " |
| 208 "the test names that were passed to make sure they match " |
| 209 "tests in the TestCase. Unknown tests: "); |
| 210 std::map<std::string, bool>::const_iterator iter = |
| 211 current_case_->remaining_tests().begin(); |
| 212 for (; iter != current_case_->remaining_tests().end(); ++iter) { |
| 213 errors_.append(iter->first); |
| 214 errors_.append(" "); |
| 215 } |
| 216 LogError(errors_); |
180 } | 217 } |
181 } | 218 } |
182 | 219 |
183 // Declare we're done by setting a cookie to either "PASS" or the errors. | 220 // Declare we're done by setting a cookie to either "PASS" or the errors. |
184 ReportProgress(errors_.empty() ? "PASS" : errors_); | 221 ReportProgress(errors_.empty() ? "PASS" : errors_); |
185 if (remove_plugin_) | 222 if (remove_plugin_) |
186 SendTestCommand("DidExecuteTests"); | 223 SendTestCommand("DidExecuteTests"); |
187 // Note, DidExecuteTests unloads the plugin. We can't really do anthing after | 224 // Note, DidExecuteTests unloads the plugin. We can't really do anthing after |
188 // this point. | 225 // this point. |
189 } | 226 } |
190 | 227 |
191 TestCase* TestingInstance::CaseForTestName(const std::string& name) { | 228 TestCase* TestingInstance::CaseForTestName(const std::string& name) { |
192 std::string case_name = name.substr(0, name.find_first_of('_')); | 229 std::string case_name = name.substr(0, name.find_first_of('_')); |
193 TestCaseFactory* iter = TestCaseFactory::head_; | 230 TestCaseFactory* iter = TestCaseFactory::head_; |
194 while (iter != NULL) { | 231 while (iter != NULL) { |
195 if (case_name == iter->name_) | 232 if (case_name == iter->name_) |
196 return iter->method_(this); | 233 return iter->method_(this); |
197 iter = iter->next_; | 234 iter = iter->next_; |
198 } | 235 } |
199 return NULL; | 236 return NULL; |
200 } | 237 } |
201 | 238 |
202 std::string TestingInstance::FilterForTestName(const std::string& name) { | |
203 size_t delim = name.find_first_of('_'); | |
204 if (delim != std::string::npos) | |
205 return name.substr(delim+1); | |
206 return ""; | |
207 } | |
208 | |
209 void TestingInstance::SendTestCommand(const std::string& command) { | 239 void TestingInstance::SendTestCommand(const std::string& command) { |
210 std::string msg("TESTING_MESSAGE:"); | 240 std::string msg("TESTING_MESSAGE:"); |
211 msg += command; | 241 msg += command; |
212 PostMessage(pp::Var(msg)); | 242 PostMessage(pp::Var(msg)); |
213 } | 243 } |
214 | 244 |
215 void TestingInstance::SendTestCommand(const std::string& command, | 245 void TestingInstance::SendTestCommand(const std::string& command, |
216 const std::string& params) { | 246 const std::string& params) { |
217 SendTestCommand(command + ":" + params); | 247 SendTestCommand(command + ":" + params); |
218 } | 248 } |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
279 } | 309 } |
280 }; | 310 }; |
281 | 311 |
282 namespace pp { | 312 namespace pp { |
283 | 313 |
284 Module* CreateModule() { | 314 Module* CreateModule() { |
285 return new ::Module(); | 315 return new ::Module(); |
286 } | 316 } |
287 | 317 |
288 } // namespace pp | 318 } // namespace pp |
OLD | NEW |