Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / components / test_runner / test_plugin.cc
blobf2fc97afcbcc3ed3858f68f256825770467716f3
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/WebTaskRunner.h"
18 #include "third_party/WebKit/public/platform/WebThread.h"
19 #include "third_party/WebKit/public/platform/WebTraceLocation.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 #include "third_party/skia/include/core/SkBitmap.h"
27 #include "third_party/skia/include/core/SkCanvas.h"
28 #include "third_party/skia/include/core/SkColor.h"
29 #include "third_party/skia/include/core/SkPaint.h"
30 #include "third_party/skia/include/core/SkPath.h"
32 namespace test_runner {
34 namespace {
36 // GLenum values copied from gl2.h.
37 #define GL_FALSE 0
38 #define GL_TRUE 1
39 #define GL_ONE 1
40 #define GL_TRIANGLES 0x0004
41 #define GL_ONE_MINUS_SRC_ALPHA 0x0303
42 #define GL_DEPTH_TEST 0x0B71
43 #define GL_BLEND 0x0BE2
44 #define GL_SCISSOR_TEST 0x0B90
45 #define GL_TEXTURE_2D 0x0DE1
46 #define GL_FLOAT 0x1406
47 #define GL_RGBA 0x1908
48 #define GL_UNSIGNED_BYTE 0x1401
49 #define GL_TEXTURE_MAG_FILTER 0x2800
50 #define GL_TEXTURE_MIN_FILTER 0x2801
51 #define GL_TEXTURE_WRAP_S 0x2802
52 #define GL_TEXTURE_WRAP_T 0x2803
53 #define GL_NEAREST 0x2600
54 #define GL_COLOR_BUFFER_BIT 0x4000
55 #define GL_CLAMP_TO_EDGE 0x812F
56 #define GL_ARRAY_BUFFER 0x8892
57 #define GL_STATIC_DRAW 0x88E4
58 #define GL_FRAGMENT_SHADER 0x8B30
59 #define GL_VERTEX_SHADER 0x8B31
60 #define GL_COMPILE_STATUS 0x8B81
61 #define GL_LINK_STATUS 0x8B82
62 #define GL_COLOR_ATTACHMENT0 0x8CE0
63 #define GL_FRAMEBUFFER_COMPLETE 0x8CD5
64 #define GL_FRAMEBUFFER 0x8D40
66 void PremultiplyAlpha(const unsigned color_in[3],
67 float alpha,
68 float color_out[4]) {
69 for (int i = 0; i < 3; ++i)
70 color_out[i] = (color_in[i] / 255.0f) * alpha;
72 color_out[3] = alpha;
75 const char* PointState(blink::WebTouchPoint::State state) {
76 switch (state) {
77 case blink::WebTouchPoint::StateReleased:
78 return "Released";
79 case blink::WebTouchPoint::StatePressed:
80 return "Pressed";
81 case blink::WebTouchPoint::StateMoved:
82 return "Moved";
83 case blink::WebTouchPoint::StateCancelled:
84 return "Cancelled";
85 default:
86 return "Unknown";
90 void PrintTouchList(WebTestDelegate* delegate,
91 const blink::WebTouchPoint* points,
92 int length) {
93 for (int i = 0; i < length; ++i) {
94 delegate->PrintMessage(base::StringPrintf("* %.2f, %.2f: %s\n",
95 points[i].position.x,
96 points[i].position.y,
97 PointState(points[i].state)));
101 void PrintEventDetails(WebTestDelegate* delegate,
102 const blink::WebInputEvent& event) {
103 if (blink::WebInputEvent::isTouchEventType(event.type)) {
104 const blink::WebTouchEvent& touch =
105 static_cast<const blink::WebTouchEvent&>(event);
106 PrintTouchList(delegate, touch.touches, touch.touchesLength);
107 } else if (blink::WebInputEvent::isMouseEventType(event.type) ||
108 event.type == blink::WebInputEvent::MouseWheel) {
109 const blink::WebMouseEvent& mouse =
110 static_cast<const blink::WebMouseEvent&>(event);
111 delegate->PrintMessage(base::StringPrintf("* %d, %d\n", mouse.x, mouse.y));
112 } else if (blink::WebInputEvent::isGestureEventType(event.type)) {
113 const blink::WebGestureEvent& gesture =
114 static_cast<const blink::WebGestureEvent&>(event);
115 delegate->PrintMessage(
116 base::StringPrintf("* %d, %d\n", gesture.x, gesture.y));
120 blink::WebPluginContainer::TouchEventRequestType ParseTouchEventRequestType(
121 const blink::WebString& string) {
122 if (string == blink::WebString::fromUTF8("raw"))
123 return blink::WebPluginContainer::TouchEventRequestTypeRaw;
124 if (string == blink::WebString::fromUTF8("synthetic"))
125 return blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse;
126 return blink::WebPluginContainer::TouchEventRequestTypeNone;
129 class DeferredDeleteTask : public blink::WebTaskRunner::Task {
130 public:
131 DeferredDeleteTask(scoped_ptr<TestPlugin> plugin) : plugin_(plugin.Pass()) {}
133 void run() override {}
135 private:
136 scoped_ptr<TestPlugin> plugin_;
139 } // namespace
141 TestPlugin::TestPlugin(blink::WebFrame* frame,
142 const blink::WebPluginParams& params,
143 WebTestDelegate* delegate)
144 : frame_(frame),
145 delegate_(delegate),
146 container_(0),
147 context_(0),
148 color_texture_(0),
149 mailbox_changed_(false),
150 framebuffer_(0),
151 touch_event_request_(
152 blink::WebPluginContainer::TouchEventRequestTypeNone),
153 re_request_touch_events_(false),
154 print_event_details_(false),
155 print_user_gesture_status_(false),
156 can_process_drag_(false),
157 supports_keyboard_focus_(false),
158 is_persistent_(params.mimeType == PluginPersistsMimeType()),
159 can_create_without_renderer_(params.mimeType ==
160 CanCreateWithoutRendererMimeType()) {
161 const CR_DEFINE_STATIC_LOCAL(
162 blink::WebString, kAttributePrimitive, ("primitive"));
163 const CR_DEFINE_STATIC_LOCAL(
164 blink::WebString, kAttributeBackgroundColor, ("background-color"));
165 const CR_DEFINE_STATIC_LOCAL(
166 blink::WebString, kAttributePrimitiveColor, ("primitive-color"));
167 const CR_DEFINE_STATIC_LOCAL(
168 blink::WebString, kAttributeOpacity, ("opacity"));
169 const CR_DEFINE_STATIC_LOCAL(
170 blink::WebString, kAttributeAcceptsTouch, ("accepts-touch"));
171 const CR_DEFINE_STATIC_LOCAL(
172 blink::WebString, kAttributeReRequestTouchEvents, ("re-request-touch"));
173 const CR_DEFINE_STATIC_LOCAL(
174 blink::WebString, kAttributePrintEventDetails, ("print-event-details"));
175 const CR_DEFINE_STATIC_LOCAL(
176 blink::WebString, kAttributeCanProcessDrag, ("can-process-drag"));
177 const CR_DEFINE_STATIC_LOCAL(blink::WebString,
178 kAttributeSupportsKeyboardFocus,
179 ("supports-keyboard-focus"));
180 const CR_DEFINE_STATIC_LOCAL(blink::WebString,
181 kAttributePrintUserGestureStatus,
182 ("print-user-gesture-status"));
184 DCHECK_EQ(params.attributeNames.size(), params.attributeValues.size());
185 size_t size = params.attributeNames.size();
186 for (size_t i = 0; i < size; ++i) {
187 const blink::WebString& attribute_name = params.attributeNames[i];
188 const blink::WebString& attribute_value = params.attributeValues[i];
190 if (attribute_name == kAttributePrimitive)
191 scene_.primitive = ParsePrimitive(attribute_value);
192 else if (attribute_name == kAttributeBackgroundColor)
193 ParseColor(attribute_value, scene_.background_color);
194 else if (attribute_name == kAttributePrimitiveColor)
195 ParseColor(attribute_value, scene_.primitive_color);
196 else if (attribute_name == kAttributeOpacity)
197 scene_.opacity = ParseOpacity(attribute_value);
198 else if (attribute_name == kAttributeAcceptsTouch)
199 touch_event_request_ = ParseTouchEventRequestType(attribute_value);
200 else if (attribute_name == kAttributeReRequestTouchEvents)
201 re_request_touch_events_ = ParseBoolean(attribute_value);
202 else if (attribute_name == kAttributePrintEventDetails)
203 print_event_details_ = ParseBoolean(attribute_value);
204 else if (attribute_name == kAttributeCanProcessDrag)
205 can_process_drag_ = ParseBoolean(attribute_value);
206 else if (attribute_name == kAttributeSupportsKeyboardFocus)
207 supports_keyboard_focus_ = ParseBoolean(attribute_value);
208 else if (attribute_name == kAttributePrintUserGestureStatus)
209 print_user_gesture_status_ = ParseBoolean(attribute_value);
211 if (can_create_without_renderer_)
212 delegate_->PrintMessage(
213 std::string("TestPlugin: canCreateWithoutRenderer\n"));
216 TestPlugin::~TestPlugin() {
219 bool TestPlugin::initialize(blink::WebPluginContainer* container) {
220 blink::WebGraphicsContext3D::Attributes attrs;
221 context_ =
222 blink::Platform::current()->createOffscreenGraphicsContext3D(attrs);
224 if (!InitScene())
225 return false;
227 layer_ = delegate_->CreateTextureLayerForMailbox(this);
228 web_layer_ = make_scoped_ptr(delegate_->InstantiateWebLayer(layer_));
229 container_ = container;
230 container_->setWebLayer(web_layer_.get());
231 if (re_request_touch_events_) {
232 container_->requestTouchEventType(
233 blink::WebPluginContainer::TouchEventRequestTypeSynthesizedMouse);
234 container_->requestTouchEventType(
235 blink::WebPluginContainer::TouchEventRequestTypeRaw);
237 container_->requestTouchEventType(touch_event_request_);
238 container_->setWantsWheelEvents(true);
239 return true;
242 void TestPlugin::destroy() {
243 if (layer_.get())
244 layer_->ClearTexture();
245 if (container_)
246 container_->setWebLayer(0);
247 web_layer_.reset();
248 layer_ = NULL;
249 DestroyScene();
251 delete context_;
252 context_ = 0;
254 container_ = 0;
255 frame_ = 0;
257 blink::Platform::current()->mainThread()->taskRunner()->postTask(
258 blink::WebTraceLocation(__FUNCTION__, __FILE__),
259 new DeferredDeleteTask(make_scoped_ptr(this)));
262 NPObject* TestPlugin::scriptableObject() {
263 return 0;
266 bool TestPlugin::canProcessDrag() const {
267 return can_process_drag_;
270 bool TestPlugin::supportsKeyboardFocus() const {
271 return supports_keyboard_focus_;
274 void TestPlugin::updateGeometry(
275 const blink::WebRect& window_rect,
276 const blink::WebRect& clip_rect,
277 const blink::WebRect& unobscured_rect,
278 const blink::WebVector<blink::WebRect>& cut_outs_rects,
279 bool is_visible) {
280 if (clip_rect == rect_)
281 return;
282 rect_ = clip_rect;
284 if (rect_.isEmpty()) {
285 texture_mailbox_ = cc::TextureMailbox();
286 } else if (context_) {
287 context_->viewport(0, 0, rect_.width, rect_.height);
289 context_->bindTexture(GL_TEXTURE_2D, color_texture_);
290 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MAG_FILTER, GL_NEAREST);
291 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_MIN_FILTER, GL_NEAREST);
292 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_S, GL_CLAMP_TO_EDGE);
293 context_->texParameteri(GL_TEXTURE_2D, GL_TEXTURE_WRAP_T, GL_CLAMP_TO_EDGE);
294 context_->texImage2D(GL_TEXTURE_2D,
296 GL_RGBA,
297 rect_.width,
298 rect_.height,
300 GL_RGBA,
301 GL_UNSIGNED_BYTE,
303 context_->bindFramebuffer(GL_FRAMEBUFFER, framebuffer_);
304 context_->framebufferTexture2D(
305 GL_FRAMEBUFFER, GL_COLOR_ATTACHMENT0, GL_TEXTURE_2D, color_texture_, 0);
307 DrawSceneGL();
309 gpu::Mailbox mailbox;
310 context_->genMailboxCHROMIUM(mailbox.name);
311 context_->produceTextureCHROMIUM(GL_TEXTURE_2D, mailbox.name);
312 context_->flush();
313 uint32 sync_point = context_->insertSyncPoint();
314 texture_mailbox_ = cc::TextureMailbox(mailbox, GL_TEXTURE_2D, sync_point);
315 } else {
316 scoped_ptr<cc::SharedBitmap> bitmap =
317 delegate_->GetSharedBitmapManager()->AllocateSharedBitmap(
318 gfx::Rect(rect_).size());
319 if (!bitmap) {
320 texture_mailbox_ = cc::TextureMailbox();
321 } else {
322 DrawSceneSoftware(bitmap->pixels());
323 texture_mailbox_ = cc::TextureMailbox(
324 bitmap.get(), gfx::Size(rect_.width, rect_.height));
325 shared_bitmap_ = bitmap.Pass();
329 mailbox_changed_ = true;
330 layer_->SetNeedsDisplay();
333 bool TestPlugin::acceptsInputEvents() {
334 return true;
337 bool TestPlugin::isPlaceholder() {
338 return false;
341 static void IgnoreReleaseCallback(uint32 sync_point, bool lost) {
344 static void ReleaseSharedMemory(scoped_ptr<cc::SharedBitmap> bitmap,
345 uint32 sync_point,
346 bool lost) {
349 bool TestPlugin::PrepareTextureMailbox(
350 cc::TextureMailbox* mailbox,
351 scoped_ptr<cc::SingleReleaseCallback>* release_callback,
352 bool use_shared_memory) {
353 if (!mailbox_changed_)
354 return false;
355 *mailbox = texture_mailbox_;
356 if (texture_mailbox_.IsTexture()) {
357 *release_callback =
358 cc::SingleReleaseCallback::Create(base::Bind(&IgnoreReleaseCallback));
359 } else if (texture_mailbox_.IsSharedMemory()) {
360 *release_callback = cc::SingleReleaseCallback::Create(
361 base::Bind(&ReleaseSharedMemory, base::Passed(&shared_bitmap_)));
363 mailbox_changed_ = false;
364 return true;
367 TestPlugin::Primitive TestPlugin::ParsePrimitive(
368 const blink::WebString& string) {
369 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveNone, ("none"));
370 const CR_DEFINE_STATIC_LOCAL(
371 blink::WebString, kPrimitiveTriangle, ("triangle"));
373 Primitive primitive = PrimitiveNone;
374 if (string == kPrimitiveNone)
375 primitive = PrimitiveNone;
376 else if (string == kPrimitiveTriangle)
377 primitive = PrimitiveTriangle;
378 else
379 NOTREACHED();
380 return primitive;
383 // FIXME: This method should already exist. Use it.
384 // For now just parse primary colors.
385 void TestPlugin::ParseColor(const blink::WebString& string, unsigned color[3]) {
386 color[0] = color[1] = color[2] = 0;
387 if (string == "black")
388 return;
390 if (string == "red")
391 color[0] = 255;
392 else if (string == "green")
393 color[1] = 255;
394 else if (string == "blue")
395 color[2] = 255;
396 else
397 NOTREACHED();
400 float TestPlugin::ParseOpacity(const blink::WebString& string) {
401 return static_cast<float>(atof(string.utf8().data()));
404 bool TestPlugin::ParseBoolean(const blink::WebString& string) {
405 const CR_DEFINE_STATIC_LOCAL(blink::WebString, kPrimitiveTrue, ("true"));
406 return string == kPrimitiveTrue;
409 bool TestPlugin::InitScene() {
410 if (!context_)
411 return true;
413 float color[4];
414 PremultiplyAlpha(scene_.background_color, scene_.opacity, color);
416 color_texture_ = context_->createTexture();
417 framebuffer_ = context_->createFramebuffer();
419 context_->viewport(0, 0, rect_.width, rect_.height);
420 context_->disable(GL_DEPTH_TEST);
421 context_->disable(GL_SCISSOR_TEST);
423 context_->clearColor(color[0], color[1], color[2], color[3]);
425 context_->enable(GL_BLEND);
426 context_->blendFunc(GL_ONE, GL_ONE_MINUS_SRC_ALPHA);
428 return scene_.primitive != PrimitiveNone ? InitProgram() && InitPrimitive()
429 : true;
432 void TestPlugin::DrawSceneGL() {
433 context_->viewport(0, 0, rect_.width, rect_.height);
434 context_->clear(GL_COLOR_BUFFER_BIT);
436 if (scene_.primitive != PrimitiveNone)
437 DrawPrimitive();
440 void TestPlugin::DrawSceneSoftware(void* memory) {
441 SkColor background_color =
442 SkColorSetARGB(static_cast<uint8>(scene_.opacity * 255),
443 scene_.background_color[0],
444 scene_.background_color[1],
445 scene_.background_color[2]);
447 const SkImageInfo info =
448 SkImageInfo::MakeN32Premul(rect_.width, rect_.height);
449 SkBitmap bitmap;
450 bitmap.installPixels(info, memory, info.minRowBytes());
451 SkCanvas canvas(bitmap);
452 canvas.clear(background_color);
454 if (scene_.primitive != PrimitiveNone) {
455 DCHECK_EQ(PrimitiveTriangle, scene_.primitive);
456 SkColor foreground_color =
457 SkColorSetARGB(static_cast<uint8>(scene_.opacity * 255),
458 scene_.primitive_color[0],
459 scene_.primitive_color[1],
460 scene_.primitive_color[2]);
461 SkPath triangle_path;
462 triangle_path.moveTo(0.5f * rect_.width, 0.9f * rect_.height);
463 triangle_path.lineTo(0.1f * rect_.width, 0.1f * rect_.height);
464 triangle_path.lineTo(0.9f * rect_.width, 0.1f * rect_.height);
465 SkPaint paint;
466 paint.setColor(foreground_color);
467 paint.setStyle(SkPaint::kFill_Style);
468 canvas.drawPath(triangle_path, paint);
472 void TestPlugin::DestroyScene() {
473 if (scene_.program) {
474 context_->deleteProgram(scene_.program);
475 scene_.program = 0;
477 if (scene_.vbo) {
478 context_->deleteBuffer(scene_.vbo);
479 scene_.vbo = 0;
482 if (framebuffer_) {
483 context_->deleteFramebuffer(framebuffer_);
484 framebuffer_ = 0;
487 if (color_texture_) {
488 context_->deleteTexture(color_texture_);
489 color_texture_ = 0;
493 bool TestPlugin::InitProgram() {
494 const std::string vertex_source(
495 "attribute vec4 position; \n"
496 "void main() { \n"
497 " gl_Position = position; \n"
498 "} \n");
500 const std::string fragment_source(
501 "precision mediump float; \n"
502 "uniform vec4 color; \n"
503 "void main() { \n"
504 " gl_FragColor = color; \n"
505 "} \n");
507 scene_.program = LoadProgram(vertex_source, fragment_source);
508 if (!scene_.program)
509 return false;
511 scene_.color_location = context_->getUniformLocation(scene_.program, "color");
512 scene_.position_location =
513 context_->getAttribLocation(scene_.program, "position");
514 return true;
517 bool TestPlugin::InitPrimitive() {
518 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
520 scene_.vbo = context_->createBuffer();
521 if (!scene_.vbo)
522 return false;
524 const float vertices[] = {0.0f, 0.8f, 0.0f, -0.8f, -0.8f,
525 0.0f, 0.8f, -0.8f, 0.0f};
526 context_->bindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
527 context_->bufferData(GL_ARRAY_BUFFER, sizeof(vertices), 0, GL_STATIC_DRAW);
528 context_->bufferSubData(GL_ARRAY_BUFFER, 0, sizeof(vertices), vertices);
529 return true;
532 void TestPlugin::DrawPrimitive() {
533 DCHECK_EQ(scene_.primitive, PrimitiveTriangle);
534 DCHECK(scene_.vbo);
535 DCHECK(scene_.program);
537 context_->useProgram(scene_.program);
539 // Bind primitive color.
540 float color[4];
541 PremultiplyAlpha(scene_.primitive_color, scene_.opacity, color);
542 context_->uniform4f(
543 scene_.color_location, color[0], color[1], color[2], color[3]);
545 // Bind primitive vertices.
546 context_->bindBuffer(GL_ARRAY_BUFFER, scene_.vbo);
547 context_->enableVertexAttribArray(scene_.position_location);
548 context_->vertexAttribPointer(
549 scene_.position_location, 3, GL_FLOAT, GL_FALSE, 0, 0);
550 context_->drawArrays(GL_TRIANGLES, 0, 3);
553 unsigned TestPlugin::LoadShader(unsigned type, const std::string& source) {
554 unsigned shader = context_->createShader(type);
555 if (shader) {
556 context_->shaderSource(shader, source.data());
557 context_->compileShader(shader);
559 int compiled = 0;
560 context_->getShaderiv(shader, GL_COMPILE_STATUS, &compiled);
561 if (!compiled) {
562 context_->deleteShader(shader);
563 shader = 0;
566 return shader;
569 unsigned TestPlugin::LoadProgram(const std::string& vertex_source,
570 const std::string& fragment_source) {
571 unsigned vertex_shader = LoadShader(GL_VERTEX_SHADER, vertex_source);
572 unsigned fragment_shader = LoadShader(GL_FRAGMENT_SHADER, fragment_source);
573 unsigned program = context_->createProgram();
574 if (vertex_shader && fragment_shader && program) {
575 context_->attachShader(program, vertex_shader);
576 context_->attachShader(program, fragment_shader);
577 context_->linkProgram(program);
579 int linked = 0;
580 context_->getProgramiv(program, GL_LINK_STATUS, &linked);
581 if (!linked) {
582 context_->deleteProgram(program);
583 program = 0;
586 if (vertex_shader)
587 context_->deleteShader(vertex_shader);
588 if (fragment_shader)
589 context_->deleteShader(fragment_shader);
591 return program;
594 bool TestPlugin::handleInputEvent(const blink::WebInputEvent& event,
595 blink::WebCursorInfo& info) {
596 const char* event_name = 0;
597 switch (event.type) {
598 case blink::WebInputEvent::Undefined:
599 event_name = "unknown";
600 break;
602 case blink::WebInputEvent::MouseDown:
603 event_name = "MouseDown";
604 break;
605 case blink::WebInputEvent::MouseUp:
606 event_name = "MouseUp";
607 break;
608 case blink::WebInputEvent::MouseMove:
609 event_name = "MouseMove";
610 break;
611 case blink::WebInputEvent::MouseEnter:
612 event_name = "MouseEnter";
613 break;
614 case blink::WebInputEvent::MouseLeave:
615 event_name = "MouseLeave";
616 break;
617 case blink::WebInputEvent::ContextMenu:
618 event_name = "ContextMenu";
619 break;
621 case blink::WebInputEvent::MouseWheel:
622 event_name = "MouseWheel";
623 break;
625 case blink::WebInputEvent::RawKeyDown:
626 event_name = "RawKeyDown";
627 break;
628 case blink::WebInputEvent::KeyDown:
629 event_name = "KeyDown";
630 break;
631 case blink::WebInputEvent::KeyUp:
632 event_name = "KeyUp";
633 break;
634 case blink::WebInputEvent::Char:
635 event_name = "Char";
636 break;
638 case blink::WebInputEvent::GestureScrollBegin:
639 event_name = "GestureScrollBegin";
640 break;
641 case blink::WebInputEvent::GestureScrollEnd:
642 event_name = "GestureScrollEnd";
643 break;
644 case blink::WebInputEvent::GestureScrollUpdate:
645 event_name = "GestureScrollUpdate";
646 break;
647 case blink::WebInputEvent::GestureFlingStart:
648 event_name = "GestureFlingStart";
649 break;
650 case blink::WebInputEvent::GestureFlingCancel:
651 event_name = "GestureFlingCancel";
652 break;
653 case blink::WebInputEvent::GestureTap:
654 event_name = "GestureTap";
655 break;
656 case blink::WebInputEvent::GestureTapUnconfirmed:
657 event_name = "GestureTapUnconfirmed";
658 break;
659 case blink::WebInputEvent::GestureTapDown:
660 event_name = "GestureTapDown";
661 break;
662 case blink::WebInputEvent::GestureShowPress:
663 event_name = "GestureShowPress";
664 break;
665 case blink::WebInputEvent::GestureTapCancel:
666 event_name = "GestureTapCancel";
667 break;
668 case blink::WebInputEvent::GestureDoubleTap:
669 event_name = "GestureDoubleTap";
670 break;
671 case blink::WebInputEvent::GestureTwoFingerTap:
672 event_name = "GestureTwoFingerTap";
673 break;
674 case blink::WebInputEvent::GestureLongPress:
675 event_name = "GestureLongPress";
676 break;
677 case blink::WebInputEvent::GestureLongTap:
678 event_name = "GestureLongTap";
679 break;
680 case blink::WebInputEvent::GesturePinchBegin:
681 event_name = "GesturePinchBegin";
682 break;
683 case blink::WebInputEvent::GesturePinchEnd:
684 event_name = "GesturePinchEnd";
685 break;
686 case blink::WebInputEvent::GesturePinchUpdate:
687 event_name = "GesturePinchUpdate";
688 break;
690 case blink::WebInputEvent::TouchStart:
691 event_name = "TouchStart";
692 break;
693 case blink::WebInputEvent::TouchMove:
694 event_name = "TouchMove";
695 break;
696 case blink::WebInputEvent::TouchEnd:
697 event_name = "TouchEnd";
698 break;
699 case blink::WebInputEvent::TouchCancel:
700 event_name = "TouchCancel";
701 break;
702 default:
703 NOTREACHED() << "Received unexpected event type: " << event.type;
704 event_name = "unknown";
705 break;
708 delegate_->PrintMessage(std::string("Plugin received event: ") +
709 (event_name ? event_name : "unknown") + "\n");
710 if (print_event_details_)
711 PrintEventDetails(delegate_, event);
712 if (print_user_gesture_status_)
713 delegate_->PrintMessage(
714 std::string("* ") +
715 (blink::WebUserGestureIndicator::isProcessingUserGesture() ? ""
716 : "not ") +
717 "handling user gesture\n");
718 if (is_persistent_)
719 delegate_->PrintMessage(std::string("TestPlugin: isPersistent\n"));
720 return false;
723 bool TestPlugin::handleDragStatusUpdate(
724 blink::WebDragStatus drag_status,
725 const blink::WebDragData& data,
726 blink::WebDragOperationsMask mask,
727 const blink::WebPoint& position,
728 const blink::WebPoint& screen_position) {
729 const char* drag_status_name = 0;
730 switch (drag_status) {
731 case blink::WebDragStatusEnter:
732 drag_status_name = "DragEnter";
733 break;
734 case blink::WebDragStatusOver:
735 drag_status_name = "DragOver";
736 break;
737 case blink::WebDragStatusLeave:
738 drag_status_name = "DragLeave";
739 break;
740 case blink::WebDragStatusDrop:
741 drag_status_name = "DragDrop";
742 break;
743 case blink::WebDragStatusUnknown:
744 NOTREACHED();
746 delegate_->PrintMessage(std::string("Plugin received event: ") +
747 drag_status_name + "\n");
748 return false;
751 TestPlugin* TestPlugin::create(blink::WebFrame* frame,
752 const blink::WebPluginParams& params,
753 WebTestDelegate* delegate) {
754 return new TestPlugin(frame, params, delegate);
757 const blink::WebString& TestPlugin::MimeType() {
758 const CR_DEFINE_STATIC_LOCAL(
759 blink::WebString, kMimeType, ("application/x-webkit-test-webplugin"));
760 return kMimeType;
763 const blink::WebString& TestPlugin::CanCreateWithoutRendererMimeType() {
764 const CR_DEFINE_STATIC_LOCAL(
765 blink::WebString,
766 kCanCreateWithoutRendererMimeType,
767 ("application/x-webkit-test-webplugin-can-create-without-renderer"));
768 return kCanCreateWithoutRendererMimeType;
771 const blink::WebString& TestPlugin::PluginPersistsMimeType() {
772 const CR_DEFINE_STATIC_LOCAL(
773 blink::WebString,
774 kPluginPersistsMimeType,
775 ("application/x-webkit-test-webplugin-persistent"));
776 return kPluginPersistsMimeType;
779 bool TestPlugin::IsSupportedMimeType(const blink::WebString& mime_type) {
780 return mime_type == TestPlugin::MimeType() ||
781 mime_type == PluginPersistsMimeType() ||
782 mime_type == CanCreateWithoutRendererMimeType();
785 } // namespace test_runner