| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "content/renderer/pepper/ppapi_unittest.h" | 5 #include "content/renderer/pepper/ppapi_unittest.h" |
| 6 | 6 |
| 7 #include "base/message_loop/message_loop.h" | 7 #include "base/message_loop/message_loop.h" |
| 8 #include "content/renderer/pepper/gfx_conversion.h" | 8 #include "content/renderer/pepper/gfx_conversion.h" |
| 9 #include "content/renderer/pepper/host_globals.h" | 9 #include "content/renderer/pepper/host_globals.h" |
| 10 #include "content/renderer/pepper/mock_plugin_delegate.h" | |
| 11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 10 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
| 12 #include "content/renderer/pepper/plugin_module.h" | 11 #include "content/renderer/pepper/plugin_module.h" |
| 12 #include "ppapi/c/pp_errors.h" |
| 13 #include "ppapi/c/pp_var.h" | 13 #include "ppapi/c/pp_var.h" |
| 14 #include "ppapi/c/ppp_instance.h" | 14 #include "ppapi/c/ppp_instance.h" |
| 15 #include "ppapi/shared_impl/ppapi_globals.h" | 15 #include "ppapi/shared_impl/ppapi_globals.h" |
| 16 #include "ppapi/shared_impl/ppapi_permissions.h" | 16 #include "ppapi/shared_impl/ppapi_permissions.h" |
| 17 | 17 |
| 18 namespace content { | 18 namespace content { |
| 19 | 19 |
| 20 namespace { | 20 namespace { |
| 21 | 21 |
| 22 PpapiUnittest* current_unittest = NULL; | 22 PpapiUnittest* current_unittest = NULL; |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 69 current_unittest = this; | 69 current_unittest = this; |
| 70 } | 70 } |
| 71 | 71 |
| 72 PpapiUnittest::~PpapiUnittest() { | 72 PpapiUnittest::~PpapiUnittest() { |
| 73 DCHECK(current_unittest == this); | 73 DCHECK(current_unittest == this); |
| 74 current_unittest = NULL; | 74 current_unittest = NULL; |
| 75 } | 75 } |
| 76 | 76 |
| 77 void PpapiUnittest::SetUp() { | 77 void PpapiUnittest::SetUp() { |
| 78 message_loop_.reset(new base::MessageLoop()); | 78 message_loop_.reset(new base::MessageLoop()); |
| 79 delegate_.reset(new MockPluginDelegate()); | |
| 80 | 79 |
| 81 // Initialize the mock module. | 80 // Initialize the mock module. |
| 82 module_ = new PluginModule("Mock plugin", base::FilePath(), | 81 module_ = new PluginModule("Mock plugin", base::FilePath(), |
| 83 ::ppapi::PpapiPermissions()); | 82 ::ppapi::PpapiPermissions()); |
| 84 ::ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); | 83 ::ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); |
| 85 PepperPluginInfo::EntryPoints entry_points; | 84 PepperPluginInfo::EntryPoints entry_points; |
| 86 entry_points.get_interface = &MockGetInterface; | 85 entry_points.get_interface = &MockGetInterface; |
| 87 entry_points.initialize_module = &MockInitializeModule; | 86 entry_points.initialize_module = &MockInitializeModule; |
| 88 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); | 87 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); |
| 89 | 88 |
| 90 // Initialize the mock instance. | 89 // Initialize the mock instance. |
| 91 instance_ = PepperPluginInstanceImpl::Create( | 90 instance_ = PepperPluginInstanceImpl::Create( |
| 92 delegate_.get(), NULL, module(), NULL, GURL()); | 91 NULL, NULL, module(), NULL, GURL()); |
| 93 } | 92 } |
| 94 | 93 |
| 95 void PpapiUnittest::TearDown() { | 94 void PpapiUnittest::TearDown() { |
| 96 instance_ = NULL; | 95 instance_ = NULL; |
| 97 module_ = NULL; | 96 module_ = NULL; |
| 98 message_loop_.reset(); | 97 message_loop_.reset(); |
| 99 PluginModule::ResetHostGlobalsForTest(); | 98 PluginModule::ResetHostGlobalsForTest(); |
| 100 } | 99 } |
| 101 | 100 |
| 102 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { | 101 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { |
| 103 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) | 102 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) |
| 104 return &mock_instance_interface; | 103 return &mock_instance_interface; |
| 105 return NULL; | 104 return NULL; |
| 106 } | 105 } |
| 107 | 106 |
| 108 void PpapiUnittest::ShutdownModule() { | 107 void PpapiUnittest::ShutdownModule() { |
| 109 DCHECK(instance_->HasOneRef()); | 108 DCHECK(instance_->HasOneRef()); |
| 110 instance_ = NULL; | 109 instance_ = NULL; |
| 111 DCHECK(module_->HasOneRef()); | 110 DCHECK(module_->HasOneRef()); |
| 112 module_ = NULL; | 111 module_ = NULL; |
| 113 } | 112 } |
| 114 | 113 |
| 115 void PpapiUnittest::SetViewSize(int width, int height) const { | 114 void PpapiUnittest::SetViewSize(int width, int height) const { |
| 116 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); | 115 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); |
| 117 instance_->view_data_.clip_rect = instance_->view_data_.rect; | 116 instance_->view_data_.clip_rect = instance_->view_data_.rect; |
| 118 } | 117 } |
| 119 | 118 |
| 120 } // namespace content | 119 } // namespace content |
| OLD | NEW |