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

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

Issue 1821103002: Migrate a bunch of LayoutTests from NPAPI to PPAPI (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@fix_open-and-close-window-with-plugin
Patch Set: rebase Created 4 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
OLDNEW
1 // Copyright 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 // A simple C++ Pepper plugin for exercising deprecated PPAPI interfaces in 5 // A simple C++ Pepper plugin for exercising deprecated PPAPI interfaces in
6 // Blink layout tests. 6 // Blink layout tests.
7 // 7 //
8 // Most layout tests should prefer to use the normal Blink test plugin, with the 8 // Most layout tests should prefer to use the normal Blink test plugin, with the
9 // MIME type application/x-blink-test-plugin. For layout tests that absolutely 9 // MIME type application/x-blink-test-plugin. For layout tests that absolutely
10 // need to test deprecated synchronous scripting interfaces, this plugin can be 10 // need to test deprecated synchronous scripting interfaces, this plugin can be
11 // instantiated using the application/x-blink-deprecated-test-plugin MIME type. 11 // instantiated using the application/x-blink-deprecated-test-plugin MIME type.
12 12
13 #include <stdint.h> 13 #include <stdint.h>
14 14
15 #include <map> 15 #include <map>
16 #include <sstream> 16 #include <sstream>
17 #include <unordered_map>
17 #include <utility> 18 #include <utility>
18 19
19 #include "base/bind.h" 20 #include "base/bind.h"
20 #include "base/bind_helpers.h" 21 #include "base/bind_helpers.h"
21 #include "base/callback.h" 22 #include "base/callback.h"
22 #include "base/strings/stringprintf.h" 23 #include "base/strings/stringprintf.h"
23 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" 24 #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
25 #include "ppapi/cpp/input_event.h"
24 #include "ppapi/cpp/module.h" 26 #include "ppapi/cpp/module.h"
25 #include "ppapi/cpp/private/instance_private.h" 27 #include "ppapi/cpp/private/instance_private.h"
26 #include "ppapi/cpp/private/var_private.h" 28 #include "ppapi/cpp/private/var_private.h"
27 #include "ppapi/cpp/var.h" 29 #include "ppapi/cpp/var.h"
28 30
29 namespace { 31 namespace {
30 32
31 class ScriptableBase : public pp::deprecated::ScriptableObject { 33 class ScriptableBase : public pp::deprecated::ScriptableObject {
32 public: 34 public:
33 explicit ScriptableBase(pp::InstancePrivate* instance) 35 explicit ScriptableBase(pp::InstancePrivate* instance)
(...skipping 85 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 } 121 }
120 122
121 pp::VarPrivate test_object_; 123 pp::VarPrivate test_object_;
122 }; 124 };
123 125
124 class InstanceSO : public ScriptableBase { 126 class InstanceSO : public ScriptableBase {
125 public: 127 public:
126 explicit InstanceSO(pp::InstancePrivate* instance) 128 explicit InstanceSO(pp::InstancePrivate* instance)
127 : ScriptableBase(instance) { 129 : ScriptableBase(instance) {
128 methods_.insert(std::make_pair( 130 methods_.insert(std::make_pair(
131 "normalize",
dcheng 2016/03/22 18:03:05 Can we add add documentation about the various att
piman 2016/03/23 05:30:24 Done.
132 base::Bind(&InstanceSO::Normalize, base::Unretained(this))));
133 methods_.insert(std::make_pair(
134 "remember",
135 base::Bind(&InstanceSO::Remember, base::Unretained(this))));
136 methods_.insert(std::make_pair(
137 "testCloneObject",
138 base::Bind(&InstanceSO::TestCloneObject, base::Unretained(this))));
139 methods_.insert(std::make_pair(
129 "testExecuteScript", 140 "testExecuteScript",
130 base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this)))); 141 base::Bind(&InstanceSO::TestExecuteScript, base::Unretained(this))));
131 methods_.insert(std::make_pair( 142 methods_.insert(std::make_pair(
132 "testGetProperty", 143 "testGetProperty",
133 base::Bind(&InstanceSO::TestGetProperty, base::Unretained(this)))); 144 base::Bind(&InstanceSO::TestGetProperty, base::Unretained(this))));
134 methods_.insert(std::make_pair( 145 methods_.insert(std::make_pair(
135 "testPassTestObject", 146 "testPassTestObject",
136 base::Bind(&InstanceSO::TestPassTestObject, base::Unretained(this)))); 147 base::Bind(&InstanceSO::TestPassTestObject, base::Unretained(this))));
148 // Note: the semantics of testScriptObjectInvoke are identical to the
149 // semantics of testPassTestObject: call args[0] with args[1] as a
150 // parameter.
151 methods_.insert(
152 std::make_pair("testScriptObjectInvoke",
153 base::Bind(&InstanceSO::TestPassTestObject,
154 base::Unretained(this))));
137 properties_.insert(std::make_pair( 155 properties_.insert(std::make_pair(
138 "testObject", base::Bind(&InstanceSO::TestObjectAccessor, 156 "testObject", base::Bind(&InstanceSO::TestObjectAccessor,
139 base::Unretained(this)))); 157 base::Unretained(this))));
140 } 158 }
141 ~InstanceSO() override {} 159 ~InstanceSO() override {}
142 160
143 private: 161 private:
162 // Requires no argument.
163 pp::Var Normalize(const std::vector<pp::Var>& args, pp::Var* exception) {
164 pp::VarPrivate object = instance_->GetWindowObject();
165 return object.Call(pp::Var("pluginCallback"), exception);
166 }
167
168 // Requires 1 argument. The argument is retained into remembered_
169 pp::Var Remember(const std::vector<pp::Var>& args, pp::Var* exception) {
170 if (args.size() != 1) {
171 *exception = pp::Var("remember requires one argument");
172 return pp::Var();
173 }
174 remembered_ = args[0];
175 return pp::Var();
176 }
177
178 // Requires no argument.
179 pp::Var TestCloneObject(const std::vector<pp::Var>& args,
180 pp::Var* exception) {
181 return pp::VarPrivate(instance_, new InstanceSO(instance_));
182 }
183
144 // Requires one argument. The argument is passed through as-is to 184 // Requires one argument. The argument is passed through as-is to
145 // pp::InstancePrivate::ExecuteScript(). 185 // pp::InstancePrivate::ExecuteScript().
146 pp::Var TestExecuteScript(const std::vector<pp::Var>& args, 186 pp::Var TestExecuteScript(const std::vector<pp::Var>& args,
147 pp::Var* exception) { 187 pp::Var* exception) {
148 if (args.size() != 1) { 188 if (args.size() != 1) {
149 *exception = pp::Var("testExecuteScript requires one argument"); 189 *exception = pp::Var("testExecuteScript requires one argument");
150 return pp::Var(); 190 return pp::Var();
151 } 191 }
152 return instance_->ExecuteScript(args[0], exception); 192 return instance_->ExecuteScript(args[0], exception);
153 } 193 }
(...skipping 30 matching lines...) Expand all
184 224
185 void TestObjectAccessor(bool set, pp::Var* var) { 225 void TestObjectAccessor(bool set, pp::Var* var) {
186 if (set) 226 if (set)
187 return; 227 return;
188 if (test_object_.is_undefined()) 228 if (test_object_.is_undefined())
189 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_)); 229 test_object_ = pp::VarPrivate(instance_, new TestObjectSO(instance_));
190 *var = test_object_; 230 *var = test_object_;
191 } 231 }
192 232
193 pp::VarPrivate test_object_; 233 pp::VarPrivate test_object_;
234 pp::Var remembered_;
194 }; 235 };
195 236
196 class BlinkDeprecatedTestInstance : public pp::InstancePrivate { 237 class BlinkDeprecatedTestInstance : public pp::InstancePrivate {
197 public: 238 public:
198 explicit BlinkDeprecatedTestInstance(PP_Instance instance) 239 explicit BlinkDeprecatedTestInstance(PP_Instance instance)
199 : pp::InstancePrivate(instance) {} 240 : pp::InstancePrivate(instance) {}
200 ~BlinkDeprecatedTestInstance() override { 241 ~BlinkDeprecatedTestInstance() override {
201 LogMessage("%s", "Destroying"); 242 LogMessage("%s", "Destroying");
202 } 243 }
203 244
204 bool Init(uint32_t argc, const char* argn[], const char* argv[]) { 245 // pp::Instance overrides
246 bool Init(uint32_t argc, const char* argn[], const char* argv[]) override {
247 for (uint32_t i = 0; i < argc; ++i)
248 attributes_[argn[i]] = argv[i];
249
250 if (HasAttribute("onnew"))
251 ExecuteScript(attributes_["onnew"]);
252
253 if (HasAttribute("loginit"))
254 LogMessage("%s", "Initializing");
255
256 if (HasAttribute("testwindowopen"))
257 return TestWindowOpen();
258
259 uint32_t event_classes = 0;
260 if (HasAttribute("keydownscript"))
261 event_classes |= PP_INPUTEVENT_CLASS_KEYBOARD;
262 if (HasAttribute("mousedownscript"))
263 event_classes |= PP_INPUTEVENT_CLASS_MOUSE;
264 RequestFilteringInputEvents(event_classes);
265
205 return true; 266 return true;
206 } 267 }
207 268
269 virtual bool HandleInputEvent(const pp::InputEvent& event) override {
270 switch (event.GetType()) {
271 case PP_INPUTEVENT_TYPE_MOUSEDOWN:
272 if (HasAttribute("mousedownscript"))
273 ExecuteScript(attributes_["mousedownscript"]);
274 return true;
275 case PP_INPUTEVENT_TYPE_KEYDOWN:
276 if (HasAttribute("keydownscript"))
277 ExecuteScript(attributes_["keydownscript"]);
278 return true;
279 default:
280 return false;
281 }
282 }
283
208 // pp::InstancePrivate overrides: 284 // pp::InstancePrivate overrides:
209 pp::Var GetInstanceObject() override { 285 pp::Var GetInstanceObject() override {
210 if (instance_var_.is_undefined()) { 286 if (instance_var_.is_undefined()) {
211 instance_so_ = new InstanceSO(this); 287 instance_so_ = new InstanceSO(this);
212 instance_var_ = pp::VarPrivate(this, instance_so_); 288 instance_var_ = pp::VarPrivate(this, instance_so_);
213 } 289 }
214 return instance_var_; 290 return instance_var_;
215 } 291 }
216 292
293 void NotifyTestCompletion() {
294 ExecuteScript("window.testRunner.notifyDone()");
295 }
296
297 bool TestWindowOpen() {
298 pp::Var result = GetWindowObject().Call(
299 pp::Var("open"), pp::Var("about:blank"), pp::Var("_blank"));
300 if (result.is_object())
301 LogMessage("PLUGIN: WINDOW OPEN SUCCESS");
302 NotifyTestCompletion();
303 return true;
304 }
305
217 void LogMessage(const char* format...) { 306 void LogMessage(const char* format...) {
218 va_list args; 307 va_list args;
219 va_start(args, format); 308 va_start(args, format);
220 LogToConsoleWithSource(PP_LOGLEVEL_LOG, 309 LogToConsoleWithSource(PP_LOGLEVEL_LOG,
221 pp::Var("Blink Deprecated Test Plugin"), 310 pp::Var("Blink Deprecated Test Plugin"),
222 pp::Var(base::StringPrintV(format, args))); 311 pp::Var(base::StringPrintV(format, args)));
223 va_end(args); 312 va_end(args);
224 } 313 }
225 314
226 private: 315 private:
316 bool HasAttribute(const std::string& name) {
317 return attributes_.find(name) != attributes_.end();
318 }
dcheng 2016/03/22 18:03:05 Nit: newline.
piman 2016/03/23 05:30:24 Done.
319 std::unordered_map<std::string, std::string> attributes_;
227 pp::VarPrivate instance_var_; 320 pp::VarPrivate instance_var_;
228 // Owned by |instance_var_|. 321 // Owned by |instance_var_|.
229 InstanceSO* instance_so_; 322 InstanceSO* instance_so_;
230 }; 323 };
231 324
232 class BlinkDeprecatedTestModule : public pp::Module { 325 class BlinkDeprecatedTestModule : public pp::Module {
233 public: 326 public:
234 BlinkDeprecatedTestModule() {} 327 BlinkDeprecatedTestModule() {}
235 ~BlinkDeprecatedTestModule() override {} 328 ~BlinkDeprecatedTestModule() override {}
236 329
237 virtual pp::Instance* CreateInstance(PP_Instance instance) { 330 virtual pp::Instance* CreateInstance(PP_Instance instance) {
238 return new BlinkDeprecatedTestInstance(instance); 331 return new BlinkDeprecatedTestInstance(instance);
239 } 332 }
240 }; 333 };
241 334
242 } // namespace 335 } // namespace
243 336
244 namespace pp { 337 namespace pp {
245 338
246 Module* CreateModule() { 339 Module* CreateModule() {
247 return new BlinkDeprecatedTestModule(); 340 return new BlinkDeprecatedTestModule();
248 } 341 }
249 342
250 } // namespace pp 343 } // namespace pp
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698