Lots of random cleanups, mostly for native_theme_win.cc:
[chromium-blink-merge.git] / cc / layers / video_layer_impl_unittest.cc
blob7a17eefd09492186fcabce76b0b14b9790c1ffa3
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 "cc/layers/video_layer_impl.h"
7 #include "cc/layers/video_frame_provider_client_impl.h"
8 #include "cc/output/context_provider.h"
9 #include "cc/output/output_surface.h"
10 #include "cc/test/fake_video_frame_provider.h"
11 #include "cc/test/layer_test_common.h"
12 #include "cc/trees/single_thread_proxy.h"
13 #include "media/base/video_frame.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace cc {
17 namespace {
19 TEST(VideoLayerImplTest, Occlusion) {
20 gfx::Size layer_size(1000, 1000);
21 gfx::Size viewport_size(1000, 1000);
23 LayerTestCommon::LayerImplTest impl;
24 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy());
26 scoped_refptr<media::VideoFrame> video_frame =
27 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
28 gfx::Size(10, 10),
29 gfx::Rect(10, 10),
30 gfx::Size(10, 10),
31 base::TimeDelta());
32 FakeVideoFrameProvider provider;
33 provider.set_frame(video_frame);
35 VideoLayerImpl* video_layer_impl =
36 impl.AddChildToRoot<VideoLayerImpl>(&provider);
37 video_layer_impl->SetBounds(layer_size);
38 video_layer_impl->SetContentBounds(layer_size);
39 video_layer_impl->SetDrawsContent(true);
41 impl.CalcDrawProps(viewport_size);
44 SCOPED_TRACE("No occlusion");
45 gfx::Rect occluded;
46 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
48 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(),
49 gfx::Rect(layer_size));
50 EXPECT_EQ(1u, impl.quad_list().size());
54 SCOPED_TRACE("Full occlusion");
55 gfx::Rect occluded(video_layer_impl->visible_content_rect());
56 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
58 LayerTestCommon::VerifyQuadsExactlyCoverRect(impl.quad_list(), gfx::Rect());
59 EXPECT_EQ(impl.quad_list().size(), 0u);
63 SCOPED_TRACE("Partial occlusion");
64 gfx::Rect occluded(200, 0, 800, 1000);
65 impl.AppendQuadsWithOcclusion(video_layer_impl, occluded);
67 size_t partially_occluded_count = 0;
68 LayerTestCommon::VerifyQuadsCoverRectWithOcclusion(
69 impl.quad_list(),
70 gfx::Rect(layer_size),
71 occluded,
72 &partially_occluded_count);
73 // The layer outputs one quad, which is partially occluded.
74 EXPECT_EQ(1u, impl.quad_list().size());
75 EXPECT_EQ(1u, partially_occluded_count);
79 TEST(VideoLayerImplTest, DidBecomeActiveShouldSetActiveVideoLayer) {
80 LayerTestCommon::LayerImplTest impl;
81 DebugScopedSetImplThreadAndMainThreadBlocked thread(impl.proxy());
83 FakeVideoFrameProvider provider;
84 VideoLayerImpl* video_layer_impl =
85 impl.AddChildToRoot<VideoLayerImpl>(&provider);
87 VideoFrameProviderClientImpl* client =
88 static_cast<VideoFrameProviderClientImpl*>(provider.client());
89 ASSERT_TRUE(client);
90 EXPECT_FALSE(client->active_video_layer());
92 video_layer_impl->DidBecomeActive();
93 EXPECT_EQ(video_layer_impl, client->active_video_layer());
96 } // namespace
97 } // namespace cc