Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / views / native_widget_win_interactive_uitest.cc
blob05cbbbe7ac749c0a1f89ea5d218f086d44923f28
1 // Copyright (c) 2013 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 "chrome/test/base/scoped_testing_local_state.h"
6 #include "chrome/test/base/testing_browser_process.h"
7 #include "chrome/test/base/view_event_test_base.h"
8 #include "ui/views/controls/native/native_view_host.h"
9 #include "ui/views/widget/widget.h"
11 class NativeWidgetWinTest : public ViewEventTestBase {
12 public:
13 NativeWidgetWinTest()
14 : ViewEventTestBase(),
15 contents_view_(new views::View) {
18 virtual void SetUp() OVERRIDE {
19 local_state_.reset(new ScopedTestingLocalState(
20 TestingBrowserProcess::GetGlobal()));
21 ViewEventTestBase::SetUp();
24 protected:
25 virtual views::View* CreateContentsView() OVERRIDE {
26 return contents_view_;
29 virtual gfx::Size GetPreferredSize() OVERRIDE {
30 return gfx::Size(500, 500);
33 views::View* contents_view_;
35 scoped_ptr<views::Widget> child_;
37 private:
38 scoped_ptr<ScopedTestingLocalState> local_state_;
40 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWinTest);
43 // This test creates a child Widget that is attached by way of a NativeViewHost.
44 // The child HWND is focused (through NativeViewHost) the top level Widget is
45 // minimized then restored and the test asserts focus is still on the child
46 // widget and corresponding NativeViewHost.
48 // This scenario replicates what happens with a browser and a corresponding
49 // RenderWidgetHostViewWin.
51 // This test really belongs in views, but as it exercises focus it needs to
52 // be here.
53 class NativeWidgetWinTest1 : public NativeWidgetWinTest {
54 public:
55 NativeWidgetWinTest1()
56 : NativeWidgetWinTest(),
57 child_(NULL),
58 native_view_host_(NULL) {
61 virtual void DoTestOnMessageLoop() OVERRIDE {
62 AttachChildWidget();
63 // Focus the native widget.
64 native_view_host_->RequestFocus();
65 EXPECT_TRUE(native_view_host_->HasFocus());
66 EXPECT_EQ(child_->GetNativeView(), ::GetFocus());
68 // Minimize then restore the window, focus should still be on the
69 // NativeViewHost and its corresponding widget.
70 window_->Minimize();
71 DLOG(WARNING) << "Restoring widget=" << window_->GetNativeView();
72 window_->Restore();
73 EXPECT_TRUE(native_view_host_->HasFocus());
74 EXPECT_EQ(child_->GetNativeView(), ::GetFocus());
76 Done();
79 private:
80 void AttachChildWidget() {
81 child_ = new views::Widget();
82 views::Widget::InitParams child_params(
83 views::Widget::InitParams::TYPE_CONTROL);
84 child_params.parent = window_->GetNativeView();
85 child_->Init(child_params);
87 native_view_host_ = new views::NativeViewHost;
88 native_view_host_->SetFocusable(true);
89 contents_view_->AddChildView(native_view_host_);
90 native_view_host_->SetBoundsRect(gfx::Rect(0, 0, 200, 200));
91 native_view_host_->Attach(child_->GetNativeView());
94 // Owned by the parent widget.
95 views::Widget* child_;
97 // Owned by the parent View.
98 views::NativeViewHost* native_view_host_;
100 DISALLOW_COPY_AND_ASSIGN(NativeWidgetWinTest1);
103 VIEW_TEST(NativeWidgetWinTest1, FocusRestoredToChildAfterMiniminize)