OLD | NEW |
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "ash/display/json_converter.h" | 5 #include "ash/display/json_converter.h" |
6 | 6 |
| 7 #include <memory> |
| 8 |
7 #include "base/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
8 #include "base/values.h" | 10 #include "base/values.h" |
9 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
10 #include "ui/display/manager/display_layout.h" | 12 #include "ui/display/manager/display_layout.h" |
11 | 13 |
12 namespace ash { | 14 namespace ash { |
13 | 15 |
14 TEST(JsonConverterTest, JsonFromToDisplayLayout) { | 16 TEST(JsonConverterTest, JsonFromToDisplayLayout) { |
15 display::DisplayLayout layout; | 17 display::DisplayLayout layout; |
16 layout.primary_id = 1; | 18 layout.primary_id = 1; |
(...skipping 25 matching lines...) Expand all Loading... |
42 " \"offset\": 0\n" | 44 " \"offset\": 0\n" |
43 " },{\n" | 45 " },{\n" |
44 " \"display_id\": \"3\",\n" | 46 " \"display_id\": \"3\",\n" |
45 " \"parent_display_id\": \"2\",\n" | 47 " \"parent_display_id\": \"2\",\n" |
46 " \"position\": \"left\",\n" | 48 " \"position\": \"left\",\n" |
47 " \"offset\": 30\n" | 49 " \"offset\": 30\n" |
48 " }]\n" | 50 " }]\n" |
49 "}"; | 51 "}"; |
50 int error_code = 0, error_line, error_column; | 52 int error_code = 0, error_line, error_column; |
51 std::string error_msg; | 53 std::string error_msg; |
52 scoped_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( | 54 std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( |
53 data, 0, &error_code, &error_msg, &error_line, &error_column)); | 55 data, 0, &error_code, &error_msg, &error_line, &error_column)); |
54 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" | 56 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" |
55 << error_column; | 57 << error_column; |
56 EXPECT_TRUE(value.Equals(read_value.get())); | 58 EXPECT_TRUE(value.Equals(read_value.get())); |
57 | 59 |
58 display::DisplayLayout read_layout; | 60 display::DisplayLayout read_layout; |
59 EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); | 61 EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); |
60 EXPECT_EQ(read_layout.mirrored, layout.mirrored); | 62 EXPECT_EQ(read_layout.mirrored, layout.mirrored); |
61 EXPECT_EQ(read_layout.primary_id, layout.primary_id); | 63 EXPECT_EQ(read_layout.primary_id, layout.primary_id); |
62 EXPECT_EQ(read_layout.default_unified, layout.default_unified); | 64 EXPECT_EQ(read_layout.default_unified, layout.default_unified); |
63 EXPECT_TRUE(read_layout.HasSamePlacementList(layout)); | 65 EXPECT_TRUE(read_layout.HasSamePlacementList(layout)); |
64 } | 66 } |
65 | 67 |
66 TEST(JsonConverterTest, OldJsonToDisplayLayout) { | 68 TEST(JsonConverterTest, OldJsonToDisplayLayout) { |
67 const char data[] = | 69 const char data[] = |
68 "{\n" | 70 "{\n" |
69 " \"primary-id\": \"1\",\n" | 71 " \"primary-id\": \"1\",\n" |
70 " \"mirrored\": true,\n" | 72 " \"mirrored\": true,\n" |
71 " \"default_unified\": false,\n" | 73 " \"default_unified\": false,\n" |
72 " \"position\": \"bottom\",\n" | 74 " \"position\": \"bottom\",\n" |
73 " \"offset\": 20\n" | 75 " \"offset\": 20\n" |
74 "}"; | 76 "}"; |
75 int error_code = 0, error_line, error_column; | 77 int error_code = 0, error_line, error_column; |
76 std::string error_msg; | 78 std::string error_msg; |
77 scoped_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( | 79 std::unique_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( |
78 data, 0, &error_code, &error_msg, &error_line, &error_column)); | 80 data, 0, &error_code, &error_msg, &error_line, &error_column)); |
79 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" | 81 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" |
80 << error_column; | 82 << error_column; |
81 | 83 |
82 display::DisplayLayout read_layout; | 84 display::DisplayLayout read_layout; |
83 EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); | 85 EXPECT_TRUE(JsonToDisplayLayout(*read_value, &read_layout)); |
84 EXPECT_EQ(true, read_layout.mirrored); | 86 EXPECT_EQ(true, read_layout.mirrored); |
85 EXPECT_EQ(1, read_layout.primary_id); | 87 EXPECT_EQ(1, read_layout.primary_id); |
86 EXPECT_EQ(false, read_layout.default_unified); | 88 EXPECT_EQ(false, read_layout.default_unified); |
87 ASSERT_EQ(1u, read_layout.placement_list.size()); | 89 ASSERT_EQ(1u, read_layout.placement_list.size()); |
88 EXPECT_EQ(display::DisplayPlacement::BOTTOM, | 90 EXPECT_EQ(display::DisplayPlacement::BOTTOM, |
89 read_layout.placement_list[0].position); | 91 read_layout.placement_list[0].position); |
90 EXPECT_EQ(20, read_layout.placement_list[0].offset); | 92 EXPECT_EQ(20, read_layout.placement_list[0].offset); |
91 } | 93 } |
92 | 94 |
93 } // namespace ash | 95 } // namespace ash |
OLD | NEW |