OLD | NEW |
1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 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 <string.h> | 8 #include <string.h> |
9 | 9 |
10 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 LogHTML(html); | 86 LogHTML(html); |
87 } | 87 } |
88 | 88 |
89 void TestingInstance::AppendError(const std::string& message) { | 89 void TestingInstance::AppendError(const std::string& message) { |
90 if (!errors_.empty()) | 90 if (!errors_.empty()) |
91 errors_.append(", "); | 91 errors_.append(", "); |
92 errors_.append(message); | 92 errors_.append(message); |
93 } | 93 } |
94 | 94 |
95 void TestingInstance::ExecuteTests(int32_t unused) { | 95 void TestingInstance::ExecuteTests(int32_t unused) { |
| 96 SetCookie("STARTUP_COOKIE", "STARTED"); |
| 97 |
96 // Clear the console. | 98 // Clear the console. |
97 // This does: window.document.getElementById("console").innerHTML = ""; | 99 // This does: window.document.getElementById("console").innerHTML = ""; |
98 pp::Var window = GetWindowObject(); | 100 pp::Var window = GetWindowObject(); |
99 window.GetProperty("document"). | 101 window.GetProperty("document"). |
100 Call("getElementById", "console").SetProperty("innerHTML", ""); | 102 Call("getElementById", "console").SetProperty("innerHTML", ""); |
101 | 103 |
102 if (!errors_.empty()) { | 104 if (!errors_.empty()) { |
103 // Catch initialization errors and output the current error string to | 105 // Catch initialization errors and output the current error string to |
104 // the console. | 106 // the console. |
105 LogError("Plugin initialization failed: " + errors_); | 107 LogError("Plugin initialization failed: " + errors_); |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
161 | 163 |
162 void TestingInstance::LogHTML(const std::string& html) { | 164 void TestingInstance::LogHTML(const std::string& html) { |
163 // This does: window.document.getElementById("console").innerHTML += html | 165 // This does: window.document.getElementById("console").innerHTML += html |
164 pp::Var console = GetWindowObject().GetProperty("document"). | 166 pp::Var console = GetWindowObject().GetProperty("document"). |
165 Call("getElementById", "console"); | 167 Call("getElementById", "console"); |
166 pp::Var inner_html = console.GetProperty("innerHTML"); | 168 pp::Var inner_html = console.GetProperty("innerHTML"); |
167 console.SetProperty("innerHTML", inner_html.AsString() + html); | 169 console.SetProperty("innerHTML", inner_html.AsString() + html); |
168 } | 170 } |
169 | 171 |
170 void TestingInstance::SetCookie(const std::string& name, | 172 void TestingInstance::SetCookie(const std::string& name, |
171 const std::string& value) { | 173 const std::string& value) { |
172 // window.document.cookie = "<name>=<value>; path=/" | 174 // window.document.cookie = "<name>=<value>; path=/" |
173 std::string cookie_string = name + "=" + value + "; path=/"; | 175 std::string cookie_string = name + "=" + value + "; path=/"; |
174 pp::Var document = GetWindowObject().GetProperty("document"); | 176 pp::Var document = GetWindowObject().GetProperty("document"); |
175 document.SetProperty("cookie", cookie_string); | 177 document.SetProperty("cookie", cookie_string); |
176 } | 178 } |
177 | 179 |
178 class Module : public pp::Module { | 180 class Module : public pp::Module { |
179 public: | 181 public: |
180 Module() : pp::Module() {} | 182 Module() : pp::Module() {} |
181 virtual ~Module() {} | 183 virtual ~Module() {} |
182 | 184 |
183 virtual pp::Instance* CreateInstance(PP_Instance instance) { | 185 virtual pp::Instance* CreateInstance(PP_Instance instance) { |
184 return new TestingInstance(instance); | 186 return new TestingInstance(instance); |
185 } | 187 } |
186 }; | 188 }; |
187 | 189 |
188 namespace pp { | 190 namespace pp { |
189 | 191 |
190 Module* CreateModule() { | 192 Module* CreateModule() { |
191 return new ::Module(); | 193 return new ::Module(); |
192 } | 194 } |
193 | 195 |
194 } // namespace pp | 196 } // namespace pp |
OLD | NEW |