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

Side by Side Diff: ui/aura/window_unittest.cc

Issue 10831297: Attempt 2 at: Makes Window not change focus and send out (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: The fix Created 8 years, 4 months 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 | Annotate | Revision Log
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 555 matching lines...) Expand 10 before | Expand all | Expand 10 after
576 private: 577 private:
577 bool called_; 578 bool called_;
578 579
579 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver); 580 DISALLOW_COPY_AND_ASSIGN(AddedToRootWindowObserver);
580 }; 581 };
581 582
582 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) { 583 TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) {
583 AddedToRootWindowObserver parent_observer; 584 AddedToRootWindowObserver parent_observer;
584 AddedToRootWindowObserver child_observer; 585 AddedToRootWindowObserver child_observer;
585 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL)); 586 scoped_ptr<Window> parent_window(CreateTestWindowWithId(1, NULL));
586 scoped_ptr<Window> child_window(CreateTestWindowWithId(1, NULL)); 587 scoped_ptr<Window> child_window(new Window(NULL));
588 child_window->Init(ui::LAYER_TEXTURED);
589 child_window->Show();
587 590
588 parent_window->AddObserver(&parent_observer); 591 parent_window->AddObserver(&parent_observer);
589 child_window->AddObserver(&child_observer); 592 child_window->AddObserver(&child_observer);
590 593
591 parent_window->AddChild(child_window.get()); 594 parent_window->AddChild(child_window.get());
592 595
593 EXPECT_FALSE(parent_observer.called()); 596 EXPECT_FALSE(parent_observer.called());
594 EXPECT_TRUE(child_observer.called()); 597 EXPECT_TRUE(child_observer.called());
595 598
596 parent_window->RemoveObserver(&parent_observer); 599 parent_window->RemoveObserver(&parent_observer);
(...skipping 1857 matching lines...) Expand 10 before | Expand all | Expand 10 after
2454 window->layer()->GetAnimator()->last_step_time(); 2457 window->layer()->GetAnimator()->last_step_time();
2455 ui::AnimationContainerElement* element = window->layer()->GetAnimator(); 2458 ui::AnimationContainerElement* element = window->layer()->GetAnimator();
2456 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000)); 2459 element->Step(start_time + base::TimeDelta::FromMilliseconds(1000));
2457 2460
2458 // No bounds changed notification at the end of animation since layer 2461 // No bounds changed notification at the end of animation since layer
2459 // delegate is NULL. 2462 // delegate is NULL.
2460 EXPECT_FALSE(delegate.bounds_changed()); 2463 EXPECT_FALSE(delegate.bounds_changed());
2461 EXPECT_NE("0,0 100x100", window->bounds().ToString()); 2464 EXPECT_NE("0,0 100x100", window->bounds().ToString());
2462 } 2465 }
2463 2466
2467 namespace {
2468
2469 // Used by AddChildNotifications to track notification counts.
2470 class AddChildNotificationsObserver : public WindowObserver {
2471 public:
2472 AddChildNotificationsObserver() : added_count_(0), removed_count_(0) {}
2473
2474 std::string CountStringAndReset() {
2475 std::string result = base::IntToString(added_count_) + " " +
2476 base::IntToString(removed_count_);
2477 added_count_ = removed_count_ = 0;
2478 return result;
2479 }
2480
2481 // WindowObserver overrides:
2482 virtual void OnWindowAddedToRootWindow(Window* window) OVERRIDE {
2483 added_count_++;
2484 }
2485 virtual void OnWindowRemovingFromRootWindow(Window* window) OVERRIDE {
2486 removed_count_++;
2487 }
2488
2489 private:
2490 int added_count_;
2491 int removed_count_;
2492
2493 DISALLOW_COPY_AND_ASSIGN(AddChildNotificationsObserver);
2494 };
2495
2496 } // namespace
2497
2498 // Assertions around when root window notifications are sent.
2499 TEST_F(WindowTest, AddChildNotifications) {
2500 AddChildNotificationsObserver observer;
2501 scoped_ptr<Window> w1(CreateTestWindowWithId(1, NULL));
2502 scoped_ptr<Window> w2(CreateTestWindowWithId(1, NULL));
2503 w2->AddObserver(&observer);
2504 w2->Focus();
2505 EXPECT_TRUE(w2->HasFocus());
2506
2507 // Move |w2| to be a child of |w1|.
2508 w1->AddChild(w2.get());
2509 // Sine we moved in the same root, observer shouldn't be notified.
2510 EXPECT_EQ("0 0", observer.CountStringAndReset());
2511 // |w2| should still have focus after moving.
2512 EXPECT_TRUE(w2->HasFocus());
2513 }
2514
2464 } // namespace test 2515 } // namespace test
2465 } // namespace aura 2516 } // namespace aura
OLDNEW
« no previous file with comments | « ui/aura/window.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698