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

Side by Side Diff: ui/views/widget/native_widget_aura_unittest.cc

Issue 1753473003: A window should not get activated or get input focus if it's behind the lock screen. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address sky@'s comments Created 4 years, 9 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 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 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/widget/native_widget_aura.h" 5 #include "ui/views/widget/native_widget_aura.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/macros.h" 8 #include "base/macros.h"
9 #include "base/memory/scoped_ptr.h" 9 #include "base/memory/scoped_ptr.h"
10 #include "base/message_loop/message_loop.h" 10 #include "base/message_loop/message_loop.h"
11 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
12 #include "ui/aura/client/aura_constants.h" 12 #include "ui/aura/client/aura_constants.h"
13 #include "ui/aura/env.h" 13 #include "ui/aura/env.h"
14 #include "ui/aura/layout_manager.h" 14 #include "ui/aura/layout_manager.h"
15 #include "ui/aura/test/aura_test_base.h" 15 #include "ui/aura/test/aura_test_base.h"
16 #include "ui/aura/window.h" 16 #include "ui/aura/window.h"
17 #include "ui/aura/window_tree_host.h" 17 #include "ui/aura/window_tree_host.h"
18 #include "ui/events/event.h" 18 #include "ui/events/event.h"
19 #include "ui/events/event_utils.h" 19 #include "ui/events/event_utils.h"
20 #include "ui/gfx/screen.h" 20 #include "ui/gfx/screen.h"
21 #include "ui/views/layout/fill_layout.h" 21 #include "ui/views/layout/fill_layout.h"
22 #include "ui/views/test/widget_test.h"
22 #include "ui/views/widget/root_view.h" 23 #include "ui/views/widget/root_view.h"
23 #include "ui/views/widget/widget_delegate.h" 24 #include "ui/views/widget/widget_delegate.h"
25 #include "ui/wm/core/base_focus_rules.h"
24 #include "ui/wm/core/default_activation_client.h" 26 #include "ui/wm/core/default_activation_client.h"
27 #include "ui/wm/core/focus_controller.h"
25 28
26 namespace views { 29 namespace views {
27 namespace { 30 namespace {
28 31
29 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) { 32 NativeWidgetAura* Init(aura::Window* parent, Widget* widget) {
30 Widget::InitParams params(Widget::InitParams::TYPE_POPUP); 33 Widget::InitParams params(Widget::InitParams::TYPE_POPUP);
31 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET; 34 params.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
32 params.parent = parent; 35 params.parent = parent;
33 widget->Init(params); 36 widget->Init(params);
34 return static_cast<NativeWidgetAura*>(widget->native_widget()); 37 return static_cast<NativeWidgetAura*>(widget->native_widget());
35 } 38 }
36 39
40 class TestFocusRules : public wm::BaseFocusRules {
sky 2016/03/03 20:22:47 Add description.
xdai1 2016/03/03 22:01:31 Done.
41 public:
42 TestFocusRules() {}
43 ~TestFocusRules() override {}
44
45 void SetActivatable(bool can_activate) { can_activate_ = can_activate; }
sky 2016/03/03 20:22:47 set_can_activate
xdai1 2016/03/03 22:01:31 Done.
46
47 // wm::BaseFocusRules overrides:
48 bool SupportsChildActivation(aura::Window* window) const override {
49 return true;
50 }
51
52 bool CanActivateWindow(aura::Window* window) const override {
53 return can_activate_;
54 }
55
56 private:
57 bool can_activate_ = true;
58
59 DISALLOW_COPY_AND_ASSIGN(TestFocusRules);
60 };
61
37 class NativeWidgetAuraTest : public aura::test::AuraTestBase { 62 class NativeWidgetAuraTest : public aura::test::AuraTestBase {
38 public: 63 public:
39 NativeWidgetAuraTest() {} 64 NativeWidgetAuraTest() {}
40 ~NativeWidgetAuraTest() override {} 65 ~NativeWidgetAuraTest() override {}
41 66
67 TestFocusRules* test_focus_rules() { return test_focus_rules_; }
68
42 // testing::Test overrides: 69 // testing::Test overrides:
43 void SetUp() override { 70 void SetUp() override {
44 AuraTestBase::SetUp(); 71 AuraTestBase::SetUp();
45 new wm::DefaultActivationClient(root_window()); 72 test_focus_rules_ = new TestFocusRules;
73 focus_controller_.reset(new wm::FocusController(test_focus_rules_));
74 aura::client::SetActivationClient(root_window(), focus_controller_.get());
46 host()->SetBounds(gfx::Rect(640, 480)); 75 host()->SetBounds(gfx::Rect(640, 480));
47 } 76 }
48 77
49 private: 78 private:
79 scoped_ptr<wm::FocusController> focus_controller_;
80 TestFocusRules* test_focus_rules_;
81
50 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest); 82 DISALLOW_COPY_AND_ASSIGN(NativeWidgetAuraTest);
51 }; 83 };
52 84
53 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) { 85 TEST_F(NativeWidgetAuraTest, CenterWindowLargeParent) {
54 // Make a parent window larger than the host represented by 86 // Make a parent window larger than the host represented by
55 // WindowEventDispatcher. 87 // WindowEventDispatcher.
56 scoped_ptr<aura::Window> parent(new aura::Window(NULL)); 88 scoped_ptr<aura::Window> parent(new aura::Window(NULL));
57 parent->Init(ui::LAYER_NOT_DRAWN); 89 parent->Init(ui::LAYER_NOT_DRAWN);
58 parent->SetBounds(gfx::Rect(0, 0, 1024, 800)); 90 parent->SetBounds(gfx::Rect(0, 0, 1024, 800));
59 scoped_ptr<Widget> widget(new Widget()); 91 scoped_ptr<Widget> widget(new Widget());
(...skipping 418 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 gfx::Rect(10, 10, 100, 200)); 510 gfx::Rect(10, 10, 100, 200));
479 widget->Show(); 511 widget->Show();
480 delegate->ClearGotMove(); 512 delegate->ClearGotMove();
481 // Simulate a maximize with animation. 513 // Simulate a maximize with animation.
482 delete widget->GetNativeView()->RecreateLayer().release(); 514 delete widget->GetNativeView()->RecreateLayer().release();
483 widget->SetBounds(gfx::Rect(0, 0, 500, 500)); 515 widget->SetBounds(gfx::Rect(0, 0, 500, 500));
484 EXPECT_TRUE(delegate->got_move()); 516 EXPECT_TRUE(delegate->got_move());
485 widget->CloseNow(); 517 widget->CloseNow();
486 } 518 }
487 519
520 // Tests that if a widget has a view which should be initially focused when the
521 // widget is shown, this view should not get focused if the associated window
522 // can not be activated.
523 TEST_F(NativeWidgetAuraTest, PreventFocusOnNonActivableWindow) {
524 test_focus_rules()->SetActivatable(false);
525 scoped_ptr<views::Widget> w1(new views::Widget);
526 views::test::TestInitialFocusWidgetDelegate* delegate =
527 new views::test::TestInitialFocusWidgetDelegate(root_window());
528 views::Widget::InitParams params1;
529 params1.delegate = delegate;
530 params1.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
531 params1.context = root_window();
532 w1->Init(params1);
533 w1->Show();
534 EXPECT_FALSE(delegate->view()->HasFocus());
535
536 test_focus_rules()->SetActivatable(true);
537 scoped_ptr<views::Widget> w2(new views::Widget);
538 views::test::TestInitialFocusWidgetDelegate* delegate2 =
539 new views::test::TestInitialFocusWidgetDelegate(root_window());
540 views::Widget::InitParams params2;
541 params2.delegate = delegate2;
542 params2.ownership = views::Widget::InitParams::WIDGET_OWNS_NATIVE_WIDGET;
543 params2.context = root_window();
544 w2->Init(params2);
545 w2->Show();
546 EXPECT_TRUE(delegate2->view()->HasFocus());
547 }
548
488 } // namespace 549 } // namespace
489 } // namespace views 550 } // namespace views
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698