This source file includes following definitions.
- CreateControlWidget
 
- SetWindowAndLayerName
 
- ChildWindowNamesAsString
 
- TEST_F
 
- TEST_F
 
- TEST_F
 
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/window.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/test/test_layers.h"
#include "ui/views/view.h"
#include "ui/views/view_constants_aura.h"
#include "ui/views/widget/widget.h"
namespace views {
namespace {
Widget* CreateControlWidget(aura::Window* parent, const gfx::Rect& bounds) {
  Widget::InitParams params(Widget::InitParams::TYPE_CONTROL);
  params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
  params.parent = parent;
  params.bounds = bounds;
  Widget* widget = new Widget();
  widget->Init(params);
  return widget;
}
void SetWindowAndLayerName(aura::Window* window, const std::string& name) {
  window->SetName(name);
  window->layer()->set_name(name);
}
std::string ChildWindowNamesAsString(const aura::Window& parent) {
  std::string names;
  typedef std::vector<aura::Window*> Windows;
  for (Windows::const_iterator it = parent.children().begin();
       it != parent.children().end(); ++it) {
    if (!names.empty())
      names += " ";
    names += (*it)->name();
  }
  return names;
}
typedef aura::test::AuraTestBase WindowReordererTest;
TEST_F(WindowReordererTest, Basic) {
  scoped_ptr<Widget> parent(CreateControlWidget(root_window(),
                                                gfx::Rect(0, 0, 100, 100)));
  parent->Show();
  aura::Window* parent_window = parent->GetNativeWindow();
  View* contents_view = new View();
  parent->SetContentsView(contents_view);
  
  
  
  View* v = new View();
  v->SetPaintToLayer(true);
  v->layer()->set_name("v");
  contents_view->AddChildView(v);
  scoped_ptr<Widget> w1(CreateControlWidget(parent_window,
                                            gfx::Rect(0, 1, 100, 101)));
  SetWindowAndLayerName(w1->GetNativeView(), "w1");
  w1->Show();
  scoped_ptr<Widget> w2(CreateControlWidget(parent_window,
                                            gfx::Rect(0, 2, 100, 102)));
  SetWindowAndLayerName(w2->GetNativeView(), "w2");
  w2->Show();
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v w1 w2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  View* host_view2 = new View();
  contents_view->AddChildView(host_view2);
  w2->GetNativeView()->SetProperty(kHostViewKey, host_view2);
  EXPECT_EQ("w2 w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v w2 w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  View* host_view1 = new View();
  w1->GetNativeView()->SetProperty(kHostViewKey, host_view1);
  contents_view->AddChildViewAt(host_view1, 0);
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w1 v w2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  contents_view->ReorderChildView(host_view1, -1);
  EXPECT_EQ("w2 w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v w2 w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  contents_view->ReorderChildView(host_view2, -1);
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v w1 w2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  contents_view->ReorderChildView(v, -1);
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w1 w2 v",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  contents_view->ReorderChildView(host_view2, -1);
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w1 v w2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  parent->Close();
}
TEST_F(WindowReordererTest, Association) {
  scoped_ptr<Widget> parent(CreateControlWidget(root_window(),
                                                gfx::Rect(0, 0, 100, 100)));
  parent->Show();
  aura::Window* parent_window = parent->GetNativeWindow();
  View* contents_view = new View();
  parent->SetContentsView(contents_view);
  aura::Window* w1 = aura::test::CreateTestWindowWithId(0,
      parent->GetNativeWindow());
  SetWindowAndLayerName(w1, "w1");
  aura::Window* w2 = aura::test::CreateTestWindowWithId(0, NULL);
  SetWindowAndLayerName(w2, "w2");
  View* host_view2 = new View();
  
  
  contents_view->AddChildView(host_view2);
  w2->SetProperty(views::kHostViewKey, host_view2);
  EXPECT_EQ("w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  parent_window->AddChild(w2);
  EXPECT_EQ("w2 w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w2 w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  View* host_view1 = new View();
  contents_view->AddChildViewAt(host_view1, 0);
  EXPECT_EQ("w2 w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w2 w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  w1->SetProperty(views::kHostViewKey, host_view1);
  EXPECT_EQ("w1 w2", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w1 w2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  contents_view->RemoveChildView(host_view2);
  contents_view->AddChildViewAt(host_view2, 0);
  EXPECT_EQ("w2 w1", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("w2 w1",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  parent->Close();
}
TEST_F(WindowReordererTest, HostViewParentHasLayer) {
  scoped_ptr<Widget> parent(CreateControlWidget(root_window(),
                                                gfx::Rect(0, 0, 100, 100)));
  parent->Show();
  aura::Window* parent_window = parent->GetNativeWindow();
  View* contents_view = new View();
  parent->SetContentsView(contents_view);
  
  
  
  
  
  
  
  
  
  View* v1 = new View();
  contents_view->AddChildView(v1);
  View* v11 = new View();
  v11->SetPaintToLayer(true);
  v11->layer()->set_name("v11");
  v1->AddChildView(v11);
  scoped_ptr<Widget> w(CreateControlWidget(parent_window,
                                           gfx::Rect(0, 1, 100, 101)));
  SetWindowAndLayerName(w->GetNativeView(), "w");
  w->Show();
  View* v12 = new View();
  v1->AddChildView(v12);
  w->GetNativeView()->SetProperty(kHostViewKey, v12);
  View* v13 = new View();
  v13->SetPaintToLayer(true);
  v13->layer()->set_name("v13");
  v1->AddChildView(v13);
  View* v2 = new View();
  v2->SetPaintToLayer(true);
  v2->layer()->set_name("v2");
  contents_view->AddChildView(v2);
  
  EXPECT_EQ("w", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v11 w v13 v2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  v1->SetPaintToLayer(true);
  v1->layer()->set_name("v1");
  EXPECT_EQ("w", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v1 w v2",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  v2->AddChildView(v12);
  EXPECT_EQ("w", ChildWindowNamesAsString(*parent_window));
  EXPECT_EQ("v1 v2 w",
            ui::test::ChildLayerNamesAsString(*parent_window->layer()));
  
  
  parent->Close();
}
}  
}