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/test/ppapi_unittest.h" | 5 #include "content/test/ppapi_unittest.h" |
6 | 6 |
7 #include <stdint.h> | 7 #include <stdint.h> |
8 | 8 |
9 #include "base/message_loop/message_loop.h" | |
10 #include "content/renderer/pepper/gfx_conversion.h" | 9 #include "content/renderer/pepper/gfx_conversion.h" |
11 #include "content/renderer/pepper/host_globals.h" | 10 #include "content/renderer/pepper/host_globals.h" |
12 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" | 11 #include "content/renderer/pepper/pepper_plugin_instance_impl.h" |
13 #include "content/renderer/pepper/plugin_module.h" | 12 #include "content/renderer/pepper/plugin_module.h" |
14 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" | 13 #include "content/renderer/pepper/renderer_ppapi_host_impl.h" |
15 #include "ppapi/c/pp_errors.h" | 14 #include "ppapi/c/pp_errors.h" |
16 #include "ppapi/c/pp_var.h" | 15 #include "ppapi/c/pp_var.h" |
17 #include "ppapi/c/ppp_instance.h" | 16 #include "ppapi/c/ppp_instance.h" |
18 #include "ppapi/shared_impl/ppapi_globals.h" | 17 #include "ppapi/shared_impl/ppapi_globals.h" |
19 #include "ppapi/shared_impl/ppapi_permissions.h" | 18 #include "ppapi/shared_impl/ppapi_permissions.h" |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
71 DCHECK(!current_unittest); | 70 DCHECK(!current_unittest); |
72 current_unittest = this; | 71 current_unittest = this; |
73 } | 72 } |
74 | 73 |
75 PpapiUnittest::~PpapiUnittest() { | 74 PpapiUnittest::~PpapiUnittest() { |
76 DCHECK(current_unittest == this); | 75 DCHECK(current_unittest == this); |
77 current_unittest = NULL; | 76 current_unittest = NULL; |
78 } | 77 } |
79 | 78 |
80 void PpapiUnittest::SetUp() { | 79 void PpapiUnittest::SetUp() { |
81 message_loop_.reset(new base::MessageLoop()); | |
82 | |
83 // Initialize the mock module. | 80 // Initialize the mock module. |
84 ppapi::PpapiPermissions perms; | 81 ppapi::PpapiPermissions perms; |
85 module_ = new PluginModule("Mock plugin", "1.0", base::FilePath(), | 82 module_ = new PluginModule("Mock plugin", "1.0", base::FilePath(), |
86 perms); | 83 perms); |
87 ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); | 84 ppapi::PpapiGlobals::Get()->ResetMainThreadMessageLoopForTesting(); |
88 PepperPluginInfo::EntryPoints entry_points; | 85 PepperPluginInfo::EntryPoints entry_points; |
89 entry_points.get_interface = &MockGetInterface; | 86 entry_points.get_interface = &MockGetInterface; |
90 entry_points.initialize_module = &MockInitializeModule; | 87 entry_points.initialize_module = &MockInitializeModule; |
91 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); | 88 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); |
92 | 89 |
93 // Initialize renderer ppapi host. | 90 // Initialize renderer ppapi host. |
94 CHECK(RendererPpapiHostImpl::CreateOnModuleForInProcess(module(), perms)); | 91 CHECK(RendererPpapiHostImpl::CreateOnModuleForInProcess(module(), perms)); |
95 CHECK(module_->renderer_ppapi_host()); | 92 CHECK(module_->renderer_ppapi_host()); |
96 | 93 |
97 // Initialize the mock instance. | 94 // Initialize the mock instance. |
98 instance_ = PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL()); | 95 instance_ = PepperPluginInstanceImpl::Create(NULL, module(), NULL, GURL()); |
99 } | 96 } |
100 | 97 |
101 void PpapiUnittest::TearDown() { | 98 void PpapiUnittest::TearDown() { |
102 instance_ = NULL; | 99 instance_ = NULL; |
103 module_ = NULL; | 100 module_ = NULL; |
104 message_loop_.reset(); | |
105 PluginModule::ResetHostGlobalsForTest(); | 101 PluginModule::ResetHostGlobalsForTest(); |
106 } | 102 } |
107 | 103 |
108 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { | 104 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { |
109 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) | 105 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) |
110 return &mock_instance_interface; | 106 return &mock_instance_interface; |
111 return NULL; | 107 return NULL; |
112 } | 108 } |
113 | 109 |
114 void PpapiUnittest::ShutdownModule() { | 110 void PpapiUnittest::ShutdownModule() { |
115 DCHECK(instance_->HasOneRef()); | 111 DCHECK(instance_->HasOneRef()); |
116 instance_ = NULL; | 112 instance_ = NULL; |
117 DCHECK(module_->HasOneRef()); | 113 DCHECK(module_->HasOneRef()); |
118 module_ = NULL; | 114 module_ = NULL; |
119 } | 115 } |
120 | 116 |
121 void PpapiUnittest::SetViewSize(int width, int height) const { | 117 void PpapiUnittest::SetViewSize(int width, int height) const { |
122 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); | 118 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); |
123 instance_->view_data_.clip_rect = instance_->view_data_.rect; | 119 instance_->view_data_.clip_rect = instance_->view_data_.rect; |
124 } | 120 } |
125 | 121 |
126 } // namespace content | 122 } // namespace content |
OLD | NEW |