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

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

Issue 2539263005: Makes WindowTreeHostMus supply properties directly to window creation (Closed)
Patch Set: types Created 4 years 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"
(...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after
139 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) { 139 TEST_F(WindowTreeClientWmTest, OnWindowHierarchyChangedWithProperties) {
140 RegisterTestProperties(GetPropertyConverter()); 140 RegisterTestProperties(GetPropertyConverter());
141 window_tree()->AckAllChanges(); 141 window_tree()->AckAllChanges();
142 const Id child_window_id = server_id(root_window()) + 11; 142 const Id child_window_id = server_id(root_window()) + 11;
143 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New(); 143 ui::mojom::WindowDataPtr data = ui::mojom::WindowData::New();
144 const uint8_t server_test_property1_value = 91; 144 const uint8_t server_test_property1_value = 91;
145 data->properties[kTestPropertyServerKey1] = 145 data->properties[kTestPropertyServerKey1] =
146 ConvertToPropertyTransportValue(server_test_property1_value); 146 ConvertToPropertyTransportValue(server_test_property1_value);
147 data->properties[ui::mojom::WindowManager::kWindowType_Property] = 147 data->properties[ui::mojom::WindowManager::kWindowType_Property] =
148 mojo::ConvertTo<std::vector<uint8_t>>( 148 mojo::ConvertTo<std::vector<uint8_t>>(
149 static_cast<int32_t>(ui::mojom::WindowType::BUBBLE)); 149 static_cast<int32_t>(ui::mojom::WindowType::BUBBLE));
msw 2016/12/02 00:31:08 Should this use ConvertToPropertyTransportValue?
sky 2016/12/02 01:08:43 As the window type can't change after the window i
150 data->parent_id = server_id(root_window()); 150 data->parent_id = server_id(root_window());
151 data->window_id = child_window_id; 151 data->window_id = child_window_id;
152 data->bounds = gfx::Rect(1, 2, 3, 4); 152 data->bounds = gfx::Rect(1, 2, 3, 4);
153 data->visible = false; 153 data->visible = false;
154 std::vector<ui::mojom::WindowDataPtr> data_array(1); 154 std::vector<ui::mojom::WindowDataPtr> data_array(1);
155 data_array[0] = std::move(data); 155 data_array[0] = std::move(data);
156 ASSERT_TRUE(root_window()->children().empty()); 156 ASSERT_TRUE(root_window()->children().empty());
157 window_tree_client()->OnWindowHierarchyChanged( 157 window_tree_client()->OnWindowHierarchyChanged(
158 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));
159 ASSERT_FALSE(window_tree()->has_change()); 159 ASSERT_FALSE(window_tree()->has_change());
(...skipping 885 matching lines...) Expand 10 before | Expand all | Expand 10 after
1045 display_id, true); 1045 display_id, true);
1046 EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size()); 1046 EXPECT_EQ(initial_root_count, window_tree_client_impl()->GetRoots().size());
1047 } 1047 }
1048 1048
1049 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsProperties) { 1049 TEST_F(WindowTreeClientClientTest, NewTopLevelWindowGetsProperties) {
1050 RegisterTestProperties(GetPropertyConverter()); 1050 RegisterTestProperties(GetPropertyConverter());
1051 const uint8_t property_value = 11; 1051 const uint8_t property_value = 11;
1052 std::map<std::string, std::vector<uint8_t>> properties; 1052 std::map<std::string, std::vector<uint8_t>> properties;
1053 properties[kTestPropertyServerKey1] = 1053 properties[kTestPropertyServerKey1] =
1054 ConvertToPropertyTransportValue(property_value); 1054 ConvertToPropertyTransportValue(property_value);
1055 const char kUnknownPropertyKey[] = "unknown-property";
1056 using UnknownPropertyType = int32_t;
1057 const UnknownPropertyType kUnknownPropertyValue = 101;
1058 properties[kUnknownPropertyKey] =
1059 mojo::ConvertTo<std::vector<uint8_t>>(kUnknownPropertyValue);
msw 2016/12/02 00:31:08 I guess PropertyConverter *never* converts this va
sky 2016/12/02 01:08:43 That's right.
1055 std::unique_ptr<WindowTreeHostMus> window_tree_host = 1060 std::unique_ptr<WindowTreeHostMus> window_tree_host =
1056 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl(), 1061 base::MakeUnique<WindowTreeHostMus>(window_tree_client_impl(),
1057 &properties); 1062 &properties);
1058 // Verify the property made it to the window. 1063 // Verify the property made it to the window.
1059 EXPECT_EQ(property_value, 1064 EXPECT_EQ(property_value,
1060 window_tree_host->window()->GetProperty(kTestPropertyKey1)); 1065 window_tree_host->window()->GetProperty(kTestPropertyKey1));
1061 1066
1062 // Get the id of the in flight change for creating the new top level window. 1067 // Get the id of the in flight change for creating the new top level window.
1063 uint32_t change_id; 1068 uint32_t change_id;
1064 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType( 1069 ASSERT_TRUE(window_tree()->GetAndRemoveFirstChangeOfType(
1065 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id)); 1070 WindowTreeChangeType::NEW_TOP_LEVEL, &change_id));
1066 1071
1067 // Verify the property was sent to the server. 1072 // Verify the properties were sent to the server.
1068 base::Optional<std::unordered_map<std::string, std::vector<uint8_t>>> 1073 base::Optional<std::unordered_map<std::string, std::vector<uint8_t>>>
1069 transport_properties = window_tree()->GetLastNewWindowProperties(); 1074 transport_properties = window_tree()->GetLastNewWindowProperties();
1070 ASSERT_TRUE(transport_properties.has_value()); 1075 ASSERT_TRUE(transport_properties.has_value());
1071 std::map<std::string, std::vector<uint8_t>> properties2 = 1076 std::map<std::string, std::vector<uint8_t>> properties2 =
1072 mojo::UnorderedMapToMap(*transport_properties); 1077 mojo::UnorderedMapToMap(*transport_properties);
1073 ASSERT_EQ(1u, properties2.count(kTestPropertyServerKey1)); 1078 ASSERT_EQ(1u, properties2.count(kTestPropertyServerKey1));
1074 // PropertyConverter uses int64_t values, even for smaller types like uint8_t. 1079 // PropertyConverter uses int64_t values, even for smaller types like uint8_t.
1075 ASSERT_EQ(8u, properties2[kTestPropertyServerKey1].size()); 1080 ASSERT_EQ(8u, properties2[kTestPropertyServerKey1].size());
1076 EXPECT_EQ(static_cast<int64_t>(property_value), 1081 EXPECT_EQ(static_cast<int64_t>(property_value),
1077 mojo::ConvertTo<int64_t>(properties2[kTestPropertyServerKey1])); 1082 mojo::ConvertTo<int64_t>(properties2[kTestPropertyServerKey1]));
1083
1084 ASSERT_EQ(1u, properties2.count(kUnknownPropertyKey));
1085 ASSERT_EQ(sizeof(UnknownPropertyType),
1086 properties2[kUnknownPropertyKey].size());
1087 EXPECT_EQ(kUnknownPropertyValue, mojo::ConvertTo<UnknownPropertyType>(
1088 properties2[kUnknownPropertyKey]));
1078 } 1089 }
1079 1090
1080 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly 1091 // Tests both SetCapture and ReleaseCapture, to ensure that Window is properly
1081 // updated on failures. 1092 // updated on failures.
1082 TEST_F(WindowTreeClientWmTest, ExplicitCapture) { 1093 TEST_F(WindowTreeClientWmTest, ExplicitCapture) {
1083 root_window()->SetCapture(); 1094 root_window()->SetCapture();
1084 EXPECT_TRUE(root_window()->HasCapture()); 1095 EXPECT_TRUE(root_window()->HasCapture());
1085 ASSERT_TRUE(window_tree()->AckSingleChangeOfType( 1096 ASSERT_TRUE(window_tree()->AckSingleChangeOfType(
1086 WindowTreeChangeType::CAPTURE, false)); 1097 WindowTreeChangeType::CAPTURE, false));
1087 EXPECT_FALSE(root_window()->HasCapture()); 1098 EXPECT_FALSE(root_window()->HasCapture());
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after
1368 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn); 1379 .CallWmNewDisplayAdded(display, std::move(root_data), parent_drawn);
1369 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels()); 1380 EXPECT_EQ(display.bounds(), window_tree_host->GetBoundsInPixels());
1370 // The root window of the WindowTreeHost always has an origin of 0,0. 1381 // The root window of the WindowTreeHost always has an origin of 0,0.
1371 EXPECT_EQ(gfx::Rect(display.bounds().size()), 1382 EXPECT_EQ(gfx::Rect(display.bounds().size()),
1372 window_tree_host->window()->bounds()); 1383 window_tree_host->window()->bounds());
1373 EXPECT_TRUE(window_tree_host->window()->IsVisible()); 1384 EXPECT_TRUE(window_tree_host->window()->IsVisible());
1374 EXPECT_EQ(display.id(), window_tree_host->display_id()); 1385 EXPECT_EQ(display.id(), window_tree_host->display_id());
1375 } 1386 }
1376 1387
1377 } // namespace aura 1388 } // namespace aura
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698