summaryrefslogtreecommitdiffstats
path: root/chrome/renderer/render_widget_unittest.cc
blob: 6c2b24f5077e185615776960c18980693a56c8e2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "testing/gtest/include/gtest/gtest.h"

#include "base/ref_counted.h"
#include "chrome/renderer/mock_render_process.h"
#include "chrome/renderer/mock_render_thread.h"
#include "chrome/renderer/render_widget.h"
#include "chrome/renderer/render_thread.h"

namespace {

const int32 kRouteId = 5;
const int32 kOpenerId = 7;

class RenderWidgetTest : public testing::Test {
 public:

 protected:
  MessageLoop msg_loop_;
  MockRenderThread render_thread_;

  // The widget, each test should verify this is non-NULL before continuing.
  scoped_refptr<RenderWidget> widget_;

 private:
  // testing::Test
  virtual void SetUp() {
    MockProcess::GlobalInit();

    render_thread_.set_routing_id(kRouteId);
    widget_ = RenderWidget::Create(kOpenerId, &render_thread_, true);
    ASSERT_TRUE(widget_);
  }
  virtual void TearDown() {
    widget_ = NULL;

    // There is a delayed task that the child process posts to terminate the
    // message loop so we need to spin the message loop to delete the task.
    MockProcess::GlobalCleanup();
    msg_loop_.Run();
  }
};

}  // namespace

TEST_F(RenderWidgetTest, CreateAndCloseWidget) {
  // After the RenderWidget it must have sent a message to the render thread
  // that sets the opener id.
  EXPECT_EQ(kOpenerId, render_thread_.opener_id());
  ASSERT_TRUE(render_thread_.has_widget());

  // Now simulate a close of the Widget.
  render_thread_.SendCloseMessage();
  EXPECT_FALSE(render_thread_.has_widget());

  // Run the loop so the release task from the renderwidget executes.
  msg_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask());
  msg_loop_.Run();
}