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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_aura_unittest.cc

Issue 10377066: aura: Close fullscreen RenderWidgetHostViewAura on blur. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: simplify testing code (reupload) Created 8 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 | Annotate | Revision Log
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.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 (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 "content/browser/renderer_host/render_widget_host_view_aura.h" 5 #include "content/browser/renderer_host/render_widget_host_view_aura.h"
6 6
7 #include "base/basictypes.h" 7 #include "base/basictypes.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/message_loop.h"
9 #include "content/browser/renderer_host/test_render_view_host.h" 9 #include "content/browser/renderer_host/render_widget_host_impl.h"
10 #include "content/public/browser/render_widget_host_view.h"
11 #include "content/test/mock_render_process_host.h"
12 #include "content/test/test_browser_context.h"
10 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
11 #include "ui/aura/client/aura_constants.h" 14 #include "ui/aura/client/aura_constants.h"
15 #include "ui/aura/env.h"
16 #include "ui/aura/monitor_manager.h"
17 #include "ui/aura/root_window.h"
18 #include "ui/aura/single_monitor_manager.h"
19 #include "ui/aura/test/test_screen.h"
20 #include "ui/aura/test/test_stacking_client.h"
21 #include "ui/aura/test/test_window_delegate.h"
12 #include "ui/aura/window.h" 22 #include "ui/aura/window.h"
23 #include "ui/aura/window_observer.h"
13 #include "ui/base/ui_base_types.h" 24 #include "ui/base/ui_base_types.h"
25 #include "ui/gfx/screen.h"
14 26
15 using content::RenderWidgetHostView; 27 // Simple observer that keeps track of changes to a window for tests.
16 using content::RenderViewHostImplTestHarness; 28 class TestWindowObserver : public aura::WindowObserver {
29 public:
30 explicit TestWindowObserver(aura::Window* window_to_observe)
31 : window_(window_to_observe) {
32 window_->AddObserver(this);
33 }
34 virtual ~TestWindowObserver() {
35 if (window_)
36 window_->RemoveObserver(this);
37 }
17 38
18 // This approach (of using RenderViewHostImplTestHarness's 39 bool destroyed() const { return destroyed_; }
19 // RenderViewHost for a new RenderWidgetHostView) is borrowed from 40
20 // RenderWidgetHostViewMacTest. 41 // aura::WindowObserver overrides:
21 class RenderWidgetHostViewAuraTest : public RenderViewHostImplTestHarness { 42 virtual void OnWindowDestroyed(aura::Window* window) {
43 CHECK_EQ(window, window_);
44 destroyed_ = true;
45 window_ = NULL;
46 }
47
48 private:
49 // Window that we're observing, or NULL if it's been destroyed.
50 aura::Window* window_;
51
52 // Was |window_| destroyed?
53 bool destroyed_;
54
55 DISALLOW_COPY_AND_ASSIGN(TestWindowObserver);
56 };
57
58 class RenderWidgetHostViewAuraTest : public testing::Test {
22 public: 59 public:
23 RenderWidgetHostViewAuraTest() : old_rwhv_(NULL) {} 60 RenderWidgetHostViewAuraTest() {}
24 61
25 virtual void SetUp() { 62 virtual void SetUp() {
26 RenderViewHostImplTestHarness::SetUp(); 63 aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager);
27 old_rwhv_ = rvh()->GetView(); 64 root_window_.reset(
28 rwhv_aura_ = static_cast<RenderWidgetHostViewAura*>( 65 aura::MonitorManager::CreateRootWindowForPrimaryMonitor());
29 RenderWidgetHostView::CreateViewForWidget(rvh())); 66 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get()));
67 test_stacking_client_.reset(
68 new aura::test::TestStackingClient(root_window_.get()));
69
70 browser_context_.reset(new TestBrowserContext);
71 content::MockRenderProcessHost* process_host =
72 new content::MockRenderProcessHost(browser_context_.get());
73 widget_host_ =
74 new content::RenderWidgetHostImpl(process_host, MSG_ROUTING_NONE);
75 view_ = static_cast<RenderWidgetHostViewAura*>(
76 content::RenderWidgetHostView::CreateViewForWidget(widget_host_));
30 } 77 }
31 78
32 virtual void TearDown() { 79 virtual void TearDown() {
33 aura::Window* window = rwhv_aura_->GetNativeView(); 80 if (view_)
34 if (window->parent()) 81 view_->Destroy();
35 window->parent()->RemoveChild(window); 82 delete widget_host_;
36 rwhv_aura_->Destroy(); 83 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
37 // Destroying RWHV sets the host's view to NULL, so destroying view first, 84 message_loop_.RunAllPending();
38 // then set the view.
39 test_rvh()->SetView(old_rwhv_);
40 RenderViewHostImplTestHarness::TearDown();
41 } 85 }
42 86
43 protected: 87 protected:
44 RenderWidgetHostViewAura* rwhv_aura_; 88 MessageLoopForUI message_loop_;
89 scoped_ptr<aura::RootWindow> root_window_;
90 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_;
91 scoped_ptr<content::BrowserContext> browser_context_;
92
93 // Tests should set these to NULL if they've already triggered their
94 // destruction.
95 content::RenderWidgetHostImpl* widget_host_;
96 RenderWidgetHostViewAura* view_;
45 97
46 private: 98 private:
47 RenderWidgetHostView* old_rwhv_;
48
49 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); 99 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest);
50 }; 100 };
51 101
52 // Checks that a fullscreen view has the correct show-state and receives the 102 // Checks that a fullscreen view has the correct show-state and receives the
53 // focus. 103 // focus.
54 TEST_F(RenderWidgetHostViewAuraTest, Fullscreen) { 104 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) {
55 rwhv_aura_->InitAsFullscreen(NULL); 105 view_->InitAsFullscreen(NULL);
56 106 aura::Window* window = view_->GetNativeView();
57 aura::Window* window = rwhv_aura_->GetNativeView();
58 ASSERT_TRUE(window != NULL); 107 ASSERT_TRUE(window != NULL);
59 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, 108 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN,
60 window->GetProperty(aura::client::kShowStateKey)); 109 window->GetProperty(aura::client::kShowStateKey));
61 110
62 // Check that we requested and received the focus. 111 // Check that we requested and received the focus.
63 EXPECT_TRUE(window->HasFocus()); 112 EXPECT_TRUE(window->HasFocus());
64 113
65 // Check that we'll also say it's okay to activate the window when there's an 114 // Check that we'll also say it's okay to activate the window when there's an
66 // ActivationClient defined. 115 // ActivationClient defined.
67 EXPECT_TRUE(rwhv_aura_->ShouldActivate(NULL)); 116 EXPECT_TRUE(view_->ShouldActivate(NULL));
68 } 117 }
118
119 // Checks that a fullscreen view is destroyed when it loses the focus.
120 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) {
121 view_->InitAsFullscreen(NULL);
122 aura::Window* window = view_->GetNativeView();
123 ASSERT_TRUE(window != NULL);
124 ASSERT_TRUE(window->HasFocus());
125
126 // After we create and focus another window, the RWHVA's window should be
127 // destroyed.
128 TestWindowObserver observer(window);
129 aura::test::TestWindowDelegate delegate;
130 scoped_ptr<aura::Window> sibling(new aura::Window(&delegate));
131 sibling->Init(ui::LAYER_TEXTURED);
132 sibling->Show();
133 window->parent()->AddChild(sibling.get());
134 sibling->Focus();
135 ASSERT_TRUE(sibling->HasFocus());
136 ASSERT_TRUE(observer.destroyed());
137
138 widget_host_ = NULL;
139 view_ = NULL;
140 }
OLDNEW
« no previous file with comments | « content/browser/renderer_host/render_widget_host_view_aura.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698