| 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 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 73 template <typename T> | 73 template <typename T> |
| 74 void TestPrimitiveProperty(PropertyConverter* property_converter, | 74 void TestPrimitiveProperty(PropertyConverter* property_converter, |
| 75 Window* window, | 75 Window* window, |
| 76 const WindowProperty<T>* key, | 76 const WindowProperty<T>* key, |
| 77 const char* transport_name, | 77 const char* transport_name, |
| 78 T value_1, | 78 T value_1, |
| 79 T value_2) { | 79 T value_2) { |
| 80 property_converter->RegisterProperty(key, transport_name); | 80 property_converter->RegisterProperty(key, transport_name); |
| 81 EXPECT_EQ(transport_name, | 81 EXPECT_EQ(transport_name, |
| 82 property_converter->GetTransportNameForPropertyKey(key)); | 82 property_converter->GetTransportNameForPropertyKey(key)); |
| 83 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); |
| 83 | 84 |
| 84 window->SetProperty(key, value_1); | 85 window->SetProperty(key, value_1); |
| 85 EXPECT_EQ(value_1, window->GetProperty(key)); | 86 EXPECT_EQ(value_1, window->GetProperty(key)); |
| 86 | 87 |
| 87 std::string transport_name_out; | 88 std::string transport_name_out; |
| 88 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 89 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 89 EXPECT_TRUE(property_converter->ConvertPropertyForTransport( | 90 EXPECT_TRUE(property_converter->ConvertPropertyForTransport( |
| 90 window, key, &transport_name_out, &transport_value_out)); | 91 window, key, &transport_name_out, &transport_value_out)); |
| 91 EXPECT_EQ(transport_name, transport_name_out); | 92 EXPECT_EQ(transport_name, transport_name_out); |
| 92 const int64_t storage_value_1 = static_cast<int64_t>(value_1); | 93 const int64_t storage_value_1 = static_cast<int64_t>(value_1); |
| (...skipping 20 matching lines...) Expand all Loading... |
| 113 | 114 |
| 114 } // namespace | 115 } // namespace |
| 115 | 116 |
| 116 using PropertyConverterTest = test::AuraTestBase; | 117 using PropertyConverterTest = test::AuraTestBase; |
| 117 | 118 |
| 118 // Verifies property setting behavior for a std::string* property. | 119 // Verifies property setting behavior for a std::string* property. |
| 119 TEST_F(PropertyConverterTest, PrimitiveProperties) { | 120 TEST_F(PropertyConverterTest, PrimitiveProperties) { |
| 120 PropertyConverter property_converter; | 121 PropertyConverter property_converter; |
| 121 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 122 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 122 | 123 |
| 124 EXPECT_FALSE( |
| 125 property_converter.IsTransportNameRegistered(kTestPropertyServerKey0)); |
| 126 |
| 123 const bool value_0a = true, value_0b = false; | 127 const bool value_0a = true, value_0b = false; |
| 124 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey0, | 128 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey0, |
| 125 kTestPropertyServerKey0, value_0a, value_0b); | 129 kTestPropertyServerKey0, value_0a, value_0b); |
| 126 | 130 |
| 127 const bool value_1a = true, value_1b = false; | 131 const bool value_1a = true, value_1b = false; |
| 128 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey1, | 132 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey1, |
| 129 kTestPropertyServerKey1, value_1a, value_1b); | 133 kTestPropertyServerKey1, value_1a, value_1b); |
| 130 | 134 |
| 131 const uint8_t value_2a = UINT8_MAX / 2, value_2b = UINT8_MAX / 3; | 135 const uint8_t value_2a = UINT8_MAX / 2, value_2b = UINT8_MAX / 3; |
| 132 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey2, | 136 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey2, |
| (...skipping 29 matching lines...) Expand all Loading... |
| 162 } | 166 } |
| 163 | 167 |
| 164 // Verifies property setting behavior for a gfx::ImageSkia* property. | 168 // Verifies property setting behavior for a gfx::ImageSkia* property. |
| 165 TEST_F(PropertyConverterTest, ImageSkiaProperty) { | 169 TEST_F(PropertyConverterTest, ImageSkiaProperty) { |
| 166 PropertyConverter property_converter; | 170 PropertyConverter property_converter; |
| 167 property_converter.RegisterProperty(kTestImagePropertyKey, | 171 property_converter.RegisterProperty(kTestImagePropertyKey, |
| 168 kTestImagePropertyServerKey); | 172 kTestImagePropertyServerKey); |
| 169 EXPECT_EQ( | 173 EXPECT_EQ( |
| 170 kTestImagePropertyServerKey, | 174 kTestImagePropertyServerKey, |
| 171 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); | 175 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); |
| 176 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
| 177 kTestImagePropertyServerKey)); |
| 172 | 178 |
| 173 SkBitmap bitmap_1; | 179 SkBitmap bitmap_1; |
| 174 bitmap_1.allocN32Pixels(16, 32); | 180 bitmap_1.allocN32Pixels(16, 32); |
| 175 bitmap_1.eraseARGB(255, 11, 22, 33); | 181 bitmap_1.eraseARGB(255, 11, 22, 33); |
| 176 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1); | 182 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1); |
| 177 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 183 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 178 window->SetProperty(kTestImagePropertyKey, new gfx::ImageSkia(value_1)); | 184 window->SetProperty(kTestImagePropertyKey, new gfx::ImageSkia(value_1)); |
| 179 gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImagePropertyKey); | 185 gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImagePropertyKey); |
| 180 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_1, *image_out_1->bitmap())); | 186 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_1, *image_out_1->bitmap())); |
| 181 | 187 |
| (...skipping 20 matching lines...) Expand all Loading... |
| 202 } | 208 } |
| 203 | 209 |
| 204 // Verifies property setting behavior for a gfx::Rect* property. | 210 // Verifies property setting behavior for a gfx::Rect* property. |
| 205 TEST_F(PropertyConverterTest, RectProperty) { | 211 TEST_F(PropertyConverterTest, RectProperty) { |
| 206 PropertyConverter property_converter; | 212 PropertyConverter property_converter; |
| 207 property_converter.RegisterProperty(kTestRectPropertyKey, | 213 property_converter.RegisterProperty(kTestRectPropertyKey, |
| 208 kTestRectPropertyServerKey); | 214 kTestRectPropertyServerKey); |
| 209 EXPECT_EQ( | 215 EXPECT_EQ( |
| 210 kTestRectPropertyServerKey, | 216 kTestRectPropertyServerKey, |
| 211 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey)); | 217 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey)); |
| 218 EXPECT_TRUE( |
| 219 property_converter.IsTransportNameRegistered(kTestRectPropertyServerKey)); |
| 212 | 220 |
| 213 gfx::Rect value_1(1, 2, 3, 4); | 221 gfx::Rect value_1(1, 2, 3, 4); |
| 214 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 222 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 215 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1)); | 223 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1)); |
| 216 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey)); | 224 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey)); |
| 217 | 225 |
| 218 std::string transport_name_out; | 226 std::string transport_name_out; |
| 219 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 227 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 220 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 228 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
| 221 window.get(), kTestRectPropertyKey, &transport_name_out, | 229 window.get(), kTestRectPropertyKey, &transport_name_out, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 233 } | 241 } |
| 234 | 242 |
| 235 // Verifies property setting behavior for a gfx::Size* property. | 243 // Verifies property setting behavior for a gfx::Size* property. |
| 236 TEST_F(PropertyConverterTest, SizeProperty) { | 244 TEST_F(PropertyConverterTest, SizeProperty) { |
| 237 PropertyConverter property_converter; | 245 PropertyConverter property_converter; |
| 238 property_converter.RegisterProperty(kTestSizePropertyKey, | 246 property_converter.RegisterProperty(kTestSizePropertyKey, |
| 239 kTestSizePropertyServerKey); | 247 kTestSizePropertyServerKey); |
| 240 EXPECT_EQ( | 248 EXPECT_EQ( |
| 241 kTestSizePropertyServerKey, | 249 kTestSizePropertyServerKey, |
| 242 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey)); | 250 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey)); |
| 251 EXPECT_TRUE( |
| 252 property_converter.IsTransportNameRegistered(kTestSizePropertyServerKey)); |
| 243 | 253 |
| 244 gfx::Size value_1(1, 2); | 254 gfx::Size value_1(1, 2); |
| 245 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 255 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 246 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1)); | 256 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1)); |
| 247 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey)); | 257 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey)); |
| 248 | 258 |
| 249 std::string transport_name_out; | 259 std::string transport_name_out; |
| 250 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 260 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 251 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 261 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
| 252 window.get(), kTestSizePropertyKey, &transport_name_out, | 262 window.get(), kTestSizePropertyKey, &transport_name_out, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 264 } | 274 } |
| 265 | 275 |
| 266 // Verifies property setting behavior for a std::string* property. | 276 // Verifies property setting behavior for a std::string* property. |
| 267 TEST_F(PropertyConverterTest, StringProperty) { | 277 TEST_F(PropertyConverterTest, StringProperty) { |
| 268 PropertyConverter property_converter; | 278 PropertyConverter property_converter; |
| 269 property_converter.RegisterProperty(kTestStringPropertyKey, | 279 property_converter.RegisterProperty(kTestStringPropertyKey, |
| 270 kTestStringPropertyServerKey); | 280 kTestStringPropertyServerKey); |
| 271 EXPECT_EQ(kTestStringPropertyServerKey, | 281 EXPECT_EQ(kTestStringPropertyServerKey, |
| 272 property_converter.GetTransportNameForPropertyKey( | 282 property_converter.GetTransportNameForPropertyKey( |
| 273 kTestStringPropertyKey)); | 283 kTestStringPropertyKey)); |
| 284 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
| 285 kTestStringPropertyServerKey)); |
| 274 | 286 |
| 275 std::string value_1 = "test value"; | 287 std::string value_1 = "test value"; |
| 276 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 288 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 277 window->SetProperty(kTestStringPropertyKey, new std::string(value_1)); | 289 window->SetProperty(kTestStringPropertyKey, new std::string(value_1)); |
| 278 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey)); | 290 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey)); |
| 279 | 291 |
| 280 std::string transport_name_out; | 292 std::string transport_name_out; |
| 281 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 293 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 282 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 294 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
| 283 window.get(), kTestStringPropertyKey, &transport_name_out, | 295 window.get(), kTestStringPropertyKey, &transport_name_out, |
| (...skipping 11 matching lines...) Expand all Loading... |
| 295 } | 307 } |
| 296 | 308 |
| 297 // Verifies property setting behavior for a base::string16* property. | 309 // Verifies property setting behavior for a base::string16* property. |
| 298 TEST_F(PropertyConverterTest, String16Property) { | 310 TEST_F(PropertyConverterTest, String16Property) { |
| 299 PropertyConverter property_converter; | 311 PropertyConverter property_converter; |
| 300 property_converter.RegisterProperty(kTestString16PropertyKey, | 312 property_converter.RegisterProperty(kTestString16PropertyKey, |
| 301 kTestString16PropertyServerKey); | 313 kTestString16PropertyServerKey); |
| 302 EXPECT_EQ(kTestString16PropertyServerKey, | 314 EXPECT_EQ(kTestString16PropertyServerKey, |
| 303 property_converter.GetTransportNameForPropertyKey( | 315 property_converter.GetTransportNameForPropertyKey( |
| 304 kTestString16PropertyKey)); | 316 kTestString16PropertyKey)); |
| 317 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
| 318 kTestString16PropertyServerKey)); |
| 305 | 319 |
| 306 base::string16 value_1 = base::ASCIIToUTF16("test value"); | 320 base::string16 value_1 = base::ASCIIToUTF16("test value"); |
| 307 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 321 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 308 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1)); | 322 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1)); |
| 309 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey)); | 323 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey)); |
| 310 | 324 |
| 311 std::string transport_name_out; | 325 std::string transport_name_out; |
| 312 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 326 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 313 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 327 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
| 314 window.get(), kTestString16PropertyKey, &transport_name_out, | 328 window.get(), kTestString16PropertyKey, &transport_name_out, |
| 315 &transport_value_out)); | 329 &transport_value_out)); |
| 316 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out); | 330 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out); |
| 317 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1), | 331 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1), |
| 318 *transport_value_out.get()); | 332 *transport_value_out.get()); |
| 319 | 333 |
| 320 base::string16 value_2 = base::ASCIIToUTF16("another test value"); | 334 base::string16 value_2 = base::ASCIIToUTF16("another test value"); |
| 321 std::vector<uint8_t> transport_value = | 335 std::vector<uint8_t> transport_value = |
| 322 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 336 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
| 323 property_converter.SetPropertyFromTransportValue( | 337 property_converter.SetPropertyFromTransportValue( |
| 324 window.get(), kTestString16PropertyServerKey, &transport_value); | 338 window.get(), kTestString16PropertyServerKey, &transport_value); |
| 325 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); | 339 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); |
| 326 } | 340 } |
| 327 | 341 |
| 328 } // namespace aura | 342 } // namespace aura |
| OLD | NEW |