summaryrefslogtreecommitdiffstats
path: root/athena/screen/screen_manager_unittest.cc
blob: 1a04ae8447d52052a49077c741f68c8ac531ed23 (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
// Copyright 2014 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 "athena/screen/public/screen_manager.h"

#include <string>

#include "athena/test/athena_test_base.h"
#include "ui/aura/window.h"

typedef athena::test::AthenaTestBase ScreenManagerTest;

namespace athena {
namespace {

aura::Window* Create(const std::string& name, int z_order_priority) {
  ScreenManager::ContainerParams params(name, z_order_priority);
  return ScreenManager::Get()->CreateContainer(params);
}

void CheckZOrder(aura::Window* w1, aura::Window* w2) {
  aura::Window* parent = w1->parent();
  const aura::Window::Windows& children = parent->children();
  aura::Window::Windows::const_iterator begin_iter = children.begin();
  aura::Window::Windows::const_iterator end_iter = children.end();

  aura::Window::Windows::const_iterator w1_iter =
      std::find(begin_iter, end_iter, w1);
  aura::Window::Windows::const_iterator w2_iter =
      std::find(begin_iter, end_iter, w2);
  EXPECT_NE(end_iter, w1_iter);
  EXPECT_NE(end_iter, w2_iter);
  EXPECT_TRUE(w1_iter < w2_iter);
}

}  // namespace

TEST_F(ScreenManagerTest, Zorder) {
  aura::Window* window_10 = Create("test10", 10);
  aura::Window* window_11 = Create("test11", 11);
  aura::Window* window_12 = Create("test12", 12);

  {
    SCOPED_TRACE("Init");
    CheckZOrder(window_10, window_11);
    CheckZOrder(window_11, window_12);
  }
  {
    SCOPED_TRACE("Delete");
    delete window_11;
    CheckZOrder(window_10, window_12);
  }
  {
    SCOPED_TRACE("Insert");
    window_11 = Create("test11", 11);
    CheckZOrder(window_10, window_11);
    CheckZOrder(window_11, window_12);
  }
}

}  // namespace athena