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

Side by Side Diff: ppapi/tests/test_var_deprecated.cc

Issue 6995083: Proxy PPB_Var, fix o-o-p string var id tracking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Updated copyright header Created 9 years, 6 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 unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « ppapi/tests/test_var.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "ppapi/tests/test_var_deprecated.h" 5 #include "ppapi/tests/test_var_deprecated.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 8
9 #include <limits> 9 #include <limits>
10 10
11 #include "base/basictypes.h"
11 #include "ppapi/c/pp_var.h" 12 #include "ppapi/c/pp_var.h"
12 #include "ppapi/c/dev/ppb_testing_dev.h" 13 #include "ppapi/c/dev/ppb_testing_dev.h"
13 #include "ppapi/c/dev/ppb_var_deprecated.h" 14 #include "ppapi/c/dev/ppb_var_deprecated.h"
14 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" 15 #include "ppapi/cpp/dev/scriptable_object_deprecated.h"
15 #include "ppapi/cpp/instance.h" 16 #include "ppapi/cpp/instance.h"
16 #include "ppapi/cpp/module.h" 17 #include "ppapi/cpp/module.h"
17 #include "ppapi/cpp/private/var_private.h" 18 #include "ppapi/cpp/private/var_private.h"
18 #include "ppapi/cpp/var.h" 19 #include "ppapi/cpp/var.h"
19 #include "ppapi/tests/testing_instance.h" 20 #include "ppapi/tests/testing_instance.h"
20 21
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
60 } 61 }
61 62
62 return pp::Var(); 63 return pp::Var();
63 } 64 }
64 65
65 } // namespace 66 } // namespace
66 67
67 REGISTER_TEST_CASE(VarDeprecated); 68 REGISTER_TEST_CASE(VarDeprecated);
68 69
69 bool TestVarDeprecated::Init() { 70 bool TestVarDeprecated::Init() {
70 var_interface_ = reinterpret_cast<PPB_Var_Deprecated const*>( 71 var_interface_ = static_cast<const PPB_Var_Deprecated*>(
71 pp::Module::Get()->GetBrowserInterface(PPB_VAR_DEPRECATED_INTERFACE)); 72 pp::Module::Get()->GetBrowserInterface(PPB_VAR_DEPRECATED_INTERFACE));
72 return var_interface_ && InitTestingInterface(); 73 return var_interface_ && InitTestingInterface();
73 } 74 }
74 75
75 void TestVarDeprecated::RunTest() { 76 void TestVarDeprecated::RunTest() {
76 RUN_TEST(BasicString); 77 RUN_TEST(BasicString);
77 RUN_TEST(InvalidAndEmpty); 78 RUN_TEST(InvalidAndEmpty);
78 RUN_TEST(InvalidUtf8); 79 RUN_TEST(InvalidUtf8);
79 RUN_TEST(NullInputInUtf8Conversion); 80 RUN_TEST(NullInputInUtf8Conversion);
80 RUN_TEST(ValidUtf8); 81 RUN_TEST(ValidUtf8);
81 RUN_TEST(Utf8WithEmbeddedNulls); 82 RUN_TEST(Utf8WithEmbeddedNulls);
82 RUN_TEST(VarToUtf8ForWrongType); 83 RUN_TEST(VarToUtf8ForWrongType);
83 RUN_TEST(HasPropertyAndMethod); 84 RUN_TEST(HasPropertyAndMethod);
84 RUN_TEST(PassReference); 85 RUN_TEST(PassReference);
85 } 86 }
86 87
87 pp::deprecated::ScriptableObject* TestVarDeprecated::CreateTestObject() { 88 pp::deprecated::ScriptableObject* TestVarDeprecated::CreateTestObject() {
88 return new VarScriptableObject(this); 89 return new VarScriptableObject(this);
89 } 90 }
90 91
91 std::string TestVarDeprecated::TestBasicString() { 92 std::string TestVarDeprecated::TestBasicString() {
92 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance( 93 uint32_t before_object = testing_interface_->GetLiveObjectsForInstance(
93 instance_->pp_instance()); 94 instance_->pp_instance());
94 { 95 {
95 const uint32_t kStrLen = 5; 96 const char kStr[] = "Hello";
96 const char kStr[kStrLen + 1] = "Hello"; 97 const uint32_t kStrLen(arraysize(kStr) - 1);
97 PP_Var str = var_interface_->VarFromUtf8(pp::Module::Get()->pp_module(), 98 PP_Var str = var_interface_->VarFromUtf8(pp::Module::Get()->pp_module(),
98 kStr, sizeof(kStr) - 1); 99 kStr, kStrLen);
99 ASSERT_EQ(PP_VARTYPE_STRING, str.type); 100 ASSERT_EQ(PP_VARTYPE_STRING, str.type);
100 101
101 // Reading back the string should work. 102 // Reading back the string should work.
102 uint32_t len = 0; 103 uint32_t len = 0;
103 const char* result = var_interface_->VarToUtf8(str, &len); 104 const char* result = var_interface_->VarToUtf8(str, &len);
104 ASSERT_EQ(kStrLen, len); 105 ASSERT_EQ(kStrLen, len);
105 ASSERT_EQ(0, strncmp(kStr, result, kStrLen)); 106 ASSERT_EQ(0, strncmp(kStr, result, kStrLen));
106 107
107 // Destroy the string, readback should now fail. 108 // Destroy the string, readback should now fail.
108 var_interface_->Release(str); 109 var_interface_->Release(str);
109 /*
110 Note: this will crash in the current out-of-process implementation since
111 we don't do actual tracking of strings (we just convert the ID to a
112 pointer).
113 TODO(brettw) This should be fixed and this checking code re-enabled.
114 result = var_interface_->VarToUtf8(str, &len); 110 result = var_interface_->VarToUtf8(str, &len);
115 ASSERT_EQ(0, len); 111 ASSERT_EQ(0, len);
116 ASSERT_EQ(NULL, result); 112 ASSERT_EQ(NULL, result);
117 */
118 } 113 }
119 114
120 // Make sure nothing leaked. 115 // Make sure nothing leaked.
121 ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance( 116 ASSERT_TRUE(testing_interface_->GetLiveObjectsForInstance(
122 instance_->pp_instance()) == before_object); 117 instance_->pp_instance()) == before_object);
123 118
124 PASS(); 119 PASS();
125 } 120 }
126 121
127 std::string TestVarDeprecated::TestInvalidAndEmpty() { 122 std::string TestVarDeprecated::TestInvalidAndEmpty() {
(...skipping 22 matching lines...) Expand all
150 ASSERT_NE(NULL, result); 145 ASSERT_NE(NULL, result);
151 146
152 PASS(); 147 PASS();
153 } 148 }
154 149
155 std::string TestVarDeprecated::TestInvalidUtf8() { 150 std::string TestVarDeprecated::TestInvalidUtf8() {
156 // utf8じゃない (japanese for "is not utf8") in shift-jis encoding. 151 // utf8じゃない (japanese for "is not utf8") in shift-jis encoding.
157 static const char kSjisString[] = "utf8\x82\xb6\x82\xe1\x82\xc8\x82\xa2"; 152 static const char kSjisString[] = "utf8\x82\xb6\x82\xe1\x82\xc8\x82\xa2";
158 pp::Var sjis(kSjisString); 153 pp::Var sjis(kSjisString);
159 if (!sjis.is_null()) 154 if (!sjis.is_null())
160 return "Non-UTF8 string permitted."; 155 return "Non-UTF8 string was permitted erroneously.";
161 156
162 PASS(); 157 PASS();
163 } 158 }
164 159
165 std::string TestVarDeprecated::TestNullInputInUtf8Conversion() { 160 std::string TestVarDeprecated::TestNullInputInUtf8Conversion() {
166 // This test talks directly to the C interface to access edge cases that 161 // This test talks directly to the C interface to access edge cases that
167 // cannot be exercised via the C++ interface. 162 // cannot be exercised via the C++ interface.
168 PP_Var converted_string; 163 PP_Var converted_string;
169 164
170 // 0-length string should not dereference input string, and should produce 165 // 0-length string should not dereference input string, and should produce
(...skipping 224 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 // If the reference counting works, the object should be valid. We can test 390 // If the reference counting works, the object should be valid. We can test
396 // this by executing it (it was a function we defined above) and it should 391 // this by executing it (it was a function we defined above) and it should
397 // return "works" concatenated with the argument. 392 // return "works" concatenated with the argument.
398 pp::VarPrivate function(var_from_page_); 393 pp::VarPrivate function(var_from_page_);
399 pp::Var result = var_from_page_.Call(pp::Var(), "nice"); 394 pp::Var result = var_from_page_.Call(pp::Var(), "nice");
400 ASSERT_TRUE(result.is_string()); 395 ASSERT_TRUE(result.is_string());
401 ASSERT_TRUE(result.AsString() == "worksnice"); 396 ASSERT_TRUE(result.AsString() == "worksnice");
402 397
403 PASS(); 398 PASS();
404 } 399 }
OLDNEW
« no previous file with comments | « ppapi/tests/test_var.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698