BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / media / base / video_frame_pool_unittest.cc
blob2d0c1202a2c327a24432eccfb1b3a282993be58a
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 "media/base/video_frame_pool.h"
6 #include "testing/gmock/include/gmock/gmock.h"
8 namespace media {
10 class VideoFramePoolTest : public ::testing::Test {
11 public:
12 VideoFramePoolTest() : pool_(new VideoFramePool()) {}
14 scoped_refptr<VideoFrame> CreateFrame(VideoPixelFormat format,
15 int timestamp_ms) {
16 gfx::Size coded_size(320,240);
17 gfx::Rect visible_rect(coded_size);
18 gfx::Size natural_size(coded_size);
20 scoped_refptr<VideoFrame> frame =
21 pool_->CreateFrame(
22 format, coded_size, visible_rect, natural_size,
23 base::TimeDelta::FromMilliseconds(timestamp_ms));
24 EXPECT_EQ(format, frame->format());
25 EXPECT_EQ(base::TimeDelta::FromMilliseconds(timestamp_ms),
26 frame->timestamp());
27 EXPECT_EQ(coded_size, frame->coded_size());
28 EXPECT_EQ(visible_rect, frame->visible_rect());
29 EXPECT_EQ(natural_size, frame->natural_size());
31 return frame;
34 void CheckPoolSize(size_t size) const {
35 EXPECT_EQ(size, pool_->GetPoolSizeForTesting());
38 protected:
39 scoped_ptr<VideoFramePool> pool_;
42 TEST_F(VideoFramePoolTest, FrameInitializedAndZeroed) {
43 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10);
45 // Verify that frame is initialized with zeros.
46 for (size_t i = 0; i < VideoFrame::NumPlanes(frame->format()); ++i)
47 EXPECT_EQ(0, frame->data(i)[0]);
50 TEST_F(VideoFramePoolTest, SimpleFrameReuse) {
51 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10);
52 const uint8* old_y_data = frame->data(VideoFrame::kYPlane);
54 // Clear frame reference to return the frame to the pool.
55 frame = NULL;
57 // Verify that the next frame from the pool uses the same memory.
58 scoped_refptr<VideoFrame> new_frame = CreateFrame(PIXEL_FORMAT_YV12, 20);
59 EXPECT_EQ(old_y_data, new_frame->data(VideoFrame::kYPlane));
62 TEST_F(VideoFramePoolTest, SimpleFormatChange) {
63 scoped_refptr<VideoFrame> frame_a = CreateFrame(PIXEL_FORMAT_YV12, 10);
64 scoped_refptr<VideoFrame> frame_b = CreateFrame(PIXEL_FORMAT_YV12, 10);
66 // Clear frame references to return the frames to the pool.
67 frame_a = NULL;
68 frame_b = NULL;
70 // Verify that both frames are in the pool.
71 CheckPoolSize(2u);
73 // Verify that requesting a frame with a different format causes the pool
74 // to get drained.
75 scoped_refptr<VideoFrame> new_frame = CreateFrame(PIXEL_FORMAT_YV12A, 10);
76 CheckPoolSize(0u);
79 TEST_F(VideoFramePoolTest, FrameValidAfterPoolDestruction) {
80 scoped_refptr<VideoFrame> frame = CreateFrame(PIXEL_FORMAT_YV12, 10);
82 // Destroy the pool.
83 pool_.reset();
85 // Write to the Y plane. The memory tools should detect a
86 // use-after-free if the storage was actually removed by pool destruction.
87 memset(frame->data(VideoFrame::kYPlane), 0xff,
88 frame->rows(VideoFrame::kYPlane) * frame->stride(VideoFrame::kYPlane));
91 } // namespace media