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

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

Issue 2499933003: Expand aura::PropertyConverter support. (Closed)
Patch Set: Revert to std::string. 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
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* property_converter) {
70 property_converter->RegisterPrimitiveProperty(
71 kTestPropertyKey1, kTestPropertyKey1->name, kTestPropertyServerKey1);
72 property_converter->RegisterPrimitiveProperty(
73 kTestPropertyKey2, kTestPropertyKey2->name, kTestPropertyServerKey2);
74 property_converter->RegisterPrimitiveProperty(
75 kTestPropertyKey3, kTestPropertyKey3->name, kTestPropertyServerKey3);
76 }
66 77
67 class TestPropertyConverter : public PropertyConverter { 78 // Get the primitive aura property value to store for a mus transport value.
68 public: 79 int64_t GetPropertyStorageValue(const std::vector<uint8_t>& data) {
69 TestPropertyConverter() {} 80 CHECK_LE(data.size(), 8u);
70 ~TestPropertyConverter() override {} 81 int64_t value = 0;
82 for (size_t i = data.size(); i > 0; --i)
83 value = (value << 8) + data[i - 1];
84 return value;
85 }
71 86
72 // PropertyConverter: 87 // Get the mus transport value to store for a primitive aura property value.
73 bool ConvertPropertyForTransport( 88 mojo::Array<uint8_t> GetPropertyTransportValue(int64_t value) {
74 Window* window, 89 mojo::Array<uint8_t> transport_value(8);
75 const void* key, 90 transport_value[7] = (value >> 56) & 0xFF;
76 std::string* server_property_name, 91 transport_value[6] = (value >> 48) & 0xFF;
77 std::unique_ptr<std::vector<uint8_t>>* server_property_value) override { 92 transport_value[5] = (value >> 40) & 0xFF;
78 if (key == kTestPropertyKey1) { 93 transport_value[4] = (value >> 32) & 0xFF;
79 *server_property_name = kTestPropertyServerKey1; 94 transport_value[3] = (value >> 24) & 0xFF;
80 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1); 95 transport_value[2] = (value >> 16) & 0xFF;
81 (*server_property_value->get())[0] = 96 transport_value[1] = (value >> 8) & 0xFF;
82 window->GetProperty(kTestPropertyKey1); 97 transport_value[0] = value & 0xFF;
83 return true; 98 return transport_value;
84 } 99 }
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 100
122 } // namespace 101 } // namespace
123 102
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; 103 using WindowTreeClientWmTest = test::AuraMusWmTestBase;
131 using WindowTreeClientClientTest = test::AuraMusClientTestBase; 104 using WindowTreeClientClientTest = test::AuraMusClientTestBase;
132 105
133 // Verifies bounds are reverted if the server replied that the change failed. 106 // Verifies bounds are reverted if the server replied that the change failed.
134 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) { 107 TEST_F(WindowTreeClientWmTest, SetBoundsFailed) {
135 Window window(nullptr); 108 Window window(nullptr);
136 window.Init(ui::LAYER_NOT_DRAWN); 109 window.Init(ui::LAYER_NOT_DRAWN);
137 const gfx::Rect original_bounds(window.bounds()); 110 const gfx::Rect original_bounds(window.bounds());
138 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100)); 111 const gfx::Rect new_bounds(gfx::Rect(0, 0, 100, 100));
139 ASSERT_NE(new_bounds, window.bounds()); 112 ASSERT_NE(new_bounds, window.bounds());
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
180 server_id(&window2), nullptr); 153 server_id(&window2), nullptr);
181 ASSERT_FALSE(window_tree()->has_change()); 154 ASSERT_FALSE(window_tree()->has_change());
182 EXPECT_EQ(&window2, window1.parent()); 155 EXPECT_EQ(&window2, window1.parent());
183 EXPECT_EQ(root_window(), window2.parent()); 156 EXPECT_EQ(root_window(), window2.parent());
184 window1.parent()->RemoveChild(&window1); 157 window1.parent()->RemoveChild(&window1);
185 } 158 }
186 159
187 // Verifies properties passed in OnWindowHierarchyChanged() make there way to 160 // Verifies properties passed in OnWindowHierarchyChanged() make there way to
188 // the new window. 161 // the new window.
189 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) { 162 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) {
190 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 163 RegisterTestProperties(GetPropertyConverter());
191 window_tree()->AckAllChanges(); 164 window_tree()->AckAllChanges();
192 const Id child_window_id = server_id(root_window()) + 11; 165 const Id child_window_id = server_id(root_window()) + 11;
193 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 166 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
194 const uint8_t server_test_property1_value = 91; 167 const uint8_t server_test_property1_value = 91;
195 data->properties[kTestPropertyServerKey1] = 168 data->properties[kTestPropertyServerKey1] =
196 Uint8ToPropertyTransportValue(server_test_property1_value); 169 GetPropertyTransportValue(server_test_property1_value);
197 data->parent_id = server_id(root_window()); 170 data->parent_id = server_id(root_window());
198 data->window_id = child_window_id; 171 data->window_id = child_window_id;
199 data->bounds = gfx::Rect(1, 2, 3, 4); 172 data->bounds = gfx::Rect(1, 2, 3, 4);
200 data->visible = false; 173 data->visible = false;
201 mojo::Array<ui::mojom::WindowDataPtr> data_array(1); 174 mojo::Array<ui::mojom::WindowDataPtr> data_array(1);
202 data_array[0] = std::move(data); 175 data_array[0] = std::move(data);
203 ASSERT_TRUE(root_window()->children().empty()); 176 ASSERT_TRUE(root_window()->children().empty());
204 window_tree_client()->OnWindowHierarchyChanged( 177 window_tree_client()->OnWindowHierarchyChanged(
205 child_window_id, 0, server_id(root_window()), std::move(data_array)); 178 child_window_id, 0, server_id(root_window()), std::move(data_array));
206 ASSERT_FALSE(window_tree()->has_change()); 179 ASSERT_FALSE(window_tree()->has_change());
(...skipping 94 matching lines...) Expand 10 before | Expand all | Expand 10 after
301 274
302 // Verifies properties are set if the server replied that the change succeeded. 275 // Verifies properties are set if the server replied that the change succeeded.
303 TEST_F(WindowTreeClientWmTest, SetPropertySucceeded) { 276 TEST_F(WindowTreeClientWmTest, SetPropertySucceeded) {
304 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 277 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
305 root_window()->SetProperty(client::kAlwaysOnTopKey, true); 278 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
306 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 279 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
307 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue(); 280 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
308 ASSERT_FALSE(value.is_null()); 281 ASSERT_FALSE(value.is_null());
309 // PropertyConverter uses int64_t values, even for smaller types, like bool. 282 // PropertyConverter uses int64_t values, even for smaller types, like bool.
310 ASSERT_EQ(8u, value.size()); 283 ASSERT_EQ(8u, value.size());
311 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value); 284 EXPECT_EQ(1, GetPropertyStorageValue(value.PassStorage()));
312 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
313 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 285 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
314 WindowTreeChangeType::PROPERTY, true)); 286 WindowTreeChangeType::PROPERTY, true));
315 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 287 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
316 } 288 }
317 289
318 // Verifies properties are reverted if the server replied that the change 290 // Verifies properties are reverted if the server replied that the change
319 // failed. 291 // failed.
320 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) { 292 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) {
321 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 293 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
322 root_window()->SetProperty(client::kAlwaysOnTopKey, true); 294 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
323 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 295 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
324 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue(); 296 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
325 ASSERT_FALSE(value.is_null()); 297 ASSERT_FALSE(value.is_null());
326 // PropertyConverter uses int64_t values, even for smaller types, like bool. 298 // PropertyConverter uses int64_t values, even for smaller types, like bool.
327 ASSERT_EQ(8u, value.size()); 299 ASSERT_EQ(8u, value.size());
328 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value); 300 EXPECT_EQ(1, GetPropertyStorageValue(value.PassStorage()));
329 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
330 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 301 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
331 WindowTreeChangeType::PROPERTY, false)); 302 WindowTreeChangeType::PROPERTY, false));
332 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 303 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
333 } 304 }
334 305
335 // Simulates a property change, and while the property change is in flight the 306 // 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. 307 // server replies with a new property and the original property change fails.
337 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) { 308 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) {
338 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 309 RegisterTestProperties(GetPropertyConverter());
339 const uint8_t value1 = 11; 310 const uint8_t value1 = 11;
340 root_window()->SetProperty(kTestPropertyKey1, value1); 311 root_window()->SetProperty(kTestPropertyKey1, value1);
341 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 312 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
342 313
343 // Simulate the server responding with a different value. 314 // Simulate the server responding with a different value.
344 const uint8_t server_value = 12; 315 const uint8_t server_value = 12;
345 window_tree_client()->OnWindowSharedPropertyChanged( 316 window_tree_client()->OnWindowSharedPropertyChanged(
346 server_id(root_window()), kTestPropertyServerKey1, 317 server_id(root_window()), kTestPropertyServerKey1,
347 Uint8ToPropertyTransportValue(server_value)); 318 GetPropertyTransportValue(server_value));
348 319
349 // This shouldn't trigger the property changing yet. 320 // This shouldn't trigger the property changing yet.
350 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 321 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
351 322
352 // Tell the client the change failed, which should trigger failing to the 323 // Tell the client the change failed, which should trigger failing to the
353 // most recent value from server. 324 // most recent value from server.
354 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 325 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
355 WindowTreeChangeType::PROPERTY, false)); 326 WindowTreeChangeType::PROPERTY, false));
356 EXPECT_EQ(server_value, root_window()->GetProperty(kTestPropertyKey1)); 327 EXPECT_EQ(server_value, root_window()->GetProperty(kTestPropertyKey1));
357 328
358 // Simulate server changing back to value1. Should take immediately. 329 // Simulate server changing back to value1. Should take immediately.
359 window_tree_client()->OnWindowSharedPropertyChanged( 330 window_tree_client()->OnWindowSharedPropertyChanged(
360 server_id(root_window()), kTestPropertyServerKey1, 331 server_id(root_window()), kTestPropertyServerKey1,
361 Uint8ToPropertyTransportValue(value1)); 332 GetPropertyTransportValue(value1));
362 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1)); 333 EXPECT_EQ(value1, root_window()->GetProperty(kTestPropertyKey1));
363 } 334 }
364 335
336 // Verifies property setting behavior with failures for primitive properties.
337 TEST_F(WindowTreeClientWmTest, SetPrimitiveProperties) {
338 PropertyConverter* property_converter = GetPropertyConverter();
339 RegisterTestProperties(property_converter);
340
341 const uint8_t value1_local = UINT8_MAX / 2;
342 const uint8_t value1_server = UINT8_MAX / 3;
343 root_window()->SetProperty(kTestPropertyKey1, value1_local);
344 EXPECT_EQ(value1_local, root_window()->GetProperty(kTestPropertyKey1));
345 window_tree_client()->OnWindowSharedPropertyChanged(
346 server_id(root_window()), kTestPropertyServerKey1,
347 GetPropertyTransportValue(value1_server));
348 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
349 WindowTreeChangeType::PROPERTY, false));
350 EXPECT_EQ(value1_server, root_window()->GetProperty(kTestPropertyKey1));
351
352 const uint16_t value2_local = UINT16_MAX / 3;
353 const uint16_t value2_server = UINT16_MAX / 4;
354 root_window()->SetProperty(kTestPropertyKey2, value2_local);
355 EXPECT_EQ(value2_local, root_window()->GetProperty(kTestPropertyKey2));
356 window_tree_client()->OnWindowSharedPropertyChanged(
357 server_id(root_window()), kTestPropertyServerKey2,
358 GetPropertyTransportValue(value2_server));
359 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
360 WindowTreeChangeType::PROPERTY, false));
361 EXPECT_EQ(value2_server, root_window()->GetProperty(kTestPropertyKey2));
362
363 EXPECT_FALSE(root_window()->GetProperty(kTestPropertyKey3));
364 root_window()->SetProperty(kTestPropertyKey3, true);
365 EXPECT_TRUE(root_window()->GetProperty(kTestPropertyKey3));
366 window_tree_client()->OnWindowSharedPropertyChanged(
367 server_id(root_window()), kTestPropertyServerKey3,
368 GetPropertyTransportValue(false));
369 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
370 WindowTreeChangeType::PROPERTY, false));
371 EXPECT_FALSE(root_window()->GetProperty(kTestPropertyKey3));
372 }
373
374 // Verifies property setting behavior for a gfx::Rect* property.
375 TEST_F(WindowTreeClientWmTest, SetRectProperty) {
376 gfx::Rect example(1, 2, 3, 4);
377 ASSERT_EQ(nullptr, root_window()->GetProperty(client::kRestoreBoundsKey));
378 root_window()->SetProperty(client::kRestoreBoundsKey, new gfx::Rect(example));
379 EXPECT_TRUE(root_window()->GetProperty(client::kRestoreBoundsKey));
380 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
381 ASSERT_FALSE(value.is_null());
382 EXPECT_EQ(example, mojo::ConvertTo<gfx::Rect>(value.PassStorage()));
383 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
384 WindowTreeChangeType::PROPERTY, true));
385 EXPECT_EQ(example, *root_window()->GetProperty(client::kRestoreBoundsKey));
386
387 root_window()->SetProperty(client::kRestoreBoundsKey, new gfx::Rect());
388 EXPECT_EQ(gfx::Rect(),
389 *root_window()->GetProperty(client::kRestoreBoundsKey));
390 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
391 WindowTreeChangeType::PROPERTY, false));
392 EXPECT_EQ(example, *root_window()->GetProperty(client::kRestoreBoundsKey));
393 }
394
395 // Verifies property setting behavior for a std::string* property.
396 TEST_F(WindowTreeClientWmTest, SetStringProperty) {
397 std::string example = "123";
398 ASSERT_EQ(nullptr, root_window()->GetProperty(client::kAppIdKey));
399 root_window()->SetProperty(client::kAppIdKey, new std::string(example));
400 EXPECT_TRUE(root_window()->GetProperty(client::kAppIdKey));
401 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
402 ASSERT_FALSE(value.is_null());
403 EXPECT_EQ(example, mojo::ConvertTo<std::string>(value.PassStorage()));
404 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
405 WindowTreeChangeType::PROPERTY, true));
406 EXPECT_EQ(example, *root_window()->GetProperty(client::kAppIdKey));
407
408 root_window()->SetProperty(client::kAppIdKey, new std::string());
409 EXPECT_EQ(std::string(), *root_window()->GetProperty(client::kAppIdKey));
410 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
411 WindowTreeChangeType::PROPERTY, false));
412 EXPECT_EQ(example, *root_window()->GetProperty(client::kAppIdKey));
413 }
414
365 // Verifies visible is reverted if the server replied that the change failed. 415 // Verifies visible is reverted if the server replied that the change failed.
366 TEST_F(WindowTreeClientWmTest, SetVisibleFailed) { 416 TEST_F(WindowTreeClientWmTest, SetVisibleFailed) {
367 const bool original_visible = root_window()->TargetVisibility(); 417 const bool original_visible = root_window()->TargetVisibility();
368 const bool new_visible = !original_visible; 418 const bool new_visible = !original_visible;
369 SetWindowVisibility(root_window(), new_visible); 419 SetWindowVisibility(root_window(), new_visible);
370 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 420 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
371 WindowTreeChangeType::VISIBLE, false)); 421 WindowTreeChangeType::VISIBLE, false));
372 EXPECT_EQ(original_visible, root_window()->TargetVisibility()); 422 EXPECT_EQ(original_visible, root_window()->TargetVisibility());
373 } 423 }
374 424
(...skipping 370 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 // Make sure all the properties took. 795 // Make sure all the properties took.
746 EXPECT_TRUE(IsWindowHostVisible(top_level)); 796 EXPECT_TRUE(IsWindowHostVisible(top_level));
747 EXPECT_TRUE(top_level->TargetVisibility()); 797 EXPECT_TRUE(top_level->TargetVisibility());
748 // TODO: check display_id. 798 // TODO: check display_id.
749 EXPECT_EQ(display_id, window_tree_host.display_id()); 799 EXPECT_EQ(display_id, window_tree_host.display_id());
750 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds()); 800 EXPECT_EQ(gfx::Rect(0, 0, 3, 4), top_level->bounds());
751 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds()); 801 EXPECT_EQ(gfx::Rect(1, 2, 3, 4), top_level->GetHost()->GetBounds());
752 } 802 }
753 803
754 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) { 804 TEST_F(WindowTreeClientClientTest, NewWindowGetsAllChangesInFlight) {
755 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 805 RegisterTestProperties(GetPropertyConverter());
756 806
757 WindowTreeHostMus window_tree_host(window_tree_client_impl()); 807 WindowTreeHostMus window_tree_host(window_tree_client_impl());
758 Window* top_level = window_tree_host.window(); 808 Window* top_level = window_tree_host.window();
759 809
760 EXPECT_FALSE(top_level->TargetVisibility()); 810 EXPECT_FALSE(top_level->TargetVisibility());
761 811
762 // Make visibility go from false->true->false. Don't ack immediately. 812 // Make visibility go from false->true->false. Don't ack immediately.
763 top_level->Show(); 813 top_level->Show();
764 top_level->Hide(); 814 top_level->Hide();
765 815
766 // Change bounds to 5, 6, 7, 8. 816 // Change bounds to 5, 6, 7, 8.
767 window_tree_host.SetBounds(gfx::Rect(5, 6, 7, 8)); 817 window_tree_host.SetBounds(gfx::Rect(5, 6, 7, 8));
768 EXPECT_EQ(gfx::Rect(0, 0, 7, 8), window_tree_host.window()->bounds()); 818 EXPECT_EQ(gfx::Rect(0, 0, 7, 8), window_tree_host.window()->bounds());
769 819
770 const uint8_t explicitly_set_test_property1_value = 2; 820 const uint8_t explicitly_set_test_property1_value = 2;
771 top_level->SetProperty(kTestPropertyKey1, 821 top_level->SetProperty(kTestPropertyKey1,
772 explicitly_set_test_property1_value); 822 explicitly_set_test_property1_value);
773 823
774 // Ack the new window top level top_level Vis and bounds shouldn't change. 824 // Ack the new window top level top_level Vis and bounds shouldn't change.
775 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 825 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
776 data->window_id = server_id(top_level); 826 data->window_id = server_id(top_level);
777 const gfx::Rect bounds_from_server(1, 2, 3, 4); 827 const gfx::Rect bounds_from_server(1, 2, 3, 4);
778 data->bounds = bounds_from_server; 828 data->bounds = bounds_from_server;
779 data->visible = true; 829 data->visible = true;
780 const uint8_t server_test_property1_value = 3; 830 const uint8_t server_test_property1_value = 3;
781 data->properties[kTestPropertyServerKey1] = 831 data->properties[kTestPropertyServerKey1] =
782 Uint8ToPropertyTransportValue(server_test_property1_value); 832 GetPropertyTransportValue(server_test_property1_value);
783 const uint8_t server_test_property2_value = 4; 833 const uint8_t server_test_property2_value = 4;
784 data->properties[kTestPropertyServerKey2] = 834 data->properties[kTestPropertyServerKey2] =
785 Uint8ToPropertyTransportValue(server_test_property2_value); 835 GetPropertyTransportValue(server_test_property2_value);
786 const int64_t display_id = 1; 836 const int64_t display_id = 1;
787 // Get the id of the in flight change for creating the new top_level. 837 // Get the id of the in flight change for creating the new top_level.
788 uint32_t new_window_in_flight_change_id; 838 uint32_t new_window_in_flight_change_id;
789 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 839 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
790 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id)); 840 WindowTreeChangeType::NEW_TOP_LEVEL, &new_window_in_flight_change_id));
791 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id, 841 window_tree_client()->OnTopLevelCreated(new_window_in_flight_change_id,
792 std::move(data), display_id, true); 842 std::move(data), display_id, true);
793 843
794 // The only value that should take effect is the property for 'yy' as it was 844 // The only value that should take effect is the property for 'yy' as it was
795 // not in flight. 845 // not in flight.
(...skipping 21 matching lines...) Expand all
817 top_level->GetRootWindow()->GetHost()->GetBounds()); 867 top_level->GetRootWindow()->GetHost()->GetBounds());
818 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 868 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
819 WindowTreeChangeType::PROPERTY, false)); 869 WindowTreeChangeType::PROPERTY, false));
820 EXPECT_EQ(server_test_property1_value, 870 EXPECT_EQ(server_test_property1_value,
821 top_level->GetProperty(kTestPropertyKey1)); 871 top_level->GetProperty(kTestPropertyKey1));
822 EXPECT_EQ(server_test_property2_value, 872 EXPECT_EQ(server_test_property2_value,
823 top_level->GetProperty(kTestPropertyKey2)); 873 top_level->GetProperty(kTestPropertyKey2));
824 } 874 }
825 875
826 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) { 876 TEST_F(WindowTreeClientClientTest, NewWindowGetsProperties) {
827 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 877 RegisterTestProperties(GetPropertyConverter());
828 Window window(nullptr); 878 Window window(nullptr);
829 const uint8_t explicitly_set_test_property1_value = 29; 879 const uint8_t explicitly_set_test_property1_value = 29;
830 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value); 880 window.SetProperty(kTestPropertyKey1, explicitly_set_test_property1_value);
831 window.Init(ui::LAYER_NOT_DRAWN); 881 window.Init(ui::LAYER_NOT_DRAWN);
832 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties = 882 mojo::Map<mojo::String, mojo::Array<uint8_t>> transport_properties =
833 window_tree()->GetLastNewWindowProperties(); 883 window_tree()->GetLastNewWindowProperties();
834 ASSERT_FALSE(transport_properties.is_null()); 884 ASSERT_FALSE(transport_properties.is_null());
835 std::map<std::string, std::vector<uint8_t>> properties = 885 std::map<std::string, std::vector<uint8_t>> properties =
836 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>(); 886 transport_properties.To<std::map<std::string, std::vector<uint8_t>>>();
837 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1)); 887 ASSERT_EQ(1u, properties.count(kTestPropertyServerKey1));
(...skipping 321 matching lines...) Expand 10 before | Expand all | Expand 10 after
1159 ASSERT_EQ(1u, root_window()->children().size()); 1209 ASSERT_EQ(1u, root_window()->children().size());
1160 Window* server_window = root_window()->children()[0]; 1210 Window* server_window = root_window()->children()[0];
1161 EXPECT_EQ(window1->parent(), server_window); 1211 EXPECT_EQ(window1->parent(), server_window);
1162 EXPECT_EQ(window2->parent(), server_window); 1212 EXPECT_EQ(window2->parent(), server_window);
1163 ASSERT_EQ(2u, server_window->children().size()); 1213 ASSERT_EQ(2u, server_window->children().size());
1164 EXPECT_EQ(window1, server_window->children()[0]); 1214 EXPECT_EQ(window1, server_window->children()[0]);
1165 EXPECT_EQ(window2, server_window->children()[1]); 1215 EXPECT_EQ(window2, server_window->children()[1]);
1166 } 1216 }
1167 1217
1168 } // namespace aura 1218 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698