| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "components/mus/ws/test_change_tracker.h" | 5 #include "components/mus/ws/test_change_tracker.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
| 10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
| (...skipping 16 matching lines...) Expand all Loading... |
| 27 | 27 |
| 28 std::string RectToString(const mojo::Rect& rect) { | 28 std::string RectToString(const mojo::Rect& rect) { |
| 29 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width, | 29 return base::StringPrintf("%d,%d %dx%d", rect.x, rect.y, rect.width, |
| 30 rect.height); | 30 rect.height); |
| 31 } | 31 } |
| 32 | 32 |
| 33 std::string DirectionToString(mojom::OrderDirection direction) { | 33 std::string DirectionToString(mojom::OrderDirection direction) { |
| 34 return direction == mojom::OrderDirection::ABOVE ? "above" : "below"; | 34 return direction == mojom::OrderDirection::ABOVE ? "above" : "below"; |
| 35 } | 35 } |
| 36 | 36 |
| 37 std::string ChangeToDescription1(const Change& change) { | 37 enum class ChangeDescriptionType { |
| 38 ONE, |
| 39 TWO, |
| 40 }; |
| 41 |
| 42 std::string ChangeToDescription(const Change& change, |
| 43 ChangeDescriptionType type) { |
| 38 switch (change.type) { | 44 switch (change.type) { |
| 39 case CHANGE_TYPE_EMBED: | 45 case CHANGE_TYPE_EMBED: |
| 40 return "OnEmbed"; | 46 if (type == ChangeDescriptionType::ONE) |
| 47 return "OnEmbed"; |
| 48 return base::StringPrintf("OnEmbed drawn=%s", |
| 49 change.bool_value ? "true" : "false"); |
| 41 | 50 |
| 42 case CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED: | 51 case CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED: |
| 43 return base::StringPrintf("OnEmbeddedAppDisconnected window=%s", | 52 return base::StringPrintf("OnEmbeddedAppDisconnected window=%s", |
| 44 WindowIdToString(change.window_id).c_str()); | 53 WindowIdToString(change.window_id).c_str()); |
| 45 | 54 |
| 46 case CHANGE_TYPE_UNEMBED: | 55 case CHANGE_TYPE_UNEMBED: |
| 47 return base::StringPrintf("OnUnembed window=%s", | 56 return base::StringPrintf("OnUnembed window=%s", |
| 48 WindowIdToString(change.window_id).c_str()); | 57 WindowIdToString(change.window_id).c_str()); |
| 49 | 58 |
| 50 case CHANGE_TYPE_LOST_CAPTURE: | 59 case CHANGE_TYPE_LOST_CAPTURE: |
| (...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 118 case CHANGE_TYPE_CURSOR_CHANGED: | 127 case CHANGE_TYPE_CURSOR_CHANGED: |
| 119 return base::StringPrintf("CursorChanged id=%s cursor_id=%d", | 128 return base::StringPrintf("CursorChanged id=%s cursor_id=%d", |
| 120 WindowIdToString(change.window_id).c_str(), | 129 WindowIdToString(change.window_id).c_str(), |
| 121 change.cursor_id); | 130 change.cursor_id); |
| 122 case CHANGE_TYPE_ON_CHANGE_COMPLETED: | 131 case CHANGE_TYPE_ON_CHANGE_COMPLETED: |
| 123 return base::StringPrintf("ChangeCompleted id=%d sucess=%s", | 132 return base::StringPrintf("ChangeCompleted id=%d sucess=%s", |
| 124 change.change_id, | 133 change.change_id, |
| 125 change.bool_value ? "true" : "false"); | 134 change.bool_value ? "true" : "false"); |
| 126 | 135 |
| 127 case CHANGE_TYPE_ON_TOP_LEVEL_CREATED: | 136 case CHANGE_TYPE_ON_TOP_LEVEL_CREATED: |
| 128 return base::StringPrintf("TopLevelCreated id=%d window_id=%s", | 137 return base::StringPrintf("TopLevelCreated id=%d window_id=%s drawn=%s", |
| 129 change.change_id, | 138 change.change_id, |
| 130 WindowIdToString(change.window_id).c_str()); | 139 WindowIdToString(change.window_id).c_str(), |
| 140 change.bool_value ? "true" : "false"); |
| 131 } | 141 } |
| 132 return std::string(); | 142 return std::string(); |
| 133 } | 143 } |
| 134 | 144 |
| 145 std::string SingleChangeToDescriptionImpl(const std::vector<Change>& changes, |
| 146 ChangeDescriptionType change_type) { |
| 147 std::string result; |
| 148 for (auto& change : changes) { |
| 149 if (!result.empty()) |
| 150 result += "\n"; |
| 151 result += ChangeToDescription(change, change_type); |
| 152 } |
| 153 return result; |
| 154 } |
| 155 |
| 135 } // namespace | 156 } // namespace |
| 136 | 157 |
| 137 std::vector<std::string> ChangesToDescription1( | 158 std::vector<std::string> ChangesToDescription1( |
| 138 const std::vector<Change>& changes) { | 159 const std::vector<Change>& changes) { |
| 139 std::vector<std::string> strings(changes.size()); | 160 std::vector<std::string> strings(changes.size()); |
| 140 for (size_t i = 0; i < changes.size(); ++i) | 161 for (size_t i = 0; i < changes.size(); ++i) |
| 141 strings[i] = ChangeToDescription1(changes[i]); | 162 strings[i] = ChangeToDescription(changes[i], ChangeDescriptionType::ONE); |
| 142 return strings; | 163 return strings; |
| 143 } | 164 } |
| 144 | 165 |
| 145 std::string SingleChangeToDescription(const std::vector<Change>& changes) { | 166 std::string SingleChangeToDescription(const std::vector<Change>& changes) { |
| 146 std::string result; | 167 return SingleChangeToDescriptionImpl(changes, ChangeDescriptionType::ONE); |
| 147 for (auto& change : changes) { | 168 } |
| 148 if (!result.empty()) | 169 |
| 149 result += "\n"; | 170 std::string SingleChangeToDescription2(const std::vector<Change>& changes) { |
| 150 result += ChangeToDescription1(change); | 171 return SingleChangeToDescriptionImpl(changes, ChangeDescriptionType::TWO); |
| 151 } | |
| 152 return result; | |
| 153 } | 172 } |
| 154 | 173 |
| 155 std::string SingleWindowDescription(const std::vector<TestWindow>& windows) { | 174 std::string SingleWindowDescription(const std::vector<TestWindow>& windows) { |
| 156 if (windows.empty()) | 175 if (windows.empty()) |
| 157 return "no windows"; | 176 return "no windows"; |
| 158 std::string result; | 177 std::string result; |
| 159 for (const TestWindow& window : windows) | 178 for (const TestWindow& window : windows) |
| 160 result += window.ToString(); | 179 result += window.ToString(); |
| 161 return result; | 180 return result; |
| 162 } | 181 } |
| 163 | 182 |
| 164 std::string ChangeWindowDescription(const std::vector<Change>& changes) { | 183 std::string ChangeWindowDescription(const std::vector<Change>& changes) { |
| 165 if (changes.size() != 1) | 184 if (changes.size() != 1) |
| 166 return std::string(); | 185 return std::string(); |
| 167 std::vector<std::string> window_strings(changes[0].windows.size()); | 186 std::vector<std::string> window_strings(changes[0].windows.size()); |
| 168 for (size_t i = 0; i < changes[0].windows.size(); ++i) | 187 for (size_t i = 0; i < changes[0].windows.size(); ++i) |
| 169 window_strings[i] = "[" + changes[0].windows[i].ToString() + "]"; | 188 window_strings[i] = "[" + changes[0].windows[i].ToString() + "]"; |
| 170 return base::JoinString(window_strings, ","); | 189 return base::JoinString(window_strings, ","); |
| 171 } | 190 } |
| 172 | 191 |
| 173 TestWindow WindowDataToTestWindow(const mojom::WindowDataPtr& data) { | 192 TestWindow WindowDataToTestWindow(const mojom::WindowDataPtr& data) { |
| 174 TestWindow window; | 193 TestWindow window; |
| 175 window.parent_id = data->parent_id; | 194 window.parent_id = data->parent_id; |
| 176 window.window_id = data->window_id; | 195 window.window_id = data->window_id; |
| 177 window.visible = data->visible; | 196 window.visible = data->visible; |
| 178 window.drawn = data->drawn; | |
| 179 window.properties = | 197 window.properties = |
| 180 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); | 198 data->properties.To<std::map<std::string, std::vector<uint8_t>>>(); |
| 181 return window; | 199 return window; |
| 182 } | 200 } |
| 183 | 201 |
| 184 void WindowDatasToTestWindows(const Array<mojom::WindowDataPtr>& data, | 202 void WindowDatasToTestWindows(const Array<mojom::WindowDataPtr>& data, |
| 185 std::vector<TestWindow>* test_windows) { | 203 std::vector<TestWindow>* test_windows) { |
| 186 for (size_t i = 0; i < data.size(); ++i) | 204 for (size_t i = 0; i < data.size(); ++i) |
| 187 test_windows->push_back(WindowDataToTestWindow(data[i])); | 205 test_windows->push_back(WindowDataToTestWindow(data[i])); |
| 188 } | 206 } |
| (...skipping 11 matching lines...) Expand all Loading... |
| 200 | 218 |
| 201 Change::Change(const Change& other) = default; | 219 Change::Change(const Change& other) = default; |
| 202 | 220 |
| 203 Change::~Change() {} | 221 Change::~Change() {} |
| 204 | 222 |
| 205 TestChangeTracker::TestChangeTracker() : delegate_(NULL) {} | 223 TestChangeTracker::TestChangeTracker() : delegate_(NULL) {} |
| 206 | 224 |
| 207 TestChangeTracker::~TestChangeTracker() {} | 225 TestChangeTracker::~TestChangeTracker() {} |
| 208 | 226 |
| 209 void TestChangeTracker::OnEmbed(ConnectionSpecificId connection_id, | 227 void TestChangeTracker::OnEmbed(ConnectionSpecificId connection_id, |
| 210 mojom::WindowDataPtr root) { | 228 mojom::WindowDataPtr root, |
| 229 bool drawn) { |
| 211 Change change; | 230 Change change; |
| 212 change.type = CHANGE_TYPE_EMBED; | 231 change.type = CHANGE_TYPE_EMBED; |
| 213 change.connection_id = connection_id; | 232 change.connection_id = connection_id; |
| 233 change.bool_value = drawn; |
| 214 change.windows.push_back(WindowDataToTestWindow(root)); | 234 change.windows.push_back(WindowDataToTestWindow(root)); |
| 215 AddChange(change); | 235 AddChange(change); |
| 216 } | 236 } |
| 217 | 237 |
| 218 void TestChangeTracker::OnEmbeddedAppDisconnected(Id window_id) { | 238 void TestChangeTracker::OnEmbeddedAppDisconnected(Id window_id) { |
| 219 Change change; | 239 Change change; |
| 220 change.type = CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED; | 240 change.type = CHANGE_TYPE_EMBEDDED_APP_DISCONNECTED; |
| 221 change.window_id = window_id; | 241 change.window_id = window_id; |
| 222 AddChange(change); | 242 AddChange(change); |
| 223 } | 243 } |
| (...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 313 } | 333 } |
| 314 | 334 |
| 315 void TestChangeTracker::OnWindowVisibilityChanged(Id window_id, bool visible) { | 335 void TestChangeTracker::OnWindowVisibilityChanged(Id window_id, bool visible) { |
| 316 Change change; | 336 Change change; |
| 317 change.type = CHANGE_TYPE_NODE_VISIBILITY_CHANGED; | 337 change.type = CHANGE_TYPE_NODE_VISIBILITY_CHANGED; |
| 318 change.window_id = window_id; | 338 change.window_id = window_id; |
| 319 change.bool_value = visible; | 339 change.bool_value = visible; |
| 320 AddChange(change); | 340 AddChange(change); |
| 321 } | 341 } |
| 322 | 342 |
| 323 void TestChangeTracker::OnWindowDrawnStateChanged(Id window_id, bool drawn) { | 343 void TestChangeTracker::OnWindowParentDrawnStateChanged(Id window_id, |
| 344 bool drawn) { |
| 324 Change change; | 345 Change change; |
| 325 change.type = CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED; | 346 change.type = CHANGE_TYPE_NODE_DRAWN_STATE_CHANGED; |
| 326 change.window_id = window_id; | 347 change.window_id = window_id; |
| 327 change.bool_value = drawn; | 348 change.bool_value = drawn; |
| 328 AddChange(change); | 349 AddChange(change); |
| 329 } | 350 } |
| 330 | 351 |
| 331 void TestChangeTracker::OnWindowInputEvent(Id window_id, | 352 void TestChangeTracker::OnWindowInputEvent(Id window_id, |
| 332 mojom::EventPtr event) { | 353 mojom::EventPtr event) { |
| 333 Change change; | 354 Change change; |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 370 | 391 |
| 371 void TestChangeTracker::OnChangeCompleted(uint32_t change_id, bool success) { | 392 void TestChangeTracker::OnChangeCompleted(uint32_t change_id, bool success) { |
| 372 Change change; | 393 Change change; |
| 373 change.type = CHANGE_TYPE_ON_CHANGE_COMPLETED; | 394 change.type = CHANGE_TYPE_ON_CHANGE_COMPLETED; |
| 374 change.change_id = change_id; | 395 change.change_id = change_id; |
| 375 change.bool_value = success; | 396 change.bool_value = success; |
| 376 AddChange(change); | 397 AddChange(change); |
| 377 } | 398 } |
| 378 | 399 |
| 379 void TestChangeTracker::OnTopLevelCreated(uint32_t change_id, | 400 void TestChangeTracker::OnTopLevelCreated(uint32_t change_id, |
| 380 mojom::WindowDataPtr window_data) { | 401 mojom::WindowDataPtr window_data, |
| 402 bool drawn) { |
| 381 Change change; | 403 Change change; |
| 382 change.type = CHANGE_TYPE_ON_TOP_LEVEL_CREATED; | 404 change.type = CHANGE_TYPE_ON_TOP_LEVEL_CREATED; |
| 383 change.change_id = change_id; | 405 change.change_id = change_id; |
| 384 change.window_id = window_data->window_id; | 406 change.window_id = window_data->window_id; |
| 407 change.bool_value = drawn; |
| 385 AddChange(change); | 408 AddChange(change); |
| 386 } | 409 } |
| 387 | 410 |
| 388 void TestChangeTracker::AddChange(const Change& change) { | 411 void TestChangeTracker::AddChange(const Change& change) { |
| 389 changes_.push_back(change); | 412 changes_.push_back(change); |
| 390 if (delegate_) | 413 if (delegate_) |
| 391 delegate_->OnChangeAdded(); | 414 delegate_->OnChangeAdded(); |
| 392 } | 415 } |
| 393 | 416 |
| 394 TestWindow::TestWindow() {} | 417 TestWindow::TestWindow() {} |
| 395 | 418 |
| 396 TestWindow::TestWindow(const TestWindow& other) = default; | 419 TestWindow::TestWindow(const TestWindow& other) = default; |
| 397 | 420 |
| 398 TestWindow::~TestWindow() {} | 421 TestWindow::~TestWindow() {} |
| 399 | 422 |
| 400 std::string TestWindow::ToString() const { | 423 std::string TestWindow::ToString() const { |
| 401 return base::StringPrintf("window=%s parent=%s", | 424 return base::StringPrintf("window=%s parent=%s", |
| 402 WindowIdToString(window_id).c_str(), | 425 WindowIdToString(window_id).c_str(), |
| 403 WindowIdToString(parent_id).c_str()); | 426 WindowIdToString(parent_id).c_str()); |
| 404 } | 427 } |
| 405 | 428 |
| 406 std::string TestWindow::ToString2() const { | 429 std::string TestWindow::ToString2() const { |
| 407 return base::StringPrintf( | 430 return base::StringPrintf( |
| 408 "window=%s parent=%s visible=%s drawn=%s", | 431 "window=%s parent=%s visible=%s", WindowIdToString(window_id).c_str(), |
| 409 WindowIdToString(window_id).c_str(), WindowIdToString(parent_id).c_str(), | 432 WindowIdToString(parent_id).c_str(), visible ? "true" : "false"); |
| 410 visible ? "true" : "false", drawn ? "true" : "false"); | |
| 411 } | 433 } |
| 412 | 434 |
| 413 } // namespace ws | 435 } // namespace ws |
| 414 | 436 |
| 415 } // namespace mus | 437 } // namespace mus |
| OLD | NEW |