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/blink/web_layer_impl.h"
13 #include "cc/layers/texture_layer.h"
14 #include "cc/resources/shared_bitmap_manager.h"
15 #include "components/test_runner/web_test_delegate.h"
16 #include "third_party/WebKit/public/platform/Platform.h"
17 #include "third_party/WebKit/public/platform/WebCompositorSupport.h"
18 #include "third_party/WebKit/public/platform/WebGraphicsContext3D.h"
19 #include "third_party/WebKit/public/platform/WebTaskRunner.h"
20 #include "third_party/WebKit/public/platform/WebThread.h"
21 #include "third_party/WebKit/public/platform/WebTraceLocation.h"
22 #include "third_party/WebKit/public/web/WebFrame.h"
23 #include "third_party/WebKit/public/web/WebInputEvent.h"
24 #include "third_party/WebKit/public/web/WebKit.h"
25 #include "third_party/WebKit/public/web/WebPluginParams.h"
26 #include "third_party/WebKit/public/web/WebTouchPoint.h"
27 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
28 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "third_party/skia/include/core/SkCanvas.h"
30 #include "third_party/skia/include/core/SkColor.h"
31 #include "third_party/skia/include/core/SkPaint.h"
32 #include "third_party/skia/include/core/SkPath.h"
34 namespace test_runner
{
38 // GLenum values copied from gl2.h.
42 #define GL_TRIANGLES 0x0004
43 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
44 #define GL_DEPTH_TEST 0x0B71
45 #define GL_BLEND 0x0BE2
46 #define GL_SCISSOR_TEST 0x0B90
47 #define GL_TEXTURE_2D 0x0DE1
48 #define GL_FLOAT 0x1406
49 #define GL_RGBA 0x1908
50 #define GL_UNSIGNED_BYTE 0x1401
51 #define GL_TEXTURE_MAG_FILTER 0x2800
52 #define GL_TEXTURE_MIN_FILTER 0x2801
53 #define GL_TEXTURE_WRAP_S 0x2802
54 #define GL_TEXTURE_WRAP_T 0x2803
55 #define GL_NEAREST 0x2600
56 #define GL_COLOR_BUFFER_BIT 0x4000
57 #define GL_CLAMP_TO_EDGE 0x812F
58 #define GL_ARRAY_BUFFER 0x8892
59 #define GL_STATIC_DRAW 0x88E4
60 #define GL_FRAGMENT_SHADER 0x8B30
61 #define GL_VERTEX_SHADER 0x8B31
62 #define GL_COMPILE_STATUS 0x8B81
63 #define GL_LINK_STATUS 0x8B82
64 #define GL_COLOR_ATTACHMENT0 0x8CE0
65 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5
66 #define GL_FRAMEBUFFER 0x8D40
68 void PremultiplyAlpha(const unsigned color_in
[3],
71 for (int i
= 0; i
< 3; ++i
)
72 color_out
[i
] = (color_in
[i
] / 255.0f
) * alpha
;
77 const char* PointState(blink::WebTouchPoint::State state
) {
79 case blink::WebTouchPoint::StateReleased
:
81 case blink::WebTouchPoint::StatePressed
:
83 case blink::WebTouchPoint::StateMoved
:
85 case blink::WebTouchPoint::StateCancelled
:
92 void PrintTouchList(WebTestDelegate
* delegate
,
93 const blink::WebTouchPoint
* points
,
95 for (int i
= 0; i
< length
; ++i
) {
96 delegate
->PrintMessage(base::StringPrintf("* %.2f, %.2f: %s\n",
99 PointState(points
[i
].state
)));
103 void PrintEventDetails(WebTestDelegate
* delegate
,
104 const blink::WebInputEvent
& event
) {
105 if (blink::WebInputEvent::isTouchEventType(event
.type
)) {
106 const blink::WebTouchEvent
& touch
=
107 static_cast<const blink::WebTouchEvent
&>(event
);
108 PrintTouchList(delegate
, touch
.touches
, touch
.touchesLength
);
109 } else if (blink::WebInputEvent::isMouseEventType(event
.type
) ||
110 event
.type
== blink::WebInputEvent::MouseWheel
) {
111 const blink::WebMouseEvent
& mouse
=
112 static_cast<const blink::WebMouseEvent
&>(event
);
113 delegate
->PrintMessage(base::StringPrintf("* %d, %d\n", mouse
.x
, mouse
.y
));
114 } else if (blink::WebInputEvent::isGestureEventType(event
.type
)) {
115 const blink::WebGestureEvent
& gesture
=
116 static_cast<const blink::WebGestureEvent
&>(event
);
117 delegate
->PrintMessage(
118 base::StringPrintf("* %d, %d\n", gesture
.x
, gesture
.y
));
122 blink::WebPluginContainer::TouchEventRequestType
ParseTouchEventRequestType(
123 const blink::WebString
& string
) {
124 if (string
== blink::WebString::fromUTF8("raw"))
125 return blink::WebPluginContainer::TouchEventRequestTypeRaw
;
126 if (string
== blink::WebString::fromUTF8("synthetic"))
127 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
;
128 return blink::WebPluginContainer::TouchEventRequestTypeNone
;
131 class DeferredDeleteTask
: public blink::WebTaskRunner::Task
{
133 DeferredDeleteTask(scoped_ptr
<TestPlugin
> plugin
) : plugin_(plugin
.Pass()) {}
135 void run() override
{}
138 scoped_ptr
<TestPlugin
> plugin_
;
143 TestPlugin::TestPlugin(blink::WebFrame
* frame
,
144 const blink::WebPluginParams
& params
,
145 WebTestDelegate
* delegate
)
151 mailbox_changed_(false),
153 touch_event_request_(
154 blink::WebPluginContainer::TouchEventRequestTypeNone
),
155 re_request_touch_events_(false),
156 print_event_details_(false),
157 print_user_gesture_status_(false),
158 can_process_drag_(false),
159 supports_keyboard_focus_(false),
160 is_persistent_(params
.mimeType
== PluginPersistsMimeType()),
161 can_create_without_renderer_(params
.mimeType
==
162 CanCreateWithoutRendererMimeType()) {
163 const CR_DEFINE_STATIC_LOCAL(
164 blink::WebString
, kAttributePrimitive
, ("primitive"));
165 const CR_DEFINE_STATIC_LOCAL(
166 blink::WebString
, kAttributeBackgroundColor
, ("background-color"));
167 const CR_DEFINE_STATIC_LOCAL(
168 blink::WebString
, kAttributePrimitiveColor
, ("primitive-color"));
169 const CR_DEFINE_STATIC_LOCAL(
170 blink::WebString
, kAttributeOpacity
, ("opacity"));
171 const CR_DEFINE_STATIC_LOCAL(
172 blink::WebString
, kAttributeAcceptsTouch
, ("accepts-touch"));
173 const CR_DEFINE_STATIC_LOCAL(
174 blink::WebString
, kAttributeReRequestTouchEvents
, ("re-request-touch"));
175 const CR_DEFINE_STATIC_LOCAL(
176 blink::WebString
, kAttributePrintEventDetails
, ("print-event-details"));
177 const CR_DEFINE_STATIC_LOCAL(
178 blink::WebString
, kAttributeCanProcessDrag
, ("can-process-drag"));
179 const CR_DEFINE_STATIC_LOCAL(blink::WebString
,
180 kAttributeSupportsKeyboardFocus
,
181 ("supports-keyboard-focus"));
182 const CR_DEFINE_STATIC_LOCAL(blink::WebString
,
183 kAttributePrintUserGestureStatus
,
184 ("print-user-gesture-status"));
186 DCHECK_EQ(params
.attributeNames
.size(), params
.attributeValues
.size());
187 size_t size
= params
.attributeNames
.size();
188 for (size_t i
= 0; i
< size
; ++i
) {
189 const blink::WebString
& attribute_name
= params
.attributeNames
[i
];
190 const blink::WebString
& attribute_value
= params
.attributeValues
[i
];
192 if (attribute_name
== kAttributePrimitive
)
193 scene_
.primitive
= ParsePrimitive(attribute_value
);
194 else if (attribute_name
== kAttributeBackgroundColor
)
195 ParseColor(attribute_value
, scene_
.background_color
);
196 else if (attribute_name
== kAttributePrimitiveColor
)
197 ParseColor(attribute_value
, scene_
.primitive_color
);
198 else if (attribute_name
== kAttributeOpacity
)
199 scene_
.opacity
= ParseOpacity(attribute_value
);
200 else if (attribute_name
== kAttributeAcceptsTouch
)
201 touch_event_request_
= ParseTouchEventRequestType(attribute_value
);
202 else if (attribute_name
== kAttributeReRequestTouchEvents
)
203 re_request_touch_events_
= ParseBoolean(attribute_value
);
204 else if (attribute_name
== kAttributePrintEventDetails
)
205 print_event_details_
= ParseBoolean(attribute_value
);
206 else if (attribute_name
== kAttributeCanProcessDrag
)
207 can_process_drag_
= ParseBoolean(attribute_value
);
208 else if (attribute_name
== kAttributeSupportsKeyboardFocus
)
209 supports_keyboard_focus_
= ParseBoolean(attribute_value
);
210 else if (attribute_name
== kAttributePrintUserGestureStatus
)
211 print_user_gesture_status_
= ParseBoolean(attribute_value
);
213 if (can_create_without_renderer_
)
214 delegate_
->PrintMessage(
215 std::string("TestPlugin: canCreateWithoutRenderer\n"));
218 TestPlugin::~TestPlugin() {
221 bool TestPlugin::initialize(blink::WebPluginContainer
* container
) {
222 blink::WebGraphicsContext3D::Attributes attrs
;
224 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs
);
229 layer_
= cc::TextureLayer::CreateForMailbox(
230 cc_blink::WebLayerImpl::LayerSettings(), this);
231 web_layer_
= make_scoped_ptr(new cc_blink::WebLayerImpl(layer_
));
232 container_
= container
;
233 container_
->setWebLayer(web_layer_
.get());
234 if (re_request_touch_events_
) {
235 container_
->requestTouchEventType(
236 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse
);
237 container_
->requestTouchEventType(
238 blink::WebPluginContainer::TouchEventRequestTypeRaw
);
240 container_
->requestTouchEventType(touch_event_request_
);
241 container_
->setWantsWheelEvents(true);
245 void TestPlugin::destroy() {
247 layer_
->ClearTexture();
249 container_
->setWebLayer(0);
260 blink::Platform::current()->mainThread()->taskRunner()->postTask(
261 blink::WebTraceLocation(__FUNCTION__
, __FILE__
),
262 new DeferredDeleteTask(make_scoped_ptr(this)));
265 NPObject
* TestPlugin::scriptableObject() {
269 bool TestPlugin::canProcessDrag() const {
270 return can_process_drag_
;
273 bool TestPlugin::supportsKeyboardFocus() const {
274 return supports_keyboard_focus_
;
277 void TestPlugin::updateGeometry(
278 const blink::WebRect
& window_rect
,
279 const blink::WebRect
& clip_rect
,
280 const blink::WebRect
& unobscured_rect
,
281 const blink::WebVector
<blink::WebRect
>& cut_outs_rects
,
283 if (clip_rect
== rect_
)
287 if (rect_
.isEmpty()) {
288 texture_mailbox_
= cc::TextureMailbox();
289 } else if (context_
) {
290 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
292 context_
->bindTexture(GL_TEXTURE_2D
, color_texture_
);
293 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MAG_FILTER
, GL_NEAREST
);
294 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_MIN_FILTER
, GL_NEAREST
);
295 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_S
, GL_CLAMP_TO_EDGE
);
296 context_
->texParameteri(GL_TEXTURE_2D
, GL_TEXTURE_WRAP_T
, GL_CLAMP_TO_EDGE
);
297 context_
->texImage2D(GL_TEXTURE_2D
,
306 context_
->bindFramebuffer(GL_FRAMEBUFFER
, framebuffer_
);
307 context_
->framebufferTexture2D(
308 GL_FRAMEBUFFER
, GL_COLOR_ATTACHMENT0
, GL_TEXTURE_2D
, color_texture_
, 0);
312 gpu::Mailbox mailbox
;
313 context_
->genMailboxCHROMIUM(mailbox
.name
);
314 context_
->produceTextureCHROMIUM(GL_TEXTURE_2D
, mailbox
.name
);
316 uint32 sync_point
= context_
->insertSyncPoint();
317 texture_mailbox_
= cc::TextureMailbox(mailbox
, GL_TEXTURE_2D
, sync_point
);
319 scoped_ptr
<cc::SharedBitmap
> bitmap
=
320 delegate_
->GetSharedBitmapManager()->AllocateSharedBitmap(
321 gfx::Rect(rect_
).size());
323 texture_mailbox_
= cc::TextureMailbox();
325 DrawSceneSoftware(bitmap
->pixels());
326 texture_mailbox_
= cc::TextureMailbox(
327 bitmap
.get(), gfx::Size(rect_
.width
, rect_
.height
));
328 shared_bitmap_
= bitmap
.Pass();
332 mailbox_changed_
= true;
333 layer_
->SetNeedsDisplay();
336 bool TestPlugin::acceptsInputEvents() {
340 bool TestPlugin::isPlaceholder() {
344 static void IgnoreReleaseCallback(uint32 sync_point
, bool lost
) {
347 static void ReleaseSharedMemory(scoped_ptr
<cc::SharedBitmap
> bitmap
,
352 bool TestPlugin::PrepareTextureMailbox(
353 cc::TextureMailbox
* mailbox
,
354 scoped_ptr
<cc::SingleReleaseCallback
>* release_callback
,
355 bool use_shared_memory
) {
356 if (!mailbox_changed_
)
358 *mailbox
= texture_mailbox_
;
359 if (texture_mailbox_
.IsTexture()) {
361 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback
));
362 } else if (texture_mailbox_
.IsSharedMemory()) {
363 *release_callback
= cc::SingleReleaseCallback::Create(
364 base::Bind(&ReleaseSharedMemory
, base::Passed(&shared_bitmap_
)));
366 mailbox_changed_
= false;
370 TestPlugin::Primitive
TestPlugin::ParsePrimitive(
371 const blink::WebString
& string
) {
372 const CR_DEFINE_STATIC_LOCAL(blink::WebString
, kPrimitiveNone
, ("none"));
373 const CR_DEFINE_STATIC_LOCAL(
374 blink::WebString
, kPrimitiveTriangle
, ("triangle"));
376 Primitive primitive
= PrimitiveNone
;
377 if (string
== kPrimitiveNone
)
378 primitive
= PrimitiveNone
;
379 else if (string
== kPrimitiveTriangle
)
380 primitive
= PrimitiveTriangle
;
386 // FIXME: This method should already exist. Use it.
387 // For now just parse primary colors.
388 void TestPlugin::ParseColor(const blink::WebString
& string
, unsigned color
[3]) {
389 color
[0] = color
[1] = color
[2] = 0;
390 if (string
== "black")
395 else if (string
== "green")
397 else if (string
== "blue")
403 float TestPlugin::ParseOpacity(const blink::WebString
& string
) {
404 return static_cast<float>(atof(string
.utf8().data()));
407 bool TestPlugin::ParseBoolean(const blink::WebString
& string
) {
408 const CR_DEFINE_STATIC_LOCAL(blink::WebString
, kPrimitiveTrue
, ("true"));
409 return string
== kPrimitiveTrue
;
412 bool TestPlugin::InitScene() {
417 PremultiplyAlpha(scene_
.background_color
, scene_
.opacity
, color
);
419 color_texture_
= context_
->createTexture();
420 framebuffer_
= context_
->createFramebuffer();
422 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
423 context_
->disable(GL_DEPTH_TEST
);
424 context_
->disable(GL_SCISSOR_TEST
);
426 context_
->clearColor(color
[0], color
[1], color
[2], color
[3]);
428 context_
->enable(GL_BLEND
);
429 context_
->blendFunc(GL_ONE
, GL_ONE_MINUS_SRC_ALPHA
);
431 return scene_
.primitive
!= PrimitiveNone
? InitProgram() && InitPrimitive()
435 void TestPlugin::DrawSceneGL() {
436 context_
->viewport(0, 0, rect_
.width
, rect_
.height
);
437 context_
->clear(GL_COLOR_BUFFER_BIT
);
439 if (scene_
.primitive
!= PrimitiveNone
)
443 void TestPlugin::DrawSceneSoftware(void* memory
) {
444 SkColor background_color
=
445 SkColorSetARGB(static_cast<uint8
>(scene_
.opacity
* 255),
446 scene_
.background_color
[0],
447 scene_
.background_color
[1],
448 scene_
.background_color
[2]);
450 const SkImageInfo info
=
451 SkImageInfo::MakeN32Premul(rect_
.width
, rect_
.height
);
453 bitmap
.installPixels(info
, memory
, info
.minRowBytes());
454 SkCanvas
canvas(bitmap
);
455 canvas
.clear(background_color
);
457 if (scene_
.primitive
!= PrimitiveNone
) {
458 DCHECK_EQ(PrimitiveTriangle
, scene_
.primitive
);
459 SkColor foreground_color
=
460 SkColorSetARGB(static_cast<uint8
>(scene_
.opacity
* 255),
461 scene_
.primitive_color
[0],
462 scene_
.primitive_color
[1],
463 scene_
.primitive_color
[2]);
464 SkPath triangle_path
;
465 triangle_path
.moveTo(0.5f
* rect_
.width
, 0.9f
* rect_
.height
);
466 triangle_path
.lineTo(0.1f
* rect_
.width
, 0.1f
* rect_
.height
);
467 triangle_path
.lineTo(0.9f
* rect_
.width
, 0.1f
* rect_
.height
);
469 paint
.setColor(foreground_color
);
470 paint
.setStyle(SkPaint::kFill_Style
);
471 canvas
.drawPath(triangle_path
, paint
);
475 void TestPlugin::DestroyScene() {
476 if (scene_
.program
) {
477 context_
->deleteProgram(scene_
.program
);
481 context_
->deleteBuffer(scene_
.vbo
);
486 context_
->deleteFramebuffer(framebuffer_
);
490 if (color_texture_
) {
491 context_
->deleteTexture(color_texture_
);
496 bool TestPlugin::InitProgram() {
497 const std::string
vertex_source(
498 "attribute vec4 position; \n"
500 " gl_Position = position; \n"
503 const std::string
fragment_source(
504 "precision mediump float; \n"
505 "uniform vec4 color; \n"
507 " gl_FragColor = color; \n"
510 scene_
.program
= LoadProgram(vertex_source
, fragment_source
);
514 scene_
.color_location
= context_
->getUniformLocation(scene_
.program
, "color");
515 scene_
.position_location
=
516 context_
->getAttribLocation(scene_
.program
, "position");
520 bool TestPlugin::InitPrimitive() {
521 DCHECK_EQ(scene_
.primitive
, PrimitiveTriangle
);
523 scene_
.vbo
= context_
->createBuffer();
527 const float vertices
[] = {0.0f
, 0.8f
, 0.0f
, -0.8f
, -0.8f
,
528 0.0f
, 0.8f
, -0.8f
, 0.0f
};
529 context_
->bindBuffer(GL_ARRAY_BUFFER
, scene_
.vbo
);
530 context_
->bufferData(GL_ARRAY_BUFFER
, sizeof(vertices
), 0, GL_STATIC_DRAW
);
531 context_
->bufferSubData(GL_ARRAY_BUFFER
, 0, sizeof(vertices
), vertices
);
535 void TestPlugin::DrawPrimitive() {
536 DCHECK_EQ(scene_
.primitive
, PrimitiveTriangle
);
538 DCHECK(scene_
.program
);
540 context_
->useProgram(scene_
.program
);
542 // Bind primitive color.
544 PremultiplyAlpha(scene_
.primitive_color
, scene_
.opacity
, color
);
546 scene_
.color_location
, color
[0], color
[1], color
[2], color
[3]);
548 // Bind primitive vertices.
549 context_
->bindBuffer(GL_ARRAY_BUFFER
, scene_
.vbo
);
550 context_
->enableVertexAttribArray(scene_
.position_location
);
551 context_
->vertexAttribPointer(
552 scene_
.position_location
, 3, GL_FLOAT
, GL_FALSE
, 0, 0);
553 context_
->drawArrays(GL_TRIANGLES
, 0, 3);
556 unsigned TestPlugin::LoadShader(unsigned type
, const std::string
& source
) {
557 unsigned shader
= context_
->createShader(type
);
559 context_
->shaderSource(shader
, source
.data());
560 context_
->compileShader(shader
);
563 context_
->getShaderiv(shader
, GL_COMPILE_STATUS
, &compiled
);
565 context_
->deleteShader(shader
);
572 unsigned TestPlugin::LoadProgram(const std::string
& vertex_source
,
573 const std::string
& fragment_source
) {
574 unsigned vertex_shader
= LoadShader(GL_VERTEX_SHADER
, vertex_source
);
575 unsigned fragment_shader
= LoadShader(GL_FRAGMENT_SHADER
, fragment_source
);
576 unsigned program
= context_
->createProgram();
577 if (vertex_shader
&& fragment_shader
&& program
) {
578 context_
->attachShader(program
, vertex_shader
);
579 context_
->attachShader(program
, fragment_shader
);
580 context_
->linkProgram(program
);
583 context_
->getProgramiv(program
, GL_LINK_STATUS
, &linked
);
585 context_
->deleteProgram(program
);
590 context_
->deleteShader(vertex_shader
);
592 context_
->deleteShader(fragment_shader
);
597 bool TestPlugin::handleInputEvent(const blink::WebInputEvent
& event
,
598 blink::WebCursorInfo
& info
) {
599 const char* event_name
= 0;
600 switch (event
.type
) {
601 case blink::WebInputEvent::Undefined
:
602 event_name
= "unknown";
605 case blink::WebInputEvent::MouseDown
:
606 event_name
= "MouseDown";
608 case blink::WebInputEvent::MouseUp
:
609 event_name
= "MouseUp";
611 case blink::WebInputEvent::MouseMove
:
612 event_name
= "MouseMove";
614 case blink::WebInputEvent::MouseEnter
:
615 event_name
= "MouseEnter";
617 case blink::WebInputEvent::MouseLeave
:
618 event_name
= "MouseLeave";
620 case blink::WebInputEvent::ContextMenu
:
621 event_name
= "ContextMenu";
624 case blink::WebInputEvent::MouseWheel
:
625 event_name
= "MouseWheel";
628 case blink::WebInputEvent::RawKeyDown
:
629 event_name
= "RawKeyDown";
631 case blink::WebInputEvent::KeyDown
:
632 event_name
= "KeyDown";
634 case blink::WebInputEvent::KeyUp
:
635 event_name
= "KeyUp";
637 case blink::WebInputEvent::Char
:
641 case blink::WebInputEvent::GestureScrollBegin
:
642 event_name
= "GestureScrollBegin";
644 case blink::WebInputEvent::GestureScrollEnd
:
645 event_name
= "GestureScrollEnd";
647 case blink::WebInputEvent::GestureScrollUpdate
:
648 event_name
= "GestureScrollUpdate";
650 case blink::WebInputEvent::GestureFlingStart
:
651 event_name
= "GestureFlingStart";
653 case blink::WebInputEvent::GestureFlingCancel
:
654 event_name
= "GestureFlingCancel";
656 case blink::WebInputEvent::GestureTap
:
657 event_name
= "GestureTap";
659 case blink::WebInputEvent::GestureTapUnconfirmed
:
660 event_name
= "GestureTapUnconfirmed";
662 case blink::WebInputEvent::GestureTapDown
:
663 event_name
= "GestureTapDown";
665 case blink::WebInputEvent::GestureShowPress
:
666 event_name
= "GestureShowPress";
668 case blink::WebInputEvent::GestureTapCancel
:
669 event_name
= "GestureTapCancel";
671 case blink::WebInputEvent::GestureDoubleTap
:
672 event_name
= "GestureDoubleTap";
674 case blink::WebInputEvent::GestureTwoFingerTap
:
675 event_name
= "GestureTwoFingerTap";
677 case blink::WebInputEvent::GestureLongPress
:
678 event_name
= "GestureLongPress";
680 case blink::WebInputEvent::GestureLongTap
:
681 event_name
= "GestureLongTap";
683 case blink::WebInputEvent::GesturePinchBegin
:
684 event_name
= "GesturePinchBegin";
686 case blink::WebInputEvent::GesturePinchEnd
:
687 event_name
= "GesturePinchEnd";
689 case blink::WebInputEvent::GesturePinchUpdate
:
690 event_name
= "GesturePinchUpdate";
693 case blink::WebInputEvent::TouchStart
:
694 event_name
= "TouchStart";
696 case blink::WebInputEvent::TouchMove
:
697 event_name
= "TouchMove";
699 case blink::WebInputEvent::TouchEnd
:
700 event_name
= "TouchEnd";
702 case blink::WebInputEvent::TouchCancel
:
703 event_name
= "TouchCancel";
706 NOTREACHED() << "Received unexpected event type: " << event
.type
;
707 event_name
= "unknown";
711 delegate_
->PrintMessage(std::string("Plugin received event: ") +
712 (event_name
? event_name
: "unknown") + "\n");
713 if (print_event_details_
)
714 PrintEventDetails(delegate_
, event
);
715 if (print_user_gesture_status_
)
716 delegate_
->PrintMessage(
718 (blink::WebUserGestureIndicator::isProcessingUserGesture() ? ""
720 "handling user gesture\n");
722 delegate_
->PrintMessage(std::string("TestPlugin: isPersistent\n"));
726 bool TestPlugin::handleDragStatusUpdate(
727 blink::WebDragStatus drag_status
,
728 const blink::WebDragData
& data
,
729 blink::WebDragOperationsMask mask
,
730 const blink::WebPoint
& position
,
731 const blink::WebPoint
& screen_position
) {
732 const char* drag_status_name
= 0;
733 switch (drag_status
) {
734 case blink::WebDragStatusEnter
:
735 drag_status_name
= "DragEnter";
737 case blink::WebDragStatusOver
:
738 drag_status_name
= "DragOver";
740 case blink::WebDragStatusLeave
:
741 drag_status_name
= "DragLeave";
743 case blink::WebDragStatusDrop
:
744 drag_status_name
= "DragDrop";
746 case blink::WebDragStatusUnknown
:
749 delegate_
->PrintMessage(std::string("Plugin received event: ") +
750 drag_status_name
+ "\n");
754 TestPlugin
* TestPlugin::create(blink::WebFrame
* frame
,
755 const blink::WebPluginParams
& params
,
756 WebTestDelegate
* delegate
) {
757 return new TestPlugin(frame
, params
, delegate
);
760 const blink::WebString
& TestPlugin::MimeType() {
761 const CR_DEFINE_STATIC_LOCAL(
762 blink::WebString
, kMimeType
, ("application/x-webkit-test-webplugin"));
766 const blink::WebString
& TestPlugin::CanCreateWithoutRendererMimeType() {
767 const CR_DEFINE_STATIC_LOCAL(
769 kCanCreateWithoutRendererMimeType
,
770 ("application/x-webkit-test-webplugin-can-create-without-renderer"));
771 return kCanCreateWithoutRendererMimeType
;
774 const blink::WebString
& TestPlugin::PluginPersistsMimeType() {
775 const CR_DEFINE_STATIC_LOCAL(
777 kPluginPersistsMimeType
,
778 ("application/x-webkit-test-webplugin-persistent"));
779 return kPluginPersistsMimeType
;
782 bool TestPlugin::IsSupportedMimeType(const blink::WebString
& mime_type
) {
783 return mime_type
== TestPlugin::MimeType() ||
784 mime_type
== PluginPersistsMimeType() ||
785 mime_type
== CanCreateWithoutRendererMimeType();
788 } // namespace test_runner