OLD | NEW |
---|---|
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_process_host_impl.h" |
10 #include "content/browser/renderer_host/render_widget_host_impl.h" | |
11 #include "content/public/browser/render_widget_host_view.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 rph_ = new RenderProcessHostImpl(browser_context_.get()); | |
Daniel Erat
2012/05/11 22:56:48
I'm having a difficult time wrapping my head aroun
jochen (gone - plz use gerrit)
2012/05/12 00:09:54
Your code only shuts down the render view host, bu
| |
72 content::RenderWidgetHostImpl* rwh = | |
73 new content::RenderWidgetHostImpl(rph_, MSG_ROUTING_NONE); | |
74 rwhv_ = static_cast<RenderWidgetHostViewAura*>( | |
75 content::RenderWidgetHostView::CreateViewForWidget(rwh)); | |
30 } | 76 } |
31 | 77 |
32 virtual void TearDown() { | 78 virtual void TearDown() { |
33 aura::Window* window = rwhv_aura_->GetNativeView(); | 79 if (rwhv_) |
34 if (window->parent()) | 80 rwhv_->Destroy(); |
35 window->parent()->RemoveChild(window); | 81 |
36 rwhv_aura_->Destroy(); | 82 MessageLoop::current()->RunAllPending(); |
37 // Destroying RWHV sets the host's view to NULL, so destroying view first, | 83 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
38 // then set the view. | 84 message_loop_.RunAllPending(); |
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 RenderProcessHostImpl* rph_; | |
93 | |
94 // Tests should set this to NULL if they've already triggered its destruction. | |
95 RenderWidgetHostViewAura* rwhv_; | |
45 | 96 |
46 private: | 97 private: |
47 RenderWidgetHostView* old_rwhv_; | |
48 | |
49 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 98 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
50 }; | 99 }; |
51 | 100 |
52 // Checks that a fullscreen view has the correct show-state and receives the | 101 // Checks that a fullscreen view has the correct show-state and receives the |
53 // focus. | 102 // focus. |
54 TEST_F(RenderWidgetHostViewAuraTest, Fullscreen) { | 103 TEST_F(RenderWidgetHostViewAuraTest, FocusFullscreen) { |
55 rwhv_aura_->InitAsFullscreen(NULL); | 104 rwhv_->InitAsFullscreen(NULL); |
56 | 105 aura::Window* window = rwhv_->GetNativeView(); |
57 aura::Window* window = rwhv_aura_->GetNativeView(); | |
58 ASSERT_TRUE(window != NULL); | 106 ASSERT_TRUE(window != NULL); |
59 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, | 107 EXPECT_EQ(ui::SHOW_STATE_FULLSCREEN, |
60 window->GetProperty(aura::client::kShowStateKey)); | 108 window->GetProperty(aura::client::kShowStateKey)); |
61 | 109 |
62 // Check that we requested and received the focus. | 110 // Check that we requested and received the focus. |
63 EXPECT_TRUE(window->HasFocus()); | 111 EXPECT_TRUE(window->HasFocus()); |
64 | 112 |
65 // Check that we'll also say it's okay to activate the window when there's an | 113 // Check that we'll also say it's okay to activate the window when there's an |
66 // ActivationClient defined. | 114 // ActivationClient defined. |
67 EXPECT_TRUE(rwhv_aura_->ShouldActivate(NULL)); | 115 EXPECT_TRUE(rwhv_->ShouldActivate(NULL)); |
68 } | 116 } |
117 | |
118 // Checks that a fullscreen view is destroyed when it loses the focus. | |
119 TEST_F(RenderWidgetHostViewAuraTest, DestroyFullscreenOnBlur) { | |
120 rwhv_->InitAsFullscreen(NULL); | |
121 aura::Window* window = rwhv_->GetNativeView(); | |
122 ASSERT_TRUE(window != NULL); | |
123 ASSERT_TRUE(window->HasFocus()); | |
124 | |
125 // After we create and focus another window, the RWHVA's window should be | |
126 // destroyed. | |
127 TestWindowObserver observer(window); | |
128 aura::test::TestWindowDelegate delegate; | |
129 scoped_ptr<aura::Window> sibling(new aura::Window(&delegate)); | |
130 sibling->Init(ui::LAYER_TEXTURED); | |
131 sibling->Show(); | |
132 window->parent()->AddChild(sibling.get()); | |
133 sibling->Focus(); | |
134 ASSERT_TRUE(sibling->HasFocus()); | |
135 ASSERT_TRUE(observer.destroyed()); | |
136 rwhv_ = NULL; | |
137 } | |
OLD | NEW |