| Index: content/renderer/pepper/unittest_instance_util.cc
|
| diff --git a/content/renderer/pepper/ppapi_unittest.cc b/content/renderer/pepper/unittest_instance_util.cc
|
| similarity index 57%
|
| copy from content/renderer/pepper/ppapi_unittest.cc
|
| copy to content/renderer/pepper/unittest_instance_util.cc
|
| index 7a94d87e5f2d0d35f1e38da1f0a0877072b1b998..82acf512a5252eddb6952d6da919579f9fa80439 100644
|
| --- a/content/renderer/pepper/ppapi_unittest.cc
|
| +++ b/content/renderer/pepper/unittest_instance_util.cc
|
| @@ -1,36 +1,27 @@
|
| -// Copyright (c) 2012 The Chromium Authors. All rights reserved.
|
| +// Copyright (c) 2013 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 "content/renderer/pepper/ppapi_unittest.h"
|
| +#include "content/renderer/pepper/unittest_instance_util.h"
|
|
|
| -#include "base/message_loop/message_loop.h"
|
| -#include "content/renderer/pepper/gfx_conversion.h"
|
| -#include "content/renderer/pepper/host_globals.h"
|
| +#include "base/logging.h"
|
| +#include "content/public/common/pepper_plugin_info.h"
|
| #include "content/renderer/pepper/pepper_plugin_instance_impl.h"
|
| #include "content/renderer/pepper/plugin_module.h"
|
| +#include "ppapi/c/pp_bool.h"
|
| #include "ppapi/c/pp_errors.h"
|
| -#include "ppapi/c/pp_var.h"
|
| #include "ppapi/c/ppp_instance.h"
|
| #include "ppapi/shared_impl/ppapi_globals.h"
|
| -#include "ppapi/shared_impl/ppapi_permissions.h"
|
|
|
| namespace content {
|
|
|
| namespace {
|
|
|
| -PpapiUnittest* current_unittest = NULL;
|
| -
|
| -const void* MockGetInterface(const char* interface_name) {
|
| - return current_unittest->GetMockInterface(interface_name);
|
| -}
|
| -
|
| int MockInitializeModule(PP_Module, PPB_GetInterface) {
|
| return PP_OK;
|
| }
|
|
|
| -// PPP_Instance implementation ------------------------------------------------
|
| -
|
| +// PPP_Instance implementation.
|
| PP_Bool Instance_DidCreate(PP_Instance pp_instance,
|
| uint32_t argc,
|
| const char* argn[],
|
| @@ -60,60 +51,54 @@ static PPP_Instance mock_instance_interface = {
|
| &Instance_HandleDocumentLoad
|
| };
|
|
|
| -} // namespace
|
| +const void* MockGetInterface(const char* interface_name) {
|
| + if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0)
|
| + return &mock_instance_interface;
|
| + return NULL;
|
| +}
|
|
|
| -// PpapiUnittest --------------------------------------------------------------
|
| +} // namespace
|
|
|
| -PpapiUnittest::PpapiUnittest() {
|
| - DCHECK(!current_unittest);
|
| - current_unittest = this;
|
| -}
|
| +UnittestInstanceUtil::UnittestInstanceUtil() : instance_(NULL),
|
| + module_(NULL) { }
|
|
|
| -PpapiUnittest::~PpapiUnittest() {
|
| - DCHECK(current_unittest == this);
|
| - current_unittest = NULL;
|
| +UnittestInstanceUtil::~UnittestInstanceUtil() {
|
| + DCHECK(!module_);
|
| + DCHECK(!instance_);
|
| }
|
|
|
| -void PpapiUnittest::SetUp() {
|
| - message_loop_.reset(new base::MessageLoop());
|
| -
|
| +bool UnittestInstanceUtil::SetUp() {
|
| + DCHECK(!module_);
|
| + DCHECK(!instance_);
|
| // Initialize the mock module.
|
| module_ = new PluginModule("Mock plugin", base::FilePath(),
|
| ::ppapi::PpapiPermissions());
|
| +
|
| ::ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting();
|
| PepperPluginInfo::EntryPoints entry_points;
|
| entry_points.get_interface = &MockGetInterface;
|
| entry_points.initialize_module = &MockInitializeModule;
|
| - ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points));
|
| + if (!module_->InitAsInternalPlugin(entry_points))
|
| + return false;
|
|
|
| // Initialize the mock instance.
|
| instance_ = PepperPluginInstanceImpl::Create(
|
| - NULL, NULL, module(), NULL, GURL());
|
| + NULL, NULL, module_, NULL, GURL());
|
| + return true;
|
| }
|
|
|
| -void PpapiUnittest::TearDown() {
|
| +void UnittestInstanceUtil::TearDown() {
|
| instance_ = NULL;
|
| module_ = NULL;
|
| - message_loop_.reset();
|
| PluginModule::ResetHostGlobalsForTest();
|
| }
|
|
|
| -const void* PpapiUnittest::GetMockInterface(const char* interface_name) const {
|
| - if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0)
|
| - return &mock_instance_interface;
|
| - return NULL;
|
| -}
|
| -
|
| -void PpapiUnittest::ShutdownModule() {
|
| - DCHECK(instance_->HasOneRef());
|
| - instance_ = NULL;
|
| - DCHECK(module_->HasOneRef());
|
| - module_ = NULL;
|
| +PepperPluginInstanceImpl* UnittestInstanceUtil::instance() const {
|
| + return instance_;
|
| }
|
|
|
| -void PpapiUnittest::SetViewSize(int width, int height) const {
|
| - instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height));
|
| - instance_->view_data_.clip_rect = instance_->view_data_.rect;
|
| +PluginModule* UnittestInstanceUtil::module() const {
|
| + return module_;
|
| }
|
|
|
| } // namespace content
|
|
|