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

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

Issue 2513753003: Add string16 and name/title support to aura::PropertyConverter. (Closed)
Patch Set: Update failing test to ack all changes as failed. Created 4 years, 1 month 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
« no previous file with comments | « ui/aura/mus/property_converter.cc ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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"
11 #include "base/macros.h" 11 #include "base/macros.h"
12 #include "base/strings/utf_string_conversions.h"
12 #include "services/ui/public/cpp/property_type_converters.h" 13 #include "services/ui/public/cpp/property_type_converters.h"
14 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/test/aura_test_base.h" 15 #include "ui/aura/test/aura_test_base.h"
14 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
15 #include "ui/aura/window_property.h" 17 #include "ui/aura/window_property.h"
16 #include "ui/gfx/geometry/rect.h" 18 #include "ui/gfx/geometry/rect.h"
17 19
18 // See aura_constants.cc for bool, int32_t, int64_t, std::string, and gfx::Rect. 20 // See aura_constants.cc for bool, int32_t, int64_t, std::string, gfx::Rect,
19 // That same file also declares the uint32_t type via SkColor. 21 // and base::string16. It also declares the uint32_t type via SkColor.
20 DECLARE_WINDOW_PROPERTY_TYPE(uint8_t) 22 DECLARE_WINDOW_PROPERTY_TYPE(uint8_t)
21 DECLARE_WINDOW_PROPERTY_TYPE(uint16_t) 23 DECLARE_WINDOW_PROPERTY_TYPE(uint16_t)
22 DECLARE_WINDOW_PROPERTY_TYPE(uint64_t) 24 DECLARE_WINDOW_PROPERTY_TYPE(uint64_t)
23 DECLARE_WINDOW_PROPERTY_TYPE(int8_t) 25 DECLARE_WINDOW_PROPERTY_TYPE(int8_t)
24 DECLARE_WINDOW_PROPERTY_TYPE(int16_t) 26 DECLARE_WINDOW_PROPERTY_TYPE(int16_t)
25 27
26 namespace aura { 28 namespace aura {
27 29
28 namespace { 30 namespace {
29 31
30 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey0, false); 32 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey0, false);
31 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); 33 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0);
32 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0); 34 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0);
33 DEFINE_WINDOW_PROPERTY_KEY(uint32_t, kTestPropertyKey3, 0); 35 DEFINE_WINDOW_PROPERTY_KEY(uint32_t, kTestPropertyKey3, 0);
34 DEFINE_WINDOW_PROPERTY_KEY(uint64_t, kTestPropertyKey4, 0); 36 DEFINE_WINDOW_PROPERTY_KEY(uint64_t, kTestPropertyKey4, 0);
35 DEFINE_WINDOW_PROPERTY_KEY(int8_t, kTestPropertyKey5, 0); 37 DEFINE_WINDOW_PROPERTY_KEY(int8_t, kTestPropertyKey5, 0);
36 DEFINE_WINDOW_PROPERTY_KEY(int16_t, kTestPropertyKey6, 0); 38 DEFINE_WINDOW_PROPERTY_KEY(int16_t, kTestPropertyKey6, 0);
37 DEFINE_WINDOW_PROPERTY_KEY(int32_t, kTestPropertyKey7, 0); 39 DEFINE_WINDOW_PROPERTY_KEY(int32_t, kTestPropertyKey7, 0);
38 DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey8, 0); 40 DEFINE_WINDOW_PROPERTY_KEY(int64_t, kTestPropertyKey8, 0);
39 41
40 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr); 42 DEFINE_OWNED_WINDOW_PROPERTY_KEY(gfx::Rect, kTestRectPropertyKey, nullptr);
41 DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr); 43 DEFINE_OWNED_WINDOW_PROPERTY_KEY(std::string, kTestStringPropertyKey, nullptr);
44 DEFINE_OWNED_WINDOW_PROPERTY_KEY(base::string16, kTestString16PropertyKey,
45 nullptr);
42 46
43 const char kTestPropertyServerKey0[] = "test-property-server0"; 47 const char kTestPropertyServerKey0[] = "test-property-server0";
44 const char kTestPropertyServerKey1[] = "test-property-server1"; 48 const char kTestPropertyServerKey1[] = "test-property-server1";
45 const char kTestPropertyServerKey2[] = "test-property-server2"; 49 const char kTestPropertyServerKey2[] = "test-property-server2";
46 const char kTestPropertyServerKey3[] = "test-property-server3"; 50 const char kTestPropertyServerKey3[] = "test-property-server3";
47 const char kTestPropertyServerKey4[] = "test-property-server4"; 51 const char kTestPropertyServerKey4[] = "test-property-server4";
48 const char kTestPropertyServerKey5[] = "test-property-server5"; 52 const char kTestPropertyServerKey5[] = "test-property-server5";
49 const char kTestPropertyServerKey6[] = "test-property-server6"; 53 const char kTestPropertyServerKey6[] = "test-property-server6";
50 const char kTestPropertyServerKey7[] = "test-property-server7"; 54 const char kTestPropertyServerKey7[] = "test-property-server7";
51 const char kTestPropertyServerKey8[] = "test-property-server8"; 55 const char kTestPropertyServerKey8[] = "test-property-server8";
52 56
53 const char kTestRectPropertyServerKey[] = "test-rect-property-server"; 57 const char kTestRectPropertyServerKey[] = "test-rect-property-server";
54 const char kTestStringPropertyServerKey[] = "test-string-property-server"; 58 const char kTestStringPropertyServerKey[] = "test-string-property-server";
59 const char kTestString16PropertyServerKey[] = "test-string16-property-server";
55 60
56 // Test registration, naming and value conversion for primitive property types. 61 // Test registration, naming and value conversion for primitive property types.
57 template <typename T> 62 template <typename T>
58 void TestPrimitiveProperty(PropertyConverter* property_converter, 63 void TestPrimitiveProperty(PropertyConverter* property_converter,
59 Window* window, 64 Window* window,
60 const WindowProperty<T>* key, 65 const WindowProperty<T>* key,
61 const char* transport_name, 66 const char* transport_name,
62 T value_1, 67 T value_1,
63 T value_2) { 68 T value_2) {
64 property_converter->RegisterProperty(key, transport_name); 69 property_converter->RegisterProperty(key, transport_name);
(...skipping 122 matching lines...) Expand 10 before | Expand all | Expand 10 after
187 *transport_value_out.get()); 192 *transport_value_out.get());
188 193
189 std::string value_2 = "another test value"; 194 std::string value_2 = "another test value";
190 std::vector<uint8_t> transport_value = 195 std::vector<uint8_t> transport_value =
191 mojo::ConvertTo<std::vector<uint8_t>>(value_2); 196 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
192 property_converter.SetPropertyFromTransportValue( 197 property_converter.SetPropertyFromTransportValue(
193 window.get(), kTestStringPropertyServerKey, &transport_value); 198 window.get(), kTestStringPropertyServerKey, &transport_value);
194 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey)); 199 EXPECT_EQ(value_2, *window->GetProperty(kTestStringPropertyKey));
195 } 200 }
196 201
202 // Verifies property setting behavior for a base::string16* property.
203 TEST_F(PropertyConverterTest, String16Property) {
204 PropertyConverter property_converter;
205 property_converter.RegisterProperty(kTestString16PropertyKey,
206 kTestString16PropertyServerKey);
207 EXPECT_EQ(kTestString16PropertyServerKey,
208 property_converter.GetTransportNameForPropertyKey(
209 kTestString16PropertyKey));
210
211 base::string16 value_1 = base::ASCIIToUTF16("test value");
212 std::unique_ptr<Window> window(CreateNormalWindow(1, root_window(), nullptr));
213 window->SetProperty(kTestString16PropertyKey, new base::string16(value_1));
214 EXPECT_EQ(value_1, *window->GetProperty(kTestString16PropertyKey));
215
216 std::string transport_name_out;
217 std::unique_ptr<std::vector<uint8_t>> transport_value_out;
218 EXPECT_TRUE(property_converter.ConvertPropertyForTransport(
219 window.get(), kTestString16PropertyKey, &transport_name_out,
220 &transport_value_out));
221 EXPECT_EQ(kTestString16PropertyServerKey, transport_name_out);
222 EXPECT_EQ(mojo::ConvertTo<std::vector<uint8_t>>(value_1),
223 *transport_value_out.get());
224
225 base::string16 value_2 = base::ASCIIToUTF16("another test value");
226 std::vector<uint8_t> transport_value =
227 mojo::ConvertTo<std::vector<uint8_t>>(value_2);
228 property_converter.SetPropertyFromTransportValue(
229 window.get(), kTestString16PropertyServerKey, &transport_value);
230 EXPECT_EQ(value_2, *window->GetProperty(kTestString16PropertyKey));
231 }
232
197 } // namespace aura 233 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter.cc ('k') | ui/aura/mus/window_tree_client_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698