summaryrefslogtreecommitdiffstats
path: root/o3d
diff options
context:
space:
mode:
authorapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 21:39:21 +0000
committerapatrick@google.com <apatrick@google.com@0039d316-1c4b-4281-b951-d872f2087c98>2009-09-02 21:39:21 +0000
commit6655e481d1af6acf30538050af3ffc6df0d8d577 (patch)
tree8991f4c6581d6b1fa20c7107bb81fe0e54543c76 /o3d
parent464dca7a6ff0f7649ec54fcac964306d07499c30 (diff)
downloadchromium_src-6655e481d1af6acf30538050af3ffc6df0d8d577.zip
chromium_src-6655e481d1af6acf30538050af3ffc6df0d8d577.tar.gz
chromium_src-6655e481d1af6acf30538050af3ffc6df0d8d577.tar.bz2
Wrote tests for GPUPluginObject::OpenCommandBuffer.
TEST=none BUG=none Review URL: http://codereview.chromium.org/188015 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@25244 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'o3d')
-rw-r--r--o3d/gpu_plugin/gpu_plugin.gyp3
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object.h1
-rw-r--r--o3d/gpu_plugin/gpu_plugin_object_unittest.cc115
-rw-r--r--o3d/gpu_plugin/np_utils/dispatched_np_object_unittest.cc54
-rw-r--r--o3d/gpu_plugin/np_utils/dynamic_np_object.cc61
-rw-r--r--o3d/gpu_plugin/np_utils/dynamic_np_object.h37
-rw-r--r--o3d/gpu_plugin/np_utils/dynamic_np_object_unittest.cc85
-rw-r--r--o3d/gpu_plugin/np_utils/np_browser.cc13
-rw-r--r--o3d/gpu_plugin/np_utils/np_browser.h9
-rw-r--r--o3d/gpu_plugin/np_utils/np_browser_stub.cc13
-rw-r--r--o3d/gpu_plugin/np_utils/np_browser_stub.h9
-rw-r--r--o3d/gpu_plugin/np_utils/np_utils.cc57
-rw-r--r--o3d/gpu_plugin/np_utils/np_utils.h33
-rw-r--r--o3d/gpu_plugin/np_utils/np_utils_unittest.cc66
14 files changed, 498 insertions, 58 deletions
diff --git a/o3d/gpu_plugin/gpu_plugin.gyp b/o3d/gpu_plugin/gpu_plugin.gyp
index 1c442ac8..2f0d1a6 100644
--- a/o3d/gpu_plugin/gpu_plugin.gyp
+++ b/o3d/gpu_plugin/gpu_plugin.gyp
@@ -29,6 +29,8 @@
'np_utils/base_np_object.h',
'np_utils/dispatched_np_object.cc',
'np_utils/dispatched_np_object.h',
+ 'np_utils/dynamic_np_object.cc',
+ 'np_utils/dynamic_np_object.h',
'np_utils/np_browser.cc',
'np_utils/np_browser.h',
'np_utils/np_dispatcher.h',
@@ -67,6 +69,7 @@
'np_utils/np_browser_stub.h',
'np_utils/np_browser_stub.cc',
'np_utils/dispatched_np_object_unittest.cc',
+ 'np_utils/dynamic_np_object_unittest.cc',
'np_utils/np_object_pointer_unittest.cc',
'np_utils/np_plugin_object_factory_mock.h',
'np_utils/np_plugin_object_mock.h',
diff --git a/o3d/gpu_plugin/gpu_plugin_object.h b/o3d/gpu_plugin/gpu_plugin_object.h
index d939982..ec4c8c3 100644
--- a/o3d/gpu_plugin/gpu_plugin_object.h
+++ b/o3d/gpu_plugin/gpu_plugin_object.h
@@ -43,6 +43,7 @@ class GPUPluginObject : public DispatchedNPObject, public PluginObject {
virtual NPObject* GetScriptableNPObject();
+ // Opens and returns the command buffer shared memory object.
NPObjectPointer<NPObject> OpenCommandBuffer();
protected:
diff --git a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
index 3cac993..30e9287 100644
--- a/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
+++ b/o3d/gpu_plugin/gpu_plugin_object_unittest.cc
@@ -4,6 +4,7 @@
#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"
@@ -19,14 +20,41 @@ 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) {
@@ -100,5 +128,92 @@ TEST_F(GPUPluginObjectTest, SetWindowFailsIfNotInitialized) {
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));
+
+ NPSharedMemory shared_memory;
+
+ EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
+ expected_command_buffer.Get(),
+ 1024,
+ false))
+ .WillOnce(Return(&shared_memory));
+
+ EXPECT_EQ(NPERR_NO_ERROR, plugin_object_->New("application/foo",
+ 0,
+ NULL,
+ NULL,
+ NULL));
+
+ NPObjectPointer<NPObject> actual_command_buffer =
+ plugin_object_->OpenCommandBuffer();
+
+ EXPECT_EQ(expected_command_buffer, actual_command_buffer);
+
+ // 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(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+}
+
+TEST_F(GPUPluginObjectTest, OpenCommandBufferFailsIfCannotMapSharedMemory) {
+ 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));
+
+ EXPECT_CALL(mock_browser_, MapSharedMemory(NULL,
+ expected_command_buffer.Get(),
+ 1024,
+ false))
+ .WillOnce(Return(static_cast<NPSharedMemory*>(NULL)));
+
+ 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(NPERR_NO_ERROR, plugin_object_->Destroy(NULL));
+}
} // namespace gpu_plugin
} // namespace o3d
diff --git a/o3d/gpu_plugin/np_utils/dispatched_np_object_unittest.cc b/o3d/gpu_plugin/np_utils/dispatched_np_object_unittest.cc
index 26a79a5..c8ad480 100644
--- a/o3d/gpu_plugin/np_utils/dispatched_np_object_unittest.cc
+++ b/o3d/gpu_plugin/np_utils/dispatched_np_object_unittest.cc
@@ -66,7 +66,7 @@ class MockDispatchedNPObject : public DispatchedNPObject {
NP_UTILS_END_DISPATCHER_CHAIN
};
-class NPObjectDispatcherTest : public testing::Test {
+class DispatchedNPObjectTest : public testing::Test {
protected:
virtual void SetUp() {
object_ = NPCreateObject<StrictMock<MockDispatchedNPObject> >(NULL);
@@ -85,7 +85,7 @@ class NPObjectDispatcherTest : public testing::Test {
NPObjectPointer<BaseNPObject> passed_object_;
};
-TEST_F(NPObjectDispatcherTest, CannotInvokeMissingFunction) {
+TEST_F(DispatchedNPObjectTest, CannotInvokeMissingFunction) {
EXPECT_FALSE(object_->Invoke(
NPBrowser::get()->GetStringIdentifier("missing"),
NULL,
@@ -94,7 +94,7 @@ TEST_F(NPObjectDispatcherTest, CannotInvokeMissingFunction) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnNoParams) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnNoParams) {
EXPECT_CALL(*object_, VoidReturnNoParams());
EXPECT_TRUE(object_->Invoke(
@@ -105,7 +105,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnNoParams) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest,
+TEST_F(DispatchedNPObjectTest,
CannotInvokeVoidReturnNoParamsWithTooManyParams) {
EXPECT_FALSE(object_->Invoke(
NPBrowser::get()->GetStringIdentifier("voidReturnNoParams"),
@@ -115,7 +115,7 @@ TEST_F(NPObjectDispatcherTest,
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnIntParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnIntParam) {
EXPECT_CALL(*object_, VoidReturnIntParam(7));
INT32_TO_NPVARIANT(7, args_[0]);
@@ -128,7 +128,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnIntParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnBoolParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnBoolParam) {
EXPECT_CALL(*object_, VoidReturnBoolParam(true));
BOOLEAN_TO_NPVARIANT(true, args_[0]);
@@ -141,7 +141,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnBoolParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnFloatParamWithDoubleParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnFloatParamWithDoubleParam) {
EXPECT_CALL(*object_, VoidReturnFloatParam(7.0f));
DOUBLE_TO_NPVARIANT(7.0, args_[0]);
@@ -154,7 +154,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnFloatParamWithDoubleParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnFloatParamWithIntParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnFloatParamWithIntParam) {
EXPECT_CALL(*object_, VoidReturnFloatParam(7.0f));
INT32_TO_NPVARIANT(7, args_[0]);
@@ -167,7 +167,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnFloatParamWithIntParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnDoubleParamWithDoubleParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnDoubleParamWithDoubleParam) {
EXPECT_CALL(*object_, VoidReturnDoubleParam(7.0));
DOUBLE_TO_NPVARIANT(7.0, args_[0]);
@@ -180,7 +180,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnDoubleParamWithDoubleParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnDoubleParamWithIntParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnDoubleParamWithIntParam) {
EXPECT_CALL(*object_, VoidReturnDoubleParam(7.0f));
INT32_TO_NPVARIANT(7, args_[0]);
@@ -193,7 +193,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnDoubleParamWithIntParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnStringParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnStringParam) {
EXPECT_CALL(*object_, VoidReturnStringParam(std::string("hello")));
STRINGZ_TO_NPVARIANT("hello", args_[0]);
@@ -206,7 +206,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnStringParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnObjectParamWithObject) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnObjectParamWithObject) {
EXPECT_CALL(*object_, VoidReturnObjectParam(passed_object_));
OBJECT_TO_NPVARIANT(passed_object_.Get(), args_[0]);
@@ -219,7 +219,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnObjectParamWithObject) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnObjectParamWithNull) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnObjectParamWithNull) {
EXPECT_CALL(
*object_,
VoidReturnObjectParam(NPObjectPointer<BaseNPObject>()));
@@ -234,7 +234,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnObjectParamWithNull) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnTwoParams) {
+TEST_F(DispatchedNPObjectTest, CanInvokeVoidReturnTwoParams) {
EXPECT_CALL(*object_, VoidReturnTwoParams(false, 7));
BOOLEAN_TO_NPVARIANT(false, args_[0]);
@@ -248,7 +248,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeVoidReturnTwoParams) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithNoParams) {
+TEST_F(DispatchedNPObjectTest, CanInvokeOverloadedWithNoParams) {
EXPECT_CALL(*object_, Overloaded());
EXPECT_TRUE(object_->Invoke(
@@ -259,7 +259,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithNoParams) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithOneStringParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeOverloadedWithOneStringParam) {
EXPECT_CALL(*object_, Overloaded(std::string("hello")));
STRINGZ_TO_NPVARIANT("hello", args_[0]);
@@ -272,7 +272,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithOneStringParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithOneBoolParam) {
+TEST_F(DispatchedNPObjectTest, CanInvokeOverloadedWithOneBoolParam) {
EXPECT_CALL(*object_, Overloaded(true));
BOOLEAN_TO_NPVARIANT(true, args_[0]);
@@ -285,7 +285,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeOverloadedWithOneBoolParam) {
EXPECT_TRUE(NPVARIANT_IS_VOID(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeBoolReturn) {
+TEST_F(DispatchedNPObjectTest, CanInvokeBoolReturn) {
EXPECT_CALL(*object_, BoolReturn()).WillOnce(Return(true));
EXPECT_TRUE(object_->Invoke(
@@ -297,7 +297,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeBoolReturn) {
EXPECT_TRUE(NPVARIANT_TO_BOOLEAN(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeIntReturn) {
+TEST_F(DispatchedNPObjectTest, CanInvokeIntReturn) {
EXPECT_CALL(*object_, IntReturn()).WillOnce(Return(7));
EXPECT_TRUE(object_->Invoke(
@@ -309,7 +309,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeIntReturn) {
EXPECT_EQ(7, NPVARIANT_TO_INT32(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeFloatReturn) {
+TEST_F(DispatchedNPObjectTest, CanInvokeFloatReturn) {
EXPECT_CALL(*object_, FloatReturn()).WillOnce(Return(7.0f));
EXPECT_TRUE(object_->Invoke(
@@ -321,7 +321,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeFloatReturn) {
EXPECT_EQ(7.0, NPVARIANT_TO_DOUBLE(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeDoubleReturn) {
+TEST_F(DispatchedNPObjectTest, CanInvokeDoubleReturn) {
EXPECT_CALL(*object_, DoubleReturn()).WillOnce(Return(7.0));
EXPECT_TRUE(object_->Invoke(
@@ -333,7 +333,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeDoubleReturn) {
EXPECT_EQ(7.0, NPVARIANT_TO_DOUBLE(result_));
}
-TEST_F(NPObjectDispatcherTest, CanInvokeStringReturn) {
+TEST_F(DispatchedNPObjectTest, CanInvokeStringReturn) {
EXPECT_CALL(*object_, StringReturn()).WillOnce(Return(std::string("hello")));
EXPECT_TRUE(object_->Invoke(
@@ -351,7 +351,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeStringReturn) {
NPBrowser::get()->ReleaseVariantValue(&result_);
}
-TEST_F(NPObjectDispatcherTest, CanInvokeObjectReturnWithObject) {
+TEST_F(DispatchedNPObjectTest, CanInvokeObjectReturnWithObject) {
EXPECT_CALL(*object_, ObjectReturn()).WillOnce(Return(passed_object_));
EXPECT_TRUE(object_->Invoke(
@@ -365,7 +365,7 @@ TEST_F(NPObjectDispatcherTest, CanInvokeObjectReturnWithObject) {
NPBrowser::get()->ReleaseVariantValue(&result_);
}
-TEST_F(NPObjectDispatcherTest, CanInvokeObjectReturnWithNull) {
+TEST_F(DispatchedNPObjectTest, CanInvokeObjectReturnWithNull) {
EXPECT_CALL(*object_, ObjectReturn())
.WillOnce(Return(NPObjectPointer<BaseNPObject>()));
@@ -377,17 +377,17 @@ TEST_F(NPObjectDispatcherTest, CanInvokeObjectReturnWithNull) {
EXPECT_TRUE(NPVARIANT_IS_NULL(result_));
}
-TEST_F(NPObjectDispatcherTest, HasMethodReturnsTrueIfMatchingMemberVariable) {
+TEST_F(DispatchedNPObjectTest, HasMethodReturnsTrueIfMatchingMemberVariable) {
EXPECT_TRUE(object_->HasMethod(
NPBrowser::get()->GetStringIdentifier("objectReturn")));
}
-TEST_F(NPObjectDispatcherTest, HasMethodReturnsTrueIfNoMatchingMemberVariable) {
+TEST_F(DispatchedNPObjectTest, HasMethodReturnsTrueIfNoMatchingMemberVariable) {
EXPECT_FALSE(object_->HasMethod(
NPBrowser::get()->GetStringIdentifier("missing")));
}
-TEST_F(NPObjectDispatcherTest, EnumeratesAllAvailableMethods) {
+TEST_F(DispatchedNPObjectTest, EnumeratesAllAvailableMethods) {
NPIdentifier* names;
uint32_t num_names;
ASSERT_TRUE(object_->Enumerate(&names, &num_names));
diff --git a/o3d/gpu_plugin/np_utils/dynamic_np_object.cc b/o3d/gpu_plugin/np_utils/dynamic_np_object.cc
new file mode 100644
index 0000000..3471e09
--- /dev/null
+++ b/o3d/gpu_plugin/np_utils/dynamic_np_object.cc
@@ -0,0 +1,61 @@
+// 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/np_utils/dynamic_np_object.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+DynamicNPObject::DynamicNPObject(NPP npp) : BaseNPObject(npp) {
+}
+
+void DynamicNPObject::Invalidate() {
+ for (PropertyMap::iterator it = properties_.begin();
+ it != properties_.end();
+ ++it) {
+ it->second.Invalidate();
+ }
+}
+
+bool DynamicNPObject::HasProperty(NPIdentifier name) {
+ PropertyMap::iterator it = properties_.find(name);
+ return it != properties_.end();
+}
+
+bool DynamicNPObject::GetProperty(NPIdentifier name, NPVariant* result) {
+ PropertyMap::iterator it = properties_.find(name);
+ if (it == properties_.end())
+ return false;
+
+ it->second.CopyTo(result);
+ return true;
+}
+
+bool DynamicNPObject::SetProperty(NPIdentifier name, const NPVariant* value) {
+ properties_[name] = *value;
+ return true;
+}
+
+bool DynamicNPObject::RemoveProperty(NPIdentifier name) {
+ properties_.erase(name);
+ return false;
+}
+
+bool DynamicNPObject::Enumerate(NPIdentifier** names, uint32_t* count) {
+ *names = static_cast<NPIdentifier*>(
+ NPBrowser::get()->MemAlloc(properties_.size() * sizeof(*names)));
+ *count = properties_.size();
+
+ int i = 0;
+ for (PropertyMap::iterator it = properties_.begin();
+ it != properties_.end();
+ ++it) {
+ (*names)[i] = it->first;
+ ++i;
+ }
+
+ return true;
+}
+} // namespace gpu_plugin
+} // namespace o3d
diff --git a/o3d/gpu_plugin/np_utils/dynamic_np_object.h b/o3d/gpu_plugin/np_utils/dynamic_np_object.h
new file mode 100644
index 0000000..a6b2cf9
--- /dev/null
+++ b/o3d/gpu_plugin/np_utils/dynamic_np_object.h
@@ -0,0 +1,37 @@
+// 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_NP_UTILS_DYNAMIC_NP_OBJECT_H_
+#define O3D_GPU_PLUGIN_NP_UTILS_DYNAMIC_NP_OBJECT_H_
+
+#include <map>
+
+#include "o3d/gpu_plugin/np_utils/base_np_object.h"
+#include "o3d/gpu_plugin/np_utils/np_utils.h"
+
+namespace o3d {
+namespace gpu_plugin {
+
+// NPObjects of this type have a dictionary of property name / variant pairs
+// that can be changed at runtime through NPAPI.
+class DynamicNPObject : public BaseNPObject {
+ public:
+ explicit DynamicNPObject(NPP npp);
+
+ virtual void Invalidate();
+ virtual bool HasProperty(NPIdentifier name);
+ virtual bool GetProperty(NPIdentifier name, NPVariant* result);
+ virtual bool SetProperty(NPIdentifier name, const NPVariant* value);
+ virtual bool RemoveProperty(NPIdentifier name);
+ virtual bool Enumerate(NPIdentifier** names, uint32_t* count);
+
+ private:
+ typedef std::map<NPIdentifier, SmartNPVariant> PropertyMap;
+ PropertyMap properties_;
+ DISALLOW_COPY_AND_ASSIGN(DynamicNPObject);
+};
+} // namespace gpu_plugin
+} // namespace o3d
+
+#endif // O3D_GPU_PLUGIN_NP_UTILS_DYNAMIC_NP_OBJECT_H_
diff --git a/o3d/gpu_plugin/np_utils/dynamic_np_object_unittest.cc b/o3d/gpu_plugin/np_utils/dynamic_np_object_unittest.cc
new file mode 100644
index 0000000..3cc8e89
--- /dev/null
+++ b/o3d/gpu_plugin/np_utils/dynamic_np_object_unittest.cc
@@ -0,0 +1,85 @@
+// 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 <string>
+
+#include "o3d/gpu_plugin/np_utils/dynamic_np_object.h"
+#include "o3d/gpu_plugin/np_utils/np_browser_stub.h"
+#include "o3d/gpu_plugin/np_utils/np_utils.h"
+#include "testing/gmock/include/gmock/gmock.h"
+#include "testing/gtest/include/gtest/gtest.h"
+
+using testing::Return;
+using testing::StrictMock;
+
+namespace o3d {
+namespace gpu_plugin {
+
+class NPDynamicNPObjectTest : public testing::Test {
+ protected:
+ virtual void SetUp() {
+ object_ = NPCreateObject<DynamicNPObject>(NULL);
+ }
+
+ StubNPBrowser stub_browser_;
+ NPObjectPointer<DynamicNPObject> object_;
+};
+
+TEST_F(NPDynamicNPObjectTest, HasPropertyReturnsFalseForMissingProperty) {
+ EXPECT_FALSE(NPHasProperty(NULL, object_, "missing"));
+}
+
+TEST_F(NPDynamicNPObjectTest, GetPropertyReturnsFalseForMissingProperty) {
+ int32 r;
+ EXPECT_FALSE(NPGetProperty(NULL, object_, "missing", &r));
+}
+
+TEST_F(NPDynamicNPObjectTest, CanSetProperty) {
+ EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));
+ int32 r;
+ EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
+ EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r));
+ EXPECT_EQ(7, r);
+}
+
+TEST_F(NPDynamicNPObjectTest, CanRemoveProperty) {
+ EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));
+ EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
+ EXPECT_FALSE(NPRemoveProperty(NULL, object_, "foo"));
+ EXPECT_FALSE(NPHasProperty(NULL, object_, "foo"));
+ int32 r;
+ EXPECT_FALSE(NPGetProperty(NULL, object_, "foo", &r));
+}
+
+TEST_F(NPDynamicNPObjectTest, CanEnumerateProperties) {
+ EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", 7));
+
+ NPIdentifier* names;
+ uint32 num_names;
+ EXPECT_TRUE(object_->_class->enumerate(object_.Get(), &names, &num_names));
+
+ EXPECT_EQ(1, num_names);
+ EXPECT_EQ(NPBrowser::get()->GetStringIdentifier("foo"), names[0]);
+
+ NPBrowser::get()->MemFree(names);
+}
+
+// Properties should not be
+TEST_F(NPDynamicNPObjectTest, InvalidateNullsObjectProperties) {
+ EXPECT_EQ(1, object_->referenceCount);
+ {
+ EXPECT_TRUE(NPSetProperty(NULL, object_, "foo", object_));
+ EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
+ object_->_class->invalidate(object_.Get());
+ EXPECT_TRUE(NPHasProperty(NULL, object_, "foo"));
+ NPObjectPointer<DynamicNPObject> r;
+ EXPECT_TRUE(NPGetProperty(NULL, object_, "foo", &r));
+ EXPECT_TRUE(NULL == r.Get());
+ }
+ // Invalidate did not release object
+ EXPECT_EQ(2, object_->referenceCount);
+ NPBrowser::get()->ReleaseObject(object_.Get());
+}
+} // namespace gpu_plugin
+} // namespace o3d
diff --git a/o3d/gpu_plugin/np_utils/np_browser.cc b/o3d/gpu_plugin/np_utils/np_browser.cc
index 6dcbc3d..d0c50c8 100644
--- a/o3d/gpu_plugin/np_utils/np_browser.cc
+++ b/o3d/gpu_plugin/np_utils/np_browser.cc
@@ -71,6 +71,19 @@ bool NPBrowser::GetProperty(NPP npp,
return netscape_funcs_->getproperty(npp, object, name, result);
}
+bool NPBrowser::SetProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name,
+ const NPVariant* result) {
+ return netscape_funcs_->setproperty(npp, object, name, result);
+}
+
+bool NPBrowser::RemoveProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name) {
+ return netscape_funcs_->removeproperty(npp, object, name);
+}
+
bool NPBrowser::HasMethod(NPP npp,
NPObject* object,
NPIdentifier name) {
diff --git a/o3d/gpu_plugin/np_utils/np_browser.h b/o3d/gpu_plugin/np_utils/np_browser.h
index 6ea8655..dd5e675 100644
--- a/o3d/gpu_plugin/np_utils/np_browser.h
+++ b/o3d/gpu_plugin/np_utils/np_browser.h
@@ -50,6 +50,15 @@ class NPBrowser {
NPIdentifier name,
NPVariant* result);
+ virtual bool SetProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name,
+ const NPVariant* result);
+
+ virtual bool RemoveProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name);
+
virtual bool HasMethod(NPP npp,
NPObject* object,
NPIdentifier name);
diff --git a/o3d/gpu_plugin/np_utils/np_browser_stub.cc b/o3d/gpu_plugin/np_utils/np_browser_stub.cc
index b074cbe..e1c8edf 100644
--- a/o3d/gpu_plugin/np_utils/np_browser_stub.cc
+++ b/o3d/gpu_plugin/np_utils/np_browser_stub.cc
@@ -72,6 +72,19 @@ bool StubNPBrowser::GetProperty(NPP npp,
return object->_class->getProperty(object, name, result);
}
+bool StubNPBrowser::SetProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name,
+ const NPVariant* result) {
+ return object->_class->setProperty(object, name, result);
+}
+
+bool StubNPBrowser::RemoveProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name) {
+ return object->_class->removeProperty(object, name);
+}
+
bool StubNPBrowser::HasMethod(NPP npp,
NPObject* object,
NPIdentifier name) {
diff --git a/o3d/gpu_plugin/np_utils/np_browser_stub.h b/o3d/gpu_plugin/np_utils/np_browser_stub.h
index 1391c55..e431c1b 100644
--- a/o3d/gpu_plugin/np_utils/np_browser_stub.h
+++ b/o3d/gpu_plugin/np_utils/np_browser_stub.h
@@ -46,6 +46,15 @@ class StubNPBrowser : public NPBrowser {
NPIdentifier name,
NPVariant* result);
+ virtual bool SetProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name,
+ const NPVariant* result);
+
+ virtual bool RemoveProperty(NPP npp,
+ NPObject* object,
+ NPIdentifier name);
+
virtual bool HasMethod(NPP npp,
NPObject* object,
NPIdentifier name);
diff --git a/o3d/gpu_plugin/np_utils/np_utils.cc b/o3d/gpu_plugin/np_utils/np_utils.cc
index 33c0d00..044dd37 100644
--- a/o3d/gpu_plugin/np_utils/np_utils.cc
+++ b/o3d/gpu_plugin/np_utils/np_utils.cc
@@ -18,7 +18,7 @@ bool NPVariantToValue(bool* value, const NPVariant& variant) {
return false;
}
-bool NPVariantToValue(int* value, const NPVariant& variant) {
+bool NPVariantToValue(int32* value, const NPVariant& variant) {
if (NPVARIANT_IS_INT32(variant)) {
*value = NPVARIANT_TO_INT32(variant);
return true;
@@ -65,7 +65,7 @@ void ValueToNPVariant(bool value, NPVariant* variant) {
BOOLEAN_TO_NPVARIANT(value, *variant);
}
-void ValueToNPVariant(int value, NPVariant* variant) {
+void ValueToNPVariant(int32 value, NPVariant* variant) {
INT32_TO_NPVARIANT(value, *variant);
}
@@ -88,7 +88,11 @@ SmartNPVariant::SmartNPVariant() {
}
SmartNPVariant::SmartNPVariant(const SmartNPVariant& rhs) {
- Copy(rhs);
+ rhs.CopyTo(this);
+}
+
+SmartNPVariant::SmartNPVariant(const NPVariant& rhs) {
+ static_cast<const SmartNPVariant&>(rhs).CopyTo(this);
}
SmartNPVariant::~SmartNPVariant() {
@@ -97,29 +101,45 @@ SmartNPVariant::~SmartNPVariant() {
SmartNPVariant& SmartNPVariant::operator=(const SmartNPVariant& rhs) {
Release();
- Copy(rhs);
+ rhs.CopyTo(this);
+ return *this;
+}
+
+SmartNPVariant& SmartNPVariant::operator=(const NPVariant& rhs) {
+ Release();
+ static_cast<const SmartNPVariant&>(rhs).CopyTo(this);
return *this;
}
+bool SmartNPVariant::IsVoid() const {
+ return NPVARIANT_IS_VOID(*this);
+}
+
void SmartNPVariant::Release() {
NPBrowser::get()->ReleaseVariantValue(this);
VOID_TO_NPVARIANT(*this);
}
-void SmartNPVariant::Copy(const NPVariant& rhs) {
- if (NPVARIANT_IS_OBJECT(rhs)) {
- NPObject* object = NPVARIANT_TO_OBJECT(rhs);
- OBJECT_TO_NPVARIANT(object, *this);
+void SmartNPVariant::Invalidate() {
+ if (NPVARIANT_IS_OBJECT(*this)) {
+ NULL_TO_NPVARIANT(*this);
+ }
+}
+
+void SmartNPVariant::CopyTo(NPVariant* rhs) const {
+ if (NPVARIANT_IS_OBJECT(*this)) {
+ NPObject* object = NPVARIANT_TO_OBJECT(*this);
+ OBJECT_TO_NPVARIANT(object, *rhs);
NPBrowser::get()->RetainObject(object);
- } else if (NPVARIANT_IS_STRING(rhs)) {
+ } else if (NPVARIANT_IS_STRING(*this)) {
NPUTF8* copy = static_cast<NPUTF8*>(NPBrowser::get()->MemAlloc(
- rhs.value.stringValue.UTF8Length));
+ value.stringValue.UTF8Length));
memcpy(copy,
- rhs.value.stringValue.UTF8Characters,
- rhs.value.stringValue.UTF8Length);
- STRINGN_TO_NPVARIANT(copy, rhs.value.stringValue.UTF8Length, *this);
+ value.stringValue.UTF8Characters,
+ value.stringValue.UTF8Length);
+ STRINGN_TO_NPVARIANT(copy, value.stringValue.UTF8Length, *rhs);
} else {
- memcpy(this, &rhs, sizeof(rhs));
+ memcpy(rhs, this, sizeof(*rhs));
}
}
@@ -141,5 +161,14 @@ bool NPHasProperty(NPP npp,
NPBrowser::get()->GetStringIdentifier(name));
}
+bool NPRemoveProperty(NPP npp,
+ const NPObjectPointer<NPObject>& object,
+ const NPUTF8* name) {
+ return NPBrowser::get()->RemoveProperty(
+ npp,
+ object.Get(),
+ NPBrowser::get()->GetStringIdentifier(name));
+}
+
} // namespace gpu_plugin
} // namespace o3d
diff --git a/o3d/gpu_plugin/np_utils/np_utils.h b/o3d/gpu_plugin/np_utils/np_utils.h
index af1555c..baec913 100644
--- a/o3d/gpu_plugin/np_utils/np_utils.h
+++ b/o3d/gpu_plugin/np_utils/np_utils.h
@@ -17,7 +17,7 @@ namespace gpu_plugin {
// Convert NPVariant to C++ type. Returns whether the conversion was successful.
bool NPVariantToValue(bool* value, const NPVariant& variant);
-bool NPVariantToValue(int* value, const NPVariant& variant);
+bool NPVariantToValue(int32* value, const NPVariant& variant);
bool NPVariantToValue(float* value, const NPVariant& variant);
bool NPVariantToValue(double* value, const NPVariant& variant);
bool NPVariantToValue(std::string* value, const NPVariant& variant);
@@ -57,7 +57,7 @@ inline bool NPVariantToValue(NPObjectPointer<NPObject>* value,
// Convert C++ type to NPVariant.
void ValueToNPVariant(bool value, NPVariant* variant);
-void ValueToNPVariant(int value, NPVariant* variant);
+void ValueToNPVariant(int32 value, NPVariant* variant);
void ValueToNPVariant(float value, NPVariant* variant);
void ValueToNPVariant(double value, NPVariant* variant);
void ValueToNPVariant(const std::string& value, NPVariant* variant);
@@ -78,6 +78,7 @@ class SmartNPVariant : public NPVariant {
public:
SmartNPVariant();
SmartNPVariant(const SmartNPVariant& rhs);
+ SmartNPVariant(const NPVariant& rhs);
template <typename T>
explicit SmartNPVariant(const T& v) {
@@ -87,22 +88,29 @@ class SmartNPVariant : public NPVariant {
~SmartNPVariant();
SmartNPVariant& operator=(const SmartNPVariant& rhs);
+ SmartNPVariant& operator=(const NPVariant& rhs);
template <typename T>
bool GetValue(T* v) const {
return NPVariantToValue(v, *this);
}
+ bool IsVoid() const;
+
template <typename T>
void SetValue(const T& v) {
Release();
ValueToNPVariant(v, this);
}
+ void CopyTo(NPVariant* target) const;
+
+ // Sets the variant to void.
void Release();
- private:
- void Copy(const NPVariant& rhs);
+ // Called when an NPObject is invalidated to clear any references to other
+ // NPObjects. Does not release the object as it might no longer be valid.
+ void Invalidate();
};
// These allow a method to be invoked with automatic conversion of C++
@@ -234,6 +242,23 @@ bool NPGetProperty(NPP npp,
return false;
}
+template <typename T>
+bool NPSetProperty(NPP npp,
+ const NPObjectPointer<NPObject>& object,
+ const NPUTF8* name,
+ const T& value) {
+ SmartNPVariant variant(value);
+ return NPBrowser::get()->SetProperty(
+ npp,
+ object.Get(),
+ NPBrowser::get()->GetStringIdentifier(name),
+ &variant);
+}
+
+bool NPRemoveProperty(NPP npp,
+ const NPObjectPointer<NPObject>& object,
+ const NPUTF8* name);
+
template <typename NPObjectType>
NPObjectPointer<NPObjectType> NPCreateObject(NPP npp) {
const NPClass* np_class = BaseNPObject::GetNPClass<NPObjectType>();
diff --git a/o3d/gpu_plugin/np_utils/np_utils_unittest.cc b/o3d/gpu_plugin/np_utils/np_utils_unittest.cc
index 9fdeaf9..6376153 100644
--- a/o3d/gpu_plugin/np_utils/np_utils_unittest.cc
+++ b/o3d/gpu_plugin/np_utils/np_utils_unittest.cc
@@ -226,6 +226,13 @@ TEST_F(NPUtilsTest, CanCopyStringSmartVariant) {
v2.value.stringValue.UTF8Characters);
}
+TEST_F(NPUtilsTest, CanReleaseSmartVariant) {
+ SmartNPVariant variant(std::string("hello"));
+ EXPECT_FALSE(variant.IsVoid());
+ variant.Release();
+ EXPECT_TRUE(variant.IsVoid());
+}
+
template <typename T>
class VariantMatcher : public testing::MatcherInterface<const NPVariant&> {
public:
@@ -272,7 +279,7 @@ TEST_F(NPUtilsTest, CanInvokeVoidMethodWithNativeTypes) {
VOID_TO_NPVARIANT(variant_);
- EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int>(7)), 1, _))
+ EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int32>(7)), 1, _))
.WillOnce(DoAll(SetArgumentPointee<3>(variant_),
Return(true)));
@@ -286,7 +293,7 @@ TEST_F(NPUtilsTest, InvokeVoidMethodCanFail) {
VOID_TO_NPVARIANT(variant_);
- EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int>(7)), 1, _))
+ EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int32>(7)), 1, _))
.WillOnce(DoAll(SetArgumentPointee<3>(variant_),
Return(false)));
@@ -296,11 +303,11 @@ TEST_F(NPUtilsTest, InvokeVoidMethodCanFail) {
TEST_F(NPUtilsTest, CanInvokeNonVoidMethodWithNativeTypes) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
DOUBLE_TO_NPVARIANT(1.5, variant_);
- EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int>(7)), 1, _))
+ EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int32>(7)), 1, _))
.WillOnce(DoAll(SetArgumentPointee<3>(variant_),
Return(true)));
@@ -312,11 +319,11 @@ TEST_F(NPUtilsTest, CanInvokeNonVoidMethodWithNativeTypes) {
TEST_F(NPUtilsTest, InvokeNonVoidMethodCanFail) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
DOUBLE_TO_NPVARIANT(1.5, variant_);
- EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int>(7)), 1, _))
+ EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int32>(7)), 1, _))
.WillOnce(DoAll(SetArgumentPointee<3>(variant_),
Return(false)));
@@ -327,11 +334,11 @@ TEST_F(NPUtilsTest, InvokeNonVoidMethodCanFail) {
TEST_F(NPUtilsTest, InvokeNonVoidMethodFailsIfResultIsIncompatible) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
DOUBLE_TO_NPVARIANT(1.5, variant_);
- EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int>(7)), 1, _))
+ EXPECT_CALL(*object, Invoke(name, Pointee(VariantMatches<int32>(7)), 1, _))
.WillOnce(DoAll(SetArgumentPointee<3>(variant_),
Return(true)));
@@ -353,7 +360,7 @@ TEST_F(NPUtilsTest, CanDetermineIfObjectHasProperty) {
TEST_F(NPUtilsTest, CanGetPropertyValue) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
DOUBLE_TO_NPVARIANT(1.5, variant_);
@@ -365,10 +372,10 @@ TEST_F(NPUtilsTest, CanGetPropertyValue) {
EXPECT_TRUE(NPGetProperty(NULL, object, "foo", &r));
}
-TEST_F(NPUtilsTest, ReportsFailureIfResultTypeIsDifferent) {
+TEST_F(NPUtilsTest, NPGetPropertyReportsFailureIfResultTypeIsDifferent) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
DOUBLE_TO_NPVARIANT(1.5, variant_);
@@ -380,10 +387,10 @@ TEST_F(NPUtilsTest, ReportsFailureIfResultTypeIsDifferent) {
EXPECT_FALSE(NPGetProperty(NULL, object, "foo", &r));
}
-TEST_F(NPUtilsTest, ReportsFailureFromGetProperty) {
+TEST_F(NPUtilsTest, NPGetPropertyReportsFailureFromGetProperty) {
NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
NPObjectPointer<MockBaseNPObject> object =
- NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);;
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
EXPECT_CALL(*object, GetProperty(name, _))
.WillOnce(Return(false));
@@ -392,5 +399,38 @@ TEST_F(NPUtilsTest, ReportsFailureFromGetProperty) {
EXPECT_FALSE(NPGetProperty(NULL, object, "foo", &r));
}
+TEST_F(NPUtilsTest, CanSetPropertyValue) {
+ NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
+ NPObjectPointer<MockBaseNPObject> object =
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
+
+ EXPECT_CALL(*object, SetProperty(name, Pointee(VariantMatches(1.5))))
+ .WillOnce(Return(true));
+
+ EXPECT_TRUE(NPSetProperty(NULL, object, "foo", 1.5));
+}
+
+TEST_F(NPUtilsTest, NPSetPropertyReportsFailureFromSetProperty) {
+ NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
+ NPObjectPointer<MockBaseNPObject> object =
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
+
+ EXPECT_CALL(*object, SetProperty(name, Pointee(VariantMatches(1.5))))
+ .WillOnce(Return(false));
+
+ EXPECT_FALSE(NPSetProperty(NULL, object, "foo", 1.5));
+}
+
+TEST_F(NPUtilsTest, CanRemovePropertyValue) {
+ NPIdentifier name = NPBrowser::get()->GetStringIdentifier("foo");
+ NPObjectPointer<MockBaseNPObject> object =
+ NPCreateObject<StrictMock<MockBaseNPObject> >(NULL);
+
+ EXPECT_CALL(*object, RemoveProperty(name))
+ .WillOnce(Return(true));
+
+ EXPECT_TRUE(NPRemoveProperty(NULL, object, "foo"));
+}
+
} // namespace gpu_plugin
} // namespace o3d