diff options
author | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 10:37:31 +0000 |
---|---|---|
committer | zork@chromium.org <zork@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2012-02-27 10:37:31 +0000 |
commit | df1c986efabe7322872eff0820c399487972a695 (patch) | |
tree | ce157a4438cfa0c5b39869bf6e729c61f580d90c /ash/focus_cycler_unittest.cc | |
parent | 2e0ccb3e677a73674f4e55d4af306bf09c620b62 (diff) | |
download | chromium_src-df1c986efabe7322872eff0820c399487972a695.zip chromium_src-df1c986efabe7322872eff0820c399487972a695.tar.gz chromium_src-df1c986efabe7322872eff0820c399487972a695.tar.bz2 |
Add a unit test for the focus cycler.
BUG=None
TEST=Run aura_shell_unittest
Committed: http://src.chromium.org/viewvc/chrome?view=rev&revision=121685
Review URL: https://chromiumcodereview.appspot.com/9317027
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@123726 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/focus_cycler_unittest.cc')
-rw-r--r-- | ash/focus_cycler_unittest.cc | 126 |
1 files changed, 126 insertions, 0 deletions
diff --git a/ash/focus_cycler_unittest.cc b/ash/focus_cycler_unittest.cc new file mode 100644 index 0000000..2642182 --- /dev/null +++ b/ash/focus_cycler_unittest.cc @@ -0,0 +1,126 @@ +// Copyright (c) 2012 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "ash/focus_cycler.h" + +#include "ash/launcher/launcher.h" +#include "ash/shell.h" +#include "ash/shell_window_ids.h" +#include "ash/wm/window_util.h" +#include "ash/test/ash_test_base.h" +#include "ash/shell_factory.h" +#include "ui/aura/test/test_windows.h" +#include "ui/aura/window.h" +#include "ui/views/controls/button/menu_button.h" +#include "ui/views/widget/widget.h" + +namespace ash { +namespace test { + +using aura::test::CreateTestWindowWithId; +using aura::Window; +using internal::FocusCycler; + +typedef AshTestBase FocusCyclerTest; + +TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) { + scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); + + // Create a single test window. + Window* default_container = + ash::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); + scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); + ActivateWindow(window0.get()); + EXPECT_TRUE(IsActiveWindow(window0.get())); + + // Cycle the window + focus_cycler->RotateFocus(FocusCycler::FORWARD); + EXPECT_TRUE(IsActiveWindow(window0.get())); +} + +TEST_F(FocusCyclerTest, CycleFocusForward) { + scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); + + // Add the Status area + views::Widget* status_widget = internal::CreateStatusArea(); + ASSERT_TRUE(status_widget); + focus_cycler->AddWidget(status_widget); + + // Add a mock button to the status area. + status_widget->GetContentsView()->AddChildView( + new views::MenuButton(NULL, string16(), NULL, false)); + + // Add the launcher + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + views::Widget* launcher_widget = launcher->widget(); + ASSERT_TRUE(launcher_widget); + focus_cycler->AddWidget(launcher_widget); + launcher->SetFocusCycler(focus_cycler.get()); + + // Create a single test window. + Window* default_container = + ash::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); + scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); + ActivateWindow(window0.get()); + EXPECT_TRUE(IsActiveWindow(window0.get())); + + // Cycle focus to the status area + focus_cycler->RotateFocus(FocusCycler::FORWARD); + EXPECT_TRUE(status_widget->IsActive()); + + // Cycle focus to the launcher + focus_cycler->RotateFocus(FocusCycler::FORWARD); + EXPECT_TRUE(launcher_widget->IsActive()); + + // Cycle focus to the browser + focus_cycler->RotateFocus(FocusCycler::FORWARD); + EXPECT_TRUE(IsActiveWindow(window0.get())); +} + +TEST_F(FocusCyclerTest, CycleFocusBackward) { + scoped_ptr<FocusCycler> focus_cycler(new FocusCycler()); + + // Add the Status area + views::Widget* status_widget = internal::CreateStatusArea(); + ASSERT_TRUE(status_widget); + focus_cycler->AddWidget(status_widget); + + // Add a mock button to the status area. + status_widget->GetContentsView()->AddChildView( + new views::MenuButton(NULL, string16(), NULL, false)); + + // Add the launcher + Launcher* launcher = Shell::GetInstance()->launcher(); + ASSERT_TRUE(launcher); + views::Widget* launcher_widget = launcher->widget(); + ASSERT_TRUE(launcher_widget); + focus_cycler->AddWidget(launcher_widget); + launcher->SetFocusCycler(focus_cycler.get()); + + // Create a single test window. + Window* default_container = + ash::Shell::GetInstance()->GetContainer( + internal::kShellWindowId_DefaultContainer); + scoped_ptr<Window> window0(CreateTestWindowWithId(0, default_container)); + ActivateWindow(window0.get()); + EXPECT_TRUE(IsActiveWindow(window0.get())); + + // Cycle focus to the launcher + focus_cycler->RotateFocus(FocusCycler::BACKWARD); + EXPECT_TRUE(launcher_widget->IsActive()); + + // Cycle focus to the status area + focus_cycler->RotateFocus(FocusCycler::BACKWARD); + EXPECT_TRUE(status_widget->IsActive()); + + // Cycle focus to the browser + focus_cycler->RotateFocus(FocusCycler::BACKWARD); + EXPECT_TRUE(IsActiveWindow(window0.get())); +} + +} // namespace test +} // namespace ash |