summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 19:41:16 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-03 19:41:16 +0000
commit1b8f411d2daf5212f678ea1493b6bd5416d0c8ad (patch)
treee10297c768c79c2cecd2fb3b49fb5a1ae98a20d1 /o3d
parentb6aa587dc3d810cbc73ad9f3f3ec062cb231d869 (diff)
downloadchromium_src-1b8f411d2daf5212f678ea1493b6bd5416d0c8ad.zip
chromium_src-1b8f411d2daf5212f678ea1493b6bd5416d0c8ad.tar.gz
chromium_src-1b8f411d2daf5212f678ea1493b6bd5416d0c8ad.tar.bz2
Exracted CommandBuffer class from GPUPluginObject.
TEST=none BUG=none Review URL: http://codereview.chromium.org/200005 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25348 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/gpu_plugin/command_buffer.cc65
-rw-r--r--o3d/gpu_plugin/command_buffer.h48
-rw-r--r--o3d/gpu_plugin/command_buffer_mock.h30
-rw-r--r--o3d/gpu_plugin/command_buffer_unittest.cc121
-rw-r--r--o3d/gpu_plugin/gpu_plugin.gyp7
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object.cc32
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object.h7
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object_unittest.cc111
-rw-r--r--o3d/gpu_plugin/np_utils/np_browser_mock.h13
9 files changed, 314 insertions, 120 deletions
diff --git a/o3d/gpu_plugin/command_buffer.cc b/o3d/gpu_plugin/command_buffer.cc
new file mode 100644
index 0000000..c962f28
--- /dev/null
+++ b/o3d/gpu_plugin/command_buffer.cc
@@ -0,0 +1,65 @@
+// Copyright (c) 2006-2008 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 "o3d/gpu_plugin/command_buffer.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+CommandBuffer::CommandBuffer(NPP npp) : DispatchedNPObject(npp) {
+}
+
+CommandBuffer::~CommandBuffer() {
+ if (shared_memory_) {
+ NPBrowser::get()->UnmapSharedMemory(npp(), shared_memory_);
+ }
+}
+
+bool CommandBuffer::Initialize(int32 size) {
+ if (buffer_object_.Get())
+ return false;
+
+ NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
+ NPBrowser::get()->GetWindowNPObject(npp()));
+ if (!window.Get())
+ return false;
+
+ NPObjectPointer<NPObject> chromium;
+ if (!NPGetProperty(npp(), window, "chromium", &chromium)) {
+ return false;
+ }
+
+ NPObjectPointer<NPObject> system;
+ if (!NPGetProperty(npp(), chromium, "system", &system)) {
+ return false;
+ }
+
+ if (!NPInvoke(npp(), system, "createSharedMemory", size,
+ &buffer_object_)) {
+ return false;
+ }
+
+ shared_memory_ = NPBrowser::get()->MapSharedMemory(
+ npp(), buffer_object_.Get(), size, false);
+ if (!shared_memory_) {
+ buffer_object_ = NPObjectPointer<NPObject>();
+ return false;
+ }
+
+ return true;
+}
+
+NPObjectPointer<NPObject> CommandBuffer::GetBuffer() {
+ return buffer_object_;
+}
+
+void CommandBuffer::SetPutOffset(int32 offset) {
+}
+
+int32 CommandBuffer::GetGetOffset() {
+ return 0;
+}
+
+} // namespace gpu_plugin
+} // namespace o3d
diff --git a/o3d/gpu_plugin/command_buffer.h b/o3d/gpu_plugin/command_buffer.h
new file mode 100644
index 0000000..454e48a
--- /dev/null
+++ b/o3d/gpu_plugin/command_buffer.h
@@ -0,0 +1,48 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef O3D_GPU_PLUGIN_COMMAND_BUFFER_H_
+#define O3D_GPU_PLUGIN_COMMAND_BUFFER_H_
+
+#include "o3d/gpu_plugin/np_utils/dispatched_np_object.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+// An NPObject that implements a shared memory command buffer and a synchronous
+// API to manage the put and get pointers.
+class CommandBuffer : public DispatchedNPObject {
+ public:
+ explicit CommandBuffer(NPP npp);
+ virtual ~CommandBuffer();
+
+ // Create a shared memory buffer of the given size.
+ virtual bool Initialize(int32 size);
+
+ // Gets the shared memory object for the command buffer.
+ virtual NPObjectPointer<NPObject> GetBuffer();
+
+ // The client calls this to update its put offset.
+ virtual void SetPutOffset(int32 offset);
+
+ // The client calls this to get the servers current get offset.
+ virtual int32 GetGetOffset();
+
+ protected:
+ NP_UTILS_BEGIN_DISPATCHER_CHAIN(CommandBuffer, DispatchedNPObject)
+ NP_UTILS_DISPATCHER(Initialize, bool(int32))
+ NP_UTILS_DISPATCHER(SetPutOffset, void(int32))
+ NP_UTILS_DISPATCHER(GetGetOffset, int32())
+ NP_UTILS_DISPATCHER(GetBuffer, NPObjectPointer<NPObject>())
+ NP_UTILS_END_DISPATCHER_CHAIN
+
+ private:
+ NPObjectPointer<NPObject> buffer_object_;
+ NPSharedMemory* shared_memory_;
+};
+
+} // namespace gpu_plugin
+} // namespace o3d
+
+#endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_H_
diff --git a/o3d/gpu_plugin/command_buffer_mock.h b/o3d/gpu_plugin/command_buffer_mock.h
new file mode 100644
index 0000000..9d3f799
--- /dev/null
+++ b/o3d/gpu_plugin/command_buffer_mock.h
@@ -0,0 +1,30 @@
+// Copyright (c) 2006-2008 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.
+
+#ifndef O3D_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_
+#define O3D_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_
+
+#include "o3d/gpu_plugin/command_buffer.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+// An NPObject that implements a shared memory command buffer and a synchronous
+// API to manage the put and get pointers.
+class MockCommandBuffer : public CommandBuffer {
+ public:
+ explicit MockCommandBuffer(NPP npp) : CommandBuffer(npp) {
+ }
+
+ MOCK_METHOD1(Initialize, bool(int32));
+ MOCK_METHOD0(GetBuffer, NPObjectPointer<NPObject>());
+ MOCK_METHOD1(SetPutOffset, void(int32));
+ MOCK_METHOD0(GetGetOffset, int32());
+};
+
+} // namespace gpu_plugin
+} // namespace o3d
+
+#endif // O3D_GPU_PLUGIN_COMMAND_BUFFER_MOCK_H_
diff --git a/o3d/gpu_plugin/command_buffer_unittest.cc b/o3d/gpu_plugin/command_buffer_unittest.cc
new file mode 100644
index 0000000..335a2cc
--- /dev/null
+++ b/o3d/gpu_plugin/command_buffer_unittest.cc
@@ -0,0 +1,121 @@
+// Copyright (c) 2006-2008 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 "o3d/gpu_plugin/command_buffer.h"
+#include "o3d/gpu_plugin/np_utils/base_np_object_mock.h"
+#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h"
+#include "o3d/gpu_plugin/np_utils/np_browser_mock.h"
+#include "o3d/gpu_plugin/np_utils/np_object_pointer.h"
+#include "testing/gtest/include/gtest/gtest.h"
+#include "testing/gmock/include/gmock/gmock.h"
+
+using testing::_;
+using testing::DoAll;
+using testing::Return;
+using testing::SetArgumentPointee;
+using testing::StrictMock;
+
+namespace o3d {
+namespace gpu_plugin {
+
+class MockSystemNPObject : public DispatchedNPObject {
+ public:
+ explicit MockSystemNPObject(NPP npp) : DispatchedNPObject(npp) {
+ }
+
+ MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32));
+
+ protected:
+ NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DispatchedNPObject)
+ NP_UTILS_DISPATCHER(CreateSharedMemory, NPObjectPointer<NPObject>(int32))
+ NP_UTILS_END_DISPATCHER_CHAIN
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject);
+};
+
+class CommandBufferTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ command_buffer_object_ = NPCreateObject<CommandBuffer>(NULL);
+
+ window_object_ = NPCreateObject<DynamicNPObject>(NULL);
+
+ chromium_object_ = NPCreateObject<DynamicNPObject>(NULL);
+ NPSetProperty(NULL, window_object_, "chromium", chromium_object_);
+
+ system_object_ = NPCreateObject<StrictMock<MockSystemNPObject> >(NULL);
+ NPSetProperty(NULL, chromium_object_, "system", system_object_);
+ }
+
+ MockNPBrowser mock_browser_;
+ NPObjectPointer<CommandBuffer> command_buffer_object_;
+ NPObjectPointer<DynamicNPObject> window_object_;
+ NPObjectPointer<DynamicNPObject> chromium_object_;
+ NPObjectPointer<MockSystemNPObject> system_object_;
+};
+
+TEST_F(CommandBufferTest, TestBehaviorWhileUninitialized) {
+ EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer());
+ EXPECT_EQ(0, command_buffer_object_->GetGetOffset());
+}
+
+TEST_F(CommandBufferTest, InitializesCommandBuffer) {
+ EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
+ .WillOnce(Return(window_object_.ToReturned()));
+
+ NPObjectPointer<BaseNPObject> expected_buffer =
+ NPCreateObject<BaseNPObject>(NULL);
+
+ EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
+ .WillOnce(Return(expected_buffer));
+
+ NPSharedMemory shared_memory;
+
+ EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
+ expected_buffer.Get(),
+ 1024,
+ false))
+ .WillOnce(Return(&shared_memory));
+
+ EXPECT_TRUE(command_buffer_object_->Initialize(1024));
+ EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer());
+
+ // Cannot reinitialize.
+ EXPECT_FALSE(command_buffer_object_->Initialize(1024));
+ EXPECT_EQ(expected_buffer, command_buffer_object_->GetBuffer());
+}
+
+TEST_F(CommandBufferTest, InitializeFailsIfCannotCreateSharedMemory) {
+ EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
+ .WillOnce(Return(window_object_.ToReturned()));
+
+ EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
+ .WillOnce(Return(NPObjectPointer<BaseNPObject>()));
+
+ EXPECT_FALSE(command_buffer_object_->Initialize(1024));
+ EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer());
+}
+
+TEST_F(CommandBufferTest, InitializeFailsIfCannotMapSharedMemory) {
+ EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
+ .WillOnce(Return(window_object_.ToReturned()));
+
+ NPObjectPointer<BaseNPObject> expected_buffer =
+ NPCreateObject<BaseNPObject>(NULL);
+
+ EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
+ .WillOnce(Return(expected_buffer));
+
+ EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
+ expected_buffer.Get(),
+ 1024,
+ false))
+ .WillOnce(Return(static_cast<NPSharedMemory*>(NULL)));
+
+ EXPECT_FALSE(command_buffer_object_->Initialize(1024));
+ EXPECT_EQ(NPObjectPointer<NPObject>(), command_buffer_object_->GetBuffer());
+}
+} // namespace gpu_plugin
+} // namespace o3d
diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp
index 2f0d1a6..3e1eb52 100644
--- a/o3d/gpu_plugin/gpu_plugin.gyp
+++ b/o3d/gpu_plugin/gpu_plugin.gyp
@@ -18,6 +18,8 @@
'../../third_party/npapi',
],
'sources': [
+ 'command_buffer.cc',
+ 'command_buffer.h',
'gpu_plugin.cc',
'gpu_plugin.h',
'gpu_plugin_object.cc',
@@ -60,14 +62,17 @@
'../../third_party/npapi',
],
'sources': [
+ 'command_buffer_mock.h',
+ 'command_buffer_unittest.cc',
'gpu_plugin_unittest.cc',
'gpu_plugin_object_unittest.cc',
'gpu_plugin_object_factory_unittest.cc',
'np_utils/base_np_object_mock.cc',
'np_utils/base_np_object_mock.h',
'np_utils/base_np_object_unittest.cc',
- 'np_utils/np_browser_stub.h',
+ 'np_utils/np_browser_mock.h',
'np_utils/np_browser_stub.cc',
+ 'np_utils/np_browser_stub.h',
'np_utils/dispatched_np_object_unittest.cc',
'np_utils/dynamic_np_object_unittest.cc',
'np_utils/np_object_pointer_unittest.cc',
diff --git a/o3d/gpu_plugin/gpu_plugin_object.cc b/o3d/gpu_plugin/gpu_plugin_object.cc
index c83dd03..9187f08 100644
--- a/o3d/gpu_plugin/gpu_plugin_object.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object.cc
@@ -10,7 +10,9 @@
namespace o3d {
namespace gpu_plugin {
+namespace {
const int32 kCommandBufferSize = 1024;
+} // namespace anonymous
const NPUTF8 GPUPluginObject::kPluginType[] =
"application/vnd.google.chrome.gpu-plugin";
@@ -61,7 +63,7 @@ NPError GPUPluginObject::Destroy(NPSavedData** saved) {
NPBrowser::get()->UnmapSharedMemory(npp(), shared_memory_);
}
- command_buffer_object_ = NPObjectPointer<NPObject>();
+ command_buffer_object_ = NPObjectPointer<CommandBuffer>();
status_ = DESTROYED;
@@ -82,31 +84,9 @@ NPObjectPointer<NPObject> GPUPluginObject::OpenCommandBuffer() {
if (command_buffer_object_.Get())
return command_buffer_object_;
- NPObjectPointer<NPObject> window = NPObjectPointer<NPObject>::FromReturned(
- NPBrowser::get()->GetWindowNPObject(npp()));
- if (!window.Get())
- return NPObjectPointer<NPObject>();
-
- NPObjectPointer<NPObject> chromium;
- if (!NPGetProperty(npp(), window, "chromium", &chromium)) {
- return NPObjectPointer<NPObject>();
- }
-
- NPObjectPointer<NPObject> system;
- if (!NPGetProperty(npp(), chromium, "system", &system)) {
- return NPObjectPointer<NPObject>();
- }
-
- if (!NPInvoke(npp(), system, "createSharedMemory", kCommandBufferSize,
- &command_buffer_object_)) {
- return NPObjectPointer<NPObject>();
- }
-
- shared_memory_ = NPBrowser::get()->MapSharedMemory(
- npp(), command_buffer_object_.Get(), 1024, false);
- if (!shared_memory_) {
- command_buffer_object_ = NPObjectPointer<NPObject>();
- return NPObjectPointer<NPObject>();
+ command_buffer_object_ = NPCreateObject<CommandBuffer>(npp());
+ if (!command_buffer_object_->Initialize(kCommandBufferSize)) {
+ command_buffer_object_ = NPObjectPointer<CommandBuffer>();
}
return command_buffer_object_;
diff --git a/o3d/gpu_plugin/gpu_plugin_object.h b/o3d/gpu_plugin/gpu_plugin_object.h
index ec4c8c3..5bafa0a 100644
--- a/o3d/gpu_plugin/gpu_plugin_object.h
+++ b/o3d/gpu_plugin/gpu_plugin_object.h
@@ -7,6 +7,7 @@
#include <string>
+#include "o3d/gpu_plugin/command_buffer.h"
#include "o3d/gpu_plugin/np_utils/dispatched_np_object.h"
#include "o3d/gpu_plugin/np_utils/np_dispatcher.h"
#include "o3d/gpu_plugin/np_utils/np_plugin_object.h"
@@ -14,8 +15,6 @@
#include "third_party/npapi/bindings/npapi.h"
#include "third_party/npapi/bindings/npruntime.h"
-struct NaClDesc;
-
namespace o3d {
namespace gpu_plugin {
@@ -43,7 +42,7 @@ class GPUPluginObject : public DispatchedNPObject, public PluginObject {
virtual NPObject* GetScriptableNPObject();
- // Opens and returns the command buffer shared memory object.
+ // Initializes and returns the command buffer object.
NPObjectPointer<NPObject> OpenCommandBuffer();
protected:
@@ -62,7 +61,7 @@ class GPUPluginObject : public DispatchedNPObject, public PluginObject {
Status status_;
NPWindow window_;
- NPObjectPointer<NPObject> command_buffer_object_;
+ NPObjectPointer<CommandBuffer> command_buffer_object_;
NPSharedMemory* shared_memory_;
};
diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
index 30e9287..35bccc8 100644
--- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
@@ -2,9 +2,9 @@
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
+#include "o3d/gpu_plugin/command_buffer_mock.h"
#include "o3d/gpu_plugin/gpu_plugin_object.h"
#include "o3d/gpu_plugin/np_utils/base_np_object_mock.h"
-#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h"
#include "o3d/gpu_plugin/np_utils/np_browser_mock.h"
#include "o3d/gpu_plugin/np_utils/np_object_pointer.h"
#include "testing/gtest/include/gtest/gtest.h"
@@ -20,41 +20,14 @@ using testing::StrictMock;
namespace o3d {
namespace gpu_plugin {
-class MockSystemNPObject : public DispatchedNPObject {
- public:
- explicit MockSystemNPObject(NPP npp) : DispatchedNPObject(npp) {
- }
-
- MOCK_METHOD1(CreateSharedMemory, NPObjectPointer<NPObject>(int32));
-
- protected:
- NP_UTILS_BEGIN_DISPATCHER_CHAIN(MockSystemNPObject, DispatchedNPObject)
- NP_UTILS_DISPATCHER(CreateSharedMemory, NPObjectPointer<NPObject>(int32))
- NP_UTILS_END_DISPATCHER_CHAIN
-
- private:
- DISALLOW_COPY_AND_ASSIGN(MockSystemNPObject);
-};
-
class GPUPluginObjectTest : public testing::Test {
protected:
virtual void SetUp() {
plugin_object_ = NPCreateObject<GPUPluginObject>(NULL);
-
- window_object_ = NPCreateObject<DynamicNPObject>(NULL);
-
- chromium_object_ = NPCreateObject<DynamicNPObject>(NULL);
- NPSetProperty(NULL, window_object_, "chromium", chromium_object_);
-
- system_object_ = NPCreateObject<StrictMock<MockSystemNPObject> >(NULL);
- NPSetProperty(NULL, chromium_object_, "system", system_object_);
}
MockNPBrowser mock_browser_;
NPObjectPointer<GPUPluginObject> plugin_object_;
- NPObjectPointer<DynamicNPObject> window_object_;
- NPObjectPointer<DynamicNPObject> chromium_object_;
- NPObjectPointer<MockSystemNPObject> system_object_;
};
TEST_F(GPUPluginObjectTest, CanInitializeAndDestroyPluginObject) {
@@ -129,23 +102,16 @@ TEST_F(GPUPluginObjectTest, CanGetScriptableNPObject) {
EXPECT_EQ(plugin_object_.Get(), plugin_object_->GetScriptableNPObject());
}
-TEST_F(GPUPluginObjectTest, OpenCommandBufferCreatesAndMapsCommandBuffer) {
- EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
- .WillOnce(Return(window_object_.ToReturned()));
-
- NPObjectPointer<BaseNPObject> expected_command_buffer =
- NPCreateObject<BaseNPObject>(NULL);
-
- EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
- .WillOnce(Return(expected_command_buffer));
+TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsInitializedCommandBuffer) {
+ // Intercept creation of command buffer object and return mock.
+ NPObjectPointer<MockCommandBuffer> command_buffer_object =
+ NPCreateObject<StrictMock<MockCommandBuffer> >(NULL);
+ EXPECT_CALL(mock_browser_, CreateObject(NULL,
+ BaseNPObject::GetNPClass<CommandBuffer>()))
+ .WillOnce(Return(command_buffer_object.ToReturned()));
- NPSharedMemory shared_memory;
-
- EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
- expected_command_buffer.Get(),
- 1024,
- false))
- .WillOnce(Return(&shared_memory));
+ EXPECT_CALL(*command_buffer_object.Get(), Initialize(1024))
+ .WillOnce(Return(true));
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
0,
@@ -153,54 +119,24 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferCreatesAndMapsCommandBuffer) {
NULL,
NULL));
- NPObjectPointer<NPObject> actual_command_buffer =
- plugin_object_->OpenCommandBuffer();
-
- EXPECT_EQ(expected_command_buffer, actual_command_buffer);
+ EXPECT_EQ(command_buffer_object, plugin_object_->OpenCommandBuffer());
// Calling OpenCommandBuffer again just returns the existing command buffer.
- actual_command_buffer = plugin_object_->OpenCommandBuffer();
- EXPECT_EQ(expected_command_buffer, actual_command_buffer);
-
- EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
-}
-
-TEST_F(GPUPluginObjectTest, OpenCommandBufferFailsIfCannotCreateSharedMemory) {
- EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
- .WillOnce(Return(window_object_.ToReturned()));
-
- EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
- .WillOnce(Return(NPObjectPointer<BaseNPObject>()));
-
- EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
- 0,
- NULL,
- NULL,
- NULL));
-
- NPObjectPointer<NPObject> actual_command_buffer =
- plugin_object_->OpenCommandBuffer();
-
- EXPECT_EQ(NPObjectPointer<NPObject>(), actual_command_buffer);
+ EXPECT_EQ(command_buffer_object, plugin_object_->OpenCommandBuffer());
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
-TEST_F(GPUPluginObjectTest, OpenCommandBufferFailsIfCannotMapSharedMemory) {
- EXPECT_CALL(mock_browser_, GetWindowNPObject(NULL))
- .WillOnce(Return(window_object_.ToReturned()));
+TEST_F(GPUPluginObjectTest, OpenCommandBufferReturnsNullIfCannotInitialize) {
+ // Intercept creation of command buffer object and return mock.
+ NPObjectPointer<MockCommandBuffer> command_buffer_object =
+ NPCreateObject<StrictMock<MockCommandBuffer> >(NULL);
+ EXPECT_CALL(mock_browser_, CreateObject(NULL,
+ BaseNPObject::GetNPClass<CommandBuffer>()))
+ .WillOnce(Return(command_buffer_object.ToReturned()));
- NPObjectPointer<BaseNPObject> expected_command_buffer =
- NPCreateObject<BaseNPObject>(NULL);
-
- EXPECT_CALL(*system_object_.Get(), CreateSharedMemory(1024))
- .WillOnce(Return(expected_command_buffer));
-
- EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
- expected_command_buffer.Get(),
- 1024,
- false))
- .WillOnce(Return(static_cast<NPSharedMemory*>(NULL)));
+ EXPECT_CALL(*command_buffer_object.Get(), Initialize(1024))
+ .WillOnce(Return(false));
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
0,
@@ -208,10 +144,7 @@ TEST_F(GPUPluginObjectTest, OpenCommandBufferFailsIfCannotMapSharedMemory) {
NULL,
NULL));
- NPObjectPointer<NPObject> actual_command_buffer =
- plugin_object_->OpenCommandBuffer();
-
- EXPECT_EQ(NPObjectPointer<NPObject>(), actual_command_buffer);
+ EXPECT_EQ(NPObjectPointer<NPObject>(), plugin_object_->OpenCommandBuffer());
EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
}
diff --git a/o3d/gpu_plugin/np_utils/np_browser_mock.h b/o3d/gpu_plugin/np_utils/np_browser_mock.h
index 9edb09a..dbbf548 100644
--- a/o3d/gpu_plugin/np_utils/np_browser_mock.h
+++ b/o3d/gpu_plugin/np_utils/np_browser_mock.h
@@ -17,6 +17,19 @@ namespace gpu_plugin {
// normal for these calls.
class MockNPBrowser : public StubNPBrowser {
public:
+ NPObject* ConcreteCreateObject(NPP npp, const NPClass* cl) {
+ return StubNPBrowser::CreateObject(npp, cl);
+ }
+
+ MockNPBrowser() {
+ // Do not mock CreateObject by default but allow it to be mocked so object
+ // creation can be intercepted.
+ ON_CALL(*this, CreateObject(testing::_, testing::_))
+ .WillByDefault(testing::Invoke(this,
+ &MockNPBrowser::ConcreteCreateObject));
+ }
+
+ MOCK_METHOD2(CreateObject, NPObject*(NPP, const NPClass*));
MOCK_METHOD1(GetWindowNPObject, NPObject*(NPP));
MOCK_METHOD4(MapSharedMemory, NPSharedMemory*(NPP, NPObject*, size_t, bool));
MOCK_METHOD2(UnmapSharedMemory, void(NPP, NPSharedMemory*));