| 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 "ui/aura/mus/property_converter.h" | 5 #include "ui/aura/mus/property_converter.h" |
| 6 | 6 |
| 7 #include <stdint.h> | 7 #include <stdint.h> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/logging.h" | 10 #include "base/logging.h" |
| (...skipping 15 matching lines...) Expand all Loading... |
| 26 DECLARE_WINDOW_PROPERTY_TYPE(uint16_t) | 26 DECLARE_WINDOW_PROPERTY_TYPE(uint16_t) |
| 27 DECLARE_WINDOW_PROPERTY_TYPE(uint64_t) | 27 DECLARE_WINDOW_PROPERTY_TYPE(uint64_t) |
| 28 DECLARE_WINDOW_PROPERTY_TYPE(int8_t) | 28 DECLARE_WINDOW_PROPERTY_TYPE(int8_t) |
| 29 DECLARE_WINDOW_PROPERTY_TYPE(int16_t) | 29 DECLARE_WINDOW_PROPERTY_TYPE(int16_t) |
| 30 | 30 |
| 31 namespace aura { | 31 namespace aura { |
| 32 | 32 |
| 33 namespace { | 33 namespace { |
| 34 | 34 |
| 35 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey0, false); | 35 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey0, false); |
| 36 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); | 36 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey1, true); |
| 37 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); | 37 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey2, UINT8_MAX / 3); |
| 38 DEFINE_WINDOW_PROPERTY_KEY(uint32_t, kTestPropertyKey3, 0); | 38 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey3, UINT16_MAX / 3); |
| 39 DEFINE_WINDOW_PROPERTY_KEY(uint64_t, kTestPropertyKey4, 0); | 39 DEFINE_WINDOW_PROPERTY_KEY(uint32_t, kTestPropertyKey4, UINT32_MAX); |
| 40 DEFINE_WINDOW_PROPERTY_KEY(int8_t, kTestPropertyKey5, 0); | 40 DEFINE_WINDOW_PROPERTY_KEY(uint64_t, kTestPropertyKey5, UINT64_MAX); |
| 41 DEFINE_WINDOW_PROPERTY_KEY(int16_t, kTestPropertyKey6, 0); | 41 DEFINE_WINDOW_PROPERTY_KEY(int8_t, kTestPropertyKey6, 0); |
| 42 DEFINE_WINDOW_PROPERTY_KEY(int32_t, kTestPropertyKey7, 0); | 42 DEFINE_WINDOW_PROPERTY_KEY(int16_t, kTestPropertyKey7, 1); |
| 43 DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey8, 0); | 43 DEFINE_WINDOW_PROPERTY_KEY(int32_t, kTestPropertyKey8, -1); |
| 44 DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey9, 777); |
| 44 | 45 |
| 45 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey, | 46 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey, |
| 46 nullptr); | 47 nullptr); |
| 47 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); | 48 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); |
| 48 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr); | 49 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr); |
| 49 DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr); | 50 DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr); |
| 50 DEFINE_OWNED_WINDOW_PROPERTY_KEY(base::string16, kTestString16PropertyKey, | 51 DEFINE_OWNED_WINDOW_PROPERTY_KEY(base::string16, kTestString16PropertyKey, |
| 51 nullptr); | 52 nullptr); |
| 52 | 53 |
| 53 const char kTestPropertyServerKey0[] = "test-property-server0"; | 54 const char kTestPropertyServerKey0[] = "test-property-server0"; |
| 54 const char kTestPropertyServerKey1[] = "test-property-server1"; | 55 const char kTestPropertyServerKey1[] = "test-property-server1"; |
| 55 const char kTestPropertyServerKey2[] = "test-property-server2"; | 56 const char kTestPropertyServerKey2[] = "test-property-server2"; |
| 56 const char kTestPropertyServerKey3[] = "test-property-server3"; | 57 const char kTestPropertyServerKey3[] = "test-property-server3"; |
| 57 const char kTestPropertyServerKey4[] = "test-property-server4"; | 58 const char kTestPropertyServerKey4[] = "test-property-server4"; |
| 58 const char kTestPropertyServerKey5[] = "test-property-server5"; | 59 const char kTestPropertyServerKey5[] = "test-property-server5"; |
| 59 const char kTestPropertyServerKey6[] = "test-property-server6"; | 60 const char kTestPropertyServerKey6[] = "test-property-server6"; |
| 60 const char kTestPropertyServerKey7[] = "test-property-server7"; | 61 const char kTestPropertyServerKey7[] = "test-property-server7"; |
| 61 const char kTestPropertyServerKey8[] = "test-property-server8"; | 62 const char kTestPropertyServerKey8[] = "test-property-server8"; |
| 63 const char kTestPropertyServerKey9[] = "test-property-server9"; |
| 62 | 64 |
| 63 const char kTestImagePropertyServerKey[] = "test-image-property-server"; | 65 const char kTestImagePropertyServerKey[] = "test-image-property-server"; |
| 64 const char kTestRectPropertyServerKey[] = "test-rect-property-server"; | 66 const char kTestRectPropertyServerKey[] = "test-rect-property-server"; |
| 65 const char kTestSizePropertyServerKey[] = "test-size-property-server"; | 67 const char kTestSizePropertyServerKey[] = "test-size-property-server"; |
| 66 const char kTestStringPropertyServerKey[] = "test-string-property-server"; | 68 const char kTestStringPropertyServerKey[] = "test-string-property-server"; |
| 67 const char kTestString16PropertyServerKey[] = "test-string16-property-server"; | 69 const char kTestString16PropertyServerKey[] = "test-string16-property-server"; |
| 68 | 70 |
| 69 // Test registration, naming and value conversion for primitive property types. | 71 // Test registration, naming and value conversion for primitive property types. |
| 70 template <typename T> | 72 template <typename T> |
| 71 void TestPrimitiveProperty(PropertyConverter* property_converter, | 73 void TestPrimitiveProperty(PropertyConverter* property_converter, |
| (...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 114 | 116 |
| 115 // Verifies property setting behavior for a std::string* property. | 117 // Verifies property setting behavior for a std::string* property. |
| 116 TEST_F(PropertyConverterTest, PrimitiveProperties) { | 118 TEST_F(PropertyConverterTest, PrimitiveProperties) { |
| 117 PropertyConverter property_converter; | 119 PropertyConverter property_converter; |
| 118 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 120 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 119 | 121 |
| 120 const bool value_0a = true, value_0b = false; | 122 const bool value_0a = true, value_0b = false; |
| 121 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey0, | 123 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey0, |
| 122 kTestPropertyServerKey0, value_0a, value_0b); | 124 kTestPropertyServerKey0, value_0a, value_0b); |
| 123 | 125 |
| 124 const uint8_t value_1a = UINT8_MAX / 2, value_1b = UINT8_MAX / 3; | 126 const bool value_1a = true, value_1b = false; |
| 125 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey1, | 127 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey1, |
| 126 kTestPropertyServerKey1, value_1a, value_1b); | 128 kTestPropertyServerKey1, value_1a, value_1b); |
| 127 | 129 |
| 128 const uint16_t value_2a = UINT16_MAX / 3, value_2b = UINT16_MAX / 4; | 130 const uint8_t value_2a = UINT8_MAX / 2, value_2b = UINT8_MAX / 3; |
| 129 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey2, | 131 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey2, |
| 130 kTestPropertyServerKey2, value_2a, value_2b); | 132 kTestPropertyServerKey2, value_2a, value_2b); |
| 131 | 133 |
| 132 const uint32_t value_3a = UINT32_MAX / 4, value_3b = UINT32_MAX / 5; | 134 const uint16_t value_3a = UINT16_MAX / 3, value_3b = UINT16_MAX / 4; |
| 133 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey3, | 135 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey3, |
| 134 kTestPropertyServerKey3, value_3a, value_3b); | 136 kTestPropertyServerKey3, value_3a, value_3b); |
| 135 | 137 |
| 136 const uint64_t value_4a = UINT64_MAX / 5, value_4b = UINT64_MAX / 6; | 138 const uint32_t value_4a = UINT32_MAX / 4, value_4b = UINT32_MAX / 5; |
| 137 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey4, | 139 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey4, |
| 138 kTestPropertyServerKey4, value_4a, value_4b); | 140 kTestPropertyServerKey4, value_4a, value_4b); |
| 139 | 141 |
| 140 const int8_t value_5a = INT8_MIN / 2, value_5b = INT8_MIN / 3; | 142 const uint64_t value_5a = UINT64_MAX / 5, value_5b = UINT64_MAX / 6; |
| 141 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey5, | 143 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey5, |
| 142 kTestPropertyServerKey5, value_5a, value_5b); | 144 kTestPropertyServerKey5, value_5a, value_5b); |
| 143 | 145 |
| 144 const int16_t value_6a = INT16_MIN / 3, value_6b = INT16_MIN / 4; | 146 const int8_t value_6a = INT8_MIN / 2, value_6b = INT8_MIN / 3; |
| 145 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey6, | 147 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey6, |
| 146 kTestPropertyServerKey6, value_6a, value_6b); | 148 kTestPropertyServerKey6, value_6a, value_6b); |
| 147 | 149 |
| 148 const int32_t value_7a = INT32_MIN / 4, value_7b = INT32_MIN / 5; | 150 const int16_t value_7a = INT16_MIN / 3, value_7b = INT16_MIN / 4; |
| 149 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey7, | 151 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey7, |
| 150 kTestPropertyServerKey7, value_7a, value_7b); | 152 kTestPropertyServerKey7, value_7a, value_7b); |
| 151 | 153 |
| 152 const int64_t value_8a = INT64_MIN / 5, value_8b = INT64_MIN / 6; | 154 const int32_t value_8a = INT32_MIN / 4, value_8b = INT32_MIN / 5; |
| 153 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey8, | 155 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey8, |
| 154 kTestPropertyServerKey8, value_8a, value_8b); | 156 kTestPropertyServerKey8, value_8a, value_8b); |
| 157 |
| 158 const int64_t value_9a = INT64_MIN / 5, value_9b = INT64_MIN / 6; |
| 159 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, |
| 160 kTestPropertyServerKey9, value_9a, value_9b); |
| 155 } | 161 } |
| 156 | 162 |
| 157 // Verifies property setting behavior for a gfx::ImageSkia* property. | 163 // Verifies property setting behavior for a gfx::ImageSkia* property. |
| 158 TEST_F(PropertyConverterTest, ImageSkiaProperty) { | 164 TEST_F(PropertyConverterTest, ImageSkiaProperty) { |
| 159 PropertyConverter property_converter; | 165 PropertyConverter property_converter; |
| 160 property_converter.RegisterProperty(kTestImagePropertyKey, | 166 property_converter.RegisterProperty(kTestImagePropertyKey, |
| 161 kTestImagePropertyServerKey); | 167 kTestImagePropertyServerKey); |
| 162 EXPECT_EQ( | 168 EXPECT_EQ( |
| 163 kTestImagePropertyServerKey, | 169 kTestImagePropertyServerKey, |
| 164 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); | 170 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); |
| (...skipping 147 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 312 | 318 |
| 313 base::string16 value_2 = base::ASCIIToUTF16("another test value"); | 319 base::string16 value_2 = base::ASCIIToUTF16("another test value"); |
| 314 std::vector<uint8_t> transport_value = | 320 std::vector<uint8_t> transport_value = |
| 315 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 321 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
| 316 property_converter.SetPropertyFromTransportValue( | 322 property_converter.SetPropertyFromTransportValue( |
| 317 window.get(), kTestString16PropertyServerKey, &transport_value); | 323 window.get(), kTestString16PropertyServerKey, &transport_value); |
| 318 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); | 324 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); |
| 319 } | 325 } |
| 320 | 326 |
| 321 } // namespace aura | 327 } // namespace aura |
| OLD | NEW |