Re-subimission of https://codereview.chromium.org/1041213003/
[chromium-blink-merge.git] / content / browser / frame_host / render_widget_host_view_guest_unittest.cc
blob114c46c2be50af2926a52e157edc1f5408be12cc
1 // Copyright 2014 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.
5 #include "content/browser/frame_host/render_widget_host_view_guest.h"
7 #include "base/basictypes.h"
8 #include "base/message_loop/message_loop.h"
9 #include "content/browser/renderer_host/render_widget_host_delegate.h"
10 #include "content/browser/renderer_host/render_widget_host_impl.h"
11 #include "content/common/view_messages.h"
12 #include "content/public/browser/render_widget_host_view.h"
13 #include "content/public/test/mock_render_process_host.h"
14 #include "content/public/test/test_browser_context.h"
15 #include "content/test/test_render_view_host.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 namespace content {
19 namespace {
20 class MockRenderWidgetHostDelegate : public RenderWidgetHostDelegate {
21 public:
22 MockRenderWidgetHostDelegate() {}
23 ~MockRenderWidgetHostDelegate() override {}
26 class RenderWidgetHostViewGuestTest : public testing::Test {
27 public:
28 RenderWidgetHostViewGuestTest() {}
30 void SetUp() override {
31 browser_context_.reset(new TestBrowserContext);
32 MockRenderProcessHost* process_host =
33 new MockRenderProcessHost(browser_context_.get());
34 widget_host_ = new RenderWidgetHostImpl(
35 &delegate_, process_host, MSG_ROUTING_NONE, false);
36 view_ = new RenderWidgetHostViewGuest(
37 widget_host_, NULL,
38 (new TestRenderWidgetHostView(widget_host_))->GetWeakPtr());
41 void TearDown() override {
42 if (view_)
43 view_->Destroy();
44 delete widget_host_;
46 browser_context_.reset();
48 message_loop_.DeleteSoon(FROM_HERE, browser_context_.release());
49 message_loop_.RunUntilIdle();
52 protected:
53 base::MessageLoopForUI message_loop_;
54 scoped_ptr<BrowserContext> browser_context_;
55 MockRenderWidgetHostDelegate delegate_;
57 // Tests should set these to NULL if they've already triggered their
58 // destruction.
59 RenderWidgetHostImpl* widget_host_;
60 RenderWidgetHostViewGuest* view_;
62 private:
63 DISALLOW_COPY_AND_ASSIGN(RenderWidgetHostViewGuestTest);
66 } // namespace
68 TEST_F(RenderWidgetHostViewGuestTest, VisibilityTest) {
69 view_->Show();
70 ASSERT_TRUE(view_->IsShowing());
72 view_->Hide();
73 ASSERT_FALSE(view_->IsShowing());
76 } // namespace content