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

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

Issue 2488353005: Implement aura::PropertyConverter for mus interop. (Closed)
Patch Set: Remove key name comparison. 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/test/aura_test_base.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 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 "mojo/common/common_type_converters.h" 11 #include "mojo/common/common_type_converters.h"
12 #include "services/ui/public/cpp/property_type_converters.h"
12 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
13 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
14 #include "ui/aura/client/capture_client.h" 15 #include "ui/aura/client/capture_client.h"
15 #include "ui/aura/client/capture_client_observer.h" 16 #include "ui/aura/client/capture_client_observer.h"
16 #include "ui/aura/client/focus_client.h" 17 #include "ui/aura/client/focus_client.h"
17 #include "ui/aura/client/transient_window_client.h" 18 #include "ui/aura/client/transient_window_client.h"
18 #include "ui/aura/mus/property_converter.h" 19 #include "ui/aura/mus/property_converter.h"
19 #include "ui/aura/mus/window_mus.h" 20 #include "ui/aura/mus/window_mus.h"
20 #include "ui/aura/mus/window_tree_client_delegate.h" 21 #include "ui/aura/mus/window_tree_client_delegate.h"
21 #include "ui/aura/mus/window_tree_client_observer.h" 22 #include "ui/aura/mus/window_tree_client_observer.h"
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
53 } 54 }
54 55
55 Window* GetFirstRoot(WindowTreeClient* client) { 56 Window* GetFirstRoot(WindowTreeClient* client) {
56 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin(); 57 return client->GetRoots().empty() ? nullptr : *client->GetRoots().begin();
57 } 58 }
58 59
59 bool IsWindowHostVisible(Window* window) { 60 bool IsWindowHostVisible(Window* window) {
60 return window->GetRootWindow()->GetHost()->compositor()->IsVisible(); 61 return window->GetRootWindow()->GetHost()->compositor()->IsVisible();
61 } 62 }
62 63
63 const char kAlwaysOnTopServerKey[] = "always-on-top-server";
64 const char kTestPropertyServerKey1[] = "test-property-server1"; 64 const char kTestPropertyServerKey1[] = "test-property-server1";
65 const char kTestPropertyServerKey2[] = "test-property-server2"; 65 const char kTestPropertyServerKey2[] = "test-property-server2";
66 66
67 class TestPropertyConverter : public PropertyConverter { 67 class TestPropertyConverter : public PropertyConverter {
68 public: 68 public:
69 TestPropertyConverter() {} 69 TestPropertyConverter() {}
70 ~TestPropertyConverter() override {} 70 ~TestPropertyConverter() override {}
71 71
72 // PropertyConverter: 72 // PropertyConverter:
73 bool ConvertPropertyForTransport( 73 bool ConvertPropertyForTransport(
74 Window* window, 74 Window* window,
75 const void* key, 75 const void* key,
76 std::string* server_property_name, 76 std::string* server_property_name,
77 std::unique_ptr<std::vector<uint8_t>>* server_property_value) override { 77 std::unique_ptr<std::vector<uint8_t>>* server_property_value) override {
78 if (key == client::kAlwaysOnTopKey) {
79 *server_property_name = kAlwaysOnTopServerKey;
80 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
81 (*server_property_value->get())[0] =
82 window->GetProperty(client::kAlwaysOnTopKey);
83 return true;
84 }
85 if (key == kTestPropertyKey1) { 78 if (key == kTestPropertyKey1) {
86 *server_property_name = kTestPropertyServerKey1; 79 *server_property_name = kTestPropertyServerKey1;
87 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1); 80 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
88 (*server_property_value->get())[0] = 81 (*server_property_value->get())[0] =
89 window->GetProperty(kTestPropertyKey1); 82 window->GetProperty(kTestPropertyKey1);
90 return true; 83 return true;
91 } 84 }
92 if (key == kTestPropertyKey2) { 85 if (key == kTestPropertyKey2) {
93 *server_property_name = kTestPropertyServerKey2; 86 *server_property_name = kTestPropertyServerKey2;
94 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1); 87 *server_property_value = base::MakeUnique<std::vector<uint8_t>>(1);
95 (*server_property_value->get())[0] = 88 (*server_property_value->get())[0] =
96 window->GetProperty(kTestPropertyKey2); 89 window->GetProperty(kTestPropertyKey2);
97 return true; 90 return true;
98 } 91 }
99 return false; 92 return PropertyConverter::ConvertPropertyForTransport(
93 window, key, server_property_name, server_property_value);
100 } 94 }
101 95
102 std::string GetTransportNameForPropertyKey(const void* key) override { 96 std::string GetTransportNameForPropertyKey(const void* key) override {
103 if (key == client::kAlwaysOnTopKey)
104 return kAlwaysOnTopServerKey;
105 if (key == kTestPropertyKey1) 97 if (key == kTestPropertyKey1)
106 return kTestPropertyServerKey1; 98 return kTestPropertyServerKey1;
107 if (key == kTestPropertyKey2) 99 if (key == kTestPropertyKey2)
108 return kTestPropertyServerKey2; 100 return kTestPropertyServerKey2;
109 return std::string(); 101 return PropertyConverter::GetTransportNameForPropertyKey(key);
110 } 102 }
111 103
112 void SetPropertyFromTransportValue( 104 void SetPropertyFromTransportValue(
113 Window* window, 105 Window* window,
114 const std::string& server_property_name, 106 const std::string& server_property_name,
115 const std::vector<uint8_t>* data) override { 107 const std::vector<uint8_t>* data) override {
116 if (server_property_name == kAlwaysOnTopServerKey) { 108 if (server_property_name == kTestPropertyServerKey1) {
117 window->SetProperty(client::kAlwaysOnTopKey,
118 static_cast<bool>((*data)[0]));
119 } else if (server_property_name == kTestPropertyServerKey1) {
120 window->SetProperty(kTestPropertyKey1, (*data)[0]); 109 window->SetProperty(kTestPropertyKey1, (*data)[0]);
121 } else if (server_property_name == kTestPropertyServerKey2) { 110 } else if (server_property_name == kTestPropertyServerKey2) {
122 window->SetProperty(kTestPropertyKey2, (*data)[0]); 111 window->SetProperty(kTestPropertyKey2, (*data)[0]);
112 } else {
113 PropertyConverter::SetPropertyFromTransportValue(
114 window, server_property_name, data);
123 } 115 }
124 } 116 }
125 117
126 private: 118 private:
127 DISALLOW_COPY_AND_ASSIGN(TestPropertyConverter); 119 DISALLOW_COPY_AND_ASSIGN(TestPropertyConverter);
128 }; 120 };
129 121
130 } // namespace 122 } // namespace
131 123
132 mojo::Array<uint8_t> Uint8ToPropertyTransportValue(uint8_t value) { 124 mojo::Array<uint8_t> Uint8ToPropertyTransportValue(uint8_t value) {
(...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 window_tree()->AckFirstChangeOfType(WindowTreeChangeType::BOUNDS, false)); 292 window_tree()->AckFirstChangeOfType(WindowTreeChangeType::BOUNDS, false));
301 EXPECT_EQ(bounds2, root_window()->bounds()); 293 EXPECT_EQ(bounds2, root_window()->bounds());
302 294
303 // Tell the client the seconds bounds failed. Should now fallback to original 295 // Tell the client the seconds bounds failed. Should now fallback to original
304 // value. 296 // value.
305 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS, 297 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(WindowTreeChangeType::BOUNDS,
306 false)); 298 false));
307 EXPECT_EQ(original_bounds, root_window()->bounds()); 299 EXPECT_EQ(original_bounds, root_window()->bounds());
308 } 300 }
309 301
302 // Verifies properties are set if the server replied that the change succeeded.
303 TEST_F(WindowTreeClientWmTest, SetPropertySucceeded) {
304 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
305 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
306 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
307 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
308 ASSERT_FALSE(value.is_null());
309 // PropertyConverter uses int64_t values, even for smaller types, like bool.
310 ASSERT_EQ(8u, value.size());
311 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value);
312 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
313 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
314 WindowTreeChangeType::PROPERTY, true));
315 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
316 }
317
310 // Verifies properties are reverted if the server replied that the change 318 // Verifies properties are reverted if the server replied that the change
311 // failed. 319 // failed.
312 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) { 320 TEST_F(WindowTreeClientWmTest, SetPropertyFailed) {
313 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
314 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 321 ASSERT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
315 root_window()->SetProperty(client::kAlwaysOnTopKey, true); 322 root_window()->SetProperty(client::kAlwaysOnTopKey, true);
316 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 323 EXPECT_TRUE(root_window()->GetProperty(client::kAlwaysOnTopKey));
317 mojo::Array<uint8_t> transport_value = window_tree()->GetLastPropertyValue(); 324 mojo::Array<uint8_t> value = window_tree()->GetLastPropertyValue();
318 ASSERT_FALSE(transport_value.is_null()); 325 ASSERT_FALSE(value.is_null());
319 ASSERT_EQ(1u, transport_value.size()); 326 // PropertyConverter uses int64_t values, even for smaller types, like bool.
320 EXPECT_EQ(1, transport_value[0]); 327 ASSERT_EQ(8u, value.size());
328 std::vector<uint8_t> array = mojo::ConvertTo<std::vector<uint8_t>>(value);
329 EXPECT_EQ(1, mojo::ConvertTo<int64_t>(array));
321 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 330 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
322 WindowTreeChangeType::PROPERTY, false)); 331 WindowTreeChangeType::PROPERTY, false));
323 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey)); 332 EXPECT_FALSE(root_window()->GetProperty(client::kAlwaysOnTopKey));
324 } 333 }
325 334
326 // Simulates a property change, and while the property change is in flight the 335 // Simulates a property change, and while the property change is in flight the
327 // server replies with a new property and the original property change fails. 336 // server replies with a new property and the original property change fails.
328 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) { 337 TEST_F(WindowTreeClientWmTest, SetPropertyFailedWithPendingChange) {
329 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>()); 338 SetPropertyConverter(base::MakeUnique<TestPropertyConverter>());
330 const uint8_t value1 = 11; 339 const uint8_t value1 = 11;
(...skipping 819 matching lines...) Expand 10 before | Expand all | Expand 10 after
1150 ASSERT_EQ(1u, root_window()->children().size()); 1159 ASSERT_EQ(1u, root_window()->children().size());
1151 Window* server_window = root_window()->children()[0]; 1160 Window* server_window = root_window()->children()[0];
1152 EXPECT_EQ(window1->parent(), server_window); 1161 EXPECT_EQ(window1->parent(), server_window);
1153 EXPECT_EQ(window2->parent(), server_window); 1162 EXPECT_EQ(window2->parent(), server_window);
1154 ASSERT_EQ(2u, server_window->children().size()); 1163 ASSERT_EQ(2u, server_window->children().size());
1155 EXPECT_EQ(window1, server_window->children()[0]); 1164 EXPECT_EQ(window1, server_window->children()[0]);
1156 EXPECT_EQ(window2, server_window->children()[1]); 1165 EXPECT_EQ(window2, server_window->children()[1]);
1157 } 1166 }
1158 1167
1159 } // namespace aura 1168 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/mus/property_converter.cc ('k') | ui/aura/test/aura_test_base.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698