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
|
// Copyright 2023 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "ui/display/manager/display_properties_parser.h"
#include <string_view>
#include "base/json/json_reader.h"
#include "base/test/gtest_util.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/display/types/display_constants.h"
namespace display {
namespace {
std::optional<base::Value> ReadJsonString(std::string_view json) {
return base::JSONReader::Read(json);
}
using DisplayPropertiesParserTest = ::testing::Test;
TEST(DisplayPropertiesParserTest, Valid_SingleDisplay) {
auto result = ReadJsonString(
"[{\"connector-type\": 14, \"rounded-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": 15, \"top-left\": 16, \"top-right\": 16}}]");
const auto radii = ParseDisplayPanelRadii(&result.value());
ASSERT_TRUE(radii.has_value());
EXPECT_EQ(radii, gfx::RoundedCornersF(16, 16, 15, 15));
}
TEST(DisplayPropertiesParserTest, Invalid_MultipleDisplays) {
auto result = ReadJsonString(
"[{\"connector-type\": 14, \"rounded-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": 15, \"top-left\": 16, \"top-right\": 16}}, "
"{\"connector-type\": 19, \"rounded-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": 15, \"top-left\": 15, \"top-right\": 15}}]");
const auto radii = ParseDisplayPanelRadii(&result.value());
ASSERT_FALSE(radii.has_value());
}
TEST(DisplayPropertiesParserTest, InValidRadii) {
auto result = ReadJsonString(
"[{\"connector-type\": 5, \"rounded-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": -15, \"top-left\": 16, \"top-right\": 16}}]");
const auto radii = ParseDisplayPanelRadii(&result.value());
ASSERT_FALSE(radii.has_value());
}
TEST(DisplayPropertiesParserTest, InValidField_WrongKey) {
auto result = ReadJsonString(
"[{\"connector-type\": 5, \"round-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": -15, \"top-left\": 16, \"top-right\": 16}}]");
const auto radii = ParseDisplayPanelRadii(&result.value());
ASSERT_FALSE(radii.has_value());
}
TEST(DisplayPropertiesParserTest, InValidField_MissingValuePair) {
auto result = ReadJsonString(
"[{\"connector-type\": 5, \"rounded-corners\": {\"bottom-left\": 15, "
"\"bottom-right\": -15, \"top-left\": 16}}]");
const auto radii = ParseDisplayPanelRadii(&result.value());
ASSERT_FALSE(radii.has_value());
}
} // namespace
} // namespace display
|