summaryrefslogtreecommitdiff
path: root/chromium/third_party/blink/renderer/core/css/threaded/css_to_length_conversion_data_threaded_test.cc
blob: afa544e06505077d1a15a81315543c44e64a5145 (plain)
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
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
// Copyright 2017 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/css/css_to_length_conversion_data.h"

#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/renderer/core/css/threaded/multi_threaded_test_util.h"
#include "third_party/blink/renderer/platform/fonts/font.h"
#include "third_party/blink/renderer/platform/fonts/font_description.h"
#include "third_party/blink/renderer/platform/geometry/length.h"

namespace blink {

TSAN_TEST(CSSToLengthConversionDataThreadedTest, Construction) {
  RunOnThreads([]() {
    FontDescription fontDescription;
    Font font(fontDescription);
    CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
    CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
    CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
                                             1);
  });
}

TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionEm) {
  RunOnThreads([]() {
    FontDescription fontDescription;
    Font font(fontDescription);
    CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
    CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
    CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
                                             1);

    CSSPrimitiveValue& value =
        *CSSPrimitiveValue::Create(3.14, CSSPrimitiveValue::UnitType::kEms);

    Length length = value.ConvertToLength(conversionData);
    EXPECT_EQ(length.Value(), 50.24f);
  });
}

TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionPixel) {
  RunOnThreads([]() {
    FontDescription fontDescription;
    Font font(fontDescription);
    CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
    CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
    CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
                                             1);

    CSSPrimitiveValue& value =
        *CSSPrimitiveValue::Create(44, CSSPrimitiveValue::UnitType::kPixels);

    Length length = value.ConvertToLength(conversionData);
    EXPECT_EQ(length.Value(), 44);
  });
}

TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionViewport) {
  RunOnThreads([]() {
    FontDescription fontDescription;
    Font font(fontDescription);
    CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
    CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
    CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
                                             1);

    CSSPrimitiveValue& value = *CSSPrimitiveValue::Create(
        1, CSSPrimitiveValue::UnitType::kViewportWidth);

    Length length = value.ConvertToLength(conversionData);
    EXPECT_EQ(length.Value(), 0);
  });
}

TSAN_TEST(CSSToLengthConversionDataThreadedTest, ConversionRem) {
  RunOnThreads([]() {
    FontDescription fontDescription;
    Font font(fontDescription);
    CSSToLengthConversionData::FontSizes fontSizes(16, 16, &font);
    CSSToLengthConversionData::ViewportSize viewportSize(0, 0);
    CSSToLengthConversionData conversionData(nullptr, fontSizes, viewportSize,
                                             1);

    CSSPrimitiveValue& value =
        *CSSPrimitiveValue::Create(1, CSSPrimitiveValue::UnitType::kRems);

    Length length = value.ConvertToLength(conversionData);
    EXPECT_EQ(length.Value(), 16);
  });
}

}  // namespace blink