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 25 matching lines...) Expand all Loading... |
36 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey1, true); | 36 DEFINE_UI_CLASS_PROPERTY_KEY(bool, kTestPropertyKey1, true); |
37 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey2, UINT8_MAX / 3); | 37 DEFINE_UI_CLASS_PROPERTY_KEY(uint8_t, kTestPropertyKey2, UINT8_MAX / 3); |
38 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey3, UINT16_MAX / 3); | 38 DEFINE_UI_CLASS_PROPERTY_KEY(uint16_t, kTestPropertyKey3, UINT16_MAX / 3); |
39 DEFINE_UI_CLASS_PROPERTY_KEY(uint32_t, kTestPropertyKey4, UINT32_MAX); | 39 DEFINE_UI_CLASS_PROPERTY_KEY(uint32_t, kTestPropertyKey4, UINT32_MAX); |
40 DEFINE_UI_CLASS_PROPERTY_KEY(uint64_t, kTestPropertyKey5, UINT64_MAX); | 40 DEFINE_UI_CLASS_PROPERTY_KEY(uint64_t, kTestPropertyKey5, UINT64_MAX); |
41 DEFINE_UI_CLASS_PROPERTY_KEY(int8_t, kTestPropertyKey6, 0); | 41 DEFINE_UI_CLASS_PROPERTY_KEY(int8_t, kTestPropertyKey6, 0); |
42 DEFINE_UI_CLASS_PROPERTY_KEY(int16_t, kTestPropertyKey7, 1); | 42 DEFINE_UI_CLASS_PROPERTY_KEY(int16_t, kTestPropertyKey7, 1); |
43 DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kTestPropertyKey8, -1); | 43 DEFINE_UI_CLASS_PROPERTY_KEY(int32_t, kTestPropertyKey8, -1); |
44 DEFINE_UI_CLASS_PROPERTY_KEY(int64_t, kTestPropertyKey9, 777); | 44 DEFINE_UI_CLASS_PROPERTY_KEY(int64_t, kTestPropertyKey9, 777); |
45 | 45 |
46 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, kTestImagePropertyKey, | 46 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::ImageSkia, |
47 nullptr); | 47 kTestImageSkiaPropertyKey, |
| 48 nullptr); |
48 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); | 49 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); |
49 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr); | 50 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(gfx::Size, kTestSizePropertyKey, nullptr); |
50 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY( | 51 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY( |
51 std::string, kTestStringPropertyKey, nullptr); | 52 std::string, kTestStringPropertyKey, nullptr); |
52 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(base::string16, kTestString16PropertyKey, | 53 DEFINE_OWNED_UI_CLASS_PROPERTY_KEY(base::string16, kTestString16PropertyKey, |
53 nullptr); | 54 nullptr); |
54 | 55 |
55 const char kTestPropertyServerKey0[] = "test-property-server0"; | 56 const char kTestPropertyServerKey0[] = "test-property-server0"; |
56 const char kTestPropertyServerKey1[] = "test-property-server1"; | 57 const char kTestPropertyServerKey1[] = "test-property-server1"; |
57 const char kTestPropertyServerKey2[] = "test-property-server2"; | 58 const char kTestPropertyServerKey2[] = "test-property-server2"; |
58 const char kTestPropertyServerKey3[] = "test-property-server3"; | 59 const char kTestPropertyServerKey3[] = "test-property-server3"; |
59 const char kTestPropertyServerKey4[] = "test-property-server4"; | 60 const char kTestPropertyServerKey4[] = "test-property-server4"; |
60 const char kTestPropertyServerKey5[] = "test-property-server5"; | 61 const char kTestPropertyServerKey5[] = "test-property-server5"; |
61 const char kTestPropertyServerKey6[] = "test-property-server6"; | 62 const char kTestPropertyServerKey6[] = "test-property-server6"; |
62 const char kTestPropertyServerKey7[] = "test-property-server7"; | 63 const char kTestPropertyServerKey7[] = "test-property-server7"; |
63 const char kTestPropertyServerKey8[] = "test-property-server8"; | 64 const char kTestPropertyServerKey8[] = "test-property-server8"; |
64 const char kTestPropertyServerKey9[] = "test-property-server9"; | 65 const char kTestPropertyServerKey9[] = "test-property-server9"; |
65 | 66 |
66 const char kTestImagePropertyServerKey[] = "test-image-property-server"; | 67 const char kTestImageSkiaPropertyServerKey[] = "test-imageskia-property-server"; |
67 const char kTestRectPropertyServerKey[] = "test-rect-property-server"; | 68 const char kTestRectPropertyServerKey[] = "test-rect-property-server"; |
68 const char kTestSizePropertyServerKey[] = "test-size-property-server"; | 69 const char kTestSizePropertyServerKey[] = "test-size-property-server"; |
69 const char kTestStringPropertyServerKey[] = "test-string-property-server"; | 70 const char kTestStringPropertyServerKey[] = "test-string-property-server"; |
70 const char kTestString16PropertyServerKey[] = "test-string16-property-server"; | 71 const char kTestString16PropertyServerKey[] = "test-string16-property-server"; |
71 | 72 |
72 // Test registration, naming and value conversion for primitive property types. | 73 // Test registration, naming and value conversion for primitive property types. |
73 template <typename T> | 74 template <typename T> |
74 void TestPrimitiveProperty(PropertyConverter* property_converter, | 75 void TestPrimitiveProperty(PropertyConverter* property_converter, |
75 Window* window, | 76 Window* window, |
76 const WindowProperty<T>* key, | 77 const WindowProperty<T>* key, |
77 const char* transport_name, | 78 const char* transport_name, |
78 T value_1, | 79 T value_1, |
79 T value_2) { | 80 T value_2) { |
80 property_converter->RegisterProperty( | 81 property_converter->RegisterPrimitiveProperty( |
81 key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback()); | 82 key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback()); |
82 EXPECT_EQ(transport_name, | 83 EXPECT_EQ(transport_name, |
83 property_converter->GetTransportNameForPropertyKey(key)); | 84 property_converter->GetTransportNameForPropertyKey(key)); |
84 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); | 85 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); |
85 | 86 |
86 window->SetProperty(key, value_1); | 87 window->SetProperty(key, value_1); |
87 EXPECT_EQ(value_1, window->GetProperty(key)); | 88 EXPECT_EQ(value_1, window->GetProperty(key)); |
88 | 89 |
89 std::string transport_name_out; | 90 std::string transport_name_out; |
90 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 91 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
167 | 168 |
168 const int64_t value_9a = INT64_MIN / 5, value_9b = INT64_MIN / 6; | 169 const int64_t value_9a = INT64_MIN / 5, value_9b = INT64_MIN / 6; |
169 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, | 170 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, |
170 kTestPropertyServerKey9, value_9a, value_9b); | 171 kTestPropertyServerKey9, value_9a, value_9b); |
171 } | 172 } |
172 | 173 |
173 TEST_F(PropertyConverterTest, TestPrimitiveVerifier) { | 174 TEST_F(PropertyConverterTest, TestPrimitiveVerifier) { |
174 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 175 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
175 | 176 |
176 PropertyConverter property_converter; | 177 PropertyConverter property_converter; |
177 property_converter.RegisterProperty(kTestPropertyKey8, | 178 property_converter.RegisterPrimitiveProperty( |
178 kTestPropertyServerKey8, | 179 kTestPropertyKey8, kTestPropertyServerKey8, |
179 base::Bind(&OnlyAllowNegativeNumbers)); | 180 base::Bind(&OnlyAllowNegativeNumbers)); |
180 | 181 |
181 // Test that we reject invalid TransportValues during | 182 // Test that we reject invalid TransportValues during |
182 // GetPropertyValueFromTransportValue(). | 183 // GetPropertyValueFromTransportValue(). |
183 int64_t int_value = 5; | 184 int64_t int_value = 5; |
184 std::vector<uint8_t> transport = | 185 std::vector<uint8_t> transport = |
185 mojo::ConvertTo<std::vector<uint8_t>>(int_value); | 186 mojo::ConvertTo<std::vector<uint8_t>>(int_value); |
186 EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue( | 187 EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue( |
187 kTestPropertyServerKey8, transport, &int_value)); | 188 kTestPropertyServerKey8, transport, &int_value)); |
188 | 189 |
189 // Test that we reject invalid TransportValues during | 190 // Test that we reject invalid TransportValues during |
190 // SetPropertyFromTransportValue(). | 191 // SetPropertyFromTransportValue(). |
191 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); | 192 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); |
192 property_converter.SetPropertyFromTransportValue( | 193 property_converter.SetPropertyFromTransportValue( |
193 window.get(), kTestPropertyServerKey8, &transport); | 194 window.get(), kTestPropertyServerKey8, &transport); |
194 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); | 195 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); |
195 } | 196 } |
196 | 197 |
197 // Verifies property setting behavior for a gfx::ImageSkia* property. | 198 // Verifies property setting behavior for a gfx::ImageSkia* property. |
198 TEST_F(PropertyConverterTest, ImageSkiaProperty) { | 199 TEST_F(PropertyConverterTest, ImageSkiaProperty) { |
199 PropertyConverter property_converter; | 200 PropertyConverter property_converter; |
200 property_converter.RegisterProperty(kTestImagePropertyKey, | 201 property_converter.RegisterImageSkiaProperty(kTestImageSkiaPropertyKey, |
201 kTestImagePropertyServerKey); | 202 kTestImageSkiaPropertyServerKey); |
202 EXPECT_EQ( | 203 EXPECT_EQ(kTestImageSkiaPropertyServerKey, |
203 kTestImagePropertyServerKey, | 204 property_converter.GetTransportNameForPropertyKey( |
204 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); | 205 kTestImageSkiaPropertyKey)); |
205 EXPECT_TRUE(property_converter.IsTransportNameRegistered( | 206 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
206 kTestImagePropertyServerKey)); | 207 kTestImageSkiaPropertyServerKey)); |
207 | 208 |
208 SkBitmap bitmap_1; | 209 SkBitmap bitmap_1; |
209 bitmap_1.allocN32Pixels(16, 32); | 210 bitmap_1.allocN32Pixels(16, 32); |
210 bitmap_1.eraseARGB(255, 11, 22, 33); | 211 bitmap_1.eraseARGB(255, 11, 22, 33); |
211 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1); | 212 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1); |
212 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 213 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
213 window->SetProperty(kTestImagePropertyKey, new gfx::ImageSkia(value_1)); | 214 window->SetProperty(kTestImageSkiaPropertyKey, new gfx::ImageSkia(value_1)); |
214 gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImagePropertyKey); | 215 gfx::ImageSkia* image_out_1 = window->GetProperty(kTestImageSkiaPropertyKey); |
215 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_1, *image_out_1->bitmap())); | 216 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_1, *image_out_1->bitmap())); |
216 | 217 |
217 std::string transport_name_out; | 218 std::string transport_name_out; |
218 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 219 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
219 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 220 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
220 window.get(), kTestImagePropertyKey, &transport_name_out, | 221 window.get(), kTestImageSkiaPropertyKey, &transport_name_out, |
221 &transport_value_out)); | 222 &transport_value_out)); |
222 EXPECT_EQ(kTestImagePropertyServerKey, transport_name_out); | 223 EXPECT_EQ(kTestImageSkiaPropertyServerKey, transport_name_out); |
223 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(bitmap_1), | 224 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(bitmap_1), |
224 *transport_value_out.get()); | 225 *transport_value_out.get()); |
225 | 226 |
226 SkBitmap bitmap_2; | 227 SkBitmap bitmap_2; |
227 bitmap_2.allocN32Pixels(16, 16); | 228 bitmap_2.allocN32Pixels(16, 16); |
228 bitmap_2.eraseARGB(255, 33, 22, 11); | 229 bitmap_2.eraseARGB(255, 33, 22, 11); |
229 EXPECT_FALSE(gfx::BitmapsAreEqual(bitmap_1, bitmap_2)); | 230 EXPECT_FALSE(gfx::BitmapsAreEqual(bitmap_1, bitmap_2)); |
230 gfx::ImageSkia value_2 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_2); | 231 gfx::ImageSkia value_2 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_2); |
231 std::vector<uint8_t> transport_value = | 232 std::vector<uint8_t> transport_value = |
232 mojo::ConvertTo<std::vector<uint8_t>>(bitmap_2); | 233 mojo::ConvertTo<std::vector<uint8_t>>(bitmap_2); |
233 property_converter.SetPropertyFromTransportValue( | 234 property_converter.SetPropertyFromTransportValue( |
234 window.get(), kTestImagePropertyServerKey, &transport_value); | 235 window.get(), kTestImageSkiaPropertyServerKey, &transport_value); |
235 gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImagePropertyKey); | 236 gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImageSkiaPropertyKey); |
236 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_2, *image_out_2->bitmap())); | 237 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_2, *image_out_2->bitmap())); |
237 } | 238 } |
238 | 239 |
239 // Verifies property setting behavior for a gfx::Rect* property. | 240 // Verifies property setting behavior for a gfx::Rect* property. |
240 TEST_F(PropertyConverterTest, RectProperty) { | 241 TEST_F(PropertyConverterTest, RectProperty) { |
241 PropertyConverter property_converter; | 242 PropertyConverter property_converter; |
242 property_converter.RegisterProperty(kTestRectPropertyKey, | 243 property_converter.RegisterRectProperty(kTestRectPropertyKey, |
243 kTestRectPropertyServerKey); | 244 kTestRectPropertyServerKey); |
244 EXPECT_EQ( | 245 EXPECT_EQ( |
245 kTestRectPropertyServerKey, | 246 kTestRectPropertyServerKey, |
246 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey)); | 247 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey)); |
247 EXPECT_TRUE( | 248 EXPECT_TRUE( |
248 property_converter.IsTransportNameRegistered(kTestRectPropertyServerKey)); | 249 property_converter.IsTransportNameRegistered(kTestRectPropertyServerKey)); |
249 | 250 |
250 gfx::Rect value_1(1, 2, 3, 4); | 251 gfx::Rect value_1(1, 2, 3, 4); |
251 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 252 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
252 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1)); | 253 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1)); |
253 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey)); | 254 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey)); |
(...skipping 11 matching lines...) Expand all Loading... |
265 std::vector<uint8_t> transport_value = | 266 std::vector<uint8_t> transport_value = |
266 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 267 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
267 property_converter.SetPropertyFromTransportValue( | 268 property_converter.SetPropertyFromTransportValue( |
268 window.get(), kTestRectPropertyServerKey, &transport_value); | 269 window.get(), kTestRectPropertyServerKey, &transport_value); |
269 EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey)); | 270 EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey)); |
270 } | 271 } |
271 | 272 |
272 // Verifies property setting behavior for a gfx::Size* property. | 273 // Verifies property setting behavior for a gfx::Size* property. |
273 TEST_F(PropertyConverterTest, SizeProperty) { | 274 TEST_F(PropertyConverterTest, SizeProperty) { |
274 PropertyConverter property_converter; | 275 PropertyConverter property_converter; |
275 property_converter.RegisterProperty(kTestSizePropertyKey, | 276 property_converter.RegisterSizeProperty(kTestSizePropertyKey, |
276 kTestSizePropertyServerKey); | 277 kTestSizePropertyServerKey); |
277 EXPECT_EQ( | 278 EXPECT_EQ( |
278 kTestSizePropertyServerKey, | 279 kTestSizePropertyServerKey, |
279 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey)); | 280 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey)); |
280 EXPECT_TRUE( | 281 EXPECT_TRUE( |
281 property_converter.IsTransportNameRegistered(kTestSizePropertyServerKey)); | 282 property_converter.IsTransportNameRegistered(kTestSizePropertyServerKey)); |
282 | 283 |
283 gfx::Size value_1(1, 2); | 284 gfx::Size value_1(1, 2); |
284 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 285 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
285 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1)); | 286 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1)); |
286 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey)); | 287 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey)); |
(...skipping 11 matching lines...) Expand all Loading... |
298 std::vector<uint8_t> transport_value = | 299 std::vector<uint8_t> transport_value = |
299 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 300 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
300 property_converter.SetPropertyFromTransportValue( | 301 property_converter.SetPropertyFromTransportValue( |
301 window.get(), kTestSizePropertyServerKey, &transport_value); | 302 window.get(), kTestSizePropertyServerKey, &transport_value); |
302 EXPECT_EQ(value_2, *window->GetProperty(kTestSizePropertyKey)); | 303 EXPECT_EQ(value_2, *window->GetProperty(kTestSizePropertyKey)); |
303 } | 304 } |
304 | 305 |
305 // Verifies property setting behavior for a std::string* property. | 306 // Verifies property setting behavior for a std::string* property. |
306 TEST_F(PropertyConverterTest, StringProperty) { | 307 TEST_F(PropertyConverterTest, StringProperty) { |
307 PropertyConverter property_converter; | 308 PropertyConverter property_converter; |
308 property_converter.RegisterProperty(kTestStringPropertyKey, | 309 property_converter.RegisterStringProperty(kTestStringPropertyKey, |
309 kTestStringPropertyServerKey); | 310 kTestStringPropertyServerKey); |
310 EXPECT_EQ(kTestStringPropertyServerKey, | 311 EXPECT_EQ(kTestStringPropertyServerKey, |
311 property_converter.GetTransportNameForPropertyKey( | 312 property_converter.GetTransportNameForPropertyKey( |
312 kTestStringPropertyKey)); | 313 kTestStringPropertyKey)); |
313 EXPECT_TRUE(property_converter.IsTransportNameRegistered( | 314 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
314 kTestStringPropertyServerKey)); | 315 kTestStringPropertyServerKey)); |
315 | 316 |
316 std::string value_1 = "test value"; | 317 std::string value_1 = "test value"; |
317 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 318 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
318 window->SetProperty(kTestStringPropertyKey, new std::string(value_1)); | 319 window->SetProperty(kTestStringPropertyKey, new std::string(value_1)); |
319 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey)); | 320 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey)); |
(...skipping 11 matching lines...) Expand all Loading... |
331 std::vector<uint8_t> transport_value = | 332 std::vector<uint8_t> transport_value = |
332 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 333 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
333 property_converter.SetPropertyFromTransportValue( | 334 property_converter.SetPropertyFromTransportValue( |
334 window.get(), kTestStringPropertyServerKey, &transport_value); | 335 window.get(), kTestStringPropertyServerKey, &transport_value); |
335 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey)); | 336 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey)); |
336 } | 337 } |
337 | 338 |
338 // Verifies property setting behavior for a base::string16* property. | 339 // Verifies property setting behavior for a base::string16* property. |
339 TEST_F(PropertyConverterTest, String16Property) { | 340 TEST_F(PropertyConverterTest, String16Property) { |
340 PropertyConverter property_converter; | 341 PropertyConverter property_converter; |
341 property_converter.RegisterProperty(kTestString16PropertyKey, | 342 property_converter.RegisterString16Property(kTestString16PropertyKey, |
342 kTestString16PropertyServerKey); | 343 kTestString16PropertyServerKey); |
343 EXPECT_EQ(kTestString16PropertyServerKey, | 344 EXPECT_EQ(kTestString16PropertyServerKey, |
344 property_converter.GetTransportNameForPropertyKey( | 345 property_converter.GetTransportNameForPropertyKey( |
345 kTestString16PropertyKey)); | 346 kTestString16PropertyKey)); |
346 EXPECT_TRUE(property_converter.IsTransportNameRegistered( | 347 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
347 kTestString16PropertyServerKey)); | 348 kTestString16PropertyServerKey)); |
348 | 349 |
349 base::string16 value_1 = base::ASCIIToUTF16("test value"); | 350 base::string16 value_1 = base::ASCIIToUTF16("test value"); |
350 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 351 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
351 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1)); | 352 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1)); |
352 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey)); | 353 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey)); |
353 | 354 |
354 std::string transport_name_out; | 355 std::string transport_name_out; |
355 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 356 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
356 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( | 357 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( |
357 window.get(), kTestString16PropertyKey, &transport_name_out, | 358 window.get(), kTestString16PropertyKey, &transport_name_out, |
358 &transport_value_out)); | 359 &transport_value_out)); |
359 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out); | 360 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out); |
360 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1), | 361 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1), |
361 *transport_value_out.get()); | 362 *transport_value_out.get()); |
362 | 363 |
363 base::string16 value_2 = base::ASCIIToUTF16("another test value"); | 364 base::string16 value_2 = base::ASCIIToUTF16("another test value"); |
364 std::vector<uint8_t> transport_value = | 365 std::vector<uint8_t> transport_value = |
365 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 366 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
366 property_converter.SetPropertyFromTransportValue( | 367 property_converter.SetPropertyFromTransportValue( |
367 window.get(), kTestString16PropertyServerKey, &transport_value); | 368 window.get(), kTestString16PropertyServerKey, &transport_value); |
368 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); | 369 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); |
369 } | 370 } |
370 | 371 |
371 } // namespace aura | 372 } // namespace aura |
OLD | NEW |