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"
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
,
26 const gfx::Rect
& bounds
,
28 return CreateTestWindowWithDelegate(new ColorTestWindowDelegate(color
), id
,
32 Window
* CreateTestWindowWithDelegate(WindowDelegate
* delegate
,
34 const gfx::Rect
& bounds
,
36 return CreateTestWindowWithDelegateAndType(
37 delegate
, ui::wm::WINDOW_TYPE_NORMAL
, id
, bounds
, parent
);
40 Window
* CreateTestWindowWithDelegateAndType(WindowDelegate
* delegate
,
41 ui::wm::WindowType type
,
43 const gfx::Rect
& bounds
,
45 Window
* window
= new Window(delegate
);
47 window
->SetType(type
);
48 window
->Init(ui::LAYER_TEXTURED
);
49 window
->SetBounds(bounds
);
52 parent
->AddChild(window
);
53 window
->SetProperty(aura::client::kCanMaximizeKey
, true);
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
) {
79 for (Window::Windows::const_iterator i
= parent
->children().begin();
80 i
!= parent
->children().end(); ++i
) {
83 result
+= base::IntToString((*i
)->id());