OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 "o3d/gpu_plugin/command_buffer_mock.h" | 5 #include "o3d/gpu_plugin/command_buffer_mock.h" |
6 #include "o3d/gpu_plugin/gpu_plugin_object.h" | 6 #include "o3d/gpu_plugin/gpu_plugin_object.h" |
7 #include "o3d/gpu_plugin/gpu_processor_mock.h" | 7 #include "o3d/gpu_plugin/gpu_processor_mock.h" |
8 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" | 8 #include "o3d/gpu_plugin/np_utils/np_browser_mock.h" |
9 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" | 9 #include "o3d/gpu_plugin/np_utils/dynamic_np_object.h" |
10 #include "o3d/gpu_plugin/np_utils/np_object_mock.h" | 10 #include "o3d/gpu_plugin/np_utils/np_object_mock.h" |
(...skipping 149 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
160 window.x = 7; | 160 window.x = 7; |
161 | 161 |
162 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->SetWindow(&window)); | 162 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->SetWindow(&window)); |
163 EXPECT_EQ(0, memcmp(&window, &plugin_object_->GetWindow(), sizeof(window))); | 163 EXPECT_EQ(0, memcmp(&window, &plugin_object_->GetWindow(), sizeof(window))); |
164 EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, | 164 EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, |
165 plugin_object_->GetStatus()); | 165 plugin_object_->GetStatus()); |
166 | 166 |
167 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); | 167 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); |
168 } | 168 } |
169 | 169 |
| 170 TEST_F(GPUPluginObjectTest, CanGetWindowSize) { |
| 171 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", |
| 172 0, |
| 173 NULL, |
| 174 NULL, |
| 175 NULL)); |
| 176 |
| 177 NPWindow window = {0}; |
| 178 window.window = &window; |
| 179 window.x = 10; |
| 180 window.y = 10; |
| 181 window.width = 100; |
| 182 window.height = 200; |
| 183 |
| 184 EXPECT_EQ(0, plugin_object_->GetWidth()); |
| 185 EXPECT_EQ(0, plugin_object_->GetHeight()); |
| 186 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->SetWindow(&window)); |
| 187 EXPECT_EQ(100, plugin_object_->GetWidth()); |
| 188 EXPECT_EQ(200, plugin_object_->GetHeight()); |
| 189 |
| 190 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); |
| 191 } |
| 192 |
170 TEST_F(GPUPluginObjectTest, SetWindowFailsIfNotInitialized) { | 193 TEST_F(GPUPluginObjectTest, SetWindowFailsIfNotInitialized) { |
171 NPWindow window = {0}; | 194 NPWindow window = {0}; |
172 EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->SetWindow(&window)); | 195 EXPECT_EQ(NPERR_GENERIC_ERROR, plugin_object_->SetWindow(&window)); |
173 EXPECT_EQ(GPUPluginObject::kWaitingForNew, plugin_object_->GetStatus()); | 196 EXPECT_EQ(GPUPluginObject::kWaitingForNew, plugin_object_->GetStatus()); |
174 } | 197 } |
175 | 198 |
176 TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) { | 199 TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) { |
177 NPObject* scriptable_object = plugin_object_->GetScriptableNPObject(); | 200 NPObject* scriptable_object = plugin_object_->GetScriptableNPObject(); |
178 EXPECT_EQ(plugin_object_.Get(), scriptable_object); | 201 EXPECT_EQ(plugin_object_.Get(), scriptable_object); |
179 NPBrowser::get()->ReleaseObject(scriptable_object); | 202 NPBrowser::get()->ReleaseObject(scriptable_object); |
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
314 plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer); | 337 plugin_object_->set_status(GPUPluginObject::kWaitingForOpenCommandBuffer); |
315 | 338 |
316 EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); | 339 EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer()); |
317 | 340 |
318 EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, | 341 EXPECT_EQ(GPUPluginObject::kWaitingForOpenCommandBuffer, |
319 plugin_object_->GetStatus()); | 342 plugin_object_->GetStatus()); |
320 | 343 |
321 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); | 344 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); |
322 } | 345 } |
323 | 346 |
| 347 class MockEventSync : public DefaultNPObject<NPObject> { |
| 348 public: |
| 349 explicit MockEventSync(NPP npp) { |
| 350 } |
| 351 |
| 352 MOCK_METHOD2(Resize, void(int32 width, int32 height)); |
| 353 |
| 354 NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockEventSync, DefaultNPObject<NPObject>) |
| 355 NP_UTILS_DISPATCHER(Resize, void(int32 width, int32 height)) |
| 356 NP_UTILS_END_DISPATCHER_CHAIN |
| 357 |
| 358 private: |
| 359 DISALLOW_COPY_AND_ASSIGN(MockEventSync); |
| 360 }; |
| 361 |
| 362 TEST_F(GPUPluginObjectTest, SendsResizeEventOnSetWindow) { |
| 363 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo", |
| 364 0, |
| 365 NULL, |
| 366 NULL, |
| 367 NULL)); |
| 368 |
| 369 NPObjectPointer<MockEventSync> event_sync = |
| 370 NPCreateObject<MockEventSync>(NULL); |
| 371 plugin_object_->SetEventSync(event_sync); |
| 372 |
| 373 EXPECT_CALL(*event_sync.Get(), Resize(100, 200)); |
| 374 |
| 375 NPWindow window = {0}; |
| 376 window.window = &window; |
| 377 window.x = 10; |
| 378 window.y = 10; |
| 379 window.width = 100; |
| 380 window.height = 200; |
| 381 |
| 382 plugin_object_->SetWindow(&window); |
| 383 |
| 384 EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL)); |
| 385 } |
| 386 |
324 } // namespace gpu_plugin | 387 } // namespace gpu_plugin |
325 } // namespace o3d | 388 } // namespace o3d |
OLD | NEW |