| 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/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_delegate.h" |
| 9 #include "content/browser/renderer_host/render_widget_host_impl.h" | 10 #include "content/browser/renderer_host/render_widget_host_impl.h" |
| 10 #include "content/public/browser/render_widget_host_view.h" | 11 #include "content/public/browser/render_widget_host_view.h" |
| 11 #include "content/test/mock_render_process_host.h" | 12 #include "content/test/mock_render_process_host.h" |
| 12 #include "content/test/test_browser_context.h" | 13 #include "content/test/test_browser_context.h" |
| 13 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 14 #include "ui/aura/client/aura_constants.h" | 15 #include "ui/aura/client/aura_constants.h" |
| 15 #include "ui/aura/env.h" | 16 #include "ui/aura/env.h" |
| 16 #include "ui/aura/monitor_manager.h" | 17 #include "ui/aura/monitor_manager.h" |
| 17 #include "ui/aura/root_window.h" | 18 #include "ui/aura/root_window.h" |
| 18 #include "ui/aura/single_monitor_manager.h" | 19 #include "ui/aura/single_monitor_manager.h" |
| 19 #include "ui/aura/test/test_screen.h" | 20 #include "ui/aura/test/test_screen.h" |
| 20 #include "ui/aura/test/test_stacking_client.h" | 21 #include "ui/aura/test/test_stacking_client.h" |
| 21 #include "ui/aura/test/test_window_delegate.h" | 22 #include "ui/aura/test/test_window_delegate.h" |
| 22 #include "ui/aura/window.h" | 23 #include "ui/aura/window.h" |
| 23 #include "ui/aura/window_observer.h" | 24 #include "ui/aura/window_observer.h" |
| 24 #include "ui/base/ui_base_types.h" | 25 #include "ui/base/ui_base_types.h" |
| 25 #include "ui/gfx/screen.h" | 26 #include "ui/gfx/screen.h" |
| 26 | 27 |
| 28 class MockRenderWidgetHostDelegate : public content::RenderWidgetHostDelegate { |
| 29 public: |
| 30 MockRenderWidgetHostDelegate() {} |
| 31 virtual ~MockRenderWidgetHostDelegate() {} |
| 32 }; |
| 33 |
| 27 // Simple observer that keeps track of changes to a window for tests. | 34 // Simple observer that keeps track of changes to a window for tests. |
| 28 class TestWindowObserver : public aura::WindowObserver { | 35 class TestWindowObserver : public aura::WindowObserver { |
| 29 public: | 36 public: |
| 30 explicit TestWindowObserver(aura::Window* window_to_observe) | 37 explicit TestWindowObserver(aura::Window* window_to_observe) |
| 31 : window_(window_to_observe) { | 38 : window_(window_to_observe) { |
| 32 window_->AddObserver(this); | 39 window_->AddObserver(this); |
| 33 } | 40 } |
| 34 virtual ~TestWindowObserver() { | 41 virtual ~TestWindowObserver() { |
| 35 if (window_) | 42 if (window_) |
| 36 window_->RemoveObserver(this); | 43 window_->RemoveObserver(this); |
| (...skipping 26 matching lines...) Expand all Loading... |
| 63 aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); | 70 aura::Env::GetInstance()->SetMonitorManager(new aura::SingleMonitorManager); |
| 64 root_window_.reset( | 71 root_window_.reset( |
| 65 aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); | 72 aura::MonitorManager::CreateRootWindowForPrimaryMonitor()); |
| 66 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); | 73 gfx::Screen::SetInstance(new aura::TestScreen(root_window_.get())); |
| 67 test_stacking_client_.reset( | 74 test_stacking_client_.reset( |
| 68 new aura::test::TestStackingClient(root_window_.get())); | 75 new aura::test::TestStackingClient(root_window_.get())); |
| 69 | 76 |
| 70 browser_context_.reset(new TestBrowserContext); | 77 browser_context_.reset(new TestBrowserContext); |
| 71 content::MockRenderProcessHost* process_host = | 78 content::MockRenderProcessHost* process_host = |
| 72 new content::MockRenderProcessHost(browser_context_.get()); | 79 new content::MockRenderProcessHost(browser_context_.get()); |
| 73 widget_host_ = | 80 widget_host_ = new content::RenderWidgetHostImpl( |
| 74 new content::RenderWidgetHostImpl(process_host, MSG_ROUTING_NONE); | 81 &delegate_, process_host, MSG_ROUTING_NONE); |
| 75 view_ = static_cast<RenderWidgetHostViewAura*>( | 82 view_ = static_cast<RenderWidgetHostViewAura*>( |
| 76 content::RenderWidgetHostView::CreateViewForWidget(widget_host_)); | 83 content::RenderWidgetHostView::CreateViewForWidget(widget_host_)); |
| 77 } | 84 } |
| 78 | 85 |
| 79 virtual void TearDown() { | 86 virtual void TearDown() { |
| 80 if (view_) | 87 if (view_) |
| 81 view_->Destroy(); | 88 view_->Destroy(); |
| 82 delete widget_host_; | 89 delete widget_host_; |
| 83 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); | 90 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release()); |
| 84 message_loop_.RunAllPending(); | 91 message_loop_.RunAllPending(); |
| 85 } | 92 } |
| 86 | 93 |
| 87 protected: | 94 protected: |
| 88 MessageLoopForUI message_loop_; | 95 MessageLoopForUI message_loop_; |
| 89 scoped_ptr<aura::RootWindow> root_window_; | 96 scoped_ptr<aura::RootWindow> root_window_; |
| 90 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; | 97 scoped_ptr<aura::test::TestStackingClient> test_stacking_client_; |
| 91 scoped_ptr<content::BrowserContext> browser_context_; | 98 scoped_ptr<content::BrowserContext> browser_context_; |
| 99 MockRenderWidgetHostDelegate delegate_; |
| 92 | 100 |
| 93 // Tests should set these to NULL if they've already triggered their | 101 // Tests should set these to NULL if they've already triggered their |
| 94 // destruction. | 102 // destruction. |
| 95 content::RenderWidgetHostImpl* widget_host_; | 103 content::RenderWidgetHostImpl* widget_host_; |
| 96 RenderWidgetHostViewAura* view_; | 104 RenderWidgetHostViewAura* view_; |
| 97 | 105 |
| 98 private: | 106 private: |
| 99 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); | 107 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewAuraTest); |
| 100 }; | 108 }; |
| 101 | 109 |
| (...skipping 29 matching lines...) Expand all Loading... |
| 131 sibling->Init(ui::LAYER_TEXTURED); | 139 sibling->Init(ui::LAYER_TEXTURED); |
| 132 sibling->Show(); | 140 sibling->Show(); |
| 133 window->parent()->AddChild(sibling.get()); | 141 window->parent()->AddChild(sibling.get()); |
| 134 sibling->Focus(); | 142 sibling->Focus(); |
| 135 ASSERT_TRUE(sibling->HasFocus()); | 143 ASSERT_TRUE(sibling->HasFocus()); |
| 136 ASSERT_TRUE(observer.destroyed()); | 144 ASSERT_TRUE(observer.destroyed()); |
| 137 | 145 |
| 138 widget_host_ = NULL; | 146 widget_host_ = NULL; |
| 139 view_ = NULL; | 147 view_ = NULL; |
| 140 } | 148 } |
| OLD | NEW |