Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Unified Diff: webkit/glue/cpp_variant_unittest.cc

Issue 6254018: Allow chrome.send to pass number, boolean, null and arrays of those (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Use malloc+strcpy instead of strdup Created 9 years, 11 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
« no previous file with comments | « webkit/glue/cpp_variant.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: webkit/glue/cpp_variant_unittest.cc
diff --git a/webkit/glue/cpp_variant_unittest.cc b/webkit/glue/cpp_variant_unittest.cc
index d4eacc6853b2e419486ae641625c1d04a7a00756..c8f9af1cf047a9a37b0aad51a6529f8381f21a3a 100644
--- a/webkit/glue/cpp_variant_unittest.cc
+++ b/webkit/glue/cpp_variant_unittest.cc
@@ -1,7 +1,9 @@
-// Copyright (c) 2006-2008 The Chromium Authors. All rights reserved.
+// Copyright (c) 2011 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 <vector>
+
#include "base/compiler_specific.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/WebKit/Source/WebKit/chromium/public/WebBindings.h"
@@ -424,3 +426,68 @@ TEST(CppVariantTest, IsTypeFunctionsWork) {
WebBindings::releaseObject(obj);
CheckObject(cpp);
}
+
+bool MockNPHasPropertyFunction(NPObject *npobj, NPIdentifier name) {
+ return true;
+}
+
+bool MockNPGetPropertyFunction(NPObject *npobj, NPIdentifier name,
+ NPVariant *result) {
+ if (WebBindings::getStringIdentifier("length") == name) {
+ DOUBLE_TO_NPVARIANT(4, *result);
+ } else if (WebBindings::getIntIdentifier(0) == name) {
+ DOUBLE_TO_NPVARIANT(0, *result);
+ } else if (WebBindings::getIntIdentifier(1) == name) {
+ BOOLEAN_TO_NPVARIANT(true, *result);
+ } else if (WebBindings::getIntIdentifier(2) == name) {
+ NULL_TO_NPVARIANT(*result);
+ } else if (WebBindings::getIntIdentifier(3) == name) {
+ const char* s = "string";
+ size_t length = strlen(s);
+ char* mem = static_cast<char*>(malloc((length + 1) * sizeof(char)));
Evan Martin 2011/01/27 22:12:58 Unless you're copying code from somewhere else, yo
arv (Not doing code reviews) 2011/01/27 23:35:10 Done.
+ strcpy(mem, s);
+ mem[length] = '\0';
+ STRINGZ_TO_NPVARIANT(mem, *result);
+ }
+
+ return true;
+}
+
+TEST(CppVariantTest, ToVector) {
+ NPClass array_like_class = {
+ NP_CLASS_STRUCT_VERSION,
+ MockNPAllocate, // NPAllocateFunctionPtr allocate;
+ MockNPDeallocate, // NPDeallocateFunctionPtr deallocate;
Evan Martin 2011/01/27 22:12:58 Do you still need these?
arv (Not doing code reviews) 2011/01/27 23:35:10 Nope. Removing
+ 0, // NPInvalidateFunctionPtr invalidate;
+ 0, // NPHasMethodFunctionPtr hasMethod;
+ 0, // NPInvokeFunctionPtr invoke;
+ 0, // NPInvokeDefaultFunctionPtr invokeDefault;
+ MockNPHasPropertyFunction, // NPHasPropertyFunctionPtr hasProperty;
+ MockNPGetPropertyFunction, // NPGetPropertyFunctionPtr getProperty;
+ 0, // NPSetPropertyFunctionPtr setProperty;
+ 0, // NPRemovePropertyFunctionPtr removeProperty;
+ 0, // NPEnumerationFunctionPtr enumerate;
+ 0 // NPConstructFunctionPtr construct;
+ };
+
+ NPObject* obj = WebBindings::createObject(NULL, &array_like_class);
+
+ CppVariant cpp;
+ cpp.Set(obj);
+
+ std::vector<CppVariant> cpp_vector = cpp.ToVector();
+ EXPECT_EQ(4u, cpp_vector.size());
+
+ EXPECT_TRUE(cpp_vector[0].isDouble());
+ EXPECT_EQ(0, cpp_vector[0].ToDouble());
+
+ EXPECT_TRUE(cpp_vector[1].isBool());
+ EXPECT_EQ(true, cpp_vector[1].ToBoolean());
+
+ EXPECT_TRUE(cpp_vector[2].isNull());
+
+ EXPECT_TRUE(cpp_vector[3].isString());
+ CheckString("string", cpp_vector[3]);
+
+ WebBindings::releaseObject(obj);
+}
« no previous file with comments | « webkit/glue/cpp_variant.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698