| 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 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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(key, transport_name); | 80 property_converter->RegisterProperty( |
| 81 key, transport_name, PropertyConverter::CreateAcceptAnyValueCallback()); |
| 81 EXPECT_EQ(transport_name, | 82 EXPECT_EQ(transport_name, |
| 82 property_converter->GetTransportNameForPropertyKey(key)); | 83 property_converter->GetTransportNameForPropertyKey(key)); |
| 83 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); | 84 EXPECT_TRUE(property_converter->IsTransportNameRegistered(transport_name)); |
| 84 | 85 |
| 85 window->SetProperty(key, value_1); | 86 window->SetProperty(key, value_1); |
| 86 EXPECT_EQ(value_1, window->GetProperty(key)); | 87 EXPECT_EQ(value_1, window->GetProperty(key)); |
| 87 | 88 |
| 88 std::string transport_name_out; | 89 std::string transport_name_out; |
| 89 std::unique_ptr<std::vector<uint8_t>> transport_value_out; | 90 std::unique_ptr<std::vector<uint8_t>> transport_value_out; |
| 90 EXPECT_TRUE(property_converter->ConvertPropertyForTransport( | 91 EXPECT_TRUE(property_converter->ConvertPropertyForTransport( |
| (...skipping 14 matching lines...) Expand all Loading... |
| 105 mojo::ConvertTo<std::vector<uint8_t>>(storage_value_2); | 106 mojo::ConvertTo<std::vector<uint8_t>>(storage_value_2); |
| 106 property_converter->SetPropertyFromTransportValue(window, transport_name, | 107 property_converter->SetPropertyFromTransportValue(window, transport_name, |
| 107 &transport_value2); | 108 &transport_value2); |
| 108 EXPECT_EQ(value_2, window->GetProperty(key)); | 109 EXPECT_EQ(value_2, window->GetProperty(key)); |
| 109 int64_t decoded_value_2 = 0; | 110 int64_t decoded_value_2 = 0; |
| 110 EXPECT_TRUE(property_converter->GetPropertyValueFromTransportValue( | 111 EXPECT_TRUE(property_converter->GetPropertyValueFromTransportValue( |
| 111 transport_name, transport_value2, &decoded_value_2)); | 112 transport_name, transport_value2, &decoded_value_2)); |
| 112 EXPECT_EQ(value_2, static_cast<T>(decoded_value_2)); | 113 EXPECT_EQ(value_2, static_cast<T>(decoded_value_2)); |
| 113 } | 114 } |
| 114 | 115 |
| 116 bool OnlyAllowNegativeNumbers(int64_t number) { |
| 117 return number < 0; |
| 118 } |
| 119 |
| 115 } // namespace | 120 } // namespace |
| 116 | 121 |
| 117 using PropertyConverterTest = test::AuraTestBase; | 122 using PropertyConverterTest = test::AuraTestBase; |
| 118 | 123 |
| 119 // Verifies property setting behavior for a std::string* property. | 124 // Verifies property setting behavior for a std::string* property. |
| 120 TEST_F(PropertyConverterTest, PrimitiveProperties) { | 125 TEST_F(PropertyConverterTest, PrimitiveProperties) { |
| 121 PropertyConverter property_converter; | 126 PropertyConverter property_converter; |
| 122 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); | 127 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 123 | 128 |
| 124 EXPECT_FALSE( | 129 EXPECT_FALSE( |
| (...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 158 | 163 |
| 159 const int32_t value_8a = INT32_MIN / 4, value_8b = INT32_MIN / 5; | 164 const int32_t value_8a = INT32_MIN / 4, value_8b = INT32_MIN / 5; |
| 160 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey8, | 165 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey8, |
| 161 kTestPropertyServerKey8, value_8a, value_8b); | 166 kTestPropertyServerKey8, value_8a, value_8b); |
| 162 | 167 |
| 163 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; |
| 164 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, | 169 TestPrimitiveProperty(&property_converter, window.get(), kTestPropertyKey9, |
| 165 kTestPropertyServerKey9, value_9a, value_9b); | 170 kTestPropertyServerKey9, value_9a, value_9b); |
| 166 } | 171 } |
| 167 | 172 |
| 173 TEST_F(PropertyConverterTest, TestPrimitiveVerifier) { |
| 174 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr)); |
| 175 |
| 176 PropertyConverter property_converter; |
| 177 property_converter.RegisterProperty(kTestPropertyKey8, |
| 178 kTestPropertyServerKey8, |
| 179 base::Bind(&OnlyAllowNegativeNumbers)); |
| 180 |
| 181 // Test that we reject invalid TransportValues during |
| 182 // GetPropertyValueFromTransportValue(). |
| 183 int64_t int_value = 5; |
| 184 std::vector<uint8_t> transport = |
| 185 mojo::ConvertTo<std::vector<uint8_t>>(int_value); |
| 186 EXPECT_FALSE(property_converter.GetPropertyValueFromTransportValue( |
| 187 kTestPropertyServerKey8, transport, &int_value)); |
| 188 |
| 189 // Test that we reject invalid TransportValues during |
| 190 // SetPropertyFromTransportValue(). |
| 191 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); |
| 192 property_converter.SetPropertyFromTransportValue( |
| 193 window.get(), kTestPropertyServerKey8, &transport); |
| 194 EXPECT_EQ(-1, window->GetProperty(kTestPropertyKey8)); |
| 195 } |
| 196 |
| 168 // Verifies property setting behavior for a gfx::ImageSkia* property. | 197 // Verifies property setting behavior for a gfx::ImageSkia* property. |
| 169 TEST_F(PropertyConverterTest, ImageSkiaProperty) { | 198 TEST_F(PropertyConverterTest, ImageSkiaProperty) { |
| 170 PropertyConverter property_converter; | 199 PropertyConverter property_converter; |
| 171 property_converter.RegisterProperty(kTestImagePropertyKey, | 200 property_converter.RegisterProperty(kTestImagePropertyKey, |
| 172 kTestImagePropertyServerKey); | 201 kTestImagePropertyServerKey); |
| 173 EXPECT_EQ( | 202 EXPECT_EQ( |
| 174 kTestImagePropertyServerKey, | 203 kTestImagePropertyServerKey, |
| 175 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); | 204 property_converter.GetTransportNameForPropertyKey(kTestImagePropertyKey)); |
| 176 EXPECT_TRUE(property_converter.IsTransportNameRegistered( | 205 EXPECT_TRUE(property_converter.IsTransportNameRegistered( |
| 177 kTestImagePropertyServerKey)); | 206 kTestImagePropertyServerKey)); |
| (...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 333 | 362 |
| 334 base::string16 value_2 = base::ASCIIToUTF16("another test value"); | 363 base::string16 value_2 = base::ASCIIToUTF16("another test value"); |
| 335 std::vector<uint8_t> transport_value = | 364 std::vector<uint8_t> transport_value = |
| 336 mojo::ConvertTo<std::vector<uint8_t>>(value_2); | 365 mojo::ConvertTo<std::vector<uint8_t>>(value_2); |
| 337 property_converter.SetPropertyFromTransportValue( | 366 property_converter.SetPropertyFromTransportValue( |
| 338 window.get(), kTestString16PropertyServerKey, &transport_value); | 367 window.get(), kTestString16PropertyServerKey, &transport_value); |
| 339 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); | 368 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey)); |
| 340 } | 369 } |
| 341 | 370 |
| 342 } // namespace aura | 371 } // namespace aura |
| OLD | NEW |