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

Side by Side Diff: ash/wm/toplevel_window_event_handler_unittest.cc

Issue 11519040: More unittests passing with new focus controller. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « ash/wm/panel_layout_manager_unittest.cc ('k') | ash/wm/window_manager_unittest.cc » ('j') | 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 "ash/wm/toplevel_window_event_handler.h" 5 #include "ash/wm/toplevel_window_event_handler.h"
6 6
7 #include "ash/shell.h" 7 #include "ash/shell.h"
8 #include "ash/shell_window_ids.h"
8 #include "ash/test/ash_test_base.h" 9 #include "ash/test/ash_test_base.h"
9 #include "ash/wm/property_util.h" 10 #include "ash/wm/property_util.h"
10 #include "ash/wm/window_util.h" 11 #include "ash/wm/window_util.h"
11 #include "ash/wm/workspace/snap_sizer.h" 12 #include "ash/wm/workspace/snap_sizer.h"
12 #include "ash/wm/workspace_controller.h" 13 #include "ash/wm/workspace_controller.h"
13 #include "base/basictypes.h" 14 #include "base/basictypes.h"
14 #include "base/compiler_specific.h" 15 #include "base/compiler_specific.h"
15 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
16 #include "ui/aura/client/aura_constants.h" 17 #include "ui/aura/client/aura_constants.h"
17 #include "ui/aura/root_window.h" 18 #include "ui/aura/root_window.h"
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after
61 } 62 }
62 63
63 int hittest_code_; 64 int hittest_code_;
64 gfx::Size min_size_; 65 gfx::Size min_size_;
65 66
66 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate); 67 DISALLOW_COPY_AND_ASSIGN(TestWindowDelegate);
67 }; 68 };
68 69
69 class ToplevelWindowEventHandlerTest : public AshTestBase { 70 class ToplevelWindowEventHandlerTest : public AshTestBase {
70 public: 71 public:
71 ToplevelWindowEventHandlerTest() : parent_(NULL) {} 72 ToplevelWindowEventHandlerTest() {}
72 virtual ~ToplevelWindowEventHandlerTest() {} 73 virtual ~ToplevelWindowEventHandlerTest() {}
73 74
74 virtual void SetUp() OVERRIDE {
75 AshTestBase::SetUp();
76 parent_ = new aura::Window(NULL);
77 parent_->Init(ui::LAYER_NOT_DRAWN);
78 parent_->Show();
79 Shell::GetPrimaryRootWindow()->AddChild(parent_);
80 parent_->SetBounds(Shell::GetPrimaryRootWindow()->bounds());
81 handler_.reset(new ToplevelWindowEventHandler(parent_));
82 parent_->AddPreTargetHandler(handler_.get());
83 }
84
85 virtual void TearDown() OVERRIDE {
86 parent_->RemovePreTargetHandler(handler_.get());
87 handler_.reset();
88 parent_ = NULL;
89 AshTestBase::TearDown();
90 }
91
92 protected: 75 protected:
93 aura::Window* CreateWindow(int hittest_code) { 76 aura::Window* CreateWindow(int hittest_code) {
94 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code); 77 TestWindowDelegate* d1 = new TestWindowDelegate(hittest_code);
95 aura::Window* w1 = new aura::Window(d1); 78 aura::Window* w1 = new aura::Window(d1);
96 w1->set_id(1); 79 w1->set_id(1);
97 w1->Init(ui::LAYER_TEXTURED); 80 w1->Init(ui::LAYER_TEXTURED);
98 parent_->AddChild(w1); 81 aura::Window* parent =
82 Shell::GetContainer(Shell::GetPrimaryRootWindow(),
83 internal::kShellWindowId_AlwaysOnTopContainer);
84 parent->AddChild(w1);
99 w1->SetBounds(gfx::Rect(0, 0, 100, 100)); 85 w1->SetBounds(gfx::Rect(0, 0, 100, 100));
100 w1->Show(); 86 w1->Show();
101 return w1; 87 return w1;
102 } 88 }
103 89
104 void DragFromCenterBy(aura::Window* window, int dx, int dy) { 90 void DragFromCenterBy(aura::Window* window, int dx, int dy) {
105 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 91 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
106 generator.DragMouseBy(dx, dy); 92 generator.DragMouseBy(dx, dy);
107 } 93 }
108 94
109 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) { 95 void TouchDragFromCenterBy(aura::Window* window, int dx, int dy) {
110 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window); 96 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), window);
111 generator.PressMoveAndReleaseTouchBy(dx, dy); 97 generator.PressMoveAndReleaseTouchBy(dx, dy);
112 } 98 }
113 99
114 scoped_ptr<ToplevelWindowEventHandler> handler_; 100 scoped_ptr<ToplevelWindowEventHandler> handler_;
115 101
116 private: 102 private:
117 // Window |handler_| is installed on. Owned by RootWindow.
118 aura::Window* parent_;
119
120 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest); 103 DISALLOW_COPY_AND_ASSIGN(ToplevelWindowEventHandlerTest);
121 }; 104 };
122 105
123 } 106 }
124 107
125 TEST_F(ToplevelWindowEventHandlerTest, Caption) { 108 TEST_F(ToplevelWindowEventHandlerTest, Caption) {
126 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION)); 109 scoped_ptr<aura::Window> w1(CreateWindow(HTCAPTION));
127 gfx::Size size = w1->bounds().size(); 110 gfx::Size size = w1->bounds().size();
128 DragFromCenterBy(w1.get(), 100, 100); 111 DragFromCenterBy(w1.get(), 100, 100);
129 // Position should have been offset by 100,100. 112 // Position should have been offset by 100,100.
(...skipping 376 matching lines...) Expand 10 before | Expand all | Expand 10 after
506 GetRestoreBoundsInScreen(window.get())->ToString()); 489 GetRestoreBoundsInScreen(window.get())->ToString());
507 } 490 }
508 491
509 // Verifies pressing escape resets the bounds to the original bounds. 492 // Verifies pressing escape resets the bounds to the original bounds.
510 #if defined(OS_MACOSX) 493 #if defined(OS_MACOSX)
511 #define MAYBE_EscapeReverts DISABLED_EscapeReverts 494 #define MAYBE_EscapeReverts DISABLED_EscapeReverts
512 #else 495 #else
513 #define MAYBE_EscapeReverts EscapeReverts 496 #define MAYBE_EscapeReverts EscapeReverts
514 #endif 497 #endif
515 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) { 498 TEST_F(ToplevelWindowEventHandlerTest, MAYBE_EscapeReverts) {
516 aura::RootWindow* root = Shell::GetPrimaryRootWindow();
517 aura::client::ActivationClient* original_client =
518 aura::client::GetActivationClient(root);
519 aura::test::TestActivationClient activation_client(root);
520 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT)); 499 scoped_ptr<aura::Window> target(CreateWindow(HTBOTTOMRIGHT));
521 target->Focus();
522 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 500 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
523 target.get()); 501 target.get());
524 generator.PressLeftButton(); 502 generator.PressLeftButton();
525 generator.MoveMouseBy(10, 11); 503 generator.MoveMouseBy(10, 11);
526 504
527 // Execute any scheduled draws so that pending mouse events are processed. 505 // Execute any scheduled draws so that pending mouse events are processed.
528 RunAllPendingInMessageLoop(); 506 RunAllPendingInMessageLoop();
529 507
530 EXPECT_EQ("0,0 110x111", target->bounds().ToString()); 508 EXPECT_EQ("0,0 110x111", target->bounds().ToString());
531 generator.PressKey(ui::VKEY_ESCAPE, 0); 509 generator.PressKey(ui::VKEY_ESCAPE, 0);
532 generator.ReleaseKey(ui::VKEY_ESCAPE, 0); 510 generator.ReleaseKey(ui::VKEY_ESCAPE, 0);
533 EXPECT_EQ("0,0 100x100", target->bounds().ToString()); 511 EXPECT_EQ("0,0 100x100", target->bounds().ToString());
534 aura::client::SetActivationClient(root, original_client);
535 } 512 }
536 513
537 // Verifies window minimization/maximization completes drag. 514 // Verifies window minimization/maximization completes drag.
538 TEST_F(ToplevelWindowEventHandlerTest, MinimizeMaximizeCompletes) { 515 TEST_F(ToplevelWindowEventHandlerTest, MinimizeMaximizeCompletes) {
539 // Once window is minimized, window dragging completes. 516 // Once window is minimized, window dragging completes.
540 { 517 {
541 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION)); 518 scoped_ptr<aura::Window> target(CreateWindow(HTCAPTION));
542 target->Focus(); 519 target->Focus();
543 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(), 520 aura::test::EventGenerator generator(Shell::GetPrimaryRootWindow(),
544 target.get()); 521 target.get());
(...skipping 27 matching lines...) Expand all
572 549
573 generator.PressLeftButton(); 550 generator.PressLeftButton();
574 generator.MoveMouseBy(10, 11); 551 generator.MoveMouseBy(10, 11);
575 RunAllPendingInMessageLoop(); 552 RunAllPendingInMessageLoop();
576 EXPECT_EQ("10,11 100x100", target->bounds().ToString()); 553 EXPECT_EQ("10,11 100x100", target->bounds().ToString());
577 } 554 }
578 } 555 }
579 556
580 } // namespace test 557 } // namespace test
581 } // namespace ash 558 } // namespace ash
OLDNEW
« no previous file with comments | « ash/wm/panel_layout_manager_unittest.cc ('k') | ash/wm/window_manager_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698