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

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

Issue 2499933003: Expand aura::PropertyConverter support. (Closed)
Patch Set: Fix the other new unit test. 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_unittest.cc ('k') | ui/aura/test/aura_test_base.h » ('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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/window_tree_client.h" 5 #include "ui/aura/mus/window_tree_client.h"
6 6
7 #include <stdint.h> 7 #include <stdint.h>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/macros.h" 10 #include "base/macros.h"
11 #include "base/strings/utf_string_conversions.h"
11 #include "mojo/common/common_type_converters.h" 12 #include "mojo/common/common_type_converters.h"
12 #include "services/ui/public/cpp/property_type_converters.h" 13 #include "services/ui/public/cpp/property_type_converters.h"
13 #include "testing/gtest/include/gtest/gtest.h" 14 #include "testing/gtest/include/gtest/gtest.h"
14 #include "ui/aura/client/aura_constants.h" 15 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/client/capture_client.h" 16 #include "ui/aura/client/capture_client.h"
16 #include "ui/aura/client/capture_client_observer.h" 17 #include "ui/aura/client/capture_client_observer.h"
17 #include "ui/aura/client/focus_client.h" 18 #include "ui/aura/client/focus_client.h"
18 #include "ui/aura/client/transient_window_client.h" 19 #include "ui/aura/client/transient_window_client.h"
19 #include "ui/aura/mus/property_converter.h" 20 #include "ui/aura/mus/property_converter.h"
20 #include "ui/aura/mus/window_mus.h" 21 #include "ui/aura/mus/window_mus.h"
21 #include "ui/aura/mus/window_tree_client_delegate.h" 22 #include "ui/aura/mus/window_tree_client_delegate.h"
22 #include "ui/aura/mus/window_tree_client_observer.h" 23 #include "ui/aura/mus/window_tree_client_observer.h"
23 #include "ui/aura/mus/window_tree_host_mus.h" 24 #include "ui/aura/mus/window_tree_host_mus.h"
24 #include "ui/aura/test/aura_mus_test_base.h" 25 #include "ui/aura/test/aura_mus_test_base.h"
25 #include "ui/aura/test/mus/test_window_tree.h" 26 #include "ui/aura/test/mus/test_window_tree.h"
26 #include "ui/aura/test/mus/window_tree_client_private.h" 27 #include "ui/aura/test/mus/window_tree_client_private.h"
27 #include "ui/aura/test/test_window_delegate.h" 28 #include "ui/aura/test/test_window_delegate.h"
28 #include "ui/aura/window.h" 29 #include "ui/aura/window.h"
29 #include "ui/aura/window_property.h" 30 #include "ui/aura/window_property.h"
30 #include "ui/aura/window_tracker.h" 31 #include "ui/aura/window_tracker.h"
31 #include "ui/compositor/compositor.h" 32 #include "ui/compositor/compositor.h"
32 #include "ui/events/event.h" 33 #include "ui/events/event.h"
33 #include "ui/events/event_utils.h" 34 #include "ui/events/event_utils.h"
34 #include "ui/gfx/geometry/rect.h" 35 #include "ui/gfx/geometry/rect.h"
35 36
36 DECLARE_WINDOW_PROPERTY_TYPE(uint8_t)
37
38 namespace aura { 37 namespace aura {
39 38
40 namespace { 39 namespace {
41 40
42 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0); 41 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey1, 0);
43 DEFINE_WINDOW_PROPERTY_KEY(uint8_t, kTestPropertyKey2, 0); 42 DEFINE_WINDOW_PROPERTY_KEY(uint16_t, kTestPropertyKey2, 0);
43 DEFINE_WINDOW_PROPERTY_KEY(bool, kTestPropertyKey3, false);
44
45 const char kTestPropertyServerKey1[] = "test-property-server1";
46 const char kTestPropertyServerKey2[] = "test-property-server2";
47 const char kTestPropertyServerKey3[] = "test-property-server3";
44 48
45 Id server_id(Window* window) { 49 Id server_id(Window* window) {
46 return WindowMus::Get(window)->server_id(); 50 return WindowMus::Get(window)->server_id();
47 } 51 }
48 52
49 void SetWindowVisibility(Window* window, bool visible) { 53 void SetWindowVisibility(Window* window, bool visible) {
50 if (visible) 54 if (visible)
51 window->Show(); 55 window->Show();
52 else 56 else
53 window->Hide(); 57 window->Hide();
54 } 58 }
55 59
56 Window* GetFirstRoot(WindowTreeClient* client) { 60 Window* GetFirstRoot(WindowTreeClient* client) {
57 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin(); 61 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
58 } 62 }
59 63
60 bool IsWindowHostVisible(Window* window) { 64 bool IsWindowHostVisible(Window* window) {
61 return window->GetRootWindow()->GetHost()->compositor()->IsVisible(); 65 return window->GetRootWindow()->GetHost()->compositor()->IsVisible();
62 } 66 }
63 67
64 const char kTestPropertyServerKey1[] = "test-property-server1"; 68 // Register some test window properties for aura/mus conversion.
65 const char kTestPropertyServerKey2[] = "test-property-server2"; 69 void RegisterTestProperties(PropertyConverter* converter) {
70 converter->RegisterProperty(kTestPropertyKey1, kTestPropertyServerKey1);
71 converter->RegisterProperty(kTestPropertyKey2, kTestPropertyServerKey2);
72 converter->RegisterProperty(kTestPropertyKey3, kTestPropertyServerKey3);
73 }
66 74
67 class TestPropertyConverter : public PropertyConverter { 75 // Convert a primitive aura property value to a mus transport value.
68 public: 76 // Note that this implicitly casts arguments to the aura storage type, int64_t.
69 TestPropertyConverter() {} 77 mojo::Array<uint8_t> ConvertToPropertyTransportValue(int64_t value) {
70 ~TestPropertyConverter() override {} 78 return mojo::Array<uint8_t>(mojo::ConvertTo<std::vector<uint8_t>>(value));
71 79 }
72 // PropertyConverter:
73 bool ConvertPropertyForTransport(
74 Window* window,
75 const void* key,
76 std::string* server_property_name,
77 std::unique_ptr<std::vector<uint8_t>>* server_property_value) override {
78 if (key == kTestPropertyKey1) {
79 *server_property_name = kTestPropertyServerKey1;
80 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
81 (*server_property_value->get())[0] =
82 window->GetProperty(kTestPropertyKey1);
83 return true;
84 }
85 if (key == kTestPropertyKey2) {
86 *server_property_name = kTestPropertyServerKey2;
87 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
88 (*server_property_value->get())[0] =
89 window->GetProperty(kTestPropertyKey2);
90 return true;
91 }
92 return PropertyConverter::ConvertPropertyForTransport(
93 window, key, server_property_name, server_property_value);
94 }
95
96 std::string GetTransportNameForPropertyKey(const void* key) override {
97 if (key == kTestPropertyKey1)
98 return kTestPropertyServerKey1;
99 if (key == kTestPropertyKey2)
100 return kTestPropertyServerKey2;
101 return PropertyConverter::GetTransportNameForPropertyKey(key);
102 }
103
104 void SetPropertyFromTransportValue(
105 Window* window,
106 const std::string& server_property_name,
107 const std::vector<uint8_t>* data) override {
108 if (server_property_name == kTestPropertyServerKey1) {
109 window->SetProperty(kTestPropertyKey1, (*data)[0]);
110 } else if (server_property_name == kTestPropertyServerKey2) {
111 window->SetProperty(kTestPropertyKey2, (*data)[0]);
112 } else {
113 PropertyConverter::SetPropertyFromTransportValue(
114 window, server_property_name, data);
115 }
116 }
117
118 private:
119 DISALLOW_COPY_AND_ASSIGN(TestPropertyConverter);
120 };
121 80
122 } // namespace 81 } // namespace
123 82
124 mojo::Array<uint8_t> Uint8ToPropertyTransportValue(uint8_t value) {
125 mojo::Array<uint8_t> transport_value(1);
126 transport_value[0] = value;
127 return transport_value;
128 }
129
130 using WindowTreeClientWmTest = test::AuraMusWmTestBase; 83 using WindowTreeClientWmTest = test::AuraMusWmTestBase;
131 using WindowTreeClientClientTest = test::AuraMusClientTestBase; 84 using WindowTreeClientClientTest = test::AuraMusClientTestBase;
132 85
133 // Verifies bounds are reverted if the server replied that the change failed. 86 // Verifies bounds are reverted if the server replied that the change failed.
134 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { 87 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) {
135 Window window(nullptr); 88 Window window(nullptr);
136 window.Init(ui::LAYER_NOT_DRAWN); 89 window.Init(ui::LAYER_NOT_DRAWN);
137 const gfx::Rect original_bounds(window.bounds()); 90 const gfx::Rect original_bounds(window.bounds());
138 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 91 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
139 ASSERT_NE(new_bounds, window.bounds()); 92 ASSERT_NE(new_bounds, window.bounds());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 server_id(&window2), nullptr); 133 server_id(&window2), nullptr);
181 ASSERT_FALSE(window_tree()->has_change()); 134 ASSERT_FALSE(window_tree()->has_change());
182 EXPECT_EQ(&window2, window1.parent()); 135 EXPECT_EQ(&window2, window1.parent());
183 EXPECT_EQ(root_window(), window2.parent()); 136 EXPECT_EQ(root_window(), window2.parent());
184 window1.parent()->RemoveChild(&window1); 137 window1.parent()->RemoveChild(&window1);
185 } 138 }
186 139
187 // Verifies properties passed in OnWindowHierarchyChanged() make there way to 140 // Verifies properties passed in OnWindowHierarchyChanged() make there way to
188 // the new window. 141 // the new window.
189 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) { 142 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) {
190 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 143 RegisterTestProperties(GetPropertyConverter());
191 window_tree()->AckAllChanges(); 144 window_tree()->AckAllChanges();
192 const Id child_window_id = server_id(root_window()) + 11; 145 const Id child_window_id = server_id(root_window()) + 11;
193 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 146 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
194 const uint8_t server_test_property1_value = 91; 147 const uint8_t server_test_property1_value = 91;
195 data->properties[kTestPropertyServerKey1] = 148 data->properties[kTestPropertyServerKey1] =
196 Uint8ToPropertyTransportValue(server_test_property1_value); 149 ConvertToPropertyTransportValue(server_test_property1_value);
197 data->parent_id = server_id(root_window()); 150 data->parent_id = server_id(root_window());
198 data->window_id = child_window_id; 151 data->window_id = child_window_id;
199 data->bounds = gfx::Rect(1, 2, 3, 4); 152 data->bounds = gfx::Rect(1, 2, 3, 4);
200 data->visible = false; 153 data->visible = false;
201 mojo::Array<ui::mojom::WindowDataPtr> data_array(1); 154 mojo::Array<ui::mojom::WindowDataPtr> data_array(1);
202 data_array[0] = std::move(data); 155 data_array[0] = std::move(data);
203 ASSERT_TRUE(root_window()->children().empty()); 156 ASSERT_TRUE(root_window()->children().empty());
204 window_tree_client()->OnWindowHierarchyChanged( 157 window_tree_client()->OnWindowHierarchyChanged(
205 child_window_id, 0, server_id(root_window()), std::move(data_array)); 158 child_window_id, 0, server_id(root_window()), std::move(data_array));
206 ASSERT_FALSE(window_tree()->has_change()); 159 ASSERT_FALSE(window_tree()->has_change());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 254
302 // Verifies properties are set if the server replied that the change succeeded. 255 // Verifies properties are set if the server replied that the change succeeded.
303 TEST_F(WindowTreeClientWmTest, SetPropertySucceeded) { 256 TEST_F(WindowTreeClientWmTest, SetPropertySucceeded) {
304 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 257 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
305 root_window()->SetProperty(client::kAlwaysOnTopKey, true); 258 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
306 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 259 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
307 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue(); 260 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
308 ASSERT_FALSE(value.is_null()); 261 ASSERT_FALSE(value.is_null());
309 // PropertyConverter uses int64_t values, even for smaller types, like bool. 262 // PropertyConverter uses int64_t values, even for smaller types, like bool.
310 ASSERT_EQ(8u, value.size()); 263 ASSERT_EQ(8u, value.size());
311 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value); 264 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(value.PassStorage()));
312 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
313 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 265 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
314 WindowTreeChangeType::PROPERTY, true)); 266 WindowTreeChangeType::PROPERTY, true));
315 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 267 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
316 } 268 }
317 269
318 // Verifies properties are reverted if the server replied that the change 270 // Verifies properties are reverted if the server replied that the change
319 // failed. 271 // failed.
320 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) { 272 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) {
321 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 273 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
322 root_window()->SetProperty(client::kAlwaysOnTopKey, true); 274 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
323 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 275 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
324 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue(); 276 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
325 ASSERT_FALSE(value.is_null()); 277 ASSERT_FALSE(value.is_null());
326 // PropertyConverter uses int64_t values, even for smaller types, like bool. 278 // PropertyConverter uses int64_t values, even for smaller types, like bool.
327 ASSERT_EQ(8u, value.size()); 279 ASSERT_EQ(8u, value.size());
328 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value); 280 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(value.PassStorage()));
329 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
330 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 281 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
331 WindowTreeChangeType::PROPERTY, false)); 282 WindowTreeChangeType::PROPERTY, false));
332 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 283 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
333 } 284 }
334 285
335 // Simulates a property change, and while the property change is in flight the 286 // Simulates a property change, and while the property change is in flight the
336 // server replies with a new property and the original property change fails. 287 // server replies with a new property and the original property change fails.
337 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) { 288 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) {
338 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 289 RegisterTestProperties(GetPropertyConverter());
339 const uint8_t value1 = 11; 290 const uint8_t value1 = 11;
340 root_window()->SetProperty(kTestPropertyKey1, value1); 291 root_window()->SetProperty(kTestPropertyKey1, value1);
341 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 292 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
342 293
343 // Simulate the server responding with a different value. 294 // Simulate the server responding with a different value.
344 const uint8_t server_value = 12; 295 const uint8_t server_value = 12;
345 window_tree_client()->OnWindowSharedPropertyChanged( 296 window_tree_client()->OnWindowSharedPropertyChanged(
346 server_id(root_window()), kTestPropertyServerKey1, 297 server_id(root_window()), kTestPropertyServerKey1,
347 Uint8ToPropertyTransportValue(server_value)); 298 ConvertToPropertyTransportValue(server_value));
348 299
349 // This shouldn't trigger the property changing yet. 300 // This shouldn't trigger the property changing yet.
350 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 301 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
351 302
352 // Tell the client the change failed, which should trigger failing to the 303 // Tell the client the change failed, which should trigger failing to the
353 // most recent value from server. 304 // most recent value from server.
354 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 305 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
355 WindowTreeChangeType::PROPERTY, false)); 306 WindowTreeChangeType::PROPERTY, false));
356 EXPECT_EQ(server_value, root_window()->GetProperty(kTestPropertyKey1)); 307 EXPECT_EQ(server_value, root_window()->GetProperty(kTestPropertyKey1));
357 308
358 // Simulate server changing back to value1. Should take immediately. 309 // Simulate server changing back to value1. Should take immediately.
359 window_tree_client()->OnWindowSharedPropertyChanged( 310 window_tree_client()->OnWindowSharedPropertyChanged(
360 server_id(root_window()), kTestPropertyServerKey1, 311 server_id(root_window()), kTestPropertyServerKey1,
361 Uint8ToPropertyTransportValue(value1)); 312 ConvertToPropertyTransportValue(value1));
362 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 313 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
363 } 314 }
364 315
316 // Verifies property setting behavior with failures for primitive properties.
317 TEST_F(WindowTreeClientWmTest, SetPrimitiveProperties) {
318 PropertyConverter* property_converter = GetPropertyConverter();
319 RegisterTestProperties(property_converter);
320
321 const uint8_t value1_local = UINT8_MAX / 2;
322 const uint8_t value1_server = UINT8_MAX / 3;
323 root_window()->SetProperty(kTestPropertyKey1, value1_local);
324 EXPECT_EQ(value1_local, root_window()->GetProperty(kTestPropertyKey1));
325 window_tree_client()->OnWindowSharedPropertyChanged(
326 server_id(root_window()), kTestPropertyServerKey1,
327 ConvertToPropertyTransportValue(value1_server));
328 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
329 WindowTreeChangeType::PROPERTY, false));
330 EXPECT_EQ(value1_server, root_window()->GetProperty(kTestPropertyKey1));
331
332 const uint16_t value2_local = UINT16_MAX / 3;
333 const uint16_t value2_server = UINT16_MAX / 4;
334 root_window()->SetProperty(kTestPropertyKey2, value2_local);
335 EXPECT_EQ(value2_local, root_window()->GetProperty(kTestPropertyKey2));
336 window_tree_client()->OnWindowSharedPropertyChanged(
337 server_id(root_window()), kTestPropertyServerKey2,
338 ConvertToPropertyTransportValue(value2_server));
339 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
340 WindowTreeChangeType::PROPERTY, false));
341 EXPECT_EQ(value2_server, root_window()->GetProperty(kTestPropertyKey2));
342
343 EXPECT_FALSE(root_window()->GetProperty(kTestPropertyKey3));
344 root_window()->SetProperty(kTestPropertyKey3, true);
345 EXPECT_TRUE(root_window()->GetProperty(kTestPropertyKey3));
346 window_tree_client()->OnWindowSharedPropertyChanged(
347 server_id(root_window()), kTestPropertyServerKey3,
348 ConvertToPropertyTransportValue(false));
349 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
350 WindowTreeChangeType::PROPERTY, false));
351 EXPECT_FALSE(root_window()->GetProperty(kTestPropertyKey3));
352 }
353
354 // Verifies property setting behavior for a gfx::Rect* property.
355 TEST_F(WindowTreeClientWmTest, SetRectProperty) {
356 gfx::Rect example(1, 2, 3, 4);
357 ASSERT_EQ(nullptr, root_window()->GetProperty(client::kRestoreBoundsKey));
358 root_window()->SetProperty(client::kRestoreBoundsKey, new gfx::Rect(example));
359 EXPECT_TRUE(root_window()->GetProperty(client::kRestoreBoundsKey));
360 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
361 ASSERT_FALSE(value.is_null());
362 EXPECT_EQ(example, mojo::ConvertTo<gfx::Rect>(value.PassStorage()));
363 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
364 WindowTreeChangeType::PROPERTY, true));
365 EXPECT_EQ(example, *root_window()->GetProperty(client::kRestoreBoundsKey));
366
367 root_window()->SetProperty(client::kRestoreBoundsKey, new gfx::Rect());
368 EXPECT_EQ(gfx::Rect(),
369 *root_window()->GetProperty(client::kRestoreBoundsKey));
370 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
371 WindowTreeChangeType::PROPERTY, false));
372 EXPECT_EQ(example, *root_window()->GetProperty(client::kRestoreBoundsKey));
373 }
374
375 // Verifies property setting behavior for a std::string* property.
376 TEST_F(WindowTreeClientWmTest, SetStringProperty) {
377 std::string example = "123";
378 ASSERT_EQ(nullptr, root_window()->GetProperty(client::kAppIdKey));
379 root_window()->SetProperty(client::kAppIdKey, new std::string(example));
380 EXPECT_TRUE(root_window()->GetProperty(client::kAppIdKey));
381 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
382 ASSERT_FALSE(value.is_null());
383 EXPECT_EQ(example, mojo::ConvertTo<std::string>(value.PassStorage()));
384 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
385 WindowTreeChangeType::PROPERTY, true));
386 EXPECT_EQ(example, *root_window()->GetProperty(client::kAppIdKey));
387
388 root_window()->SetProperty(client::kAppIdKey, new std::string());
389 EXPECT_EQ(std::string(), *root_window()->GetProperty(client::kAppIdKey));
390 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
391 WindowTreeChangeType::PROPERTY, false));
392 EXPECT_EQ(example, *root_window()->GetProperty(client::kAppIdKey));
393 }
394
365 // Verifies visible is reverted if the server replied that the change failed. 395 // Verifies visible is reverted if the server replied that the change failed.
366 TEST_F(WindowTreeClientWmTest, SetVisibleFailed) { 396 TEST_F(WindowTreeClientWmTest, SetVisibleFailed) {
367 const bool original_visible = root_window()->TargetVisibility(); 397 const bool original_visible = root_window()->TargetVisibility();
368 const bool new_visible = !original_visible; 398 const bool new_visible = !original_visible;
369 SetWindowVisibility(root_window(), new_visible); 399 SetWindowVisibility(root_window(), new_visible);
370 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 400 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
371 WindowTreeChangeType::VISIBLE, false)); 401 WindowTreeChangeType::VISIBLE, false));
372 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); 402 EXPECT_EQ(original_visible, root_window()->TargetVisibility());
373 } 403 }
374 404
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 // Make sure all the properties took. 775 // Make sure all the properties took.
746 EXPECT_TRUE(IsWindowHostVisible(top_level)); 776 EXPECT_TRUE(IsWindowHostVisible(top_level));
747 EXPECT_TRUE(top_level->TargetVisibility()); 777 EXPECT_TRUE(top_level->TargetVisibility());
748 // TODO: check display_id. 778 // TODO: check display_id.
749 EXPECT_EQ(display_id, window_tree_host.display_id()); 779 EXPECT_EQ(display_id, window_tree_host.display_id());
750 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); 780 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
751 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds()); 781 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds());
752 } 782 }
753 783
754 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) { 784 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) {
755 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 785 RegisterTestProperties(GetPropertyConverter());
756 786
757 WindowTreeHostMus window_tree_host(window_tree_client_impl()); 787 WindowTreeHostMus window_tree_host(window_tree_client_impl());
758 Window* top_level = window_tree_host.window(); 788 Window* top_level = window_tree_host.window();
759 789
760 EXPECT_FALSE(top_level->TargetVisibility()); 790 EXPECT_FALSE(top_level->TargetVisibility());
761 791
762 // Make visibility go from false->true->false. Don't ack immediately. 792 // Make visibility go from false->true->false. Don't ack immediately.
763 top_level->Show(); 793 top_level->Show();
764 top_level->Hide(); 794 top_level->Hide();
765 795
766 // Change bounds to 5, 6, 7, 8. 796 // Change bounds to 5, 6, 7, 8.
767 window_tree_host.SetBounds(gfx::Rect(5, 6, 7, 8)); 797 window_tree_host.SetBounds(gfx::Rect(5, 6, 7, 8));
768 EXPECT_EQ(gfx::Rect(0, 0, 7, 8), window_tree_host.window()->bounds()); 798 EXPECT_EQ(gfx::Rect(0, 0, 7, 8), window_tree_host.window()->bounds());
769 799
770 const uint8_t explicitly_set_test_property1_value = 2; 800 const uint8_t explicitly_set_test_property1_value = 2;
771 top_level->SetProperty(kTestPropertyKey1, 801 top_level->SetProperty(kTestPropertyKey1,
772 explicitly_set_test_property1_value); 802 explicitly_set_test_property1_value);
773 803
774 // Ack the new window top level top_level Vis and bounds shouldn't change. 804 // Ack the new window top level top_level Vis and bounds shouldn't change.
775 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 805 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
776 data->window_id = server_id(top_level); 806 data->window_id = server_id(top_level);
777 const gfx::Rect bounds_from_server(1, 2, 3, 4); 807 const gfx::Rect bounds_from_server(1, 2, 3, 4);
778 data->bounds = bounds_from_server; 808 data->bounds = bounds_from_server;
779 data->visible = true; 809 data->visible = true;
780 const uint8_t server_test_property1_value = 3; 810 const uint8_t server_test_property1_value = 3;
781 data->properties[kTestPropertyServerKey1] = 811 data->properties[kTestPropertyServerKey1] =
782 Uint8ToPropertyTransportValue(server_test_property1_value); 812 ConvertToPropertyTransportValue(server_test_property1_value);
783 const uint8_t server_test_property2_value = 4; 813 const uint8_t server_test_property2_value = 4;
784 data->properties[kTestPropertyServerKey2] = 814 data->properties[kTestPropertyServerKey2] =
785 Uint8ToPropertyTransportValue(server_test_property2_value); 815 ConvertToPropertyTransportValue(server_test_property2_value);
786 const int64_t display_id = 1; 816 const int64_t display_id = 1;
787 // Get the id of the in flight change for creating the new top_level. 817 // Get the id of the in flight change for creating the new top_level.
788 uint32_t new_window_in_flight_change_id; 818 uint32_t new_window_in_flight_change_id;
789 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 819 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
790 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id)); 820 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id));
791 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, 821 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
792 std::move(data), display_id, true); 822 std::move(data), display_id, true);
793 823
794 // The only value that should take effect is the property for 'yy' as it was 824 // The only value that should take effect is the property for 'yy' as it was
795 // not in flight. 825 // not in flight.
(...skipping 21 matching lines...) Expand all
817 top_level->GetRootWindow()->GetHost()->GetBounds()); 847 top_level->GetRootWindow()->GetHost()->GetBounds());
818 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 848 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
819 WindowTreeChangeType::PROPERTY, false)); 849 WindowTreeChangeType::PROPERTY, false));
820 EXPECT_EQ(server_test_property1_value, 850 EXPECT_EQ(server_test_property1_value,
821 top_level->GetProperty(kTestPropertyKey1)); 851 top_level->GetProperty(kTestPropertyKey1));
822 EXPECT_EQ(server_test_property2_value, 852 EXPECT_EQ(server_test_property2_value,
823 top_level->GetProperty(kTestPropertyKey2)); 853 top_level->GetProperty(kTestPropertyKey2));
824 } 854 }
825 855
826 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) { 856 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) {
827 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 857 RegisterTestProperties(GetPropertyConverter());
828 Window window(nullptr); 858 Window window(nullptr);
829 const uint8_t explicitly_set_test_property1_value = 29; 859 const uint8_t explicitly_set_test_property1_value = 29;
830 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 860 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
831 window.Init(ui::LAYER_NOT_DRAWN); 861 window.Init(ui::LAYER_NOT_DRAWN);
832 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties = 862 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
833 window_tree()->GetLastNewWindowProperties(); 863 window_tree()->GetLastNewWindowProperties();
834 ASSERT_FALSE(transport_properties.is_null()); 864 ASSERT_FALSE(transport_properties.is_null());
835 std::map<std::string, std::vector<uint8_t>> properties = 865 std::map<std::string, std::vector<uint8_t>> properties =
836 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 866 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
837 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1)); 867 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1));
838 ASSERT_EQ(1u, properties[kTestPropertyServerKey1].size()); 868 // PropertyConverter uses int64_t values, even for smaller types like uint8_t.
839 EXPECT_EQ(explicitly_set_test_property1_value, 869 ASSERT_EQ(8u, properties[kTestPropertyServerKey1].size());
840 properties[kTestPropertyServerKey1][0]); 870 EXPECT_EQ(static_cast<int64_t>(explicitly_set_test_property1_value),
871 mojo::ConvertTo<int64_t>(properties[kTestPropertyServerKey1]));
841 ASSERT_EQ(0u, properties.count(kTestPropertyServerKey2)); 872 ASSERT_EQ(0u, properties.count(kTestPropertyServerKey2));
842 } 873 }
843 874
844 // Assertions around transient windows. 875 // Assertions around transient windows.
845 TEST_F(WindowTreeClientClientTest, Transients) { 876 TEST_F(WindowTreeClientClientTest, Transients) {
846 client::TransientWindowClient* transient_client = 877 client::TransientWindowClient* transient_client =
847 client::GetTransientWindowClient(); 878 client::GetTransientWindowClient();
848 Window parent(nullptr); 879 Window parent(nullptr);
849 parent.Init(ui::LAYER_NOT_DRAWN); 880 parent.Init(ui::LAYER_NOT_DRAWN);
850 root_window()->AddChild(&parent); 881 root_window()->AddChild(&parent);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
898 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 929 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
899 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); 930 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
900 931
901 const int64_t display_id = 1; 932 const int64_t display_id = 1;
902 window_tree_client()->OnTopLevelCreated(change_id, std::move(data), 933 window_tree_client()->OnTopLevelCreated(change_id, std::move(data),
903 display_id, true); 934 display_id, true);
904 EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size()); 935 EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size());
905 } 936 }
906 937
907 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsProperties) { 938 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsProperties) {
939 RegisterTestProperties(GetPropertyConverter());
908 const uint8_t property_value = 11; 940 const uint8_t property_value = 11;
909 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
910 std::map<std::string, std::vector<uint8_t>> properties; 941 std::map<std::string, std::vector<uint8_t>> properties;
911 properties[kTestPropertyServerKey1].resize(1); 942 properties[kTestPropertyServerKey1] =
912 properties[kTestPropertyServerKey1][0] = property_value; 943 ConvertToPropertyTransportValue(property_value);
913 std::unique_ptr<WindowTreeHostMus> window_tree_host = 944 std::unique_ptr<WindowTreeHostMus> window_tree_host =
914 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl(), 945 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl(),
915 &properties); 946 &properties);
916 // Verify the property made it to the window. 947 // Verify the property made it to the window.
917 EXPECT_EQ(property_value, 948 EXPECT_EQ(property_value,
918 window_tree_host->window()->GetProperty(kTestPropertyKey1)); 949 window_tree_host->window()->GetProperty(kTestPropertyKey1));
919 950
920 // Get the id of the in flight change for creating the new top level window. 951 // Get the id of the in flight change for creating the new top level window.
921 uint32_t change_id; 952 uint32_t change_id;
922 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 953 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
923 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); 954 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
924 955
925 // Verify the property was sent to the server. 956 // Verify the property was sent to the server.
926 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties = 957 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
927 window_tree()->GetLastNewWindowProperties(); 958 window_tree()->GetLastNewWindowProperties();
928 ASSERT_FALSE(transport_properties.is_null()); 959 ASSERT_FALSE(transport_properties.is_null());
929 std::map<std::string, std::vector<uint8_t>> properties2 = 960 std::map<std::string, std::vector<uint8_t>> properties2 =
930 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 961 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
931 ASSERT_EQ(1u, properties2.count(kTestPropertyServerKey1)); 962 ASSERT_EQ(1u, properties2.count(kTestPropertyServerKey1));
932 ASSERT_EQ(1u, properties2[kTestPropertyServerKey1].size()); 963 // PropertyConverter uses int64_t values, even for smaller types like uint8_t.
933 EXPECT_EQ(property_value, properties2[kTestPropertyServerKey1][0]); 964 ASSERT_EQ(8u, properties2[kTestPropertyServerKey1].size());
965 EXPECT_EQ(static_cast<int64_t>(property_value),
966 mojo::ConvertTo<int64_t>(properties2[kTestPropertyServerKey1]));
934 } 967 }
935 968
936 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly 969 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly
937 // updated on failures. 970 // updated on failures.
938 TEST_F(WindowTreeClientWmTest, ExplicitCapture) { 971 TEST_F(WindowTreeClientWmTest, ExplicitCapture) {
939 root_window()->SetCapture(); 972 root_window()->SetCapture();
940 EXPECT_TRUE(root_window()->HasCapture()); 973 EXPECT_TRUE(root_window()->HasCapture());
941 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 974 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
942 WindowTreeChangeType::CAPTURE, false)); 975 WindowTreeChangeType::CAPTURE, false));
943 EXPECT_FALSE(root_window()->HasCapture()); 976 EXPECT_FALSE(root_window()->HasCapture());
(...skipping 244 matching lines...) Expand 10 before | Expand all | Expand 10 after
1188 ASSERT_EQ(1u, root_window()->children().size()); 1221 ASSERT_EQ(1u, root_window()->children().size());
1189 Window* server_window = root_window()->children()[0]; 1222 Window* server_window = root_window()->children()[0];
1190 EXPECT_EQ(window1->parent(), server_window); 1223 EXPECT_EQ(window1->parent(), server_window);
1191 EXPECT_EQ(window2->parent(), server_window); 1224 EXPECT_EQ(window2->parent(), server_window);
1192 ASSERT_EQ(2u, server_window->children().size()); 1225 ASSERT_EQ(2u, server_window->children().size());
1193 EXPECT_EQ(window1, server_window->children()[0]); 1226 EXPECT_EQ(window1, server_window->children()[0]);
1194 EXPECT_EQ(window2, server_window->children()[1]); 1227 EXPECT_EQ(window2, server_window->children()[1]);
1195 } 1228 }
1196 1229
1197 } // namespace aura 1230 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter_unittest.cc ('k') | ui/aura/test/aura_test_base.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698