OLD | NEW |
---|---|
(Empty) | |
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 | |
3 // found in the LICENSE file. | |
4 | |
5 #include "ash/wm/ash_activation_controller.h" | |
6 | |
7 #include "ash/launcher/launcher.h" | |
8 #include "ash/root_window_controller.h" | |
9 #include "ash/shell_delegate.h" | |
10 #include "ash/test/ash_test_base.h" | |
11 #include "ash/wm/property_util.h" | |
12 #include "ash/wm/window_util.h" | |
13 #include "ui/aura/window.h" | |
14 | |
15 namespace ash { | |
16 | |
17 namespace wm { | |
18 | |
19 namespace { | |
20 | |
21 class AshActivationControllerTest : public test::AshTestBase { | |
22 public: | |
23 AshActivationControllerTest() | |
24 : launcher_(NULL), launcher_widget_(NULL), launcher_window_(NULL) {} | |
25 virtual ~AshActivationControllerTest() {} | |
26 | |
27 virtual void SetUp() OVERRIDE { | |
28 test::AshTestBase::SetUp(); | |
29 ash_activation_controller_.reset(new internal::AshActivationController()); | |
30 launcher_ = Launcher::ForPrimaryDisplay(); | |
31 ASSERT_TRUE(launcher_); | |
32 launcher_widget_ = launcher_->widget(); | |
33 ASSERT_TRUE(launcher_widget_); | |
34 launcher_window_ = launcher_widget_->GetNativeWindow(); | |
35 ASSERT_TRUE(launcher_window_); | |
36 } | |
37 | |
38 void SetSpokenFeedbackState(bool enabled) { | |
39 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled() != | |
40 enabled) { | |
41 Shell::GetInstance()->delegate()->ToggleSpokenFeedback( | |
42 A11Y_NOTIFICATION_NONE); | |
43 } | |
44 } | |
45 | |
46 protected: | |
47 scoped_ptr<internal::ActivationControllerDelegate> ash_activation_controller_; | |
48 ash::Launcher* launcher_; | |
49 views::Widget* launcher_widget_; | |
50 aura::Window* launcher_window_; | |
51 | |
52 DISALLOW_COPY_AND_ASSIGN(AshActivationControllerTest); | |
53 }; | |
54 | |
55 TEST_F(AshActivationControllerTest, LauncherFallback) { | |
56 // When spoken feedback is disabled, then fallback should not occur. | |
57 { | |
58 SetSpokenFeedbackState(false); | |
59 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); | |
60 EXPECT_EQ(NULL, result); | |
61 } | |
62 | |
63 // When spoken feedback is enabled, then fallback should occur. | |
64 { | |
65 SetSpokenFeedbackState(true); | |
66 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); | |
67 EXPECT_EQ(launcher_window_, result); | |
68 } | |
69 | |
70 // No fallback when activating another window. | |
71 { | |
72 aura::Window* test_window = CreateTestWindowInShellWithId(0); | |
73 aura::Window* result = ash_activation_controller_-> | |
74 WillActivateWindow(test_window); | |
75 EXPECT_EQ(test_window, result); | |
76 } | |
77 } | |
78 | |
79 TEST_F(AshActivationControllerTest, LauncherFallbackOnShutdown) { | |
80 SetSpokenFeedbackState(true); | |
81 // While shutting down a root window controller, activation controller | |
82 // is notified about destroyed windows and therefore will try to activate | |
83 // a launcher as fallback, which would result in segmentation faults since | |
84 // the launcher's window or the workspace's controller may be already | |
85 // destroyed. | |
86 GetRootWindowController(Shell::GetActiveRootWindow())->CloseChildWindows(); | |
87 | |
88 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL); | |
89 EXPECT_EQ(NULL, result); | |
90 } | |
91 | |
92 TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnDestroyTest) { | |
93 // This test checks the whole fallback activation flow. | |
94 SetSpokenFeedbackState(true); | |
95 | |
96 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); | |
97 ActivateWindow(test_window.get()); | |
98 ASSERT_EQ(test_window.get(), GetActiveWindow()); | |
99 | |
100 // Close the window. | |
101 test_window.reset(); | |
102 | |
103 // Verify if the launcher got activated as fallback. | |
104 ASSERT_EQ(launcher_window_, GetActiveWindow()); | |
105 } | |
106 | |
107 TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnMinimizeTest) { | |
108 // This test checks the whole fallback activation flow. | |
109 SetSpokenFeedbackState(true); | |
110 | |
111 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0)); | |
112 ActivateWindow(test_window.get()); | |
113 ASSERT_EQ(test_window.get(), GetActiveWindow()); | |
114 | |
115 // Minimize the window. | |
116 MinimizeWindow(test_window.get()); | |
117 | |
118 // Verify if the launcher got activated as fallback. | |
119 ASSERT_EQ(launcher_window_, GetActiveWindow()); | |
sky
2012/12/14 17:36:10
Can you also add a test that that verifies the lau
| |
120 } | |
121 | |
122 } // namespace | |
123 | |
124 } // namespace wm | |
125 | |
126 } // namespace ash | |
OLD | NEW |