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

Side by Side Diff: content/shell/renderer/test_runner/test_plugin.cc

Issue 469943003: TestPlugin to chromium c++ style. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: rebase Created 6 years, 3 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
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/test_plugin.h"
6
7 #include "base/basictypes.h"
8 #include "base/bind.h"
9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/strings/stringprintf.h"
12 #include "content/public/renderer/render_thread.h"
13 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
14 #include "third_party/skia/include/core/SkBitmap.h"
15 #include "third_party/skia/include/core/SkCanvas.h"
16 #include "third_party/skia/include/core/SkColor.h"
17 #include "third_party/WebKit/public/platform/Platform.h"
18 #include "third_party/WebKit/public/platform/WebCompositorSupport.h"
19 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
20 #include "third_party/WebKit/public/web/WebFrame.h"
21 #include "third_party/WebKit/public/web/WebInputEvent.h"
22 #include "third_party/WebKit/public/web/WebKit.h"
23 #include "third_party/WebKit/public/web/WebPluginParams.h"
24 #include "third_party/WebKit/public/web/WebTouchPoint.h"
25 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
26
27 namespace content {
28
29 namespace {
30
31 // GLenum values copied from gl2.h.
32 #define GL_FALSE 0
33 #define GL_TRUE 1
34 #define GL_ONE 1
35 #define GL_TRIANGLES 0x0004
36 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
37 #define GL_DEPTH_TEST 0x0B71
38 #define GL_BLEND 0x0BE2
39 #define GL_SCISSOR_TEST 0x0B90
40 #define GL_TEXTURE_2D 0x0DE1
41 #define GL_FLOAT 0x1406
42 #define GL_RGBA 0x1908
43 #define GL_UNSIGNED_BYTE 0x1401
44 #define GL_TEXTURE_MAG_FILTER 0x2800
45 #define GL_TEXTURE_MIN_FILTER 0x2801
46 #define GL_TEXTURE_WRAP_S 0x2802
47 #define GL_TEXTURE_WRAP_T 0x2803
48 #define GL_NEAREST 0x2600
49 #define GL_COLOR_BUFFER_BIT 0x4000
50 #define GL_CLAMP_TO_EDGE 0x812F
51 #define GL_ARRAY_BUFFER 0x8892
52 #define GL_STATIC_DRAW 0x88E4
53 #define GL_FRAGMENT_SHADER 0x8B30
54 #define GL_VERTEX_SHADER 0x8B31
55 #define GL_COMPILE_STATUS 0x8B81
56 #define GL_LINK_STATUS 0x8B82
57 #define GL_COLOR_ATTACHMENT0 0x8CE0
58 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5
59 #define GL_FRAMEBUFFER 0x8D40
60
61 void PremultiplyAlpha(const unsigned color_in[3],
62 float alpha,
63 float color_out[4]) {
64 for (int i = 0; i < 3; ++i)
65 color_out[i] = (color_in[i] / 255.0f) * alpha;
66
67 color_out[3] = alpha;
68 }
69
70 const char* PointState(blink::WebTouchPoint::State state) {
71 switch (state) {
72 case blink::WebTouchPoint::StateReleased:
73 return "Released";
74 case blink::WebTouchPoint::StatePressed:
75 return "Pressed";
76 case blink::WebTouchPoint::StateMoved:
77 return "Moved";
78 case blink::WebTouchPoint::StateCancelled:
79 return "Cancelled";
80 default:
81 return "Unknown";
82 }
83 }
84
85 void PrintTouchList(WebTestDelegate* delegate,
86 const blink::WebTouchPoint* points,
87 int length) {
88 for (int i = 0; i < length; ++i) {
89 delegate->printMessage(base::StringPrintf("* %.2f, %.2f: %s\n",
90 points[i].position.x,
91 points[i].position.y,
92 PointState(points[i].state)));
93 }
94 }
95
96 void PrintEventDetails(WebTestDelegate* delegate,
97 const blink::WebInputEvent& event) {
98 if (blink::WebInputEvent::isTouchEventType(event.type)) {
99 const blink::WebTouchEvent& touch =
100 static_cast<const blink::WebTouchEvent&>(event);
101 PrintTouchList(delegate, touch.touches, touch.touchesLength);
102 PrintTouchList(delegate, touch.changedTouches, touch.changedTouchesLength);
103 PrintTouchList(delegate, touch.targetTouches, touch.targetTouchesLength);
104 } else if (blink::WebInputEvent::isMouseEventType(event.type) ||
105 event.type == blink::WebInputEvent::MouseWheel) {
106 const blink::WebMouseEvent& mouse =
107 static_cast<const blink::WebMouseEvent&>(event);
108 delegate->printMessage(base::StringPrintf("* %d, %d\n", mouse.x, mouse.y));
109 } else if (blink::WebInputEvent::isGestureEventType(event.type)) {
110 const blink::WebGestureEvent& gesture =
111 static_cast<const blink::WebGestureEvent&>(event);
112 delegate->printMessage(
113 base::StringPrintf("* %d, %d\n", gesture.x, gesture.y));
114 }
115 }
116
117 blink::WebPluginContainer::TouchEventRequestType ParseTouchEventRequestType(
118 const blink::WebString& string) {
119 if (string == blink::WebString::fromUTF8("raw"))
120 return blink::WebPluginContainer::TouchEventRequestTypeRaw;
121 if (string == blink::WebString::fromUTF8("synthetic"))
122 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse;
123 return blink::WebPluginContainer::TouchEventRequestTypeNone;
124 }
125
126 void DeferredDelete(void* context) {
127 TestPlugin* plugin = static_cast<TestPlugin*>(context);
128 delete plugin;
129 }
130
131 } // namespace
132
133 TestPlugin::TestPlugin(blink::WebFrame* frame,
134 const blink::WebPluginParams& params,
135 WebTestDelegate* delegate)
136 : frame_(frame),
137 delegate_(delegate),
138 container_(0),
139 context_(0),
140 color_texture_(0),
141 mailbox_changed_(false),
142 framebuffer_(0),
143 touch_event_request_(
144 blink::WebPluginContainer::TouchEventRequestTypeNone),
145 re_request_touch_events_(false),
146 print_event_details_(false),
147 print_user_gesture_status_(false),
148 can_process_drag_(false),
149 is_persistent_(params.mimeType == PluginPersistsMimeType()),
150 can_create_without_renderer_(params.mimeType ==
151 CanCreateWithoutRendererMimeType()) {
152 const CR_DEFINE_STATIC_LOCAL(
153 blink::WebString, kAttributePrimitive, ("primitive"));
154 const CR_DEFINE_STATIC_LOCAL(
155 blink::WebString, kAttributeBackgroundColor, ("background-color"));
156 const CR_DEFINE_STATIC_LOCAL(
157 blink::WebString, kAttributePrimitiveColor, ("primitive-color"));
158 const CR_DEFINE_STATIC_LOCAL(
159 blink::WebString, kAttributeOpacity, ("opacity"));
160 const CR_DEFINE_STATIC_LOCAL(
161 blink::WebString, kAttributeAcceptsTouch, ("accepts-touch"));
162 const CR_DEFINE_STATIC_LOCAL(
163 blink::WebString, kAttributeReRequestTouchEvents, ("re-request-touch"));
164 const CR_DEFINE_STATIC_LOCAL(
165 blink::WebString, kAttributePrintEventDetails, ("print-event-details"));
166 const CR_DEFINE_STATIC_LOCAL(
167 blink::WebString, kAttributeCanProcessDrag, ("can-process-drag"));
168 const CR_DEFINE_STATIC_LOCAL(blink::WebString,
169 kAttributePrintUserGestureStatus,
170 ("print-user-gesture-status"));
171
172 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
173 size_t size = params.attributeNames.size();
174 for (size_t i = 0; i < size; ++i) {
175 const blink::WebString& attribute_name = params.attributeNames[i];
176 const blink::WebString& attribute_value = params.attributeValues[i];
177
178 if (attribute_name == kAttributePrimitive)
179 scene_.primitive = ParsePrimitive(attribute_value);
180 else if (attribute_name == kAttributeBackgroundColor)
181 ParseColor(attribute_value, scene_.background_color);
182 else if (attribute_name == kAttributePrimitiveColor)
183 ParseColor(attribute_value, scene_.primitive_color);
184 else if (attribute_name == kAttributeOpacity)
185 scene_.opacity = ParseOpacity(attribute_value);
186 else if (attribute_name == kAttributeAcceptsTouch)
187 touch_event_request_ = ParseTouchEventRequestType(attribute_value);
188 else if (attribute_name == kAttributeReRequestTouchEvents)
189 re_request_touch_events_ = ParseBoolean(attribute_value);
190 else if (attribute_name == kAttributePrintEventDetails)
191 print_event_details_ = ParseBoolean(attribute_value);
192 else if (attribute_name == kAttributeCanProcessDrag)
193 can_process_drag_ = ParseBoolean(attribute_value);
194 else if (attribute_name == kAttributePrintUserGestureStatus)
195 print_user_gesture_status_ = ParseBoolean(attribute_value);
196 }
197 if (can_create_without_renderer_)
198 delegate_->printMessage(
199 std::string("TestPlugin: canCreateWithoutRenderer\n"));
200 }
201
202 TestPlugin::~TestPlugin() {
203 }
204
205 bool TestPlugin::initialize(blink::WebPluginContainer* container) {
206 blink::WebGraphicsContext3D::Attributes attrs;
207 context_ =
208 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs);
209
210 if (!InitScene())
211 return false;
212
213 layer_ = cc::TextureLayer::CreateForMailbox(this);
214 web_layer_ = make_scoped_ptr(InstantiateWebLayer(layer_));
215 container_ = container;
216 container_->setWebLayer(web_layer_.get());
217 if (re_request_touch_events_) {
218 container_->requestTouchEventType(
219 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse);
220 container_->requestTouchEventType(
221 blink::WebPluginContainer::TouchEventRequestTypeRaw);
222 }
223 container_->requestTouchEventType(touch_event_request_);
224 container_->setWantsWheelEvents(true);
225 return true;
226 }
227
228 void TestPlugin::destroy() {
229 if (layer_.get())
230 layer_->ClearTexture();
231 if (container_)
232 container_->setWebLayer(0);
233 web_layer_.reset();
234 layer_ = NULL;
235 DestroyScene();
236
237 delete context_;
238 context_ = 0;
239
240 container_ = 0;
241 frame_ = 0;
242
243 blink::Platform::current()->callOnMainThread(DeferredDelete, this);
244 }
245
246 NPObject* TestPlugin::scriptableObject() {
247 return 0;
248 }
249
250 bool TestPlugin::canProcessDrag() const {
251 return can_process_drag_;
252 }
253
254 void TestPlugin::updateGeometry(
255 const blink::WebRect& frame_rect,
256 const blink::WebRect& clip_rect,
257 const blink::WebVector<blink::WebRect>& cut_outs_rects,
258 bool is_visible) {
259 if (clip_rect == rect_)
260 return;
261 rect_ = clip_rect;
262
263 if (rect_.isEmpty()) {
264 texture_mailbox_ = cc::TextureMailbox();
265 } else if (context_) {
266 context_->viewport(0, 0, rect_.width, rect_.height);
267
268 context_->bindTexture(GL_TEXTURE_2D, color_texture_);
269 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
270 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
271 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
272 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
273 context_->texImage2D(GL_TEXTURE_2D,
274 0,
275 GL_RGBA,
276 rect_.width,
277 rect_.height,
278 0,
279 GL_RGBA,
280 GL_UNSIGNED_BYTE,
281 0);
282 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
283 context_->framebufferTexture2D(
284 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture_, 0);
285
286 DrawSceneGL();
287
288 gpu::Mailbox mailbox;
289 context_->genMailboxCHROMIUM(mailbox.name);
290 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
291 context_->flush();
292 uint32 sync_point = context_->insertSyncPoint();
293 texture_mailbox_ = cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point);
294 } else {
295 size_t bytes = 4 * rect_.width * rect_.height;
296 scoped_ptr<base::SharedMemory> bitmap =
297 RenderThread::Get()->HostAllocateSharedMemoryBuffer(bytes);
298 if (!bitmap->Map(bytes)) {
299 texture_mailbox_ = cc::TextureMailbox();
300 } else {
301 DrawSceneSoftware(bitmap->memory(), bytes);
302 texture_mailbox_ = cc::TextureMailbox(
303 bitmap.get(), gfx::Size(rect_.width, rect_.height));
304 shared_bitmap_ = bitmap.Pass();
305 }
306 }
307
308 mailbox_changed_ = true;
309 layer_->SetNeedsDisplay();
310 }
311
312 bool TestPlugin::acceptsInputEvents() {
313 return true;
314 }
315
316 bool TestPlugin::isPlaceholder() {
317 return false;
318 }
319
320 static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {
321 }
322
323 static void ReleaseSharedMemory(scoped_ptr<base::SharedMemory> bitmap,
324 uint32 sync_point,
325 bool lost) {
326 }
327
328 bool TestPlugin::PrepareTextureMailbox(
329 cc::TextureMailbox* mailbox,
330 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
331 bool use_shared_memory) {
332 if (!mailbox_changed_)
333 return false;
334 *mailbox = texture_mailbox_;
335 if (texture_mailbox_.IsTexture()) {
336 *release_callback =
337 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback));
338 } else {
339 *release_callback = cc::SingleReleaseCallback::Create(
340 base::Bind(&ReleaseSharedMemory, base::Passed(&shared_bitmap_)));
341 }
342 mailbox_changed_ = false;
343 return true;
344 }
345
346 TestPlugin::Primitive TestPlugin::ParsePrimitive(
347 const blink::WebString& string) {
348 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveNone, ("none"));
349 const CR_DEFINE_STATIC_LOCAL(
350 blink::WebString, kPrimitiveTriangle, ("triangle"));
351
352 Primitive primitive = PrimitiveNone;
353 if (string == kPrimitiveNone)
354 primitive = PrimitiveNone;
355 else if (string == kPrimitiveTriangle)
356 primitive = PrimitiveTriangle;
357 else
358 NOTREACHED();
359 return primitive;
360 }
361
362 // FIXME: This method should already exist. Use it.
363 // For now just parse primary colors.
364 void TestPlugin::ParseColor(const blink::WebString& string, unsigned color[3]) {
365 color[0] = color[1] = color[2] = 0;
366 if (string == "black")
367 return;
368
369 if (string == "red")
370 color[0] = 255;
371 else if (string == "green")
372 color[1] = 255;
373 else if (string == "blue")
374 color[2] = 255;
375 else
376 NOTREACHED();
377 }
378
379 float TestPlugin::ParseOpacity(const blink::WebString& string) {
380 return static_cast<float>(atof(string.utf8().data()));
381 }
382
383 bool TestPlugin::ParseBoolean(const blink::WebString& string) {
384 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveTrue, ("true"));
385 return string == kPrimitiveTrue;
386 }
387
388 bool TestPlugin::InitScene() {
389 if (!context_)
390 return true;
391
392 float color[4];
393 PremultiplyAlpha(scene_.background_color, scene_.opacity, color);
394
395 color_texture_ = context_->createTexture();
396 framebuffer_ = context_->createFramebuffer();
397
398 context_->viewport(0, 0, rect_.width, rect_.height);
399 context_->disable(GL_DEPTH_TEST);
400 context_->disable(GL_SCISSOR_TEST);
401
402 context_->clearColor(color[0], color[1], color[2], color[3]);
403
404 context_->enable(GL_BLEND);
405 context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
406
407 return scene_.primitive != PrimitiveNone ? InitProgram() && InitPrimitive()
408 : true;
409 }
410
411 void TestPlugin::DrawSceneGL() {
412 context_->viewport(0, 0, rect_.width, rect_.height);
413 context_->clear(GL_COLOR_BUFFER_BIT);
414
415 if (scene_.primitive != PrimitiveNone)
416 DrawPrimitive();
417 }
418
419 void TestPlugin::DrawSceneSoftware(void* memory, size_t bytes) {
420 DCHECK_EQ(bytes, rect_.width * rect_.height * 4u);
421
422 SkColor background_color =
423 SkColorSetARGB(static_cast<uint8>(scene_.opacity * 255),
424 scene_.background_color[0],
425 scene_.background_color[1],
426 scene_.background_color[2]);
427
428 const SkImageInfo info =
429 SkImageInfo::MakeN32Premul(rect_.width, rect_.height);
430 SkBitmap bitmap;
431 bitmap.installPixels(info, memory, info.minRowBytes());
432 SkCanvas canvas(bitmap);
433 canvas.clear(background_color);
434
435 if (scene_.primitive != PrimitiveNone) {
436 DCHECK_EQ(PrimitiveTriangle, scene_.primitive);
437 SkColor foreground_color =
438 SkColorSetARGB(static_cast<uint8>(scene_.opacity * 255),
439 scene_.primitive_color[0],
440 scene_.primitive_color[1],
441 scene_.primitive_color[2]);
442 SkPath triangle_path;
443 triangle_path.moveTo(0.5f * rect_.width, 0.9f * rect_.height);
444 triangle_path.lineTo(0.1f * rect_.width, 0.1f * rect_.height);
445 triangle_path.lineTo(0.9f * rect_.width, 0.1f * rect_.height);
446 SkPaint paint;
447 paint.setColor(foreground_color);
448 paint.setStyle(SkPaint::kFill_Style);
449 canvas.drawPath(triangle_path, paint);
450 }
451 }
452
453 void TestPlugin::DestroyScene() {
454 if (scene_.program) {
455 context_->deleteProgram(scene_.program);
456 scene_.program = 0;
457 }
458 if (scene_.vbo) {
459 context_->deleteBuffer(scene_.vbo);
460 scene_.vbo = 0;
461 }
462
463 if (framebuffer_) {
464 context_->deleteFramebuffer(framebuffer_);
465 framebuffer_ = 0;
466 }
467
468 if (color_texture_) {
469 context_->deleteTexture(color_texture_);
470 color_texture_ = 0;
471 }
472 }
473
474 bool TestPlugin::InitProgram() {
475 const std::string vertex_source(
476 "attribute vec4 position; \n"
477 "void main() { \n"
478 " gl_Position = position; \n"
479 "} \n");
480
481 const std::string fragment_source(
482 "precision mediump float; \n"
483 "uniform vec4 color; \n"
484 "void main() { \n"
485 " gl_FragColor = color; \n"
486 "} \n");
487
488 scene_.program = LoadProgram(vertex_source, fragment_source);
489 if (!scene_.program)
490 return false;
491
492 scene_.color_location = context_->getUniformLocation(scene_.program, "color");
493 scene_.position_location =
494 context_->getAttribLocation(scene_.program, "position");
495 return true;
496 }
497
498 bool TestPlugin::InitPrimitive() {
499 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
500
501 scene_.vbo = context_->createBuffer();
502 if (!scene_.vbo)
503 return false;
504
505 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f,
506 0.0f, 0.8f, -0.8f, 0.0f};
507 context_->bindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
508 context_->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW);
509 context_->bufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
510 return true;
511 }
512
513 void TestPlugin::DrawPrimitive() {
514 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
515 DCHECK(scene_.vbo);
516 DCHECK(scene_.program);
517
518 context_->useProgram(scene_.program);
519
520 // Bind primitive color.
521 float color[4];
522 PremultiplyAlpha(scene_.primitive_color, scene_.opacity, color);
523 context_->uniform4f(
524 scene_.color_location, color[0], color[1], color[2], color[3]);
525
526 // Bind primitive vertices.
527 context_->bindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
528 context_->enableVertexAttribArray(scene_.position_location);
529 context_->vertexAttribPointer(
530 scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
531 context_->drawArrays(GL_TRIANGLES, 0, 3);
532 }
533
534 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) {
535 unsigned shader = context_->createShader(type);
536 if (shader) {
537 context_->shaderSource(shader, source.data());
538 context_->compileShader(shader);
539
540 int compiled = 0;
541 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compiled);
542 if (!compiled) {
543 context_->deleteShader(shader);
544 shader = 0;
545 }
546 }
547 return shader;
548 }
549
550 unsigned TestPlugin::LoadProgram(const std::string& vertex_source,
551 const std::string& fragment_source) {
552 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source);
553 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source);
554 unsigned program = context_->createProgram();
555 if (vertex_shader && fragment_shader && program) {
556 context_->attachShader(program, vertex_shader);
557 context_->attachShader(program, fragment_shader);
558 context_->linkProgram(program);
559
560 int linked = 0;
561 context_->getProgramiv(program, GL_LINK_STATUS, &linked);
562 if (!linked) {
563 context_->deleteProgram(program);
564 program = 0;
565 }
566 }
567 if (vertex_shader)
568 context_->deleteShader(vertex_shader);
569 if (fragment_shader)
570 context_->deleteShader(fragment_shader);
571
572 return program;
573 }
574
575 bool TestPlugin::handleInputEvent(const blink::WebInputEvent& event,
576 blink::WebCursorInfo& info) {
577 const char* event_name = 0;
578 switch (event.type) {
579 case blink::WebInputEvent::Undefined:
580 event_name = "unknown";
581 break;
582
583 case blink::WebInputEvent::MouseDown:
584 event_name = "MouseDown";
585 break;
586 case blink::WebInputEvent::MouseUp:
587 event_name = "MouseUp";
588 break;
589 case blink::WebInputEvent::MouseMove:
590 event_name = "MouseMove";
591 break;
592 case blink::WebInputEvent::MouseEnter:
593 event_name = "MouseEnter";
594 break;
595 case blink::WebInputEvent::MouseLeave:
596 event_name = "MouseLeave";
597 break;
598 case blink::WebInputEvent::ContextMenu:
599 event_name = "ContextMenu";
600 break;
601
602 case blink::WebInputEvent::MouseWheel:
603 event_name = "MouseWheel";
604 break;
605
606 case blink::WebInputEvent::RawKeyDown:
607 event_name = "RawKeyDown";
608 break;
609 case blink::WebInputEvent::KeyDown:
610 event_name = "KeyDown";
611 break;
612 case blink::WebInputEvent::KeyUp:
613 event_name = "KeyUp";
614 break;
615 case blink::WebInputEvent::Char:
616 event_name = "Char";
617 break;
618
619 case blink::WebInputEvent::GestureScrollBegin:
620 event_name = "GestureScrollBegin";
621 break;
622 case blink::WebInputEvent::GestureScrollEnd:
623 event_name = "GestureScrollEnd";
624 break;
625 case blink::WebInputEvent::GestureScrollUpdateWithoutPropagation:
626 case blink::WebInputEvent::GestureScrollUpdate:
627 event_name = "GestureScrollUpdate";
628 break;
629 case blink::WebInputEvent::GestureFlingStart:
630 event_name = "GestureFlingStart";
631 break;
632 case blink::WebInputEvent::GestureFlingCancel:
633 event_name = "GestureFlingCancel";
634 break;
635 case blink::WebInputEvent::GestureTap:
636 event_name = "GestureTap";
637 break;
638 case blink::WebInputEvent::GestureTapUnconfirmed:
639 event_name = "GestureTapUnconfirmed";
640 break;
641 case blink::WebInputEvent::GestureTapDown:
642 event_name = "GestureTapDown";
643 break;
644 case blink::WebInputEvent::GestureShowPress:
645 event_name = "GestureShowPress";
646 break;
647 case blink::WebInputEvent::GestureTapCancel:
648 event_name = "GestureTapCancel";
649 break;
650 case blink::WebInputEvent::GestureDoubleTap:
651 event_name = "GestureDoubleTap";
652 break;
653 case blink::WebInputEvent::GestureTwoFingerTap:
654 event_name = "GestureTwoFingerTap";
655 break;
656 case blink::WebInputEvent::GestureLongPress:
657 event_name = "GestureLongPress";
658 break;
659 case blink::WebInputEvent::GestureLongTap:
660 event_name = "GestureLongTap";
661 break;
662 case blink::WebInputEvent::GesturePinchBegin:
663 event_name = "GesturePinchBegin";
664 break;
665 case blink::WebInputEvent::GesturePinchEnd:
666 event_name = "GesturePinchEnd";
667 break;
668 case blink::WebInputEvent::GesturePinchUpdate:
669 event_name = "GesturePinchUpdate";
670 break;
671
672 case blink::WebInputEvent::TouchStart:
673 event_name = "TouchStart";
674 break;
675 case blink::WebInputEvent::TouchMove:
676 event_name = "TouchMove";
677 break;
678 case blink::WebInputEvent::TouchEnd:
679 event_name = "TouchEnd";
680 break;
681 case blink::WebInputEvent::TouchCancel:
682 event_name = "TouchCancel";
683 break;
684 }
685
686 delegate_->printMessage(std::string("Plugin received event: ") +
687 (event_name ? event_name : "unknown") + "\n");
688 if (print_event_details_)
689 PrintEventDetails(delegate_, event);
690 if (print_user_gesture_status_)
691 delegate_->printMessage(
692 std::string("* ") +
693 (blink::WebUserGestureIndicator::isProcessingUserGesture() ? ""
694 : "not ") +
695 "handling user gesture\n");
696 if (is_persistent_)
697 delegate_->printMessage(std::string("TestPlugin: isPersistent\n"));
698 return false;
699 }
700
701 bool TestPlugin::handleDragStatusUpdate(
702 blink::WebDragStatus drag_status,
703 const blink::WebDragData& data,
704 blink::WebDragOperationsMask mask,
705 const blink::WebPoint& position,
706 const blink::WebPoint& screen_position) {
707 const char* drag_status_name = 0;
708 switch (drag_status) {
709 case blink::WebDragStatusEnter:
710 drag_status_name = "DragEnter";
711 break;
712 case blink::WebDragStatusOver:
713 drag_status_name = "DragOver";
714 break;
715 case blink::WebDragStatusLeave:
716 drag_status_name = "DragLeave";
717 break;
718 case blink::WebDragStatusDrop:
719 drag_status_name = "DragDrop";
720 break;
721 case blink::WebDragStatusUnknown:
722 NOTREACHED();
723 }
724 delegate_->printMessage(std::string("Plugin received event: ") +
725 drag_status_name + "\n");
726 return false;
727 }
728
729 TestPlugin* TestPlugin::create(blink::WebFrame* frame,
730 const blink::WebPluginParams& params,
731 WebTestDelegate* delegate) {
732 return new TestPlugin(frame, params, delegate);
733 }
734
735 const blink::WebString& TestPlugin::MimeType() {
736 const CR_DEFINE_STATIC_LOCAL(
737 blink::WebString, kMimeType, ("application/x-webkit-test-webplugin"));
738 return kMimeType;
739 }
740
741 const blink::WebString& TestPlugin::CanCreateWithoutRendererMimeType() {
742 const CR_DEFINE_STATIC_LOCAL(
743 blink::WebString,
744 kCanCreateWithoutRendererMimeType,
745 ("application/x-webkit-test-webplugin-can-create-without-renderer"));
746 return kCanCreateWithoutRendererMimeType;
747 }
748
749 const blink::WebString& TestPlugin::PluginPersistsMimeType() {
750 const CR_DEFINE_STATIC_LOCAL(
751 blink::WebString,
752 kPluginPersistsMimeType,
753 ("application/x-webkit-test-webplugin-persistent"));
754 return kPluginPersistsMimeType;
755 }
756
757 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) {
758 return mime_type == TestPlugin::MimeType() ||
759 mime_type == PluginPersistsMimeType() ||
760 mime_type == CanCreateWithoutRendererMimeType();
761 }
762
763 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/test_plugin.h ('k') | content/shell/renderer/test_runner/web_test_proxy.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698