| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "testing/gtest/include/gtest/gtest.h" | |
| 6 | |
| 7 #include "base/ref_counted.h" | |
| 8 #include "chrome/renderer/mock_render_process.h" | |
| 9 #include "chrome/renderer/mock_render_thread.h" | |
| 10 #include "chrome/renderer/render_widget.h" | |
| 11 #include "chrome/renderer/render_thread.h" | |
| 12 #include "third_party/WebKit/Source/WebKit/chromium/public/WebPopupType.h" | |
| 13 | |
| 14 namespace { | |
| 15 | |
| 16 const int32 kRouteId = 5; | |
| 17 const int32 kOpenerId = 7; | |
| 18 | |
| 19 class RenderWidgetTest : public testing::Test { | |
| 20 public: | |
| 21 | |
| 22 protected: | |
| 23 MessageLoop msg_loop_; | |
| 24 MockRenderThread render_thread_; | |
| 25 | |
| 26 // The widget, each test should verify this is non-NULL before continuing. | |
| 27 scoped_refptr<RenderWidget> widget_; | |
| 28 | |
| 29 private: | |
| 30 // testing::Test | |
| 31 virtual void SetUp() { | |
| 32 mock_process_.reset(new MockRenderProcess); | |
| 33 render_thread_.set_routing_id(kRouteId); | |
| 34 widget_ = RenderWidget::Create(kOpenerId, &render_thread_, | |
| 35 WebKit::WebPopupTypeNone); | |
| 36 ASSERT_TRUE(widget_); | |
| 37 } | |
| 38 virtual void TearDown() { | |
| 39 widget_ = NULL; | |
| 40 mock_process_.reset(); | |
| 41 } | |
| 42 | |
| 43 scoped_ptr<MockRenderProcess> mock_process_; | |
| 44 }; | |
| 45 | |
| 46 TEST_F(RenderWidgetTest, CreateAndCloseWidget) { | |
| 47 // After the RenderWidget it must have sent a message to the render thread | |
| 48 // that sets the opener id. | |
| 49 EXPECT_EQ(kOpenerId, render_thread_.opener_id()); | |
| 50 ASSERT_TRUE(render_thread_.has_widget()); | |
| 51 | |
| 52 // Now simulate a close of the Widget. | |
| 53 render_thread_.SendCloseMessage(); | |
| 54 EXPECT_FALSE(render_thread_.has_widget()); | |
| 55 | |
| 56 // Run the loop so the release task from the renderwidget executes. | |
| 57 msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask()); | |
| 58 msg_loop_.Run(); | |
| 59 } | |
| 60 | |
| 61 } // namespace | |
| OLD | NEW |