summaryrefslogtreecommitdiffstats
path: root/ash/focus_cycler_unittest.cc
diff options
context:
space:
mode:
authorsky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-20 00:50:25 +0000
committersky@chromium.org <sky@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2012-10-20 00:50:25 +0000
commiteb5a0abf353b4a960117ca8272aeb6188dc7f8bf (patch)
treea879d098a34633bd43013c896a37d54e4bcb8ef9 /ash/focus_cycler_unittest.cc
parent507af8ff346c164f947641544be2cfd9fb7ca7c4 (diff)
downloadchromium_src-eb5a0abf353b4a960117ca8272aeb6188dc7f8bf.zip
chromium_src-eb5a0abf353b4a960117ca8272aeb6188dc7f8bf.tar.gz
chromium_src-eb5a0abf353b4a960117ca8272aeb6188dc7f8bf.tar.bz2
Cleans up FocusCycler test so that it doesn't trigger calling
ShouldActivate on a deleted object. BUG=156827 TEST=primarily test only change R=oshima@chromium.org Review URL: https://chromiumcodereview.appspot.com/11237003 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@163112 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'ash/focus_cycler_unittest.cc')
-rw-r--r--ash/focus_cycler_unittest.cc293
1 files changed, 121 insertions, 172 deletions
diff --git a/ash/focus_cycler_unittest.cc b/ash/focus_cycler_unittest.cc
index fab93d0..a55472b 100644
--- a/ash/focus_cycler_unittest.cc
+++ b/ash/focus_cycler_unittest.cc
@@ -33,49 +33,87 @@ internal::StatusAreaWidgetDelegate* GetStatusAreaWidgetDelegate(
widget->GetContentsView());
}
-SystemTray* CreateSystemTray() {
- internal::StatusAreaWidget* widget = new internal::StatusAreaWidget;
- widget->CreateTrayViews(NULL);
- widget->Show();
- return widget->system_tray();
-}
-
} // namespace
-typedef AshTestBase FocusCyclerTest;
+class FocusCyclerTest : public AshTestBase {
+ public:
+ FocusCyclerTest() {}
+
+ virtual void SetUp() OVERRIDE {
+ AshTestBase::SetUp();
+
+ focus_cycler_.reset(new FocusCycler());
+
+ ASSERT_TRUE(Launcher::ForPrimaryDisplay());
+ }
+
+ virtual void TearDown() OVERRIDE {
+ if (tray_.get()) {
+ GetStatusAreaWidgetDelegate(tray_->GetWidget())->
+ SetFocusCyclerForTesting(NULL);
+ tray_.reset();
+ }
+
+ Launcher::ForPrimaryDisplay()->SetFocusCycler(NULL);
+
+ focus_cycler_.reset();
+
+ AshTestBase::TearDown();
+ }
+
+ protected:
+ // Creates the system tray, returning true on success.
+ bool CreateTray() {
+ if (tray_.get())
+ return false;
+ internal::StatusAreaWidget* widget = new internal::StatusAreaWidget;
+ widget->CreateTrayViews(NULL);
+ widget->Show();
+ tray_.reset(widget->system_tray());
+ if (!tray_->GetWidget())
+ return false;
+ focus_cycler_->AddWidget(tray()->GetWidget());
+ GetStatusAreaWidgetDelegate(tray_->GetWidget())->SetFocusCyclerForTesting(
+ focus_cycler());
+ return true;
+ }
+
+ FocusCycler* focus_cycler() { return focus_cycler_.get(); }
+
+ SystemTray* tray() { return tray_.get(); }
+
+ views::Widget* launcher_widget() {
+ return Launcher::ForPrimaryDisplay()->widget();
+ }
+
+ void InstallFocusCycleOnLauncher() {
+ // Add the launcher
+ Launcher* launcher = Launcher::ForPrimaryDisplay();
+ launcher->SetFocusCycler(focus_cycler());
+ }
+
+ private:
+ scoped_ptr<FocusCycler> focus_cycler_;
+ scoped_ptr<SystemTray> tray_;
-// FocusCyclerTest and FocusCyclerLauncherTest tests are disabled due to
-// use-after-free bugs in them detectable by both AddressSanitizer and Valgrind.
-// See also http://crbug.com/156827.
-TEST_F(FocusCyclerTest, DISABLED_CycleFocusBrowserOnly) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
+ DISALLOW_COPY_AND_ASSIGN(FocusCyclerTest);
+};
+TEST_F(FocusCyclerTest, CycleFocusBrowserOnly) {
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
wm::ActivateWindow(window0.get());
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle the window
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
-TEST_F(FocusCyclerTest, DISABLED_CycleFocusForward) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
+TEST_F(FocusCyclerTest, CycleFocusForward) {
+ ASSERT_TRUE(CreateTray());
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
-
- // Add the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
+ InstallFocusCycleOnLauncher();
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
@@ -83,34 +121,22 @@ TEST_F(FocusCyclerTest, DISABLED_CycleFocusForward) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
-TEST_F(FocusCyclerTest, DISABLED_CycleFocusBackward) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
-
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
+TEST_F(FocusCyclerTest, CycleFocusBackward) {
+ ASSERT_TRUE(CreateTray());
- // Add the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
+ InstallFocusCycleOnLauncher();
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
@@ -118,34 +144,22 @@ TEST_F(FocusCyclerTest, DISABLED_CycleFocusBackward) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
-TEST_F(FocusCyclerTest, DISABLED_CycleFocusForwardBackward) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
+TEST_F(FocusCyclerTest, CycleFocusForwardBackward) {
+ ASSERT_TRUE(CreateTray());
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
-
- // Add the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
+ InstallFocusCycleOnLauncher();
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
@@ -153,116 +167,63 @@ TEST_F(FocusCyclerTest, DISABLED_CycleFocusForwardBackward) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
-TEST_F(FocusCyclerTest, DISABLED_CycleFocusNoBrowser) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
+TEST_F(FocusCyclerTest, CycleFocusNoBrowser) {
+ ASSERT_TRUE(CreateTray());
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
+ InstallFocusCycleOnLauncher();
// Add the launcher and focus it
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
- focus_cycler->FocusWidget(launcher_widget);
+ focus_cycler()->FocusWidget(launcher_widget());
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the launcher
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(launcher_widget->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(launcher_widget()->IsActive());
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
}
-class FocusCyclerLauncherTest : public AshTestBase {
- public:
- FocusCyclerLauncherTest() : AshTestBase() {}
- virtual ~FocusCyclerLauncherTest() {}
-
- virtual void SetUp() OVERRIDE {
- AshTestBase::SetUp();
-
- // Hide the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher_widget->Hide();
- }
-
- virtual void TearDown() OVERRIDE {
- // Show the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher_widget->Show();
-
- AshTestBase::TearDown();
- }
-
- private:
- DISALLOW_COPY_AND_ASSIGN(FocusCyclerLauncherTest);
-};
-
-TEST_F(FocusCyclerLauncherTest, DISABLED_CycleFocusForwardInvisible) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
-
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
-
- // Add the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
+TEST_F(FocusCyclerTest, Launcher_CycleFocusForward) {
+ ASSERT_TRUE(CreateTray());
+ InstallFocusCycleOnLauncher();
+ launcher_widget()->Hide();
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
@@ -270,30 +231,18 @@ TEST_F(FocusCyclerLauncherTest, DISABLED_CycleFocusForwardInvisible) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::FORWARD);
+ focus_cycler()->RotateFocus(FocusCycler::FORWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}
-TEST_F(FocusCyclerLauncherTest, DISABLED_CycleFocusBackwardInvisible) {
- scoped_ptr<FocusCycler> focus_cycler(new FocusCycler());
-
- // Add the Status area
- scoped_ptr<SystemTray> tray(CreateSystemTray());
- ASSERT_TRUE(tray->GetWidget());
- focus_cycler->AddWidget(tray->GetWidget());
- GetStatusAreaWidgetDelegate(tray->GetWidget())->SetFocusCyclerForTesting(
- focus_cycler.get());
-
- // Add the launcher
- Launcher* launcher = Launcher::ForPrimaryDisplay();
- ASSERT_TRUE(launcher);
- views::Widget* launcher_widget = launcher->widget();
- ASSERT_TRUE(launcher_widget);
- launcher->SetFocusCycler(focus_cycler.get());
+TEST_F(FocusCyclerTest, Launcher_CycleFocusBackwardInvisible) {
+ ASSERT_TRUE(CreateTray());
+ InstallFocusCycleOnLauncher();
+ launcher_widget()->Hide();
// Create a single test window.
scoped_ptr<Window> window0(CreateTestWindowWithId(0, NULL));
@@ -301,11 +250,11 @@ TEST_F(FocusCyclerLauncherTest, DISABLED_CycleFocusBackwardInvisible) {
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
// Cycle focus to the status area
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
- EXPECT_TRUE(tray->GetWidget()->IsActive());
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
+ EXPECT_TRUE(tray()->GetWidget()->IsActive());
// Cycle focus to the browser
- focus_cycler->RotateFocus(FocusCycler::BACKWARD);
+ focus_cycler()->RotateFocus(FocusCycler::BACKWARD);
EXPECT_TRUE(wm::IsActiveWindow(window0.get()));
}