summaryrefslogtreecommitdiff
path: root/chromium/ash/wm/ash_activation_controller_unittest.cc
blob: e332990e19aed13295d72329e76218090ed22b07 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
// 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/shelf/shelf_widget.h"
#include "ash/shell_delegate.h"
#include "ash/test/ash_test_base.h"
#include "ash/wm/property_util.h"
#include "ash/wm/window_util.h"
#include "ui/aura/window.h"
#include "ui/views/corewm/corewm_switches.h"

namespace ash {

namespace wm {

namespace {

class AshActivationControllerTest : public test::AshTestBase {
 public:
  AshActivationControllerTest()
      : launcher_(NULL), launcher_widget_(NULL), launcher_window_(NULL) {}
  virtual ~AshActivationControllerTest() {}

  virtual void SetUp() OVERRIDE {
    test::AshTestBase::SetUp();
    ash_activation_controller_.reset(new internal::AshActivationController());
    launcher_ = Launcher::ForPrimaryDisplay();
    ASSERT_TRUE(launcher_);
    launcher_widget_ = launcher_->shelf_widget();
    ASSERT_TRUE(launcher_widget_);
    launcher_window_ = launcher_widget_->GetNativeWindow();
    ASSERT_TRUE(launcher_window_);
  }

  void SetSpokenFeedbackState(bool enabled) {
    if (Shell::GetInstance()->delegate()->IsSpokenFeedbackEnabled() !=
        enabled) {
      Shell::GetInstance()->delegate()->ToggleSpokenFeedback(
          A11Y_NOTIFICATION_NONE);
    }
  }

 protected:
  scoped_ptr<internal::ActivationControllerDelegate> ash_activation_controller_;
  ash::Launcher* launcher_;
  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);
    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);
}

TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnDestroyTest) {
  // TODO(mtomasz): make this test work with the FocusController.
  if (views::corewm::UseFocusController())
    return;

  // This test checks the whole fallback activation flow.
  SetSpokenFeedbackState(true);

  scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
  ActivateWindow(test_window.get());
  ASSERT_EQ(test_window.get(), GetActiveWindow());

  // Close the window.
  test_window.reset();

  // Verify if the launcher got activated as fallback.
  ASSERT_EQ(launcher_window_, GetActiveWindow());
}

TEST_F(AshActivationControllerTest, LauncherEndToEndFallbackOnMinimizeTest) {
  // TODO(mtomasz): make this test work with the FocusController.
  if (views::corewm::UseFocusController())
    return;

  // This test checks the whole fallback activation flow.
  SetSpokenFeedbackState(true);

  scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
  ActivateWindow(test_window.get());
  ASSERT_EQ(test_window.get(), GetActiveWindow());

  // Minimize the window.
  MinimizeWindow(test_window.get());

  // Verify if the launcher got activated as fallback.
  ASSERT_EQ(launcher_window_, GetActiveWindow());
}

TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnDestroyTest) {
  // This test checks the whole fallback activation flow when spoken feedback
  // is disabled.
  SetSpokenFeedbackState(false);

  scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
  ActivateWindow(test_window.get());
  ASSERT_EQ(test_window.get(), GetActiveWindow());

  // Close the window.
  test_window.reset();

  // Verify if the launcher didn't get activated as fallback.
  ASSERT_NE(launcher_window_, GetActiveWindow());
}

TEST_F(AshActivationControllerTest, LauncherEndToEndNoFallbackOnMinimizeTest) {
  // This test checks the whole fallback activation flow when spoken feedback
  // is disabled.
  SetSpokenFeedbackState(false);

  scoped_ptr<aura::Window> test_window(CreateTestWindowInShellWithId(0));
  ActivateWindow(test_window.get());
  ASSERT_EQ(test_window.get(), GetActiveWindow());

  // Minimize the window.
  MinimizeWindow(test_window.get());

  // Verify if the launcher didn't get activated as fallback.
  ASSERT_NE(launcher_window_, GetActiveWindow());
}

}  // namespace

}  // namespace wm

}  // namespace ash