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

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

Issue 7677031: Try to reduce the flankness of the PPAPI UI tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 4 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') | no next file » | 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 <vector> 10 #include <vector>
10 11
11 #include "ppapi/cpp/module.h" 12 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/var.h" 13 #include "ppapi/cpp/var.h"
13 #include "ppapi/tests/test_case.h" 14 #include "ppapi/tests/test_case.h"
14 15
15 TestCaseFactory* TestCaseFactory::head_ = NULL; 16 TestCaseFactory* TestCaseFactory::head_ = NULL;
16 17
18 // Cookie value we use to signal "we're still working." See the comment above
19 // the class declaration for how this works.
20 static const char kProgressSignal[] = "...";
21
17 // Returns a new heap-allocated test case for the given test, or NULL on 22 // Returns a new heap-allocated test case for the given test, or NULL on
18 // failure. 23 // failure.
19 TestingInstance::TestingInstance(PP_Instance instance) 24 TestingInstance::TestingInstance(PP_Instance instance)
20 #if (defined __native_client__) 25 #if (defined __native_client__)
21 : pp::Instance(instance), 26 : pp::Instance(instance),
22 #else 27 #else
23 : pp::InstancePrivate(instance), 28 : pp::InstancePrivate(instance),
24 #endif 29 #endif
25 current_case_(NULL), 30 current_case_(NULL),
31 progress_cookie_number_(0),
26 executed_tests_(false), 32 executed_tests_(false),
27 nacl_mode_(false) { 33 nacl_mode_(false) {
28 callback_factory_.Initialize(this); 34 callback_factory_.Initialize(this);
29 } 35 }
30 36
31 TestingInstance::~TestingInstance() { 37 TestingInstance::~TestingInstance() {
32 if (current_case_) 38 if (current_case_)
33 delete current_case_; 39 delete current_case_;
34 } 40 }
35 41
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
80 if (!executed_tests_) { 86 if (!executed_tests_) {
81 executed_tests_ = true; 87 executed_tests_ = true;
82 pp::Module::Get()->core()->CallOnMainThread( 88 pp::Module::Get()->core()->CallOnMainThread(
83 0, 89 0,
84 callback_factory_.NewCallback(&TestingInstance::ExecuteTests)); 90 callback_factory_.NewCallback(&TestingInstance::ExecuteTests));
85 } 91 }
86 } 92 }
87 93
88 void TestingInstance::LogTest(const std::string& test_name, 94 void TestingInstance::LogTest(const std::string& test_name,
89 const std::string& error_message) { 95 const std::string& error_message) {
96 // Tell the browser we're still working.
97 ReportProgress(kProgressSignal);
98
90 std::string html; 99 std::string html;
91 html.append("<div class=\"test_line\"><span class=\"test_name\">"); 100 html.append("<div class=\"test_line\"><span class=\"test_name\">");
92 html.append(test_name); 101 html.append(test_name);
93 html.append("</span> "); 102 html.append("</span> ");
94 if (error_message.empty()) { 103 if (error_message.empty()) {
95 html.append("<span class=\"pass\">PASS</span>"); 104 html.append("<span class=\"pass\">PASS</span>");
96 } else { 105 } else {
97 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); 106 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">");
98 html.append(error_message); 107 html.append(error_message);
99 html.append("</span>"); 108 html.append("</span>");
100 109
101 if (!errors_.empty()) 110 if (!errors_.empty())
102 errors_.append(", "); // Separator for different error messages. 111 errors_.append(", "); // Separator for different error messages.
103 errors_.append(test_name + " FAIL: " + error_message); 112 errors_.append(test_name + " FAIL: " + error_message);
104 } 113 }
105 html.append("</div>"); 114 html.append("</div>");
106 LogHTML(html); 115 LogHTML(html);
107 } 116 }
108 117
109 void TestingInstance::AppendError(const std::string& message) { 118 void TestingInstance::AppendError(const std::string& message) {
110 if (!errors_.empty()) 119 if (!errors_.empty())
111 errors_.append(", "); 120 errors_.append(", ");
112 errors_.append(message); 121 errors_.append(message);
113 } 122 }
114 123
115 void TestingInstance::ExecuteTests(int32_t unused) { 124 void TestingInstance::ExecuteTests(int32_t unused) {
116 SetCookie("STARTUP_COOKIE", "STARTED"); 125 ReportProgress(kProgressSignal);
117 126
118 // Clear the console. 127 // Clear the console.
119 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole")); 128 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole"));
120 129
121 if (!errors_.empty()) { 130 if (!errors_.empty()) {
122 // Catch initialization errors and output the current error string to 131 // Catch initialization errors and output the current error string to
123 // the console. 132 // the console.
124 LogError("Plugin initialization failed: " + errors_); 133 LogError("Plugin initialization failed: " + errors_);
125 } else if (!current_case_) { 134 } else if (!current_case_) {
126 LogAvailableTests(); 135 LogAvailableTests();
127 errors_.append("FAIL: Only listed tests"); 136 errors_.append("FAIL: Only listed tests");
128 } else { 137 } else {
129 current_case_->RunTest(); 138 current_case_->RunTest();
130 // Automated PyAuto tests rely on finding the exact strings below. 139 // Automated PyAuto tests rely on finding the exact strings below.
131 LogHTML(errors_.empty() ? 140 LogHTML(errors_.empty() ?
132 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : 141 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." :
133 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); 142 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed.");
134 } 143 }
135 144
136 // Declare we're done by setting a cookie to either "PASS" or the errors. 145 // Declare we're done by setting a cookie to either "PASS" or the errors.
137 SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_); 146 ReportProgress(errors_.empty() ? "PASS" : errors_);
138 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests")); 147 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests"));
139 } 148 }
140 149
141 TestCase* TestingInstance::CaseForTestName(const char* name) { 150 TestCase* TestingInstance::CaseForTestName(const char* name) {
142 TestCaseFactory* iter = TestCaseFactory::head_; 151 TestCaseFactory* iter = TestCaseFactory::head_;
143 while (iter != NULL) { 152 while (iter != NULL) {
144 if (std::strcmp(name, iter->name_) == 0) 153 if (std::strcmp(name, iter->name_) == 0)
145 return iter->method_(this); 154 return iter->method_(this);
146 iter = iter->next_; 155 iter = iter->next_;
147 } 156 }
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
182 html.append("</span>"); 191 html.append("</span>");
183 LogHTML(html); 192 LogHTML(html);
184 } 193 }
185 194
186 void TestingInstance::LogHTML(const std::string& html) { 195 void TestingInstance::LogHTML(const std::string& html) {
187 std::string message("TESTING_MESSAGE:LogHTML:"); 196 std::string message("TESTING_MESSAGE:LogHTML:");
188 message.append(html); 197 message.append(html);
189 PostMessage(pp::Var(message)); 198 PostMessage(pp::Var(message));
190 } 199 }
191 200
201 void TestingInstance::ReportProgress(const std::string& progress_value) {
202 // Use streams since nacl doesn't compile base yet (for StringPrintf).
203 std::ostringstream cookie_name;
204 cookie_name << "PPAPI_PROGRESS_" << progress_cookie_number_;
205 SetCookie(cookie_name.str(), progress_value);
206 progress_cookie_number_++;
207 }
208
192 void TestingInstance::SetCookie(const std::string& name, 209 void TestingInstance::SetCookie(const std::string& name,
193 const std::string& value) { 210 const std::string& value) {
194 std::string message("TESTING_MESSAGE:SetCookie:"); 211 std::string message("TESTING_MESSAGE:SetCookie:");
195 message.append(name); 212 message.append(name);
196 message.append("="); 213 message.append("=");
197 message.append(value); 214 message.append(value);
198 PostMessage(pp::Var(message)); 215 PostMessage(pp::Var(message));
199 } 216 }
200 217
201 class Module : public pp::Module { 218 class Module : public pp::Module {
202 public: 219 public:
203 Module() : pp::Module() {} 220 Module() : pp::Module() {}
204 virtual ~Module() {} 221 virtual ~Module() {}
205 222
206 virtual pp::Instance* CreateInstance(PP_Instance instance) { 223 virtual pp::Instance* CreateInstance(PP_Instance instance) {
207 return new TestingInstance(instance); 224 return new TestingInstance(instance);
208 } 225 }
209 }; 226 };
210 227
211 namespace pp { 228 namespace pp {
212 229
213 Module* CreateModule() { 230 Module* CreateModule() {
214 return new ::Module(); 231 return new ::Module();
215 } 232 }
216 233
217 } // namespace pp 234 } // namespace pp
OLDNEW
« no previous file with comments | « ppapi/tests/testing_instance.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698