| 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/public/cpp/window.h" | 5 #include "components/mus/public/cpp/window.h" |
| 6 | 6 |
| 7 #include "base/logging.h" | 7 #include "base/logging.h" |
| 8 #include "base/strings/stringprintf.h" | 8 #include "base/strings/stringprintf.h" |
| 9 #include "components/mus/public/cpp/lib/window_private.h" | 9 #include "components/mus/public/cpp/lib/window_private.h" |
| 10 #include "components/mus/public/cpp/util.h" | 10 #include "components/mus/public/cpp/util.h" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 416 EXPECT_TRUE(TreeChangeParamsMatch(p111, o111.received_params().back())); | 416 EXPECT_TRUE(TreeChangeParamsMatch(p111, o111.received_params().back())); |
| 417 } | 417 } |
| 418 | 418 |
| 419 namespace { | 419 namespace { |
| 420 | 420 |
| 421 class OrderChangeObserver : public WindowObserver { | 421 class OrderChangeObserver : public WindowObserver { |
| 422 public: | 422 public: |
| 423 struct Change { | 423 struct Change { |
| 424 Window* window; | 424 Window* window; |
| 425 Window* relative_window; | 425 Window* relative_window; |
| 426 mojo::OrderDirection direction; | 426 mojom::OrderDirection direction; |
| 427 }; | 427 }; |
| 428 typedef std::vector<Change> Changes; | 428 typedef std::vector<Change> Changes; |
| 429 | 429 |
| 430 explicit OrderChangeObserver(Window* observee) : observee_(observee) { | 430 explicit OrderChangeObserver(Window* observee) : observee_(observee) { |
| 431 observee_->AddObserver(this); | 431 observee_->AddObserver(this); |
| 432 } | 432 } |
| 433 ~OrderChangeObserver() override { observee_->RemoveObserver(this); } | 433 ~OrderChangeObserver() override { observee_->RemoveObserver(this); } |
| 434 | 434 |
| 435 Changes GetAndClearChanges() { | 435 Changes GetAndClearChanges() { |
| 436 Changes changes; | 436 Changes changes; |
| 437 changes_.swap(changes); | 437 changes_.swap(changes); |
| 438 return changes; | 438 return changes; |
| 439 } | 439 } |
| 440 | 440 |
| 441 private: | 441 private: |
| 442 // Overridden from WindowObserver: | 442 // Overridden from WindowObserver: |
| 443 void OnWindowReordering(Window* window, | 443 void OnWindowReordering(Window* window, |
| 444 Window* relative_window, | 444 Window* relative_window, |
| 445 mojo::OrderDirection direction) override { | 445 mojom::OrderDirection direction) override { |
| 446 OnWindowReordered(window, relative_window, direction); | 446 OnWindowReordered(window, relative_window, direction); |
| 447 } | 447 } |
| 448 | 448 |
| 449 void OnWindowReordered(Window* window, | 449 void OnWindowReordered(Window* window, |
| 450 Window* relative_window, | 450 Window* relative_window, |
| 451 mojo::OrderDirection direction) override { | 451 mojom::OrderDirection direction) override { |
| 452 Change change; | 452 Change change; |
| 453 change.window = window; | 453 change.window = window; |
| 454 change.relative_window = relative_window; | 454 change.relative_window = relative_window; |
| 455 change.direction = direction; | 455 change.direction = direction; |
| 456 changes_.push_back(change); | 456 changes_.push_back(change); |
| 457 } | 457 } |
| 458 | 458 |
| 459 Window* observee_; | 459 Window* observee_; |
| 460 Changes changes_; | 460 Changes changes_; |
| 461 | 461 |
| (...skipping 19 matching lines...) Expand all Loading... |
| 481 // Move w11 to front. | 481 // Move w11 to front. |
| 482 // Resulting order: w12, w13, w11 | 482 // Resulting order: w12, w13, w11 |
| 483 w11.MoveToFront(); | 483 w11.MoveToFront(); |
| 484 EXPECT_EQ(&w12, w1.children().front()); | 484 EXPECT_EQ(&w12, w1.children().front()); |
| 485 EXPECT_EQ(&w11, w1.children().back()); | 485 EXPECT_EQ(&w11, w1.children().back()); |
| 486 | 486 |
| 487 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); | 487 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
| 488 ASSERT_EQ(2U, changes.size()); | 488 ASSERT_EQ(2U, changes.size()); |
| 489 EXPECT_EQ(&w11, changes[0].window); | 489 EXPECT_EQ(&w11, changes[0].window); |
| 490 EXPECT_EQ(&w13, changes[0].relative_window); | 490 EXPECT_EQ(&w13, changes[0].relative_window); |
| 491 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[0].direction); | 491 EXPECT_EQ(mojom::ORDER_DIRECTION_ABOVE, changes[0].direction); |
| 492 | 492 |
| 493 EXPECT_EQ(&w11, changes[1].window); | 493 EXPECT_EQ(&w11, changes[1].window); |
| 494 EXPECT_EQ(&w13, changes[1].relative_window); | 494 EXPECT_EQ(&w13, changes[1].relative_window); |
| 495 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[1].direction); | 495 EXPECT_EQ(mojom::ORDER_DIRECTION_ABOVE, changes[1].direction); |
| 496 } | 496 } |
| 497 | 497 |
| 498 { | 498 { |
| 499 OrderChangeObserver observer(&w11); | 499 OrderChangeObserver observer(&w11); |
| 500 | 500 |
| 501 // Move w11 to back. | 501 // Move w11 to back. |
| 502 // Resulting order: w11, w12, w13 | 502 // Resulting order: w11, w12, w13 |
| 503 w11.MoveToBack(); | 503 w11.MoveToBack(); |
| 504 EXPECT_EQ(&w11, w1.children().front()); | 504 EXPECT_EQ(&w11, w1.children().front()); |
| 505 EXPECT_EQ(&w13, w1.children().back()); | 505 EXPECT_EQ(&w13, w1.children().back()); |
| 506 | 506 |
| 507 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); | 507 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
| 508 ASSERT_EQ(2U, changes.size()); | 508 ASSERT_EQ(2U, changes.size()); |
| 509 EXPECT_EQ(&w11, changes[0].window); | 509 EXPECT_EQ(&w11, changes[0].window); |
| 510 EXPECT_EQ(&w12, changes[0].relative_window); | 510 EXPECT_EQ(&w12, changes[0].relative_window); |
| 511 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[0].direction); | 511 EXPECT_EQ(mojom::ORDER_DIRECTION_BELOW, changes[0].direction); |
| 512 | 512 |
| 513 EXPECT_EQ(&w11, changes[1].window); | 513 EXPECT_EQ(&w11, changes[1].window); |
| 514 EXPECT_EQ(&w12, changes[1].relative_window); | 514 EXPECT_EQ(&w12, changes[1].relative_window); |
| 515 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[1].direction); | 515 EXPECT_EQ(mojom::ORDER_DIRECTION_BELOW, changes[1].direction); |
| 516 } | 516 } |
| 517 | 517 |
| 518 { | 518 { |
| 519 OrderChangeObserver observer(&w11); | 519 OrderChangeObserver observer(&w11); |
| 520 | 520 |
| 521 // Move w11 above w12. | 521 // Move w11 above w12. |
| 522 // Resulting order: w12. w11, w13 | 522 // Resulting order: w12. w11, w13 |
| 523 w11.Reorder(&w12, mojo::ORDER_DIRECTION_ABOVE); | 523 w11.Reorder(&w12, mojom::ORDER_DIRECTION_ABOVE); |
| 524 EXPECT_EQ(&w12, w1.children().front()); | 524 EXPECT_EQ(&w12, w1.children().front()); |
| 525 EXPECT_EQ(&w13, w1.children().back()); | 525 EXPECT_EQ(&w13, w1.children().back()); |
| 526 | 526 |
| 527 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); | 527 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
| 528 ASSERT_EQ(2U, changes.size()); | 528 ASSERT_EQ(2U, changes.size()); |
| 529 EXPECT_EQ(&w11, changes[0].window); | 529 EXPECT_EQ(&w11, changes[0].window); |
| 530 EXPECT_EQ(&w12, changes[0].relative_window); | 530 EXPECT_EQ(&w12, changes[0].relative_window); |
| 531 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[0].direction); | 531 EXPECT_EQ(mojom::ORDER_DIRECTION_ABOVE, changes[0].direction); |
| 532 | 532 |
| 533 EXPECT_EQ(&w11, changes[1].window); | 533 EXPECT_EQ(&w11, changes[1].window); |
| 534 EXPECT_EQ(&w12, changes[1].relative_window); | 534 EXPECT_EQ(&w12, changes[1].relative_window); |
| 535 EXPECT_EQ(mojo::ORDER_DIRECTION_ABOVE, changes[1].direction); | 535 EXPECT_EQ(mojom::ORDER_DIRECTION_ABOVE, changes[1].direction); |
| 536 } | 536 } |
| 537 | 537 |
| 538 { | 538 { |
| 539 OrderChangeObserver observer(&w11); | 539 OrderChangeObserver observer(&w11); |
| 540 | 540 |
| 541 // Move w11 below w12. | 541 // Move w11 below w12. |
| 542 // Resulting order: w11, w12, w13 | 542 // Resulting order: w11, w12, w13 |
| 543 w11.Reorder(&w12, mojo::ORDER_DIRECTION_BELOW); | 543 w11.Reorder(&w12, mojom::ORDER_DIRECTION_BELOW); |
| 544 EXPECT_EQ(&w11, w1.children().front()); | 544 EXPECT_EQ(&w11, w1.children().front()); |
| 545 EXPECT_EQ(&w13, w1.children().back()); | 545 EXPECT_EQ(&w13, w1.children().back()); |
| 546 | 546 |
| 547 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); | 547 OrderChangeObserver::Changes changes = observer.GetAndClearChanges(); |
| 548 ASSERT_EQ(2U, changes.size()); | 548 ASSERT_EQ(2U, changes.size()); |
| 549 EXPECT_EQ(&w11, changes[0].window); | 549 EXPECT_EQ(&w11, changes[0].window); |
| 550 EXPECT_EQ(&w12, changes[0].relative_window); | 550 EXPECT_EQ(&w12, changes[0].relative_window); |
| 551 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[0].direction); | 551 EXPECT_EQ(mojom::ORDER_DIRECTION_BELOW, changes[0].direction); |
| 552 | 552 |
| 553 EXPECT_EQ(&w11, changes[1].window); | 553 EXPECT_EQ(&w11, changes[1].window); |
| 554 EXPECT_EQ(&w12, changes[1].relative_window); | 554 EXPECT_EQ(&w12, changes[1].relative_window); |
| 555 EXPECT_EQ(mojo::ORDER_DIRECTION_BELOW, changes[1].direction); | 555 EXPECT_EQ(mojom::ORDER_DIRECTION_BELOW, changes[1].direction); |
| 556 } | 556 } |
| 557 } | 557 } |
| 558 | 558 |
| 559 namespace { | 559 namespace { |
| 560 | 560 |
| 561 typedef std::vector<std::string> Changes; | 561 typedef std::vector<std::string> Changes; |
| 562 | 562 |
| 563 std::string WindowIdToString(Id id) { | 563 std::string WindowIdToString(Id id) { |
| 564 return (id == 0) ? "null" | 564 return (id == 0) ? "null" |
| 565 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); | 565 : base::StringPrintf("%d,%d", HiWord(id), LoWord(id)); |
| (...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 866 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); | 866 EXPECT_EQ(PropertyChangeInfo(&prop, -2), o.PropertyChangeInfoAndClear()); |
| 867 w1.ClearLocalProperty(&prop); | 867 w1.ClearLocalProperty(&prop); |
| 868 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); | 868 EXPECT_EQ(PropertyChangeInfo(&prop, 3), o.PropertyChangeInfoAndClear()); |
| 869 | 869 |
| 870 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. | 870 // Sanity check to see if |PropertyChangeInfoAndClear| really clears. |
| 871 EXPECT_EQ(PropertyChangeInfo(reinterpret_cast<const void*>(NULL), -3), | 871 EXPECT_EQ(PropertyChangeInfo(reinterpret_cast<const void*>(NULL), -3), |
| 872 o.PropertyChangeInfoAndClear()); | 872 o.PropertyChangeInfoAndClear()); |
| 873 } | 873 } |
| 874 | 874 |
| 875 } // namespace mus | 875 } // namespace mus |
| OLD | NEW |