1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
|
// Copyright 2020 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "third_party/blink/renderer/core/layout/layout_video.h"
#include "third_party/blink/renderer/core/layout/layout_image.h"
#include "third_party/blink/renderer/core/loader/resource/image_resource_content.h"
#include "third_party/blink/renderer/core/testing/core_unit_test_helper.h"
#include "third_party/blink/renderer/platform/graphics/unaccelerated_static_bitmap_image.h"
#include "third_party/skia/include/core/SkImage.h"
#include "third_party/skia/include/core/SkSurface.h"
namespace blink {
class LayoutVideoTest : public RenderingTest {
public:
void CreateAndSetImage(const char* id, int width, int height) {
// Create one image with size(width, height)
sk_sp<SkColorSpace> src_rgb_color_space = SkColorSpace::MakeSRGB();
SkImageInfo raster_image_info =
SkImageInfo::MakeN32Premul(width, height, src_rgb_color_space);
sk_sp<SkSurface> surface(SkSurface::MakeRaster(raster_image_info));
sk_sp<SkImage> image = surface->makeImageSnapshot();
ImageResourceContent* image_content = ImageResourceContent::CreateLoaded(
UnacceleratedStaticBitmapImage::Create(image).get());
// Set image to video
auto* layout_image = (LayoutImage*)GetLayoutObjectByElementId(id);
layout_image->ImageResource()->SetImageResource(image_content);
}
};
TEST_F(LayoutVideoTest, PosterSizeWithNormal) {
SetBodyInnerHTML(R"HTML(
<style>
video {zoom:1}
</style>
<video id='video' />
)HTML");
CreateAndSetImage("video", 10, 10);
UpdateAllLifecyclePhasesForTest();
int width = ((LayoutBox*)GetLayoutObjectByElementId("video"))
->AbsoluteBoundingBoxRect()
.Width();
EXPECT_EQ(width, 10);
}
TEST_F(LayoutVideoTest, PosterSizeWithZoom) {
SetBodyInnerHTML(R"HTML(
<style>
video {zoom:1.5}
</style>
<video id='video' />
)HTML");
CreateAndSetImage("video", 10, 10);
UpdateAllLifecyclePhasesForTest();
int width = ((LayoutBox*)GetLayoutObjectByElementId("video"))
->AbsoluteBoundingBoxRect()
.Width();
EXPECT_EQ(width, 15);
}
} // namespace blink
|