blob: 6c2b24f5077e185615776960c18980693a56c8e2 [file] [log] [blame]
// 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();
}