Disable ExtensionApiTest:DontInjectContentScriptsInBackgroundPages with OOPI
[chromium-blink-merge.git] / cc / trees / layer_tree_host_unittest_video.cc
blob2ae61bda51250b6c36ec58d4140438c9e6d960e8
1 // Copyright 2012 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 "cc/trees/layer_tree_host.h"
7 #include "base/basictypes.h"
8 #include "cc/layers/render_surface_impl.h"
9 #include "cc/layers/video_layer.h"
10 #include "cc/layers/video_layer_impl.h"
11 #include "cc/test/fake_video_frame_provider.h"
12 #include "cc/test/layer_tree_test.h"
13 #include "cc/trees/damage_tracker.h"
14 #include "cc/trees/layer_tree_impl.h"
16 namespace cc {
17 namespace {
19 // These tests deal with compositing video.
20 class LayerTreeHostVideoTest : public LayerTreeTest {};
22 class LayerTreeHostVideoTestSetNeedsDisplay
23 : public LayerTreeHostVideoTest {
24 public:
25 void SetupTree() override {
26 scoped_refptr<Layer> root = Layer::Create(layer_settings());
27 root->SetBounds(gfx::Size(10, 10));
28 root->SetIsDrawable(true);
30 scoped_refptr<VideoLayer> video = VideoLayer::Create(
31 layer_settings(), &video_frame_provider_, media::VIDEO_ROTATION_90);
32 video->SetPosition(gfx::PointF(3.f, 3.f));
33 video->SetBounds(gfx::Size(4, 5));
34 video->SetIsDrawable(true);
35 root->AddChild(video);
37 layer_tree_host()->SetRootLayer(root);
38 layer_tree_host()->SetDeviceScaleFactor(2.f);
39 LayerTreeHostVideoTest::SetupTree();
42 void BeginTest() override {
43 num_draws_ = 0;
44 PostSetNeedsCommitToMainThread();
47 DrawResult PrepareToDrawOnThread(LayerTreeHostImpl* host_impl,
48 LayerTreeHostImpl::FrameData* frame,
49 DrawResult draw_result) override {
50 LayerImpl* root_layer = host_impl->active_tree()->root_layer();
51 RenderSurfaceImpl* root_surface = root_layer->render_surface();
52 gfx::Rect damage_rect =
53 root_surface->damage_tracker()->current_damage_rect();
55 switch (num_draws_) {
56 case 0:
57 // First frame the whole viewport is damaged.
58 EXPECT_EQ(gfx::Rect(0, 0, 20, 20), damage_rect);
59 break;
60 case 1:
61 // Second frame the video layer is damaged.
62 EXPECT_EQ(gfx::Rect(6, 6, 8, 10), damage_rect);
63 EndTest();
64 break;
67 EXPECT_EQ(DRAW_SUCCESS, draw_result);
68 return draw_result;
71 void DrawLayersOnThread(LayerTreeHostImpl* host_impl) override {
72 VideoLayerImpl* video = static_cast<VideoLayerImpl*>(
73 host_impl->active_tree()->root_layer()->children()[0]);
75 EXPECT_EQ(media::VIDEO_ROTATION_90, video->video_rotation());
77 if (num_draws_ == 0)
78 video->SetNeedsRedraw();
80 ++num_draws_;
83 void AfterTest() override { EXPECT_EQ(2, num_draws_); }
85 private:
86 int num_draws_;
88 FakeVideoFrameProvider video_frame_provider_;
91 SINGLE_AND_MULTI_THREAD_TEST_F(LayerTreeHostVideoTestSetNeedsDisplay);
93 } // namespace
94 } // namespace cc