Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / android_webview / browser / browser_view_renderer_unittest.cc
blob634e1f3390e9a4f377b0597293d88de861d09cd1
1 // Copyright 2014 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 "android_webview/browser/browser_view_renderer.h"
6 #include "android_webview/browser/child_frame.h"
7 #include "android_webview/browser/test/rendering_test.h"
9 namespace android_webview {
11 class SmokeTest : public RenderingTest {
12 void StartTest() override { browser_view_renderer_->PostInvalidate(); }
14 void DidDrawOnRT(SharedRendererState* functor) override {
15 EndTest();
19 RENDERING_TEST_F(SmokeTest);
21 class ClearViewTest : public RenderingTest {
22 public:
23 ClearViewTest() : on_draw_count_(0) {}
25 void StartTest() override {
26 browser_view_renderer_->PostInvalidate();
27 browser_view_renderer_->ClearView();
30 void DidOnDraw(bool success) override {
31 on_draw_count_++;
32 if (on_draw_count_ == 1) {
33 // First OnDraw should be skipped due to ClearView.
34 EXPECT_FALSE(success);
35 browser_view_renderer_->DidUpdateContent(); // Unset ClearView.
36 browser_view_renderer_->PostInvalidate();
37 } else {
38 // Following OnDraws should succeed.
39 EXPECT_TRUE(success);
43 void DidDrawOnRT(SharedRendererState* functor) override {
44 EndTest();
46 private:
47 int on_draw_count_;
50 RENDERING_TEST_F(ClearViewTest);
52 class TestAnimateInAndOutOfScreen : public RenderingTest {
53 public:
54 TestAnimateInAndOutOfScreen() : on_draw_count_(0), draw_gl_count_on_rt_(0) {}
56 void StartTest() override {
57 new_constraints_ = ParentCompositorDrawConstraints(
58 false, gfx::Transform(), gfx::Rect(window_->surface_size()));
59 new_constraints_.transform.Scale(2.0, 2.0);
60 browser_view_renderer_->PostInvalidate();
63 void WillOnDraw() override {
64 // Step 0: A single onDraw on screen. The parent draw constraints
65 // of the BVR will updated to be the initial constraints.
66 // Step 1: A single onDrraw off screen. The parent draw constraints of the
67 // BVR will be updated to the new constraints.
68 // Step 2: This onDraw is to introduce the DrawGL that animates the
69 // webview onto the screen on render thread. End the test when the parent
70 // draw constraints of BVR is updated to initial constraints.
71 if (on_draw_count_ == 1 || on_draw_count_ == 2)
72 browser_view_renderer_->PrepareToDraw(gfx::Vector2d(), gfx::Rect());
75 void DidOnDraw(bool success) override {
76 EXPECT_TRUE(success);
77 on_draw_count_++;
80 bool WillDrawOnRT(SharedRendererState* functor,
81 AwDrawGLInfo* draw_info) override {
82 if (draw_gl_count_on_rt_ == 1) {
83 draw_gl_count_on_rt_++;
84 ui_proxy_->PostTask(FROM_HERE, base::Bind(&RenderingTest::PostInvalidate,
85 base::Unretained(this)));
86 return false;
89 draw_info->width = window_->surface_size().width();
90 draw_info->height = window_->surface_size().height();
91 draw_info->is_layer = false;
93 gfx::Transform transform;
94 if (draw_gl_count_on_rt_ == 0)
95 transform = new_constraints_.transform;
97 transform.matrix().asColMajorf(draw_info->transform);
98 return true;
101 void DidDrawOnRT(SharedRendererState* functor) override {
102 draw_gl_count_on_rt_++;
105 bool DrawConstraintsEquals(
106 const ParentCompositorDrawConstraints& constraints1,
107 const ParentCompositorDrawConstraints& constraints2) {
108 if (constraints1.is_layer != constraints2.is_layer ||
109 constraints1.transform != constraints2.transform)
110 return false;
112 return !constraints1.is_layer ||
113 constraints1.surface_rect == constraints2.surface_rect;
116 void ParentDrawConstraintsUpdated(
117 const ParentCompositorDrawConstraints& constraints) override {
118 switch (on_draw_count_) {
119 case 1u:
120 EXPECT_TRUE(DrawConstraintsEquals(constraints, new_constraints_));
121 break;
122 case 3u:
123 EXPECT_TRUE(DrawConstraintsEquals(constraints, initial_constraints_));
124 EndTest();
125 break;
126 // There will be a following 4th onDraw. But the hardware renderer won't
127 // post back the draw constraints in DrawGL because the constraints
128 // don't change.
129 default:
130 FAIL();
134 private:
135 int on_draw_count_;
136 int draw_gl_count_on_rt_;
137 ParentCompositorDrawConstraints initial_constraints_;
138 ParentCompositorDrawConstraints new_constraints_;
141 RENDERING_TEST_F(TestAnimateInAndOutOfScreen);
143 } // namespace android_webview