Android: Get rid of extra dup()s on launching child processes
[chromium-blink-merge.git] / ui / views / widget / desktop_aura / desktop_focus_rules_unittest.cc
blob39eda7dcb4758fcb94876ea40ebfd30bfb4f79b5
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 "ui/views/widget/desktop_aura/desktop_focus_rules.h"
7 #include "ui/aura/client/focus_client.h"
8 #include "ui/aura/test/test_window_delegate.h"
9 #include "ui/aura/window.h"
10 #include "ui/aura/window_event_dispatcher.h"
11 #include "ui/aura/window_layer_type.h"
12 #include "ui/views/test/views_test_base.h"
13 #include "ui/views/widget/desktop_aura/desktop_native_widget_aura.h"
14 #include "ui/views/widget/widget.h"
15 #include "ui/wm/core/window_util.h"
17 namespace views {
19 namespace {
21 scoped_ptr<Widget> CreateDesktopWidget() {
22 scoped_ptr<Widget> widget(new Widget);
23 Widget::InitParams params = Widget::InitParams(
24 Widget::InitParams::TYPE_WINDOW);
25 params.bounds = gfx::Rect(0, 0, 200, 200);
26 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
27 params.native_widget = new DesktopNativeWidgetAura(widget.get());
28 widget->Init(params);
29 return widget.Pass();
32 } // namespace
34 typedef ViewsTestBase DesktopFocusRulesTest;
36 // Verifies we don't attempt to activate a window in another widget.
37 TEST_F(DesktopFocusRulesTest, DontFocusWindowsInOtherHierarchies) {
38 // Two widgets (each with a DesktopNativeWidgetAura). |w2| has a child Window
39 // |w2_child| that is not focusable. |w2_child|'s has a transient parent in
40 // |w1|.
41 scoped_ptr<views::Widget> w1(CreateDesktopWidget());
42 scoped_ptr<views::Widget> w2(CreateDesktopWidget());
43 aura::test::TestWindowDelegate w2_child_delegate;
44 w2_child_delegate.set_can_focus(false);
45 aura::Window* w2_child = new aura::Window(&w2_child_delegate);
46 w2_child->Init(aura::WINDOW_LAYER_SOLID_COLOR);
47 w2->GetNativeView()->AddChild(w2_child);
48 wm::AddTransientChild(w1->GetNativeView(), w2_child);
49 aura::client::GetFocusClient(w2->GetNativeView())->FocusWindow(w2_child);
50 aura::Window* focused =
51 aura::client::GetFocusClient(w2->GetNativeView())->GetFocusedWindow();
52 EXPECT_TRUE((focused == NULL) || w2->GetNativeView()->Contains(focused));
53 wm::RemoveTransientChild(w1->GetNativeView(), w2_child);
54 w1.reset();
55 w2.reset();
58 } // namespace views