Only fsync leveldb's directory when the manifest is being updated.
[chromium-blink-merge.git] / ash / wm / ash_activation_controller_unittest.cc
blobe332990e19aed13295d72329e76218090ed22b07
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.
5 #include "ash/wm/ash_activation_controller.h"
7 #include "ash/launcher/launcher.h"
8 #include "ash/root_window_controller.h"
9 #include "ash/shelf/shelf_widget.h"
10 #include "ash/shell_delegate.h"
11 #include "ash/test/ash_test_base.h"
12 #include "ash/wm/property_util.h"
13 #include "ash/wm/window_util.h"
14 #include "ui/aura/window.h"
15 #include "ui/views/corewm/corewm_switches.h"
17 namespace ash {
19 namespace wm {
21 namespace {
23 class AshActivationControllerTest : public test::AshTestBase {
24 public:
25 AshActivationControllerTest()
26 : launcher_(NULL), launcher_widget_(NULL), launcher_window_(NULL) {}
27 virtual ~AshActivationControllerTest() {}
29 virtual void SetUp() OVERRIDE {
30 test::AshTestBase::SetUp();
31 ash_activation_controller_.reset(new internal::AshActivationController());
32 launcher_ = Launcher::ForPrimaryDisplay();
33 ASSERT_TRUE(launcher_);
34 launcher_widget_ = launcher_->shelf_widget();
35 ASSERT_TRUE(launcher_widget_);
36 launcher_window_ = launcher_widget_->GetNativeWindow();
37 ASSERT_TRUE(launcher_window_);
40 void SetSpokenFeedbackState(bool enabled) {
41 if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled() !=
42 enabled) {
43 Shell::GetInstance()->delegate()->ToggleSpokenFeedback(
44 A11Y_NOTIFICATION_NONE);
48 protected:
49 scoped_ptr<internal::ActivationControllerDelegate> ash_activation_controller_;
50 ash::Launcher* launcher_;
51 views::Widget* launcher_widget_;
52 aura::Window* launcher_window_;
54 DISALLOW_COPY_AND_ASSIGN(AshActivationControllerTest);
57 TEST_F(AshActivationControllerTest, LauncherFallback) {
58 // When spoken feedback is disabled, then fallback should not occur.
60 SetSpokenFeedbackState(false);
61 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL);
62 EXPECT_EQ(NULL, result);
65 // When spoken feedback is enabled, then fallback should occur.
67 SetSpokenFeedbackState(true);
68 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL);
69 EXPECT_EQ(launcher_window_, result);
72 // No fallback when activating another window.
74 aura::Window* test_window = CreateTestWindowInShellWithId(0);
75 aura::Window* result = ash_activation_controller_->
76 WillActivateWindow(test_window);
77 EXPECT_EQ(test_window, result);
81 TEST_F(AshActivationControllerTest, LauncherFallbackOnShutdown) {
82 SetSpokenFeedbackState(true);
83 // While shutting down a root window controller, activation controller
84 // is notified about destroyed windows and therefore will try to activate
85 // a launcher as fallback, which would result in segmentation faults since
86 // the launcher's window or the workspace's controller may be already
87 // destroyed.
88 GetRootWindowController(Shell::GetActiveRootWindow())->CloseChildWindows();
90 aura::Window* result = ash_activation_controller_->WillActivateWindow(NULL);
91 EXPECT_EQ(NULL, result);
94 TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnDestroyTest) {
95 // TODO(mtomasz): make this test work with the FocusController.
96 if (views::corewm::UseFocusController())
97 return;
99 // This test checks the whole fallback activation flow.
100 SetSpokenFeedbackState(true);
102 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
103 ActivateWindow(test_window.get());
104 ASSERT_EQ(test_window.get(), GetActiveWindow());
106 // Close the window.
107 test_window.reset();
109 // Verify if the launcher got activated as fallback.
110 ASSERT_EQ(launcher_window_, GetActiveWindow());
113 TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnMinimizeTest) {
114 // TODO(mtomasz): make this test work with the FocusController.
115 if (views::corewm::UseFocusController())
116 return;
118 // This test checks the whole fallback activation flow.
119 SetSpokenFeedbackState(true);
121 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
122 ActivateWindow(test_window.get());
123 ASSERT_EQ(test_window.get(), GetActiveWindow());
125 // Minimize the window.
126 MinimizeWindow(test_window.get());
128 // Verify if the launcher got activated as fallback.
129 ASSERT_EQ(launcher_window_, GetActiveWindow());
132 TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnDestroyTest) {
133 // This test checks the whole fallback activation flow when spoken feedback
134 // is disabled.
135 SetSpokenFeedbackState(false);
137 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
138 ActivateWindow(test_window.get());
139 ASSERT_EQ(test_window.get(), GetActiveWindow());
141 // Close the window.
142 test_window.reset();
144 // Verify if the launcher didn't get activated as fallback.
145 ASSERT_NE(launcher_window_, GetActiveWindow());
148 TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnMinimizeTest) {
149 // This test checks the whole fallback activation flow when spoken feedback
150 // is disabled.
151 SetSpokenFeedbackState(false);
153 scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
154 ActivateWindow(test_window.get());
155 ASSERT_EQ(test_window.get(), GetActiveWindow());
157 // Minimize the window.
158 MinimizeWindow(test_window.get());
160 // Verify if the launcher didn't get activated as fallback.
161 ASSERT_NE(launcher_window_, GetActiveWindow());
164 } // namespace
166 } // namespace wm
168 } // namespace ash