| OLD | NEW |
| (Empty) |
| 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 | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ash/display/display_layout.h" | |
| 6 | |
| 7 #include "base/json/json_reader.h" | |
| 8 #include "base/values.h" | |
| 9 #include "testing/gtest/include/gtest/gtest.h" | |
| 10 | |
| 11 namespace ash { | |
| 12 | |
| 13 typedef testing::Test DisplayLayoutTest; | |
| 14 | |
| 15 TEST_F(DisplayLayoutTest, ConvertFromToValue) { | |
| 16 DisplayLayout layout; | |
| 17 layout.primary_id = 1; | |
| 18 layout.mirrored = true; | |
| 19 layout.default_unified = false; | |
| 20 layout.placement_list.push_back(new DisplayPlacement); | |
| 21 layout.placement_list.push_back(new DisplayPlacement); | |
| 22 layout.placement_list[0]->display_id = 2; | |
| 23 layout.placement_list[0]->parent_display_id = 1; | |
| 24 layout.placement_list[0]->position = DisplayPlacement::BOTTOM; | |
| 25 | |
| 26 layout.placement_list[1]->display_id = 3; | |
| 27 layout.placement_list[1]->parent_display_id = 2; | |
| 28 layout.placement_list[1]->position = DisplayPlacement::LEFT; | |
| 29 layout.placement_list[1]->offset = 30; | |
| 30 | |
| 31 base::DictionaryValue value; | |
| 32 DisplayLayout::ConvertToValue(layout, &value); | |
| 33 | |
| 34 const char data[] = | |
| 35 "{\n" | |
| 36 " \"primary-id\": \"1\",\n" | |
| 37 " \"mirrored\": true,\n" | |
| 38 " \"default_unified\": false,\n" | |
| 39 " \"display_placement\": [{\n" | |
| 40 " \"display_id\": \"2\",\n" | |
| 41 " \"parent_display_id\": \"1\",\n" | |
| 42 " \"position\": \"bottom\",\n" | |
| 43 " \"offset\": 0\n" | |
| 44 " },{\n" | |
| 45 " \"display_id\": \"3\",\n" | |
| 46 " \"parent_display_id\": \"2\",\n" | |
| 47 " \"position\": \"left\",\n" | |
| 48 " \"offset\": 30\n" | |
| 49 " }]\n" | |
| 50 "}"; | |
| 51 int error_code = 0, error_line, error_column; | |
| 52 std::string error_msg; | |
| 53 scoped_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( | |
| 54 data, 0, &error_code, &error_msg, &error_line, &error_column)); | |
| 55 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" | |
| 56 << error_column; | |
| 57 EXPECT_TRUE(value.Equals(read_value.get())); | |
| 58 | |
| 59 DisplayLayout read_layout; | |
| 60 EXPECT_TRUE(DisplayLayout::ConvertFromValue(*read_value, &read_layout)); | |
| 61 EXPECT_EQ(read_layout.mirrored, layout.mirrored); | |
| 62 EXPECT_EQ(read_layout.primary_id, layout.primary_id); | |
| 63 EXPECT_EQ(read_layout.default_unified, layout.default_unified); | |
| 64 EXPECT_TRUE(read_layout.HasSamePlacementList(layout)); | |
| 65 } | |
| 66 | |
| 67 TEST_F(DisplayLayoutTest, ConvertFromOldJSON) { | |
| 68 const char data[] = | |
| 69 "{\n" | |
| 70 " \"primary-id\": \"1\",\n" | |
| 71 " \"mirrored\": true,\n" | |
| 72 " \"default_unified\": false,\n" | |
| 73 " \"position\": \"bottom\",\n" | |
| 74 " \"offset\": 20\n" | |
| 75 "}"; | |
| 76 int error_code = 0, error_line, error_column; | |
| 77 std::string error_msg; | |
| 78 scoped_ptr<base::Value> read_value(base::JSONReader::ReadAndReturnError( | |
| 79 data, 0, &error_code, &error_msg, &error_line, &error_column)); | |
| 80 ASSERT_EQ(0, error_code) << error_msg << " at " << error_line << ":" | |
| 81 << error_column; | |
| 82 | |
| 83 DisplayLayout read_layout; | |
| 84 EXPECT_TRUE(DisplayLayout::ConvertFromValue(*read_value, &read_layout)); | |
| 85 EXPECT_EQ(true, read_layout.mirrored); | |
| 86 EXPECT_EQ(1, read_layout.primary_id); | |
| 87 EXPECT_EQ(false, read_layout.default_unified); | |
| 88 ASSERT_EQ(1u, read_layout.placement_list.size()); | |
| 89 EXPECT_EQ(DisplayPlacement::BOTTOM, read_layout.placement_list[0]->position); | |
| 90 EXPECT_EQ(20, read_layout.placement_list[0]->offset); | |
| 91 } | |
| 92 | |
| 93 } // namespace ash | |
| OLD | NEW |