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_mac.h" | 5 #include "content/browser/renderer_host/render_widget_host_view_mac.h" |
6 | 6 |
7 #include "base/mac/scoped_nsautorelease_pool.h" | 7 #include "base/mac/scoped_nsautorelease_pool.h" |
8 #include "content/browser/browser_thread_impl.h" | 8 #include "content/browser/browser_thread_impl.h" |
9 #include "content/browser/renderer_host/test_render_view_host.h" | 9 #include "content/browser/renderer_host/test_render_view_host.h" |
10 #include "content/common/gpu/gpu_messages.h" | 10 #include "content/common/gpu/gpu_messages.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 #include "ui/base/test/cocoa_test_event_utils.h" | 12 #include "ui/base/test/cocoa_test_event_utils.h" |
13 #import "ui/base/test/ui_cocoa_test_helper.h" | 13 #import "ui/base/test/ui_cocoa_test_helper.h" |
14 #include "webkit/plugins/npapi/webplugin.h" | 14 #include "webkit/plugins/npapi/webplugin.h" |
15 | 15 |
16 using content::BrowserThread; | 16 using content::BrowserThread; |
17 using content::BrowserThreadImpl; | 17 using content::BrowserThreadImpl; |
| 18 using content::RenderViewHostImplTestHarness; |
18 | 19 |
19 class RenderWidgetHostViewMacTest : public RenderViewHostTestHarness { | 20 class RenderWidgetHostViewMacTest : public RenderViewHostImplTestHarness { |
20 public: | 21 public: |
21 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) {} | 22 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) {} |
22 | 23 |
23 virtual void SetUp() { | 24 virtual void SetUp() { |
24 RenderViewHostTestHarness::SetUp(); | 25 RenderViewHostTestHarness::SetUp(); |
25 | 26 |
26 // TestRenderViewHost's destruction assumes that its view is a | 27 // TestRenderViewHost's destruction assumes that its view is a |
27 // TestRenderWidgetHostView, so store its view and reset it back to the | 28 // TestRenderWidgetHostView, so store its view and reset it back to the |
28 // stored view in |TearDown()|. | 29 // stored view in |TearDown()|. |
29 old_rwhv_ = rvh()->GetView(); | 30 old_rwhv_ = rvh()->GetView(); |
30 | 31 |
31 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. | 32 // Owned by its |cocoa_view()|, i.e. |rwhv_cocoa_|. |
32 rwhv_mac_ = static_cast<RenderWidgetHostViewMac*>( | 33 rwhv_mac_ = static_cast<RenderWidgetHostViewMac*>( |
33 content::RenderWidgetHostView::CreateViewForWidget(rvh())); | 34 content::RenderWidgetHostView::CreateViewForWidget(rvh())); |
34 rwhv_cocoa_.reset([rwhv_mac_->cocoa_view() retain]); | 35 rwhv_cocoa_.reset([rwhv_mac_->cocoa_view() retain]); |
35 } | 36 } |
36 virtual void TearDown() { | 37 virtual void TearDown() { |
37 // See comment in SetUp(). | 38 // See comment in SetUp(). |
38 rvh()->SetView(old_rwhv_); | 39 test_rvh()->SetView(old_rwhv_); |
39 | 40 |
40 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs. | 41 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs. |
41 rwhv_cocoa_.reset(); | 42 rwhv_cocoa_.reset(); |
42 pool_.Recycle(); | 43 pool_.Recycle(); |
43 MessageLoop::current()->RunAllPending(); | 44 MessageLoop::current()->RunAllPending(); |
44 pool_.Recycle(); | 45 pool_.Recycle(); |
45 | 46 |
46 RenderViewHostTestHarness::TearDown(); | 47 RenderViewHostTestHarness::TearDown(); |
47 } | 48 } |
48 protected: | 49 protected: |
(...skipping 144 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
193 | 194 |
194 // A click on the accelerated view should focus the RWHVCocoa. | 195 // A click on the accelerated view should focus the RWHVCocoa. |
195 std::pair<NSEvent*, NSEvent*> clicks = | 196 std::pair<NSEvent*, NSEvent*> clicks = |
196 cocoa_test_event_utils::MouseClickInView(accelerated_view, 1); | 197 cocoa_test_event_utils::MouseClickInView(accelerated_view, 1); |
197 [rwhv_cocoa_.get() mouseDown:clicks.first]; | 198 [rwhv_cocoa_.get() mouseDown:clicks.first]; |
198 EXPECT_EQ(rwhv_cocoa_.get(), [window firstResponder]); | 199 EXPECT_EQ(rwhv_cocoa_.get(), [window firstResponder]); |
199 | 200 |
200 // Clean up. | 201 // Clean up. |
201 rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); | 202 rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); |
202 } | 203 } |
OLD | NEW |