Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(141)

Side by Side Diff: ui/views/mus/native_widget_mus_unittest.cc

Issue 1991673002: views/mus: Fix window activation. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: test Created 4 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2016 The Chromium Authors. All rights reserved. 1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "ui/views/mus/native_widget_mus.h" 5 #include "ui/views/mus/native_widget_mus.h"
6 6
7 #include "base/macros.h" 7 #include "base/macros.h"
8 #include "components/mus/public/cpp/property_type_converters.h" 8 #include "components/mus/public/cpp/property_type_converters.h"
9 #include "components/mus/public/cpp/window.h" 9 #include "components/mus/public/cpp/window.h"
10 #include "components/mus/public/cpp/window_property.h" 10 #include "components/mus/public/cpp/window_property.h"
11 #include "components/mus/public/interfaces/window_manager.mojom.h" 11 #include "components/mus/public/interfaces/window_manager.mojom.h"
12 #include "testing/gtest/include/gtest/gtest.h" 12 #include "testing/gtest/include/gtest/gtest.h"
13 #include "third_party/skia/include/core/SkBitmap.h" 13 #include "third_party/skia/include/core/SkBitmap.h"
14 #include "third_party/skia/include/core/SkColor.h" 14 #include "third_party/skia/include/core/SkColor.h"
15 #include "ui/aura/window.h" 15 #include "ui/aura/window.h"
16 #include "ui/gfx/geometry/rect.h" 16 #include "ui/gfx/geometry/rect.h"
17 #include "ui/gfx/image/image_skia.h" 17 #include "ui/gfx/image/image_skia.h"
18 #include "ui/gfx/skia_util.h" 18 #include "ui/gfx/skia_util.h"
19 #include "ui/views/controls/native/native_view_host.h"
19 #include "ui/views/test/focus_manager_test.h" 20 #include "ui/views/test/focus_manager_test.h"
20 #include "ui/views/test/views_test_base.h" 21 #include "ui/views/test/views_test_base.h"
21 #include "ui/views/widget/widget.h" 22 #include "ui/views/widget/widget.h"
22 #include "ui/views/widget/widget_delegate.h" 23 #include "ui/views/widget/widget_delegate.h"
23 #include "ui/views/widget/widget_observer.h" 24 #include "ui/views/widget/widget_observer.h"
25 #include "ui/wm/public/activation_client.h"
24 26
25 namespace views { 27 namespace views {
26 namespace { 28 namespace {
27 29
28 // Returns a small colored bitmap. 30 // Returns a small colored bitmap.
29 SkBitmap MakeBitmap(SkColor color) { 31 SkBitmap MakeBitmap(SkColor color) {
30 SkBitmap bitmap; 32 SkBitmap bitmap;
31 bitmap.allocN32Pixels(8, 8); 33 bitmap.allocN32Pixels(8, 8);
32 bitmap.eraseColor(color); 34 bitmap.eraseColor(color);
33 return bitmap; 35 return bitmap;
(...skipping 185 matching lines...) Expand 10 before | Expand all | Expand 10 after
219 Widget widget; 221 Widget widget;
220 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW); 222 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
221 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 223 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
222 params.name = "MyWidget"; 224 params.name = "MyWidget";
223 widget.Init(params); 225 widget.Init(params);
224 mus::Window* window = 226 mus::Window* window =
225 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window(); 227 static_cast<NativeWidgetMus*>(widget.native_widget_private())->window();
226 EXPECT_EQ("MyWidget", window->GetName()); 228 EXPECT_EQ("MyWidget", window->GetName());
227 } 229 }
228 230
231 // Tests that child aura::Windows cannot be activated.
232 TEST_F(NativeWidgetMusTest, FocusChildAuraWindow) {
233 Widget widget;
234 Widget::InitParams params = CreateParams(Widget::InitParams::TYPE_WINDOW);
235 params.ownership = Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
236 widget.Init(params);
237
238 View* focusable = new View;
239 focusable->SetFocusBehavior(View::FocusBehavior::ALWAYS);
240 widget.GetContentsView()->AddChildView(focusable);
241
242 NativeViewHost* native_host = new NativeViewHost;
243 widget.GetContentsView()->AddChildView(native_host);
244
245 std::unique_ptr<aura::Window> window(new aura::Window(nullptr));
246 window->Init(ui::LayerType::LAYER_SOLID_COLOR);
247 native_host->SetBounds(5, 10, 20, 30);
248 native_host->Attach(window.get());
249 widget.Show();
250 window->Show();
251 widget.SetBounds(gfx::Rect(10, 20, 30, 40));
252
253 // Sanity check that the |window| is a descendent of the Widget's window.
254 ASSERT_TRUE(widget.GetNativeView()->Contains(window->parent()));
255
256 // Focusing the child window should not activate it.
257 window->Focus();
258 EXPECT_TRUE(window->HasFocus());
259 aura::Window* active_window =
260 aura::client::GetActivationClient(window.get()->GetRootWindow())
261 ->GetActiveWindow();
262 EXPECT_NE(window.get(), active_window);
263 EXPECT_EQ(widget.GetNativeView(), active_window);
264
265 // Moving focus to a child View should move focus away from |window|, and to
266 // the Widget's window instead.
267 focusable->RequestFocus();
268 EXPECT_FALSE(window->HasFocus());
269 EXPECT_TRUE(widget.GetNativeView()->HasFocus());
270 active_window =
271 aura::client::GetActivationClient(window.get()->GetRootWindow())
272 ->GetActiveWindow();
273 EXPECT_EQ(widget.GetNativeView(), active_window);
274 }
275
229 } // namespace 276 } // namespace
230 } // namespace views 277 } // namespace views
OLDNEW
« no previous file with comments | « ui/views/mus/native_widget_mus.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698