| OLD | NEW |
| 1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/browser/renderer_host/render_widget_host_view_mac.h" | 5 #include "chrome/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 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" | 8 #import "chrome/browser/ui/cocoa/cocoa_test_helper.h" |
| 9 #include "chrome/test/base/chrome/render_view_host_test_harness.h" |
| 9 #include "content/browser/browser_thread.h" | 10 #include "content/browser/browser_thread.h" |
| 10 #include "content/browser/renderer_host/test_render_view_host.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 #include "webkit/plugins/npapi/webplugin.h" | 13 #include "webkit/plugins/npapi/webplugin.h" |
| 14 | 14 |
| 15 class RenderWidgetHostViewMacTest : public RenderViewHostTestHarness { | 15 class RenderWidgetHostViewMacTest : public ChromeRenderViewHostTestHarness { |
| 16 public: | 16 public: |
| 17 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) {} | 17 RenderWidgetHostViewMacTest() : old_rwhv_(NULL), rwhv_mac_(NULL) {} |
| 18 | 18 |
| 19 virtual void SetUp() { | 19 virtual void SetUp() { |
| 20 RenderViewHostTestHarness::SetUp(); | 20 ChromeRenderViewHostTestHarness::SetUp(); |
| 21 | 21 |
| 22 // TestRenderViewHost's destruction assumes that its view is a | 22 // TestRenderViewHost's destruction assumes that its view is a |
| 23 // TestRenderWidgetHostView, so store its view and reset it back to the | 23 // TestRenderWidgetHostView, so store its view and reset it back to the |
| 24 // stored view in |TearDown()|. | 24 // stored view in |TearDown()|. |
| 25 old_rwhv_ = rvh()->view(); | 25 old_rwhv_ = rvh()->view(); |
| 26 | 26 |
| 27 // Owned by its |native_view()|, i.e. |rwhv_cocoa_|. | 27 // Owned by its |native_view()|, i.e. |rwhv_cocoa_|. |
| 28 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()); | 28 rwhv_mac_ = new RenderWidgetHostViewMac(rvh()); |
| 29 rwhv_cocoa_.reset([rwhv_mac_->native_view() retain]); | 29 rwhv_cocoa_.reset([rwhv_mac_->native_view() retain]); |
| 30 } | 30 } |
| 31 virtual void TearDown() { | 31 virtual void TearDown() { |
| 32 // See comment in SetUp(). | 32 // See comment in SetUp(). |
| 33 rvh()->SetView(old_rwhv_); | 33 rvh()->SetView(old_rwhv_); |
| 34 | 34 |
| 35 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs. | 35 // Make sure the rwhv_mac_ is gone once the superclass's |TearDown()| runs. |
| 36 rwhv_cocoa_.reset(); | 36 rwhv_cocoa_.reset(); |
| 37 pool_.Recycle(); | 37 pool_.Recycle(); |
| 38 MessageLoop::current()->RunAllPending(); | 38 MessageLoop::current()->RunAllPending(); |
| 39 pool_.Recycle(); | 39 pool_.Recycle(); |
| 40 | 40 |
| 41 RenderViewHostTestHarness::TearDown(); | 41 ChromeRenderViewHostTestHarness::TearDown(); |
| 42 } | 42 } |
| 43 protected: | 43 protected: |
| 44 // Adds an accelerated plugin view to |rwhv_cocoa_|. Returns a handle to the | 44 // Adds an accelerated plugin view to |rwhv_cocoa_|. Returns a handle to the |
| 45 // newly-added view. Callers must ensure that a UI thread is present and | 45 // newly-added view. Callers must ensure that a UI thread is present and |
| 46 // running before calling this function. | 46 // running before calling this function. |
| 47 gfx::PluginWindowHandle AddAcceleratedPluginView(int w, int h) { | 47 gfx::PluginWindowHandle AddAcceleratedPluginView(int w, int h) { |
| 48 // Create an accelerated view the size of the rhwvmac. | 48 // Create an accelerated view the size of the rhwvmac. |
| 49 [rwhv_cocoa_.get() setFrame:NSMakeRect(0, 0, w, h)]; | 49 [rwhv_cocoa_.get() setFrame:NSMakeRect(0, 0, w, h)]; |
| 50 gfx::PluginWindowHandle accelerated_handle = | 50 gfx::PluginWindowHandle accelerated_handle = |
| 51 rwhv_mac_->AllocateFakePluginWindowHandle(/*opaque=*/false, | 51 rwhv_mac_->AllocateFakePluginWindowHandle(/*opaque=*/false, |
| (...skipping 133 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 185 | 185 |
| 186 // A click on the accelerated view should focus the RWHVCocoa. | 186 // A click on the accelerated view should focus the RWHVCocoa. |
| 187 std::pair<NSEvent*, NSEvent*> clicks = | 187 std::pair<NSEvent*, NSEvent*> clicks = |
| 188 cocoa_test_event_utils::MouseClickInView(accelerated_view, 1); | 188 cocoa_test_event_utils::MouseClickInView(accelerated_view, 1); |
| 189 [rwhv_cocoa_.get() mouseDown:clicks.first]; | 189 [rwhv_cocoa_.get() mouseDown:clicks.first]; |
| 190 EXPECT_EQ(rwhv_cocoa_.get(), [window firstResponder]); | 190 EXPECT_EQ(rwhv_cocoa_.get(), [window firstResponder]); |
| 191 | 191 |
| 192 // Clean up. | 192 // Clean up. |
| 193 rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); | 193 rwhv_mac_->DestroyFakePluginWindowHandle(accelerated_handle); |
| 194 } | 194 } |
| OLD | NEW |