Index: ash/wm/ash_activation_controller_unittest.cc |
diff --git a/ash/wm/ash_activation_controller_unittest.cc b/ash/wm/ash_activation_controller_unittest.cc |
new file mode 100644 |
index 0000000000000000000000000000000000000000..1ad5540d2f8c3ec85df9bbc3a1dafb8a3bcabfdf |
--- /dev/null |
+++ b/ash/wm/ash_activation_controller_unittest.cc |
@@ -0,0 +1,90 @@ |
+// 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/wm/ash_activation_controller.h" |
+ |
+#include "ash/launcher/launcher.h" |
+#include "ash/root_window_controller.h" |
+#include "ash/shell_delegate.h" |
+#include "ash/test/ash_test_base.h" |
+#include "ash/wm/property_util.h" |
+#include "ui/aura/window.h" |
+ |
+namespace ash { |
+ |
+namespace { |
+ |
+class AshActivationControllerTest : public test::AshTestBase { |
+ public: |
+ AshActivationControllerTest() {} |
+ virtual ~AshActivationControllerTest() {} |
+ |
+ virtual void SetUp() OVERRIDE { |
+ test::AshTestBase::SetUp(); |
+ ash_activation_controller_.reset(new internal::AshActivationController()); |
+ launcher_ = Launcher::ForPrimaryDisplay(); |
+ launcher_widget_ = launcher_->widget(); |
+ launcher_window_ = |
sky
2012/12/10 15:37:51
launcher_window_ = launcher_widget_->GetNativeWind
mtomasz
2012/12/11 05:03:32
Done.
|
+ Launcher::ForPrimaryDisplay()->widget()->GetNativeWindow(); |
+ DCHECK(launcher_ != NULL); |
sky
2012/12/10 15:37:51
DCHECK->ASSERT_TRUE Also, this should be between 2
mtomasz
2012/12/11 05:03:32
Done.
|
+ DCHECK(launcher_widget_ != NULL); |
+ DCHECK(launcher_window_ != NULL); |
+ } |
+ |
+ void SetSpokenFeedbackState(bool enabled) { |
+ if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled() != |
+ enabled) { |
+ Shell::GetInstance()->delegate()->ToggleSpokenFeedback(); |
+ } |
+ } |
+ |
+ protected: |
+ scoped_ptr<internal::ActivationControllerDelegate> ash_activation_controller_; |
+ ash::Launcher* launcher_; |
sky
2012/12/10 15:37:51
Member initialize these to NULL.
mtomasz
2012/12/11 05:03:32
Done.
|
+ views::Widget* launcher_widget_; |
+ aura::Window* launcher_window_; |
+ |
+ DISALLOW_COPY_AND_ASSIGN(AshActivationControllerTest); |
+}; |
+ |
+TEST_F(AshActivationControllerTest, LauncherFallback) { |
+ // When spoken feedback is disabled, then fallback should not occur. |
+ { |
+ SetSpokenFeedbackState(false); |
+ aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); |
sky
2012/12/10 15:37:51
Rather than explicitly calling through like this c
mtomasz
2012/12/11 05:03:32
I could, but would it be better? We would loose is
sky
2012/12/11 16:30:47
I'm for testing actual window activation since in
mtomasz
2012/12/13 07:55:29
My concern is that I don't think we want AshActiva
sky
2012/12/13 19:16:27
Exactly.
mtomasz
2012/12/14 05:31:42
Done.
|
+ EXPECT_EQ(NULL, result); |
+ } |
+ |
+ // When spoken feedback is enabled, then fallback should occur. |
+ { |
+ SetSpokenFeedbackState(true); |
+ aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); |
+ EXPECT_EQ(launcher_window_, result); |
+ } |
+ |
+ // No fallback when activating another window. |
+ { |
+ aura::Window* test_window = CreateTestWindowInShellWithId(0); |
+ aura::Window* result = ash_activation_controller_-> |
+ WillActivateWindow(test_window); |
+ EXPECT_EQ(test_window, result); |
+ } |
+} |
+ |
+TEST_F(AshActivationControllerTest, LauncherFallbackOnShutdown) { |
+ SetSpokenFeedbackState(true); |
+ // While shutting down a root window controller, activation controller |
+ // is notified about destroyed windows and therefore will try to activate |
+ // a launcher as fallback, which would result in segmentation faults since |
+ // the launcher's window or the workspace's controller may be already |
+ // destroyed. |
+ GetRootWindowController(Shell::GetActiveRootWindow())->CloseChildWindows(); |
+ |
+ aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); |
+ EXPECT_EQ(NULL, result); |
+} |
+ |
+} // namespace |
+ |
+} // namespace ash |