Update V8 to version 4.7.21.
[chromium-blink-merge.git] / ui / aura / test / test_windows.cc
blob50f831585abe47607a6a9f8d03b9dc607698cfae
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 "ui/aura/test/test_windows.h"
7 #include "base/strings/string_number_conversions.h"
8 #include "ui/aura/client/aura_constants.h"
9 #include "ui/aura/window.h"
10 #include "ui/compositor/layer.h"
11 #include "ui/gfx/geometry/rect.h"
13 namespace aura {
14 namespace test {
16 Window* CreateTestWindowWithId(int id, Window* parent) {
17 return CreateTestWindowWithDelegate(NULL, id, gfx::Rect(), parent);
20 Window* CreateTestWindowWithBounds(const gfx::Rect& bounds, Window* parent) {
21 return CreateTestWindowWithDelegate(NULL, 0, bounds, parent);
24 Window* CreateTestWindow(SkColor color,
25 int id,
26 const gfx::Rect& bounds,
27 Window* parent) {
28 return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color), id,
29 bounds, parent);
32 Window* CreateTestWindowWithDelegate(WindowDelegate* delegate,
33 int id,
34 const gfx::Rect& bounds,
35 Window* parent) {
36 return CreateTestWindowWithDelegateAndType(
37 delegate, ui::wm::WINDOW_TYPE_NORMAL, id, bounds, parent);
40 Window* CreateTestWindowWithDelegateAndType(WindowDelegate* delegate,
41 ui::wm::WindowType type,
42 int id,
43 const gfx::Rect& bounds,
44 Window* parent) {
45 Window* window = new Window(delegate);
46 window->set_id(id);
47 window->SetType(type);
48 window->Init(ui::LAYER_TEXTURED);
49 window->SetBounds(bounds);
50 window->Show();
51 if (parent)
52 parent->AddChild(window);
53 window->SetProperty(aura::client::kCanMaximizeKey, true);
54 return window;
57 template <typename T>
58 bool ObjectIsAbove(T* upper, T* lower) {
59 DCHECK_EQ(upper->parent(), lower->parent());
60 DCHECK_NE(upper, lower);
61 const std::vector<T*>& children = upper->parent()->children();
62 const size_t upper_i =
63 std::find(children.begin(), children.end(), upper) - children.begin();
64 const size_t lower_i =
65 std::find(children.begin(), children.end(), lower) - children.begin();
66 return upper_i > lower_i;
69 bool WindowIsAbove(Window* upper, Window* lower) {
70 return ObjectIsAbove<Window>(upper, lower);
73 bool LayerIsAbove(Window* upper, Window* lower) {
74 return ObjectIsAbove<ui::Layer>(upper->layer(), lower->layer());
77 std::string ChildWindowIDsAsString(aura::Window* parent) {
78 std::string result;
79 for (Window::Windows::const_iterator i = parent->children().begin();
80 i != parent->children().end(); ++i) {
81 if (!result.empty())
82 result += " ";
83 result += base::IntToString((*i)->id());
85 return result;
88 } // namespace test
89 } // namespace aura