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

Side by Side Diff: components/test_runner/test_plugin.h

Issue 2707183003: Move //components/test_runner back into //content/shell (Closed)
Patch Set: Trim DEPS Created 3 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
(Empty)
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #ifndef COMPONENTS_TEST_RUNNER_TEST_PLUGIN_H_
6 #define COMPONENTS_TEST_RUNNER_TEST_PLUGIN_H_
7
8 #include <memory>
9 #include <string>
10
11 #include "base/macros.h"
12 #include "cc/layers/texture_layer.h"
13 #include "cc/layers/texture_layer_client.h"
14 #include "third_party/WebKit/public/platform/WebLayer.h"
15 #include "third_party/WebKit/public/web/WebDocument.h"
16 #include "third_party/WebKit/public/web/WebElement.h"
17 #include "third_party/WebKit/public/web/WebPlugin.h"
18 #include "third_party/WebKit/public/web/WebPluginContainer.h"
19 #include "third_party/khronos/GLES2/gl2.h"
20
21 namespace blink {
22 class WebFrame;
23 class WebGraphicsContext3DProvider;
24 class WebLayer;
25 struct WebPluginParams;
26 }
27
28 namespace cc {
29 class SharedBitmap;
30 }
31
32 namespace gpu {
33 namespace gles2 {
34 class GLES2Interface;
35 }
36 }
37
38 namespace test_runner {
39
40 class WebTestDelegate;
41
42 // A fake implemention of blink::WebPlugin for testing purposes.
43 //
44 // It uses GL to paint a scene consisiting of a primitive over a background. The
45 // primitive and background can be customized using the following plugin
46 // parameters.
47 // primitive: none (default), triangle.
48 // background-color: black (default), red, green, blue.
49 // primitive-color: black (default), red, green, blue.
50 // opacity: [0.0 - 1.0]. Default is 1.0.
51 //
52 // Whether the plugin accepts touch events or not can be customized using the
53 // 'accepts-touch' plugin parameter (defaults to false).
54 class TestPlugin : public blink::WebPlugin, public cc::TextureLayerClient {
55 public:
56 static TestPlugin* create(blink::WebFrame* frame,
57 const blink::WebPluginParams& params,
58 WebTestDelegate* delegate);
59 ~TestPlugin() override;
60
61 static const blink::WebString& MimeType();
62 static const blink::WebString& CanCreateWithoutRendererMimeType();
63 static const blink::WebString& PluginPersistsMimeType();
64 static bool IsSupportedMimeType(const blink::WebString& mime_type);
65
66 // WebPlugin methods:
67 bool initialize(blink::WebPluginContainer* container) override;
68 void destroy() override;
69 blink::WebPluginContainer* container() const override;
70 bool canProcessDrag() const override;
71 bool supportsKeyboardFocus() const override;
72 void updateAllLifecyclePhases() override {}
73 void paint(blink::WebCanvas* canvas, const blink::WebRect& rect) override {}
74 void updateGeometry(const blink::WebRect& window_rect,
75 const blink::WebRect& clip_rect,
76 const blink::WebRect& unobscured_rect,
77 const blink::WebVector<blink::WebRect>& cut_outs_rects,
78 bool is_visible) override;
79 void updateFocus(bool focus, blink::WebFocusType focus_type) override {}
80 void updateVisibility(bool visibility) override {}
81 blink::WebInputEventResult handleInputEvent(
82 const blink::WebInputEvent& event,
83 blink::WebCursorInfo& info) override;
84 bool handleDragStatusUpdate(blink::WebDragStatus drag_status,
85 const blink::WebDragData& data,
86 blink::WebDragOperationsMask mask,
87 const blink::WebPoint& position,
88 const blink::WebPoint& screen_position) override;
89 void didReceiveResponse(const blink::WebURLResponse& response) override {}
90 void didReceiveData(const char* data, int data_length) override {}
91 void didFinishLoading() override {}
92 void didFailLoading(const blink::WebURLError& error) override {}
93 bool isPlaceholder() override;
94
95 // cc::TextureLayerClient methods:
96 bool PrepareTextureMailbox(
97 cc::TextureMailbox* mailbox,
98 std::unique_ptr<cc::SingleReleaseCallback>* release_callback) override;
99
100 private:
101 TestPlugin(blink::WebFrame* frame,
102 const blink::WebPluginParams& params,
103 WebTestDelegate* delegate);
104
105 enum Primitive { PrimitiveNone, PrimitiveTriangle };
106
107 struct Scene {
108 Primitive primitive;
109 uint8_t background_color[3];
110 uint8_t primitive_color[3];
111 float opacity;
112
113 GLuint vbo;
114 GLuint program;
115 int color_location;
116 int position_location;
117
118 Scene()
119 : primitive(PrimitiveNone),
120 opacity(1.0f) // Fully opaque.
121 ,
122 vbo(0),
123 program(0),
124 color_location(-1),
125 position_location(-1) {
126 background_color[0] = background_color[1] = background_color[2] = 0;
127 primitive_color[0] = primitive_color[1] = primitive_color[2] = 0;
128 }
129 };
130
131 // Functions for parsing plugin parameters.
132 Primitive ParsePrimitive(const blink::WebString& string);
133 void ParseColor(const blink::WebString& string, uint8_t color[3]);
134 float ParseOpacity(const blink::WebString& string);
135 bool ParseBoolean(const blink::WebString& string);
136
137 // Functions for loading and drawing scene in GL.
138 bool InitScene();
139 void DrawSceneGL();
140 void DestroyScene();
141 bool InitProgram();
142 bool InitPrimitive();
143 void DrawPrimitive();
144 GLuint LoadShader(GLenum type, const std::string& source);
145 GLuint LoadProgram(const std::string& vertex_source,
146 const std::string& fragment_source);
147
148 // Functions for drawing scene in Software.
149 void DrawSceneSoftware(void* memory);
150
151 blink::WebFrame* frame_;
152 WebTestDelegate* delegate_;
153 blink::WebPluginContainer* container_;
154
155 blink::WebRect rect_;
156 std::unique_ptr<blink::WebGraphicsContext3DProvider> context_provider_;
157 gpu::gles2::GLES2Interface* gl_;
158 GLuint color_texture_;
159 cc::TextureMailbox texture_mailbox_;
160 std::unique_ptr<cc::SharedBitmap> shared_bitmap_;
161 bool mailbox_changed_;
162 GLuint framebuffer_;
163 Scene scene_;
164 scoped_refptr<cc::TextureLayer> layer_;
165 std::unique_ptr<blink::WebLayer> web_layer_;
166
167 blink::WebPluginContainer::TouchEventRequestType touch_event_request_;
168 // Requests touch events from the WebPluginContainerImpl multiple times to
169 // tickle webkit.org/b/108381
170 bool re_request_touch_events_;
171 bool print_event_details_;
172 bool print_user_gesture_status_;
173 bool can_process_drag_;
174 bool supports_keyboard_focus_;
175
176 bool is_persistent_;
177 bool can_create_without_renderer_;
178
179 DISALLOW_COPY_AND_ASSIGN(TestPlugin);
180 };
181
182 } // namespace test_runner
183
184 #endif // COMPONENTS_TEST_RUNNER_TEST_PLUGIN_H_
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698