Updating trunk VERSION from 2139.0 to 2140.0
[chromium-blink-merge.git] / athena / wm / window_list_provider_impl_unittest.cc
blobeba6b7a9ca58fd446860e4ff0261850d429f44ca
1 // Copyright 2014 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 "athena/wm/window_list_provider_impl.h"
7 #include <algorithm>
9 #include "athena/test/athena_test_base.h"
10 #include "ui/aura/test/test_window_delegate.h"
11 #include "ui/aura/window.h"
13 namespace athena {
15 namespace {
17 bool AreWindowListsEqual(const aura::Window::Windows& one,
18 const aura::Window::Windows& two) {
19 return one.size() == two.size() &&
20 std::equal(one.begin(), one.end(), two.begin());
23 scoped_ptr<aura::Window> CreateWindow(aura::WindowDelegate* delegate,
24 ui::wm::WindowType window_type) {
25 scoped_ptr<aura::Window> window(new aura::Window(delegate));
26 window->SetType(window_type);
27 window->Init(aura::WINDOW_LAYER_SOLID_COLOR);
28 return window.Pass();
31 } // namespace
33 typedef test::AthenaTestBase WindowListProviderImplTest;
35 // Tests that the order of windows match the stacking order of the windows in
36 // the container, even after the order is changed through the aura Window API.
37 TEST_F(WindowListProviderImplTest, StackingOrder) {
38 aura::test::TestWindowDelegate delegate;
39 scoped_ptr<aura::Window> container(new aura::Window(&delegate));
40 scoped_ptr<aura::Window> first =
41 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL);
42 scoped_ptr<aura::Window> second =
43 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL);
44 scoped_ptr<aura::Window> third =
45 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL);
46 container->AddChild(first.get());
47 container->AddChild(second.get());
48 container->AddChild(third.get());
50 scoped_ptr<WindowListProvider> list_provider(
51 new WindowListProviderImpl(container.get()));
52 EXPECT_TRUE(AreWindowListsEqual(container->children(),
53 list_provider->GetWindowList()));
55 container->StackChildAtTop(first.get());
56 EXPECT_TRUE(AreWindowListsEqual(container->children(),
57 list_provider->GetWindowList()));
58 EXPECT_EQ(first.get(), container->children().back());
61 TEST_F(WindowListProviderImplTest, ListContainsOnlyNormalWindows) {
62 aura::test::TestWindowDelegate delegate;
63 scoped_ptr<aura::Window> container(new aura::Window(&delegate));
64 scoped_ptr<aura::Window> first =
65 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL);
66 scoped_ptr<aura::Window> second =
67 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_POPUP);
68 scoped_ptr<aura::Window> third =
69 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_NORMAL);
70 scoped_ptr<aura::Window> fourth =
71 CreateWindow(&delegate, ui::wm::WINDOW_TYPE_MENU);
72 container->AddChild(first.get());
73 container->AddChild(second.get());
74 container->AddChild(third.get());
75 container->AddChild(fourth.get());
77 scoped_ptr<WindowListProvider> list_provider(
78 new WindowListProviderImpl(container.get()));
79 const aura::Window::Windows list = list_provider->GetWindowList();
80 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), second.get()));
81 EXPECT_EQ(list.end(), std::find(list.begin(), list.end(), fourth.get()));
82 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), first.get()));
83 EXPECT_NE(list.end(), std::find(list.begin(), list.end(), third.get()));
86 } // namespace athena