Revert "Fix broken channel icon in chrome://help on CrOS" and try again
[chromium-blink-merge.git] / components / test_runner / test_plugin.cc
blob4b3d50064ff44374585478977ba3ab480a3829de
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"
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 "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 {
33 namespace {
35 // GLenum values copied from gl2.h.
36 #define GL_FALSE 0
37 #define GL_TRUE 1
38 #define GL_ONE 1
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],
66 float alpha,
67 float color_out[4]) {
68 for (int i = 0; i < 3; ++i)
69 color_out[i] = (color_in[i] / 255.0f) * alpha;
71 color_out[3] = alpha;
74 const char* PointState(blink::WebTouchPoint::State state) {
75 switch (state) {
76 case blink::WebTouchPoint::StateReleased:
77 return "Released";
78 case blink::WebTouchPoint::StatePressed:
79 return "Pressed";
80 case blink::WebTouchPoint::StateMoved:
81 return "Moved";
82 case blink::WebTouchPoint::StateCancelled:
83 return "Cancelled";
84 default:
85 return "Unknown";
89 void PrintTouchList(WebTestDelegate* delegate,
90 const blink::WebTouchPoint* points,
91 int length) {
92 for (int i = 0; i < length; ++i) {
93 delegate->PrintMessage(base::StringPrintf("* %.2f, %.2f: %s\n",
94 points[i].position.x,
95 points[i].position.y,
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 {
129 public:
130 DeferredDeleteTask(scoped_ptr<TestPlugin> plugin) : plugin_(plugin.Pass()) {}
132 void run() override {}
134 private:
135 scoped_ptr<TestPlugin> plugin_;
138 } // namespace
140 TestPlugin::TestPlugin(blink::WebFrame* frame,
141 const blink::WebPluginParams& params,
142 WebTestDelegate* delegate)
143 : frame_(frame),
144 delegate_(delegate),
145 container_(0),
146 context_(0),
147 color_texture_(0),
148 mailbox_changed_(false),
149 framebuffer_(0),
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;
220 context_ =
221 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs);
223 if (!InitScene())
224 return false;
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);
238 return true;
241 void TestPlugin::destroy() {
242 if (layer_.get())
243 layer_->ClearTexture();
244 if (container_)
245 container_->setWebLayer(0);
246 web_layer_.reset();
247 layer_ = NULL;
248 DestroyScene();
250 delete context_;
251 context_ = 0;
253 container_ = 0;
254 frame_ = 0;
256 blink::Platform::current()->mainThread()->postTask(
257 blink::WebTraceLocation(__FUNCTION__, __FILE__),
258 new DeferredDeleteTask(make_scoped_ptr(this)));
261 NPObject* TestPlugin::scriptableObject() {
262 return 0;
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,
278 bool is_visible) {
279 if (clip_rect == rect_)
280 return;
281 rect_ = clip_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,
295 GL_RGBA,
296 rect_.width,
297 rect_.height,
299 GL_RGBA,
300 GL_UNSIGNED_BYTE,
302 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
303 context_->framebufferTexture2D(
304 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture_, 0);
306 DrawSceneGL();
308 gpu::Mailbox mailbox;
309 context_->genMailboxCHROMIUM(mailbox.name);
310 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
311 context_->flush();
312 uint32 sync_point = context_->insertSyncPoint();
313 texture_mailbox_ = cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point);
314 } else {
315 scoped_ptr<cc::SharedBitmap> bitmap =
316 delegate_->GetSharedBitmapManager()->AllocateSharedBitmap(
317 gfx::Rect(rect_).size());
318 if (!bitmap) {
319 texture_mailbox_ = cc::TextureMailbox();
320 } else {
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() {
333 return true;
336 bool TestPlugin::isPlaceholder() {
337 return false;
340 static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {
343 static void ReleaseSharedMemory(scoped_ptr<cc::SharedBitmap> bitmap,
344 uint32 sync_point,
345 bool lost) {
348 bool TestPlugin::PrepareTextureMailbox(
349 cc::TextureMailbox* mailbox,
350 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
351 bool use_shared_memory) {
352 if (!mailbox_changed_)
353 return false;
354 *mailbox = texture_mailbox_;
355 if (texture_mailbox_.IsTexture()) {
356 *release_callback =
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;
363 return true;
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;
377 else
378 NOTREACHED();
379 return primitive;
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")
387 return;
389 if (string == "red")
390 color[0] = 255;
391 else if (string == "green")
392 color[1] = 255;
393 else if (string == "blue")
394 color[2] = 255;
395 else
396 NOTREACHED();
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() {
409 if (!context_)
410 return true;
412 float color[4];
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()
428 : true;
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)
436 DrawPrimitive();
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);
448 SkBitmap bitmap;
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);
464 SkPaint paint;
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);
474 scene_.program = 0;
476 if (scene_.vbo) {
477 context_->deleteBuffer(scene_.vbo);
478 scene_.vbo = 0;
481 if (framebuffer_) {
482 context_->deleteFramebuffer(framebuffer_);
483 framebuffer_ = 0;
486 if (color_texture_) {
487 context_->deleteTexture(color_texture_);
488 color_texture_ = 0;
492 bool TestPlugin::InitProgram() {
493 const std::string vertex_source(
494 "attribute vec4 position; \n"
495 "void main() { \n"
496 " gl_Position = position; \n"
497 "} \n");
499 const std::string fragment_source(
500 "precision mediump float; \n"
501 "uniform vec4 color; \n"
502 "void main() { \n"
503 " gl_FragColor = color; \n"
504 "} \n");
506 scene_.program = LoadProgram(vertex_source, fragment_source);
507 if (!scene_.program)
508 return false;
510 scene_.color_location = context_->getUniformLocation(scene_.program, "color");
511 scene_.position_location =
512 context_->getAttribLocation(scene_.program, "position");
513 return true;
516 bool TestPlugin::InitPrimitive() {
517 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
519 scene_.vbo = context_->createBuffer();
520 if (!scene_.vbo)
521 return false;
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);
528 return true;
531 void TestPlugin::DrawPrimitive() {
532 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
533 DCHECK(scene_.vbo);
534 DCHECK(scene_.program);
536 context_->useProgram(scene_.program);
538 // Bind primitive color.
539 float color[4];
540 PremultiplyAlpha(scene_.primitive_color, scene_.opacity, color);
541 context_->uniform4f(
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);
554 if (shader) {
555 context_->shaderSource(shader, source.data());
556 context_->compileShader(shader);
558 int compiled = 0;
559 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compiled);
560 if (!compiled) {
561 context_->deleteShader(shader);
562 shader = 0;
565 return 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);
578 int linked = 0;
579 context_->getProgramiv(program, GL_LINK_STATUS, &linked);
580 if (!linked) {
581 context_->deleteProgram(program);
582 program = 0;
585 if (vertex_shader)
586 context_->deleteShader(vertex_shader);
587 if (fragment_shader)
588 context_->deleteShader(fragment_shader);
590 return program;
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";
599 break;
601 case blink::WebInputEvent::MouseDown:
602 event_name = "MouseDown";
603 break;
604 case blink::WebInputEvent::MouseUp:
605 event_name = "MouseUp";
606 break;
607 case blink::WebInputEvent::MouseMove:
608 event_name = "MouseMove";
609 break;
610 case blink::WebInputEvent::MouseEnter:
611 event_name = "MouseEnter";
612 break;
613 case blink::WebInputEvent::MouseLeave:
614 event_name = "MouseLeave";
615 break;
616 case blink::WebInputEvent::ContextMenu:
617 event_name = "ContextMenu";
618 break;
620 case blink::WebInputEvent::MouseWheel:
621 event_name = "MouseWheel";
622 break;
624 case blink::WebInputEvent::RawKeyDown:
625 event_name = "RawKeyDown";
626 break;
627 case blink::WebInputEvent::KeyDown:
628 event_name = "KeyDown";
629 break;
630 case blink::WebInputEvent::KeyUp:
631 event_name = "KeyUp";
632 break;
633 case blink::WebInputEvent::Char:
634 event_name = "Char";
635 break;
637 case blink::WebInputEvent::GestureScrollBegin:
638 event_name = "GestureScrollBegin";
639 break;
640 case blink::WebInputEvent::GestureScrollEnd:
641 event_name = "GestureScrollEnd";
642 break;
643 case blink::WebInputEvent::GestureScrollUpdate:
644 event_name = "GestureScrollUpdate";
645 break;
646 case blink::WebInputEvent::GestureFlingStart:
647 event_name = "GestureFlingStart";
648 break;
649 case blink::WebInputEvent::GestureFlingCancel:
650 event_name = "GestureFlingCancel";
651 break;
652 case blink::WebInputEvent::GestureTap:
653 event_name = "GestureTap";
654 break;
655 case blink::WebInputEvent::GestureTapUnconfirmed:
656 event_name = "GestureTapUnconfirmed";
657 break;
658 case blink::WebInputEvent::GestureTapDown:
659 event_name = "GestureTapDown";
660 break;
661 case blink::WebInputEvent::GestureShowPress:
662 event_name = "GestureShowPress";
663 break;
664 case blink::WebInputEvent::GestureTapCancel:
665 event_name = "GestureTapCancel";
666 break;
667 case blink::WebInputEvent::GestureDoubleTap:
668 event_name = "GestureDoubleTap";
669 break;
670 case blink::WebInputEvent::GestureTwoFingerTap:
671 event_name = "GestureTwoFingerTap";
672 break;
673 case blink::WebInputEvent::GestureLongPress:
674 event_name = "GestureLongPress";
675 break;
676 case blink::WebInputEvent::GestureLongTap:
677 event_name = "GestureLongTap";
678 break;
679 case blink::WebInputEvent::GesturePinchBegin:
680 event_name = "GesturePinchBegin";
681 break;
682 case blink::WebInputEvent::GesturePinchEnd:
683 event_name = "GesturePinchEnd";
684 break;
685 case blink::WebInputEvent::GesturePinchUpdate:
686 event_name = "GesturePinchUpdate";
687 break;
689 case blink::WebInputEvent::TouchStart:
690 event_name = "TouchStart";
691 break;
692 case blink::WebInputEvent::TouchMove:
693 event_name = "TouchMove";
694 break;
695 case blink::WebInputEvent::TouchEnd:
696 event_name = "TouchEnd";
697 break;
698 case blink::WebInputEvent::TouchCancel:
699 event_name = "TouchCancel";
700 break;
701 default:
702 NOTREACHED() << "Received unexpected event type: " << event.type;
703 event_name = "unknown";
704 break;
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(
713 std::string("* ") +
714 (blink::WebUserGestureIndicator::isProcessingUserGesture() ? ""
715 : "not ") +
716 "handling user gesture\n");
717 if (is_persistent_)
718 delegate_->PrintMessage(std::string("TestPlugin: isPersistent\n"));
719 return false;
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";
732 break;
733 case blink::WebDragStatusOver:
734 drag_status_name = "DragOver";
735 break;
736 case blink::WebDragStatusLeave:
737 drag_status_name = "DragLeave";
738 break;
739 case blink::WebDragStatusDrop:
740 drag_status_name = "DragDrop";
741 break;
742 case blink::WebDragStatusUnknown:
743 NOTREACHED();
745 delegate_->PrintMessage(std::string("Plugin received event: ") +
746 drag_status_name + "\n");
747 return false;
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"));
759 return kMimeType;
762 const blink::WebString& TestPlugin::CanCreateWithoutRendererMimeType() {
763 const CR_DEFINE_STATIC_LOCAL(
764 blink::WebString,
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(
772 blink::WebString,
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