summaryrefslogtreecommitdiffstats
path: root/ui/aura_shell/stacking_controller_unittest.cc
blob: 5b8fa096372ab813bff556f406b677f2ff0c6a87 (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
// Copyright (c) 2011 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 "ui/aura_shell/stacking_controller.h"

#include "ui/aura/root_window.h"
#include "ui/aura/test/event_generator.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura_shell/test/aura_shell_test_base.h"

namespace aura_shell {
namespace test {

typedef aura_shell::test::AuraShellTestBase StackingControllerTest;

TEST_F(StackingControllerTest, GetTopmostWindowToActivate) {
  aura::test::ActivateWindowDelegate activate;
  aura::test::ActivateWindowDelegate non_activate(false);

  scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(
      &non_activate, 1, gfx::Rect(), NULL));
  scoped_ptr<aura::Window> w2(aura::test::CreateTestWindowWithDelegate(
      &activate, 2, gfx::Rect(), NULL));
  scoped_ptr<aura::Window> w3(aura::test::CreateTestWindowWithDelegate(
      &non_activate, 3, gfx::Rect(), NULL));
  EXPECT_EQ(w2.get(), aura::RootWindow::GetInstance()->stacking_client()->
      GetTopmostWindowToActivate(NULL));
}

// Test if the clicking on a menu picks the transient parent as activatable
// window.
TEST_F(StackingControllerTest, ClickOnMenu) {
  aura::test::ActivateWindowDelegate activate;
  aura::test::ActivateWindowDelegate non_activate(false);

  scoped_ptr<aura::Window> w1(aura::test::CreateTestWindowWithDelegate(
      &activate, 1, gfx::Rect(100, 100), NULL));
  EXPECT_EQ(NULL, aura::RootWindow::GetInstance()->active_window());

  // Clicking on an activatable window activtes the window.
  aura::test::EventGenerator generator(w1.get());
  generator.ClickLeftButton();
  EXPECT_EQ(w1.get(), aura::RootWindow::GetInstance()->active_window());

  // Creates a menu that covers the transient parent.
  scoped_ptr<aura::Window> menu(aura::test::CreateTestWindowWithDelegateAndType(
      &non_activate, aura::WINDOW_TYPE_MENU, 2, gfx::Rect(100, 100), NULL));
  w1->AddTransientChild(menu.get());

  // Clicking on a menu whose transient parent is active window shouldn't
  // change the active window.
  generator.ClickLeftButton();
  EXPECT_EQ(w1.get(), aura::RootWindow::GetInstance()->active_window());
}

}  // namespace test
}  // namespace aura_shell