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 "webkit/plugins/ppapi/ppapi_unittest.h" | 5 #include "webkit/plugins/ppapi/ppapi_unittest.h" |
6 | 6 |
| 7 #include "base/message_loop.h" |
7 #include "ppapi/c/pp_var.h" | 8 #include "ppapi/c/pp_var.h" |
8 #include "ppapi/c/ppp_instance.h" | 9 #include "ppapi/c/ppp_instance.h" |
9 #include "ppapi/shared_impl/ppapi_permissions.h" | 10 #include "ppapi/shared_impl/ppapi_permissions.h" |
10 #include "webkit/plugins/ppapi/gfx_conversion.h" | 11 #include "webkit/plugins/ppapi/gfx_conversion.h" |
11 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" | 12 #include "webkit/plugins/ppapi/mock_plugin_delegate.h" |
12 #include "webkit/plugins/ppapi/plugin_module.h" | 13 #include "webkit/plugins/ppapi/plugin_module.h" |
13 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" | 14 #include "webkit/plugins/ppapi/ppapi_interface_factory.h" |
14 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" | 15 #include "webkit/plugins/ppapi/ppapi_plugin_instance.h" |
15 | 16 |
16 namespace webkit { | 17 namespace webkit { |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
67 DCHECK(!current_unittest); | 68 DCHECK(!current_unittest); |
68 current_unittest = this; | 69 current_unittest = this; |
69 } | 70 } |
70 | 71 |
71 PpapiUnittest::~PpapiUnittest() { | 72 PpapiUnittest::~PpapiUnittest() { |
72 DCHECK(current_unittest == this); | 73 DCHECK(current_unittest == this); |
73 current_unittest = NULL; | 74 current_unittest = NULL; |
74 } | 75 } |
75 | 76 |
76 void PpapiUnittest::SetUp() { | 77 void PpapiUnittest::SetUp() { |
| 78 message_loop_.reset(new base::MessageLoop()); |
77 delegate_.reset(NewPluginDelegate()); | 79 delegate_.reset(NewPluginDelegate()); |
78 | 80 |
79 // Initialize the mock module. | 81 // Initialize the mock module. |
80 module_ = new PluginModule("Mock plugin", base::FilePath(), this, | 82 module_ = new PluginModule("Mock plugin", base::FilePath(), this, |
81 ::ppapi::PpapiPermissions()); | 83 ::ppapi::PpapiPermissions()); |
82 PluginModule::EntryPoints entry_points; | 84 PluginModule::EntryPoints entry_points; |
83 entry_points.get_interface = &MockGetInterface; | 85 entry_points.get_interface = &MockGetInterface; |
84 entry_points.initialize_module = &MockInitializeModule; | 86 entry_points.initialize_module = &MockInitializeModule; |
85 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); | 87 ASSERT_TRUE(module_->InitAsInternalPlugin(entry_points)); |
86 | 88 |
87 // Initialize the mock instance. | 89 // Initialize the mock instance. |
88 instance_ = PluginInstance::Create(delegate_.get(), module(), NULL, GURL()); | 90 instance_ = PluginInstance::Create(delegate_.get(), module(), NULL, GURL()); |
89 } | 91 } |
90 | 92 |
91 void PpapiUnittest::TearDown() { | 93 void PpapiUnittest::TearDown() { |
92 instance_ = NULL; | 94 instance_ = NULL; |
93 module_ = NULL; | 95 module_ = NULL; |
| 96 message_loop_.reset(); |
94 } | 97 } |
95 | 98 |
96 MockPluginDelegate* PpapiUnittest::NewPluginDelegate() { | 99 MockPluginDelegate* PpapiUnittest::NewPluginDelegate() { |
97 return new MockPluginDelegate; | 100 return new MockPluginDelegate; |
98 } | 101 } |
99 | 102 |
100 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { | 103 const void* PpapiUnittest::GetMockInterface(const char* interface_name) const { |
101 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) | 104 if (strcmp(interface_name, PPP_INSTANCE_INTERFACE_1_0) == 0) |
102 return &mock_instance_interface; | 105 return &mock_instance_interface; |
103 return NULL; | 106 return NULL; |
(...skipping 10 matching lines...) Expand all Loading... |
114 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); | 117 instance_->view_data_.rect = PP_FromGfxRect(gfx::Rect(0, 0, width, height)); |
115 instance_->view_data_.clip_rect = instance_->view_data_.rect; | 118 instance_->view_data_.clip_rect = instance_->view_data_.rect; |
116 } | 119 } |
117 | 120 |
118 void PpapiUnittest::PluginModuleDead(PluginModule* /* dead_module */) { | 121 void PpapiUnittest::PluginModuleDead(PluginModule* /* dead_module */) { |
119 // Nothing needed (this is necessary to make the module compile). | 122 // Nothing needed (this is necessary to make the module compile). |
120 } | 123 } |
121 | 124 |
122 // Tests whether custom PPAPI interface factories are called when PPAPI | 125 // Tests whether custom PPAPI interface factories are called when PPAPI |
123 // interfaces are requested. | 126 // interfaces are requested. |
124 class PpapiCustomInterfaceFactoryTest | 127 class PpapiCustomInterfaceFactoryTest : public PpapiUnittest { |
125 : public testing::Test, | |
126 public webkit::ppapi::PluginDelegate::ModuleLifetime { | |
127 public: | 128 public: |
128 PpapiCustomInterfaceFactoryTest() {} | 129 PpapiCustomInterfaceFactoryTest() {} |
129 virtual ~PpapiCustomInterfaceFactoryTest() {} | 130 virtual ~PpapiCustomInterfaceFactoryTest() {} |
130 | 131 |
131 bool result() { | 132 bool result() { |
132 return result_; | 133 return result_; |
133 } | 134 } |
134 | 135 |
135 void reset_result() { | 136 void reset_result() { |
136 result_ = false; | 137 result_ = false; |
137 } | 138 } |
138 | 139 |
139 static const void* InterfaceFactory(const std::string& interface_name) { | 140 static const void* InterfaceFactory(const std::string& interface_name) { |
140 result_ = true; | 141 result_ = true; |
141 return NULL; | 142 return NULL; |
142 } | 143 } |
143 | 144 |
144 private: | 145 private: |
145 static bool result_; | 146 static bool result_; |
146 // ModuleLifetime implementation. | |
147 virtual void PluginModuleDead(PluginModule* dead_module) {} | |
148 }; | 147 }; |
149 | 148 |
150 bool PpapiCustomInterfaceFactoryTest::result_ = false; | 149 bool PpapiCustomInterfaceFactoryTest::result_ = false; |
151 | 150 |
152 // This test validates whether custom PPAPI interface factories are invoked in | 151 // This test validates whether custom PPAPI interface factories are invoked in |
153 // response to PluginModule::GetPluginInterface calls. | 152 // response to PluginModule::GetPluginInterface calls. |
154 TEST_F(PpapiCustomInterfaceFactoryTest, BasicFactoryTest) { | 153 TEST_F(PpapiCustomInterfaceFactoryTest, BasicFactoryTest) { |
155 PpapiInterfaceFactoryManager::GetInstance()->RegisterFactory( | 154 PpapiInterfaceFactoryManager::GetInstance()->RegisterFactory( |
156 PpapiCustomInterfaceFactoryTest::InterfaceFactory); | 155 PpapiCustomInterfaceFactoryTest::InterfaceFactory); |
157 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface"); | 156 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface"); |
158 EXPECT_TRUE(result()); | 157 EXPECT_TRUE(result()); |
159 | 158 |
160 reset_result(); | 159 reset_result(); |
161 PpapiInterfaceFactoryManager::GetInstance()->UnregisterFactory( | 160 PpapiInterfaceFactoryManager::GetInstance()->UnregisterFactory( |
162 PpapiCustomInterfaceFactoryTest::InterfaceFactory); | 161 PpapiCustomInterfaceFactoryTest::InterfaceFactory); |
163 | 162 |
164 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface"); | 163 (*PluginModule::GetLocalGetInterfaceFunc())("DummyInterface"); |
165 EXPECT_FALSE(result()); | 164 EXPECT_FALSE(result()); |
166 } | 165 } |
167 | 166 |
168 } // namespace ppapi | 167 } // namespace ppapi |
169 } // namespace webkit | 168 } // namespace webkit |
OLD | NEW |