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

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

Issue 7312008: Porting ppapi_tests framework to postMessage. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Disable Scrollbar test on Mac for now, merge Created 9 years, 5 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 <vector> 9 #include <vector>
10 10
11 #include "ppapi/cpp/module.h" 11 #include "ppapi/cpp/module.h"
12 #include "ppapi/cpp/var.h" 12 #include "ppapi/cpp/var.h"
13 #include "ppapi/tests/test_case.h" 13 #include "ppapi/tests/test_case.h"
14 14
15 TestCaseFactory* TestCaseFactory::head_ = NULL; 15 TestCaseFactory* TestCaseFactory::head_ = NULL;
16 16
17 // Returns a new heap-allocated test case for the given test, or NULL on 17 // Returns a new heap-allocated test case for the given test, or NULL on
18 // failure. 18 // failure.
19 TestingInstance::TestingInstance(PP_Instance instance) 19 TestingInstance::TestingInstance(PP_Instance instance)
20 #if (defined __native_client__)
20 : pp::Instance(instance), 21 : pp::Instance(instance),
22 #else
23 : pp::InstancePrivate(instance),
24 #endif
21 current_case_(NULL), 25 current_case_(NULL),
22 executed_tests_(false), 26 executed_tests_(false),
23 nacl_mode_(false) { 27 nacl_mode_(false) {
24 callback_factory_.Initialize(this); 28 callback_factory_.Initialize(this);
25 } 29 }
26 30
27 TestingInstance::~TestingInstance() { 31 TestingInstance::~TestingInstance() {
28 if (current_case_) 32 if (current_case_)
29 delete current_case_; 33 delete current_case_;
30 } 34 }
31 35
32 bool TestingInstance::Init(uint32_t argc, 36 bool TestingInstance::Init(uint32_t argc,
33 const char* argn[], 37 const char* argn[],
34 const char* argv[]) { 38 const char* argv[]) {
35 for (uint32_t i = 0; i < argc; i++) { 39 for (uint32_t i = 0; i < argc; i++) {
36 if (std::strcmp(argn[i], "mode") == 0) { 40 if (std::strcmp(argn[i], "mode") == 0) {
37 if (std::strcmp(argv[i], "nacl") == 0) 41 if (std::strcmp(argv[i], "nacl") == 0)
38 nacl_mode_ = true; 42 nacl_mode_ = true;
39 break;
40 } 43 }
44 else if (std::strcmp(argn[i], "protocol") == 0)
45 protocol_ = argv[i];
41 } 46 }
42 // Create the proper test case from the argument. 47 // Create the proper test case from the argument.
43 for (uint32_t i = 0; i < argc; i++) { 48 for (uint32_t i = 0; i < argc; i++) {
44 if (std::strcmp(argn[i], "testcase") == 0) { 49 if (std::strcmp(argn[i], "testcase") == 0) {
45 if (argv[i][0] == '\0') 50 if (argv[i][0] == '\0')
46 break; 51 break;
47 current_case_ = CaseForTestName(argv[i]); 52 current_case_ = CaseForTestName(argv[i]);
48 if (!current_case_) 53 if (!current_case_)
49 errors_.append(std::string("Unknown test case ") + argv[i]); 54 errors_.append(std::string("Unknown test case ") + argv[i]);
50 else if (!current_case_->Init()) 55 else if (!current_case_->Init())
51 errors_.append(" Test case could not initialize."); 56 errors_.append(" Test case could not initialize.");
52 return true; 57 return true;
53 } 58 }
54 } 59 }
55 60
56 // In DidChangeView, we'll dump out a list of all available tests. 61 // In DidChangeView, we'll dump out a list of all available tests.
57 return true; 62 return true;
58 } 63 }
59 64
65 #if !(defined __native_client__)
60 pp::Var TestingInstance::GetInstanceObject() { 66 pp::Var TestingInstance::GetInstanceObject() {
61 if (current_case_) 67 if (current_case_)
62 return current_case_->GetTestObject(); 68 return current_case_->GetTestObject();
63 69
64 return pp::Var(this, NULL); 70 return pp::VarPrivate();
65 } 71 }
72 #endif
66 73
67 void TestingInstance::HandleMessage(const pp::Var& message_data) { 74 void TestingInstance::HandleMessage(const pp::Var& message_data) {
68 current_case_->HandleMessage(message_data); 75 current_case_->HandleMessage(message_data);
69 } 76 }
70 77
71 void TestingInstance::DidChangeView(const pp::Rect& position, 78 void TestingInstance::DidChangeView(const pp::Rect& position,
72 const pp::Rect& clip) { 79 const pp::Rect& clip) {
73 if (!executed_tests_) { 80 if (!executed_tests_) {
74 executed_tests_ = true; 81 executed_tests_ = true;
75 pp::Module::Get()->core()->CallOnMainThread( 82 pp::Module::Get()->core()->CallOnMainThread(
(...skipping 26 matching lines...) Expand all
102 void TestingInstance::AppendError(const std::string& message) { 109 void TestingInstance::AppendError(const std::string& message) {
103 if (!errors_.empty()) 110 if (!errors_.empty())
104 errors_.append(", "); 111 errors_.append(", ");
105 errors_.append(message); 112 errors_.append(message);
106 } 113 }
107 114
108 void TestingInstance::ExecuteTests(int32_t unused) { 115 void TestingInstance::ExecuteTests(int32_t unused) {
109 SetCookie("STARTUP_COOKIE", "STARTED"); 116 SetCookie("STARTUP_COOKIE", "STARTED");
110 117
111 // Clear the console. 118 // Clear the console.
112 // This does: window.document.getElementById("console").innerHTML = ""; 119 PostMessage(pp::Var("TESTING_MESSAGE:ClearConsole"));
113 pp::Var window = GetWindowObject();
114 window.GetProperty("document").
115 Call("getElementById", "console").SetProperty("innerHTML", "");
116 120
117 if (!errors_.empty()) { 121 if (!errors_.empty()) {
118 // Catch initialization errors and output the current error string to 122 // Catch initialization errors and output the current error string to
119 // the console. 123 // the console.
120 LogError("Plugin initialization failed: " + errors_); 124 LogError("Plugin initialization failed: " + errors_);
121 } else if (!current_case_) { 125 } else if (!current_case_) {
122 LogAvailableTests(); 126 LogAvailableTests();
123 errors_.append("FAIL: Only listed tests"); 127 errors_.append("FAIL: Only listed tests");
124 } else { 128 } else {
125 current_case_->RunTest(); 129 current_case_->RunTest();
126 // Automated PyAuto tests rely on finding the exact strings below. 130 // Automated PyAuto tests rely on finding the exact strings below.
127 LogHTML(errors_.empty() ? 131 LogHTML(errors_.empty() ?
128 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." : 132 "<span class=\"pass\">[SHUTDOWN]</span> All tests passed." :
129 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed."); 133 "<span class=\"fail\">[SHUTDOWN]</span> Some tests failed.");
130 } 134 }
131 135
132 // Declare we're done by setting a cookie to either "PASS" or the errors. 136 // Declare we're done by setting a cookie to either "PASS" or the errors.
133 SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_); 137 SetCookie("COMPLETION_COOKIE", errors_.empty() ? "PASS" : errors_);
134 138 PostMessage(pp::Var("TESTING_MESSAGE:DidExecuteTests"));
135 window.Call("DidExecuteTests");
136 } 139 }
137 140
138 TestCase* TestingInstance::CaseForTestName(const char* name) { 141 TestCase* TestingInstance::CaseForTestName(const char* name) {
139 TestCaseFactory* iter = TestCaseFactory::head_; 142 TestCaseFactory* iter = TestCaseFactory::head_;
140 while (iter != NULL) { 143 while (iter != NULL) {
141 if (std::strcmp(name, iter->name_) == 0) 144 if (std::strcmp(name, iter->name_) == 0)
142 return iter->method_(this); 145 return iter->method_(this);
143 iter = iter->next_; 146 iter = iter->next_;
144 } 147 }
145 return NULL; 148 return NULL;
(...skipping 15 matching lines...) Expand all
161 html.append("<dd><a href='?testcase="); 164 html.append("<dd><a href='?testcase=");
162 html.append(test_cases[i]); 165 html.append(test_cases[i]);
163 if (nacl_mode_) 166 if (nacl_mode_)
164 html.append("&mode=nacl"); 167 html.append("&mode=nacl");
165 html.append("'>"); 168 html.append("'>");
166 html.append(test_cases[i]); 169 html.append(test_cases[i]);
167 html.append("</a></dd>"); 170 html.append("</a></dd>");
168 } 171 }
169 html.append("</dl>"); 172 html.append("</dl>");
170 html.append("<button onclick='RunAll()'>Run All Tests</button>"); 173 html.append("<button onclick='RunAll()'>Run All Tests</button>");
174
171 LogHTML(html); 175 LogHTML(html);
172 } 176 }
173 177
174 void TestingInstance::LogError(const std::string& text) { 178 void TestingInstance::LogError(const std::string& text) {
175 std::string html; 179 std::string html;
176 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">"); 180 html.append("<span class=\"fail\">FAIL</span>: <span class=\"err_msg\">");
177 html.append(text); 181 html.append(text);
178 html.append("</span>"); 182 html.append("</span>");
179 LogHTML(html); 183 LogHTML(html);
180 } 184 }
181 185
182 void TestingInstance::LogHTML(const std::string& html) { 186 void TestingInstance::LogHTML(const std::string& html) {
183 // This does: window.document.getElementById("console").innerHTML += html 187 std::string message("TESTING_MESSAGE:LogHTML:");
184 pp::Var console = GetWindowObject().GetProperty("document"). 188 message.append(html);
185 Call("getElementById", "console"); 189 PostMessage(pp::Var(message));
186 pp::Var inner_html = console.GetProperty("innerHTML");
187 console.SetProperty("innerHTML", inner_html.AsString() + html);
188 } 190 }
189 191
190 void TestingInstance::SetCookie(const std::string& name, 192 void TestingInstance::SetCookie(const std::string& name,
191 const std::string& value) { 193 const std::string& value) {
192 // window.document.cookie = "<name>=<value>; path=/" 194 std::string message("TESTING_MESSAGE:SetCookie:");
193 std::string cookie_string = name + "=" + value + "; path=/"; 195 message.append(name);
194 pp::Var document = GetWindowObject().GetProperty("document"); 196 message.append("=");
195 document.SetProperty("cookie", cookie_string); 197 message.append(value);
198 PostMessage(pp::Var(message));
196 } 199 }
197 200
198 class Module : public pp::Module { 201 class Module : public pp::Module {
199 public: 202 public:
200 Module() : pp::Module() {} 203 Module() : pp::Module() {}
201 virtual ~Module() {} 204 virtual ~Module() {}
202 205
203 virtual pp::Instance* CreateInstance(PP_Instance instance) { 206 virtual pp::Instance* CreateInstance(PP_Instance instance) {
204 return new TestingInstance(instance); 207 return new TestingInstance(instance);
205 } 208 }
206 }; 209 };
207 210
208 namespace pp { 211 namespace pp {
209 212
210 Module* CreateModule() { 213 Module* CreateModule() {
211 return new ::Module(); 214 return new ::Module();
212 } 215 }
213 216
214 } // namespace pp 217 } // 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