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.
5 #include "components/test_runner/test_plugin.h"
7 #include "base/basictypes.h"
9 #include "base/logging.h"
10 #include "base/memory/shared_memory.h"
11 #include "base/strings/stringprintf.h"
12 #include "cc/resources/shared_bitmap_manager.h"
13 #include "components/test_runner/web_test_delegate.h"
14 #include "third_party/WebKit/public/platform/Platform.h"
15 #include "third_party/WebKit/public/platform/WebCompositorSupport.h"
16 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
17 #include "third_party/WebKit/public/platform/WebThread.h"
18 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
19 #include "third_party/WebKit/public/web/WebFrame.h"
20 #include "third_party/WebKit/public/web/WebInputEvent.h"
21 #include "third_party/WebKit/public/web/WebKit.h"
22 #include "third_party/WebKit/public/web/WebPluginParams.h"
23 #include "third_party/WebKit/public/web/WebTouchPoint.h"
24 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
25 #include "third_party/skia/include/core/SkBitmap.h"
26 #include "third_party/skia/include/core/SkCanvas.h"
27 #include "third_party/skia/include/core/SkColor.h"
28 #include "third_party/skia/include/core/SkPaint.h"
29 #include "third_party/skia/include/core/SkPath.h"
31 namespace test_runner
{
35 // GLenum values copied from gl2.h.
39 #define GL_TRIANGLES 0x0004
40 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
41 #define GL_DEPTH_TEST 0x0B71
42 #define GL_BLEND 0x0BE2
43 #define GL_SCISSOR_TEST 0x0B90
44 #define GL_TEXTURE_2D 0x0DE1
45 #define GL_FLOAT 0x1406
46 #define GL_RGBA 0x1908
47 #define GL_UNSIGNED_BYTE 0x1401
48 #define GL_TEXTURE_MAG_FILTER 0x2800
49 #define GL_TEXTURE_MIN_FILTER 0x2801
50 #define GL_TEXTURE_WRAP_S 0x2802
51 #define GL_TEXTURE_WRAP_T 0x2803
52 #define GL_NEAREST 0x2600
53 #define GL_COLOR_BUFFER_BIT 0x4000
54 #define GL_CLAMP_TO_EDGE 0x812F
55 #define GL_ARRAY_BUFFER 0x8892
56 #define GL_STATIC_DRAW 0x88E4
57 #define GL_FRAGMENT_SHADER 0x8B30
58 #define GL_VERTEX_SHADER 0x8B31
59 #define GL_COMPILE_STATUS 0x8B81
60 #define GL_LINK_STATUS 0x8B82
61 #define GL_COLOR_ATTACHMENT0 0x8CE0
62 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5
63 #define GL_FRAMEBUFFER 0x8D40
65 void PremultiplyAlpha(const unsigned color_in
[3],
68 for (int i
= 0; i
< 3; ++i
)
69 color_out
[i
] = (color_in
[i
] / 255.0f
) * alpha
;
74 const char* PointState(blink::WebTouchPoint::State state
) {
76 case blink::WebTouchPoint::StateReleased
:
78 case blink::WebTouchPoint::StatePressed
:
80 case blink::WebTouchPoint::StateMoved
:
82 case blink::WebTouchPoint::StateCancelled
:
89 void PrintTouchList(WebTestDelegate
* delegate
,
90 const blink::WebTouchPoint
* points
,
92 for (int i
= 0; i
< length
; ++i
) {
93 delegate
->PrintMessage(base::StringPrintf("* %.2f, %.2f: %s\n",
96 PointState(points
[i
].state
)));
100 void PrintEventDetails(WebTestDelegate
* delegate
,
101 const blink::WebInputEvent
& event
) {
102 if (blink::WebInputEvent::isTouchEventType(event
.type
)) {
103 const blink::WebTouchEvent
& touch
=
104 static_cast<const blink::WebTouchEvent
&>(event
);
105 PrintTouchList(delegate
, touch
.touches
, touch
.touchesLength
);
106 } else if (blink::WebInputEvent::isMouseEventType(event
.type
) ||
107 event
.type
== blink::WebInputEvent::MouseWheel
) {
108 const blink::WebMouseEvent
& mouse
=
109 static_cast<const blink::WebMouseEvent
&>(event
);
110 delegate
->PrintMessage(base::StringPrintf("* %d, %d\n", mouse
.x
, mouse
.y
));
111 } else if (blink::WebInputEvent::isGestureEventType(event
.type
)) {
112 const blink::WebGestureEvent
& gesture
=
113 static_cast<const blink::WebGestureEvent
&>(event
);
114 delegate
->PrintMessage(
115 base::StringPrintf("* %d, %d\n", gesture
.x
, gesture
.y
));
119 blink::WebPluginContainer::TouchEventRequestType
ParseTouchEventRequestType(
120 const blink::WebString
& string
) {
121 if (string
== blink::WebString::fromUTF8("raw"))
122 return blink::WebPluginContainer::TouchEventRequestTypeRaw
;
123 if (string
== blink::WebString::fromUTF8("synthetic"))
124 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
;
125 return blink::WebPluginContainer::TouchEventRequestTypeNone
;
128 class DeferredDeleteTask
: public blink::WebThread::Task
{
130 DeferredDeleteTask(scoped_ptr
<TestPlugin
> plugin
) : plugin_(plugin
.Pass()) {}
132 void run() override
{}
135 scoped_ptr
<TestPlugin
> plugin_
;
140 TestPlugin::TestPlugin(blink::WebFrame
* frame
,
141 const blink::WebPluginParams
& params
,
142 WebTestDelegate
* delegate
)
148 mailbox_changed_(false),
150 touch_event_request_(
151 blink::WebPluginContainer::TouchEventRequestTypeNone
),
152 re_request_touch_events_(false),
153 print_event_details_(false),
154 print_user_gesture_status_(false),
155 can_process_drag_(false),
156 supports_keyboard_focus_(false),
157 is_persistent_(params
.mimeType
== PluginPersistsMimeType()),
158 can_create_without_renderer_(params
.mimeType
==
159 CanCreateWithoutRendererMimeType()) {
160 const CR_DEFINE_STATIC_LOCAL(
161 blink::WebString
, kAttributePrimitive
, ("primitive"));
162 const CR_DEFINE_STATIC_LOCAL(
163 blink::WebString
, kAttributeBackgroundColor
, ("background-color"));
164 const CR_DEFINE_STATIC_LOCAL(
165 blink::WebString
, kAttributePrimitiveColor
, ("primitive-color"));
166 const CR_DEFINE_STATIC_LOCAL(
167 blink::WebString
, kAttributeOpacity
, ("opacity"));
168 const CR_DEFINE_STATIC_LOCAL(
169 blink::WebString
, kAttributeAcceptsTouch
, ("accepts-touch"));
170 const CR_DEFINE_STATIC_LOCAL(
171 blink::WebString
, kAttributeReRequestTouchEvents
, ("re-request-touch"));
172 const CR_DEFINE_STATIC_LOCAL(
173 blink::WebString
, kAttributePrintEventDetails
, ("print-event-details"));
174 const CR_DEFINE_STATIC_LOCAL(
175 blink::WebString
, kAttributeCanProcessDrag
, ("can-process-drag"));
176 const CR_DEFINE_STATIC_LOCAL(blink::WebString
,
177 kAttributeSupportsKeyboardFocus
,
178 ("supports-keyboard-focus"));
179 const CR_DEFINE_STATIC_LOCAL(blink::WebString
,
180 kAttributePrintUserGestureStatus
,
181 ("print-user-gesture-status"));
183 DCHECK_EQ(params
.attributeNames
.size(), params
.attributeValues
.size());
184 size_t size
= params
.attributeNames
.size();
185 for (size_t i
= 0; i
< size
; ++i
) {
186 const blink::WebString
& attribute_name
= params
.attributeNames
[i
];
187 const blink::WebString
& attribute_value
= params
.attributeValues
[i
];
189 if (attribute_name
== kAttributePrimitive
)
190 scene_
.primitive
= ParsePrimitive(attribute_value
);
191 else if (attribute_name
== kAttributeBackgroundColor
)
192 ParseColor(attribute_value
, scene_
.background_color
);
193 else if (attribute_name
== kAttributePrimitiveColor
)
194 ParseColor(attribute_value
, scene_
.primitive_color
);
195 else if (attribute_name
== kAttributeOpacity
)
196 scene_
.opacity
= ParseOpacity(attribute_value
);
197 else if (attribute_name
== kAttributeAcceptsTouch
)
198 touch_event_request_
= ParseTouchEventRequestType(attribute_value
);
199 else if (attribute_name
== kAttributeReRequestTouchEvents
)
200 re_request_touch_events_
= ParseBoolean(attribute_value
);
201 else if (attribute_name
== kAttributePrintEventDetails
)
202 print_event_details_
= ParseBoolean(attribute_value
);
203 else if (attribute_name
== kAttributeCanProcessDrag
)
204 can_process_drag_
= ParseBoolean(attribute_value
);
205 else if (attribute_name
== kAttributeSupportsKeyboardFocus
)
206 supports_keyboard_focus_
= ParseBoolean(attribute_value
);
207 else if (attribute_name
== kAttributePrintUserGestureStatus
)
208 print_user_gesture_status_
= ParseBoolean(attribute_value
);
210 if (can_create_without_renderer_
)
211 delegate_
->PrintMessage(
212 std::string("TestPlugin: canCreateWithoutRenderer\n"));
215 TestPlugin::~TestPlugin() {
218 bool TestPlugin::initialize(blink::WebPluginContainer
* container
) {
219 blink::WebGraphicsContext3D::Attributes attrs
;
221 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs
);
226 layer_
= delegate_
->CreateTextureLayerForMailbox(this);
227 web_layer_
= make_scoped_ptr(delegate_
->InstantiateWebLayer(layer_
));
228 container_
= container
;
229 container_
->setWebLayer(web_layer_
.get());
230 if (re_request_touch_events_
) {
231 container_
->requestTouchEventType(
232 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
);
233 container_
->requestTouchEventType(
234 blink::WebPluginContainer::TouchEventRequestTypeRaw
);
236 container_
->requestTouchEventType(touch_event_request_
);
237 container_
->setWantsWheelEvents(true);
241 void TestPlugin::destroy() {
243 layer_
->ClearTexture();
245 container_
->setWebLayer(0);
256 blink::Platform::current()->mainThread()->postTask(
257 blink::WebTraceLocation(__FUNCTION__
, __FILE__
),
258 new DeferredDeleteTask(make_scoped_ptr(this)));
261 NPObject
* TestPlugin::scriptableObject() {
265 bool TestPlugin::canProcessDrag() const {
266 return can_process_drag_
;
269 bool TestPlugin::supportsKeyboardFocus() const {
270 return supports_keyboard_focus_
;
273 void TestPlugin::updateGeometry(
274 const blink::WebRect
& window_rect
,
275 const blink::WebRect
& clip_rect
,
276 const blink::WebRect
& unobscured_rect
,
277 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
279 if (clip_rect
== rect_
)
283 if (rect_
.isEmpty()) {
284 texture_mailbox_
= cc::TextureMailbox();
285 } else if (context_
) {
286 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
288 context_
->bindTexture(GL_TEXTURE_2D
, color_texture_
);
289 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
290 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
291 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
292 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
293 context_
->texImage2D(GL_TEXTURE_2D
,
302 context_
->bindFramebuffer(GL_FRAMEBUFFER
, framebuffer_
);
303 context_
->framebufferTexture2D(
304 GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color_texture_
, 0);
308 gpu::Mailbox mailbox
;
309 context_
->genMailboxCHROMIUM(mailbox
.name
);
310 context_
->produceTextureCHROMIUM(GL_TEXTURE_2D
, mailbox
.name
);
312 uint32 sync_point
= context_
->insertSyncPoint();
313 texture_mailbox_
= cc::TextureMailbox(mailbox
, GL_TEXTURE_2D
, sync_point
);
315 scoped_ptr
<cc::SharedBitmap
> bitmap
=
316 delegate_
->GetSharedBitmapManager()->AllocateSharedBitmap(
317 gfx::Rect(rect_
).size());
319 texture_mailbox_
= cc::TextureMailbox();
321 DrawSceneSoftware(bitmap
->pixels());
322 texture_mailbox_
= cc::TextureMailbox(
323 bitmap
.get(), gfx::Size(rect_
.width
, rect_
.height
));
324 shared_bitmap_
= bitmap
.Pass();
328 mailbox_changed_
= true;
329 layer_
->SetNeedsDisplay();
332 bool TestPlugin::acceptsInputEvents() {
336 bool TestPlugin::isPlaceholder() {
340 static void IgnoreReleaseCallback(uint32 sync_point
, bool lost
) {
343 static void ReleaseSharedMemory(scoped_ptr
<cc::SharedBitmap
> bitmap
,
348 bool TestPlugin::PrepareTextureMailbox(
349 cc::TextureMailbox
* mailbox
,
350 scoped_ptr
<cc::SingleReleaseCallback
>* release_callback
,
351 bool use_shared_memory
) {
352 if (!mailbox_changed_
)
354 *mailbox
= texture_mailbox_
;
355 if (texture_mailbox_
.IsTexture()) {
357 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback
));
358 } else if (texture_mailbox_
.IsSharedMemory()) {
359 *release_callback
= cc::SingleReleaseCallback::Create(
360 base::Bind(&ReleaseSharedMemory
, base::Passed(&shared_bitmap_
)));
362 mailbox_changed_
= false;
366 TestPlugin::Primitive
TestPlugin::ParsePrimitive(
367 const blink::WebString
& string
) {
368 const CR_DEFINE_STATIC_LOCAL(blink::WebString
, kPrimitiveNone
, ("none"));
369 const CR_DEFINE_STATIC_LOCAL(
370 blink::WebString
, kPrimitiveTriangle
, ("triangle"));
372 Primitive primitive
= PrimitiveNone
;
373 if (string
== kPrimitiveNone
)
374 primitive
= PrimitiveNone
;
375 else if (string
== kPrimitiveTriangle
)
376 primitive
= PrimitiveTriangle
;
382 // FIXME: This method should already exist. Use it.
383 // For now just parse primary colors.
384 void TestPlugin::ParseColor(const blink::WebString
& string
, unsigned color
[3]) {
385 color
[0] = color
[1] = color
[2] = 0;
386 if (string
== "black")
391 else if (string
== "green")
393 else if (string
== "blue")
399 float TestPlugin::ParseOpacity(const blink::WebString
& string
) {
400 return static_cast<float>(atof(string
.utf8().data()));
403 bool TestPlugin::ParseBoolean(const blink::WebString
& string
) {
404 const CR_DEFINE_STATIC_LOCAL(blink::WebString
, kPrimitiveTrue
, ("true"));
405 return string
== kPrimitiveTrue
;
408 bool TestPlugin::InitScene() {
413 PremultiplyAlpha(scene_
.background_color
, scene_
.opacity
, color
);
415 color_texture_
= context_
->createTexture();
416 framebuffer_
= context_
->createFramebuffer();
418 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
419 context_
->disable(GL_DEPTH_TEST
);
420 context_
->disable(GL_SCISSOR_TEST
);
422 context_
->clearColor(color
[0], color
[1], color
[2], color
[3]);
424 context_
->enable(GL_BLEND
);
425 context_
->blendFunc(GL_ONE
, GL_ONE_MINUS_SRC_ALPHA
);
427 return scene_
.primitive
!= PrimitiveNone
? InitProgram() && InitPrimitive()
431 void TestPlugin::DrawSceneGL() {
432 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
433 context_
->clear(GL_COLOR_BUFFER_BIT
);
435 if (scene_
.primitive
!= PrimitiveNone
)
439 void TestPlugin::DrawSceneSoftware(void* memory
) {
440 SkColor background_color
=
441 SkColorSetARGB(static_cast<uint8
>(scene_
.opacity
* 255),
442 scene_
.background_color
[0],
443 scene_
.background_color
[1],
444 scene_
.background_color
[2]);
446 const SkImageInfo info
=
447 SkImageInfo::MakeN32Premul(rect_
.width
, rect_
.height
);
449 bitmap
.installPixels(info
, memory
, info
.minRowBytes());
450 SkCanvas
canvas(bitmap
);
451 canvas
.clear(background_color
);
453 if (scene_
.primitive
!= PrimitiveNone
) {
454 DCHECK_EQ(PrimitiveTriangle
, scene_
.primitive
);
455 SkColor foreground_color
=
456 SkColorSetARGB(static_cast<uint8
>(scene_
.opacity
* 255),
457 scene_
.primitive_color
[0],
458 scene_
.primitive_color
[1],
459 scene_
.primitive_color
[2]);
460 SkPath triangle_path
;
461 triangle_path
.moveTo(0.5f
* rect_
.width
, 0.9f
* rect_
.height
);
462 triangle_path
.lineTo(0.1f
* rect_
.width
, 0.1f
* rect_
.height
);
463 triangle_path
.lineTo(0.9f
* rect_
.width
, 0.1f
* rect_
.height
);
465 paint
.setColor(foreground_color
);
466 paint
.setStyle(SkPaint::kFill_Style
);
467 canvas
.drawPath(triangle_path
, paint
);
471 void TestPlugin::DestroyScene() {
472 if (scene_
.program
) {
473 context_
->deleteProgram(scene_
.program
);
477 context_
->deleteBuffer(scene_
.vbo
);
482 context_
->deleteFramebuffer(framebuffer_
);
486 if (color_texture_
) {
487 context_
->deleteTexture(color_texture_
);
492 bool TestPlugin::InitProgram() {
493 const std::string
vertex_source(
494 "attribute vec4 position; \n"
496 " gl_Position = position; \n"
499 const std::string
fragment_source(
500 "precision mediump float; \n"
501 "uniform vec4 color; \n"
503 " gl_FragColor = color; \n"
506 scene_
.program
= LoadProgram(vertex_source
, fragment_source
);
510 scene_
.color_location
= context_
->getUniformLocation(scene_
.program
, "color");
511 scene_
.position_location
=
512 context_
->getAttribLocation(scene_
.program
, "position");
516 bool TestPlugin::InitPrimitive() {
517 DCHECK_EQ(scene_
.primitive
, PrimitiveTriangle
);
519 scene_
.vbo
= context_
->createBuffer();
523 const float vertices
[] = {0.0f
, 0.8f
, 0.0f
, -0.8f
, -0.8f
,
524 0.0f
, 0.8f
, -0.8f
, 0.0f
};
525 context_
->bindBuffer(GL_ARRAY_BUFFER
, scene_
.vbo
);
526 context_
->bufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), 0, GL_STATIC_DRAW
);
527 context_
->bufferSubData(GL_ARRAY_BUFFER
, 0, sizeof(vertices
), vertices
);
531 void TestPlugin::DrawPrimitive() {
532 DCHECK_EQ(scene_
.primitive
, PrimitiveTriangle
);
534 DCHECK(scene_
.program
);
536 context_
->useProgram(scene_
.program
);
538 // Bind primitive color.
540 PremultiplyAlpha(scene_
.primitive_color
, scene_
.opacity
, color
);
542 scene_
.color_location
, color
[0], color
[1], color
[2], color
[3]);
544 // Bind primitive vertices.
545 context_
->bindBuffer(GL_ARRAY_BUFFER
, scene_
.vbo
);
546 context_
->enableVertexAttribArray(scene_
.position_location
);
547 context_
->vertexAttribPointer(
548 scene_
.position_location
, 3, GL_FLOAT
, GL_FALSE
, 0, 0);
549 context_
->drawArrays(GL_TRIANGLES
, 0, 3);
552 unsigned TestPlugin::LoadShader(unsigned type
, const std::string
& source
) {
553 unsigned shader
= context_
->createShader(type
);
555 context_
->shaderSource(shader
, source
.data());
556 context_
->compileShader(shader
);
559 context_
->getShaderiv(shader
, GL_COMPILE_STATUS
, &compiled
);
561 context_
->deleteShader(shader
);
568 unsigned TestPlugin::LoadProgram(const std::string
& vertex_source
,
569 const std::string
& fragment_source
) {
570 unsigned vertex_shader
= LoadShader(GL_VERTEX_SHADER
, vertex_source
);
571 unsigned fragment_shader
= LoadShader(GL_FRAGMENT_SHADER
, fragment_source
);
572 unsigned program
= context_
->createProgram();
573 if (vertex_shader
&& fragment_shader
&& program
) {
574 context_
->attachShader(program
, vertex_shader
);
575 context_
->attachShader(program
, fragment_shader
);
576 context_
->linkProgram(program
);
579 context_
->getProgramiv(program
, GL_LINK_STATUS
, &linked
);
581 context_
->deleteProgram(program
);
586 context_
->deleteShader(vertex_shader
);
588 context_
->deleteShader(fragment_shader
);
593 bool TestPlugin::handleInputEvent(const blink::WebInputEvent
& event
,
594 blink::WebCursorInfo
& info
) {
595 const char* event_name
= 0;
596 switch (event
.type
) {
597 case blink::WebInputEvent::Undefined
:
598 event_name
= "unknown";
601 case blink::WebInputEvent::MouseDown
:
602 event_name
= "MouseDown";
604 case blink::WebInputEvent::MouseUp
:
605 event_name
= "MouseUp";
607 case blink::WebInputEvent::MouseMove
:
608 event_name
= "MouseMove";
610 case blink::WebInputEvent::MouseEnter
:
611 event_name
= "MouseEnter";
613 case blink::WebInputEvent::MouseLeave
:
614 event_name
= "MouseLeave";
616 case blink::WebInputEvent::ContextMenu
:
617 event_name
= "ContextMenu";
620 case blink::WebInputEvent::MouseWheel
:
621 event_name
= "MouseWheel";
624 case blink::WebInputEvent::RawKeyDown
:
625 event_name
= "RawKeyDown";
627 case blink::WebInputEvent::KeyDown
:
628 event_name
= "KeyDown";
630 case blink::WebInputEvent::KeyUp
:
631 event_name
= "KeyUp";
633 case blink::WebInputEvent::Char
:
637 case blink::WebInputEvent::GestureScrollBegin
:
638 event_name
= "GestureScrollBegin";
640 case blink::WebInputEvent::GestureScrollEnd
:
641 event_name
= "GestureScrollEnd";
643 case blink::WebInputEvent::GestureScrollUpdate
:
644 event_name
= "GestureScrollUpdate";
646 case blink::WebInputEvent::GestureFlingStart
:
647 event_name
= "GestureFlingStart";
649 case blink::WebInputEvent::GestureFlingCancel
:
650 event_name
= "GestureFlingCancel";
652 case blink::WebInputEvent::GestureTap
:
653 event_name
= "GestureTap";
655 case blink::WebInputEvent::GestureTapUnconfirmed
:
656 event_name
= "GestureTapUnconfirmed";
658 case blink::WebInputEvent::GestureTapDown
:
659 event_name
= "GestureTapDown";
661 case blink::WebInputEvent::GestureShowPress
:
662 event_name
= "GestureShowPress";
664 case blink::WebInputEvent::GestureTapCancel
:
665 event_name
= "GestureTapCancel";
667 case blink::WebInputEvent::GestureDoubleTap
:
668 event_name
= "GestureDoubleTap";
670 case blink::WebInputEvent::GestureTwoFingerTap
:
671 event_name
= "GestureTwoFingerTap";
673 case blink::WebInputEvent::GestureLongPress
:
674 event_name
= "GestureLongPress";
676 case blink::WebInputEvent::GestureLongTap
:
677 event_name
= "GestureLongTap";
679 case blink::WebInputEvent::GesturePinchBegin
:
680 event_name
= "GesturePinchBegin";
682 case blink::WebInputEvent::GesturePinchEnd
:
683 event_name
= "GesturePinchEnd";
685 case blink::WebInputEvent::GesturePinchUpdate
:
686 event_name
= "GesturePinchUpdate";
689 case blink::WebInputEvent::TouchStart
:
690 event_name
= "TouchStart";
692 case blink::WebInputEvent::TouchMove
:
693 event_name
= "TouchMove";
695 case blink::WebInputEvent::TouchEnd
:
696 event_name
= "TouchEnd";
698 case blink::WebInputEvent::TouchCancel
:
699 event_name
= "TouchCancel";
702 NOTREACHED() << "Received unexpected event type: " << event
.type
;
703 event_name
= "unknown";
707 delegate_
->PrintMessage(std::string("Plugin received event: ") +
708 (event_name
? event_name
: "unknown") + "\n");
709 if (print_event_details_
)
710 PrintEventDetails(delegate_
, event
);
711 if (print_user_gesture_status_
)
712 delegate_
->PrintMessage(
714 (blink::WebUserGestureIndicator::isProcessingUserGesture() ? ""
716 "handling user gesture\n");
718 delegate_
->PrintMessage(std::string("TestPlugin: isPersistent\n"));
722 bool TestPlugin::handleDragStatusUpdate(
723 blink::WebDragStatus drag_status
,
724 const blink::WebDragData
& data
,
725 blink::WebDragOperationsMask mask
,
726 const blink::WebPoint
& position
,
727 const blink::WebPoint
& screen_position
) {
728 const char* drag_status_name
= 0;
729 switch (drag_status
) {
730 case blink::WebDragStatusEnter
:
731 drag_status_name
= "DragEnter";
733 case blink::WebDragStatusOver
:
734 drag_status_name
= "DragOver";
736 case blink::WebDragStatusLeave
:
737 drag_status_name
= "DragLeave";
739 case blink::WebDragStatusDrop
:
740 drag_status_name
= "DragDrop";
742 case blink::WebDragStatusUnknown
:
745 delegate_
->PrintMessage(std::string("Plugin received event: ") +
746 drag_status_name
+ "\n");
750 TestPlugin
* TestPlugin::create(blink::WebFrame
* frame
,
751 const blink::WebPluginParams
& params
,
752 WebTestDelegate
* delegate
) {
753 return new TestPlugin(frame
, params
, delegate
);
756 const blink::WebString
& TestPlugin::MimeType() {
757 const CR_DEFINE_STATIC_LOCAL(
758 blink::WebString
, kMimeType
, ("application/x-webkit-test-webplugin"));
762 const blink::WebString
& TestPlugin::CanCreateWithoutRendererMimeType() {
763 const CR_DEFINE_STATIC_LOCAL(
765 kCanCreateWithoutRendererMimeType
,
766 ("application/x-webkit-test-webplugin-can-create-without-renderer"));
767 return kCanCreateWithoutRendererMimeType
;
770 const blink::WebString
& TestPlugin::PluginPersistsMimeType() {
771 const CR_DEFINE_STATIC_LOCAL(
773 kPluginPersistsMimeType
,
774 ("application/x-webkit-test-webplugin-persistent"));
775 return kPluginPersistsMimeType
;
778 bool TestPlugin::IsSupportedMimeType(const blink::WebString
& mime_type
) {
779 return mime_type
== TestPlugin::MimeType() ||
780 mime_type
== PluginPersistsMimeType() ||
781 mime_type
== CanCreateWithoutRendererMimeType();
784 } // namespace test_runner