Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(298)

Side by Side Diff: ui/aura/mus/property_converter_unittest.cc

Issue 2889443002: mash: Add type names to PropertyConverter::Register*Property. (Closed)
Patch Set: Alphabetize calls by function name. Created 3 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after
70 const char kTestString16PropertyServerKey[] = "test-string16-property-server"; 70 const char kTestString16PropertyServerKey[] = "test-string16-property-server";
71 71
72 // Test registration, naming and value conversion for primitive property types. 72 // Test registration, naming and value conversion for primitive property types.
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( 80 property_converter->RegisterPrimitiveProperty(
81 key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback()); 81 key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback());
82 EXPECT_EQ(transport_name, 82 EXPECT_EQ(transport_name,
83 property_converter->GetTransportNameForPropertyKey(key)); 83 property_converter->GetTransportNameForPropertyKey(key));
84 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); 84 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name));
85 85
86 window->SetProperty(key, value_1); 86 window->SetProperty(key, value_1);
87 EXPECT_EQ(value_1, window->GetProperty(key)); 87 EXPECT_EQ(value_1, window->GetProperty(key));
88 88
89 std::string transport_name_out; 89 std::string transport_name_out;
90 std::unique_ptr<std::vector<uint8_t>> transport_value_out; 90 std::unique_ptr<std::vector<uint8_t>> transport_value_out;
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
167 167
168 const int64_t value_9a = INT64_MIN / 5, value_9b = INT64_MIN / 6; 168 const int64_t value_9a = INT64_MIN / 5, value_9b = INT64_MIN / 6;
169 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, 169 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9,
170 kTestPropertyServerKey9, value_9a, value_9b); 170 kTestPropertyServerKey9, value_9a, value_9b);
171 } 171 }
172 172
173 TEST_F(PropertyConverterTest, TestPrimitiveVerifier) { 173 TEST_F(PropertyConverterTest, TestPrimitiveVerifier) {
174 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); 174 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
175 175
176 PropertyConverter property_converter; 176 PropertyConverter property_converter;
177 property_converter.RegisterProperty(kTestPropertyKey8, 177 property_converter.RegisterPrimitiveProperty(
178 kTestPropertyServerKey8, 178 kTestPropertyKey8, kTestPropertyServerKey8,
179 base::Bind(&OnlyAllowNegativeNumbers)); 179 base::Bind(&OnlyAllowNegativeNumbers));
180 180
181 // Test that we reject invalid TransportValues during 181 // Test that we reject invalid TransportValues during
182 // GetPropertyValueFromTransportValue(). 182 // GetPropertyValueFromTransportValue().
183 int64_t int_value = 5; 183 int64_t int_value = 5;
184 std::vector<uint8_t> transport = 184 std::vector<uint8_t> transport =
185 mojo::ConvertTo<std::vector<uint8_t>>(int_value); 185 mojo::ConvertTo<std::vector<uint8_t>>(int_value);
186 EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue( 186 EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue(
187 kTestPropertyServerKey8, transport, &int_value)); 187 kTestPropertyServerKey8, transport, &int_value));
188 188
189 // Test that we reject invalid TransportValues during 189 // Test that we reject invalid TransportValues during
190 // SetPropertyFromTransportValue(). 190 // SetPropertyFromTransportValue().
191 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); 191 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8));
192 property_converter.SetPropertyFromTransportValue( 192 property_converter.SetPropertyFromTransportValue(
193 window.get(), kTestPropertyServerKey8, &transport); 193 window.get(), kTestPropertyServerKey8, &transport);
194 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); 194 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8));
195 } 195 }
196 196
197 // Verifies property setting behavior for a gfx::ImageSkia* property. 197 // Verifies property setting behavior for a gfx::ImageSkia* property.
198 TEST_F(PropertyConverterTest, ImageSkiaProperty) { 198 TEST_F(PropertyConverterTest, ImageSkiaProperty) {
199 PropertyConverter property_converter; 199 PropertyConverter property_converter;
200 property_converter.RegisterProperty(kTestImagePropertyKey, 200 property_converter.RegisterImageProperty(kTestImagePropertyKey,
201 kTestImagePropertyServerKey); 201 kTestImagePropertyServerKey);
202 EXPECT_EQ( 202 EXPECT_EQ(
203 kTestImagePropertyServerKey, 203 kTestImagePropertyServerKey,
204 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); 204 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey));
205 EXPECT_TRUE(property_converter.IsTransportNameRegistered( 205 EXPECT_TRUE(property_converter.IsTransportNameRegistered(
206 kTestImagePropertyServerKey)); 206 kTestImagePropertyServerKey));
207 207
208 SkBitmap bitmap_1; 208 SkBitmap bitmap_1;
209 bitmap_1.allocN32Pixels(16, 32); 209 bitmap_1.allocN32Pixels(16, 32);
210 bitmap_1.eraseARGB(255, 11, 22, 33); 210 bitmap_1.eraseARGB(255, 11, 22, 33);
211 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1); 211 gfx::ImageSkia value_1 = gfx::ImageSkia::CreateFrom1xBitmap(bitmap_1);
(...skipping 20 matching lines...) Expand all
232 mojo::ConvertTo<std::vector<uint8_t>>(bitmap_2); 232 mojo::ConvertTo<std::vector<uint8_t>>(bitmap_2);
233 property_converter.SetPropertyFromTransportValue( 233 property_converter.SetPropertyFromTransportValue(
234 window.get(), kTestImagePropertyServerKey, &transport_value); 234 window.get(), kTestImagePropertyServerKey, &transport_value);
235 gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImagePropertyKey); 235 gfx::ImageSkia* image_out_2 = window->GetProperty(kTestImagePropertyKey);
236 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_2, *image_out_2->bitmap())); 236 EXPECT_TRUE(gfx::BitmapsAreEqual(bitmap_2, *image_out_2->bitmap()));
237 } 237 }
238 238
239 // Verifies property setting behavior for a gfx::Rect* property. 239 // Verifies property setting behavior for a gfx::Rect* property.
240 TEST_F(PropertyConverterTest, RectProperty) { 240 TEST_F(PropertyConverterTest, RectProperty) {
241 PropertyConverter property_converter; 241 PropertyConverter property_converter;
242 property_converter.RegisterProperty(kTestRectPropertyKey, 242 property_converter.RegisterRectProperty(kTestRectPropertyKey,
243 kTestRectPropertyServerKey); 243 kTestRectPropertyServerKey);
244 EXPECT_EQ( 244 EXPECT_EQ(
245 kTestRectPropertyServerKey, 245 kTestRectPropertyServerKey,
246 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey)); 246 property_converter.GetTransportNameForPropertyKey(kTestRectPropertyKey));
247 EXPECT_TRUE( 247 EXPECT_TRUE(
248 property_converter.IsTransportNameRegistered(kTestRectPropertyServerKey)); 248 property_converter.IsTransportNameRegistered(kTestRectPropertyServerKey));
249 249
250 gfx::Rect value_1(1, 2, 3, 4); 250 gfx::Rect value_1(1, 2, 3, 4);
251 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); 251 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
252 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1)); 252 window->SetProperty(kTestRectPropertyKey, new gfx::Rect(value_1));
253 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey)); 253 EXPECT_EQ(value_1, *window->GetProperty(kTestRectPropertyKey));
(...skipping 11 matching lines...) Expand all
265 std::vector<uint8_t> transport_value = 265 std::vector<uint8_t> transport_value =
266 mojo::ConvertTo<std::vector<uint8_t>>(value_2); 266 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
267 property_converter.SetPropertyFromTransportValue( 267 property_converter.SetPropertyFromTransportValue(
268 window.get(), kTestRectPropertyServerKey, &transport_value); 268 window.get(), kTestRectPropertyServerKey, &transport_value);
269 EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey)); 269 EXPECT_EQ(value_2, *window->GetProperty(kTestRectPropertyKey));
270 } 270 }
271 271
272 // Verifies property setting behavior for a gfx::Size* property. 272 // Verifies property setting behavior for a gfx::Size* property.
273 TEST_F(PropertyConverterTest, SizeProperty) { 273 TEST_F(PropertyConverterTest, SizeProperty) {
274 PropertyConverter property_converter; 274 PropertyConverter property_converter;
275 property_converter.RegisterProperty(kTestSizePropertyKey, 275 property_converter.RegisterSizeProperty(kTestSizePropertyKey,
276 kTestSizePropertyServerKey); 276 kTestSizePropertyServerKey);
277 EXPECT_EQ( 277 EXPECT_EQ(
278 kTestSizePropertyServerKey, 278 kTestSizePropertyServerKey,
279 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey)); 279 property_converter.GetTransportNameForPropertyKey(kTestSizePropertyKey));
280 EXPECT_TRUE( 280 EXPECT_TRUE(
281 property_converter.IsTransportNameRegistered(kTestSizePropertyServerKey)); 281 property_converter.IsTransportNameRegistered(kTestSizePropertyServerKey));
282 282
283 gfx::Size value_1(1, 2); 283 gfx::Size value_1(1, 2);
284 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); 284 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
285 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1)); 285 window->SetProperty(kTestSizePropertyKey, new gfx::Size(value_1));
286 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey)); 286 EXPECT_EQ(value_1, *window->GetProperty(kTestSizePropertyKey));
(...skipping 11 matching lines...) Expand all
298 std::vector<uint8_t> transport_value = 298 std::vector<uint8_t> transport_value =
299 mojo::ConvertTo<std::vector<uint8_t>>(value_2); 299 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
300 property_converter.SetPropertyFromTransportValue( 300 property_converter.SetPropertyFromTransportValue(
301 window.get(), kTestSizePropertyServerKey, &transport_value); 301 window.get(), kTestSizePropertyServerKey, &transport_value);
302 EXPECT_EQ(value_2, *window->GetProperty(kTestSizePropertyKey)); 302 EXPECT_EQ(value_2, *window->GetProperty(kTestSizePropertyKey));
303 } 303 }
304 304
305 // Verifies property setting behavior for a std::string* property. 305 // Verifies property setting behavior for a std::string* property.
306 TEST_F(PropertyConverterTest, StringProperty) { 306 TEST_F(PropertyConverterTest, StringProperty) {
307 PropertyConverter property_converter; 307 PropertyConverter property_converter;
308 property_converter.RegisterProperty(kTestStringPropertyKey, 308 property_converter.RegisterStringProperty(kTestStringPropertyKey,
309 kTestStringPropertyServerKey); 309 kTestStringPropertyServerKey);
310 EXPECT_EQ(kTestStringPropertyServerKey, 310 EXPECT_EQ(kTestStringPropertyServerKey,
311 property_converter.GetTransportNameForPropertyKey( 311 property_converter.GetTransportNameForPropertyKey(
312 kTestStringPropertyKey)); 312 kTestStringPropertyKey));
313 EXPECT_TRUE(property_converter.IsTransportNameRegistered( 313 EXPECT_TRUE(property_converter.IsTransportNameRegistered(
314 kTestStringPropertyServerKey)); 314 kTestStringPropertyServerKey));
315 315
316 std::string value_1 = "test value"; 316 std::string value_1 = "test value";
317 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); 317 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
318 window->SetProperty(kTestStringPropertyKey, new std::string(value_1)); 318 window->SetProperty(kTestStringPropertyKey, new std::string(value_1));
319 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey)); 319 EXPECT_EQ(value_1, *window->GetProperty(kTestStringPropertyKey));
(...skipping 11 matching lines...) Expand all
331 std::vector<uint8_t> transport_value = 331 std::vector<uint8_t> transport_value =
332 mojo::ConvertTo<std::vector<uint8_t>>(value_2); 332 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
333 property_converter.SetPropertyFromTransportValue( 333 property_converter.SetPropertyFromTransportValue(
334 window.get(), kTestStringPropertyServerKey, &transport_value); 334 window.get(), kTestStringPropertyServerKey, &transport_value);
335 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey)); 335 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey));
336 } 336 }
337 337
338 // Verifies property setting behavior for a base::string16* property. 338 // Verifies property setting behavior for a base::string16* property.
339 TEST_F(PropertyConverterTest, String16Property) { 339 TEST_F(PropertyConverterTest, String16Property) {
340 PropertyConverter property_converter; 340 PropertyConverter property_converter;
341 property_converter.RegisterProperty(kTestString16PropertyKey, 341 property_converter.RegisterString16Property(kTestString16PropertyKey,
342 kTestString16PropertyServerKey); 342 kTestString16PropertyServerKey);
343 EXPECT_EQ(kTestString16PropertyServerKey, 343 EXPECT_EQ(kTestString16PropertyServerKey,
344 property_converter.GetTransportNameForPropertyKey( 344 property_converter.GetTransportNameForPropertyKey(
345 kTestString16PropertyKey)); 345 kTestString16PropertyKey));
346 EXPECT_TRUE(property_converter.IsTransportNameRegistered( 346 EXPECT_TRUE(property_converter.IsTransportNameRegistered(
347 kTestString16PropertyServerKey)); 347 kTestString16PropertyServerKey));
348 348
349 base::string16 value_1 = base::ASCIIToUTF16("test value"); 349 base::string16 value_1 = base::ASCIIToUTF16("test value");
350 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); 350 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
351 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1)); 351 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1));
352 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey)); 352 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey));
353 353
354 std::string transport_name_out; 354 std::string transport_name_out;
355 std::unique_ptr<std::vector<uint8_t>> transport_value_out; 355 std::unique_ptr<std::vector<uint8_t>> transport_value_out;
356 EXPECT_TRUE(property_converter.ConvertPropertyForTransport( 356 EXPECT_TRUE(property_converter.ConvertPropertyForTransport(
357 window.get(), kTestString16PropertyKey, &transport_name_out, 357 window.get(), kTestString16PropertyKey, &transport_name_out,
358 &transport_value_out)); 358 &transport_value_out));
359 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out); 359 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out);
360 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1), 360 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1),
361 *transport_value_out.get()); 361 *transport_value_out.get());
362 362
363 base::string16 value_2 = base::ASCIIToUTF16("another test value"); 363 base::string16 value_2 = base::ASCIIToUTF16("another test value");
364 std::vector<uint8_t> transport_value = 364 std::vector<uint8_t> transport_value =
365 mojo::ConvertTo<std::vector<uint8_t>>(value_2); 365 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
366 property_converter.SetPropertyFromTransportValue( 366 property_converter.SetPropertyFromTransportValue(
367 window.get(), kTestString16PropertyServerKey, &transport_value); 367 window.get(), kTestString16PropertyServerKey, &transport_value);
368 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); 368 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey));
369 } 369 }
370 370
371 } // namespace aura 371 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698