OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/window.h" | 5 #include "ui/aura/window.h" |
6 | 6 |
7 #include <utility> | 7 #include <utility> |
8 | 8 |
9 #include "base/basictypes.h" | 9 #include "base/basictypes.h" |
10 #include "base/compiler_specific.h" | 10 #include "base/compiler_specific.h" |
| 11 #include "base/string_number_conversions.h" |
11 #include "base/stringprintf.h" | 12 #include "base/stringprintf.h" |
12 #include "testing/gtest/include/gtest/gtest.h" | 13 #include "testing/gtest/include/gtest/gtest.h" |
13 #include "ui/aura/client/capture_client.h" | 14 #include "ui/aura/client/capture_client.h" |
14 #include "ui/aura/client/stacking_client.h" | 15 #include "ui/aura/client/stacking_client.h" |
15 #include "ui/aura/client/visibility_client.h" | 16 #include "ui/aura/client/visibility_client.h" |
16 #include "ui/aura/layout_manager.h" | 17 #include "ui/aura/layout_manager.h" |
17 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
18 #include "ui/aura/root_window_host.h" | 19 #include "ui/aura/root_window_host.h" |
19 #include "ui/aura/root_window_observer.h" | 20 #include "ui/aura/root_window_observer.h" |
20 #include "ui/aura/test/aura_test_base.h" | 21 #include "ui/aura/test/aura_test_base.h" |
(...skipping 2433 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2454 window->layer()->GetAnimator()->last_step_time(); | 2455 window->layer()->GetAnimator()->last_step_time(); |
2455 ui::AnimationContainerElement* element = window->layer()->GetAnimator(); | 2456 ui::AnimationContainerElement* element = window->layer()->GetAnimator(); |
2456 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); | 2457 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); |
2457 | 2458 |
2458 // No bounds changed notification at the end of animation since layer | 2459 // No bounds changed notification at the end of animation since layer |
2459 // delegate is NULL. | 2460 // delegate is NULL. |
2460 EXPECT_FALSE(delegate.bounds_changed()); | 2461 EXPECT_FALSE(delegate.bounds_changed()); |
2461 EXPECT_NE("0,0 100x100", window->bounds().ToString()); | 2462 EXPECT_NE("0,0 100x100", window->bounds().ToString()); |
2462 } | 2463 } |
2463 | 2464 |
| 2465 namespace { |
| 2466 |
| 2467 // Used by AddChildNotifications to track notification counts. |
| 2468 class AddChildNotificationsObserver : public WindowObserver { |
| 2469 public: |
| 2470 AddChildNotificationsObserver() : added_count_(0), removed_count_(0) {} |
| 2471 |
| 2472 std::string CountStringAndReset() { |
| 2473 std::string result = base::IntToString(added_count_) + " " + |
| 2474 base::IntToString(removed_count_); |
| 2475 added_count_ = removed_count_ = 0; |
| 2476 return result; |
| 2477 } |
| 2478 |
| 2479 // WindowObserver overrides: |
| 2480 virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE { |
| 2481 added_count_++; |
| 2482 } |
| 2483 virtual void OnWindowRemovingFromRootWindow(Window* window) OVERRIDE { |
| 2484 removed_count_++; |
| 2485 } |
| 2486 |
| 2487 private: |
| 2488 int added_count_; |
| 2489 int removed_count_; |
| 2490 |
| 2491 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver); |
| 2492 }; |
| 2493 |
| 2494 } // namespace |
| 2495 |
| 2496 // Assertions around when root window notifications are sent. |
| 2497 TEST_F(WindowTest, AddChildNotifications) { |
| 2498 AddChildNotificationsObserver observer; |
| 2499 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL)); |
| 2500 scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL)); |
| 2501 w2->AddObserver(&observer); |
| 2502 w2->Focus(); |
| 2503 EXPECT_TRUE(w2->HasFocus()); |
| 2504 |
| 2505 // Move |w2| to be a child of |w1|. |
| 2506 w1->AddChild(w2.get()); |
| 2507 // Sine we moved in the same root, observer shouldn't be notified. |
| 2508 EXPECT_EQ("0 0", observer.CountStringAndReset()); |
| 2509 // |w2| should still have focus after moving. |
| 2510 EXPECT_TRUE(w2->HasFocus()); |
| 2511 } |
| 2512 |
2464 } // namespace test | 2513 } // namespace test |
2465 } // namespace aura | 2514 } // namespace aura |
OLD | NEW |