OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/proxy/raw_var_data.h" | 5 #include "ppapi/proxy/raw_var_data.h" |
6 | 6 |
7 #include "base/logging.h" | 7 #include "base/logging.h" |
8 #include "base/memory/ref_counted.h" | 8 #include "base/memory/ref_counted.h" |
9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
10 #include "base/values.h" | 10 #include "base/values.h" |
(...skipping 26 matching lines...) Expand all Loading... |
37 } | 37 } |
38 virtual void TearDown() { | 38 virtual void TearDown() { |
39 ASSERT_TRUE(PpapiGlobals::Get()->GetVarTracker()->GetLiveVars().empty()); | 39 ASSERT_TRUE(PpapiGlobals::Get()->GetVarTracker()->GetLiveVars().empty()); |
40 ProxyLock::Release(); | 40 ProxyLock::Release(); |
41 } | 41 } |
42 | 42 |
43 private: | 43 private: |
44 TestGlobals globals_; | 44 TestGlobals globals_; |
45 }; | 45 }; |
46 | 46 |
47 PP_Var WriteAndRead(const PP_Var& var) { | 47 bool WriteAndRead(const PP_Var& var, PP_Var* result) { |
48 PP_Instance dummy_instance = 1234; | 48 PP_Instance dummy_instance = 1234; |
49 scoped_ptr<RawVarDataGraph> expected_data(RawVarDataGraph::Create( | 49 scoped_ptr<RawVarDataGraph> expected_data(RawVarDataGraph::Create( |
50 var, dummy_instance)); | 50 var, dummy_instance)); |
| 51 if (!expected_data) |
| 52 return false; |
51 IPC::Message m; | 53 IPC::Message m; |
52 expected_data->Write(&m); | 54 expected_data->Write(&m); |
53 PickleIterator iter(m); | 55 PickleIterator iter(m); |
54 scoped_ptr<RawVarDataGraph> actual_data(RawVarDataGraph::Read(&m, &iter)); | 56 scoped_ptr<RawVarDataGraph> actual_data(RawVarDataGraph::Read(&m, &iter)); |
55 return actual_data->CreatePPVar(dummy_instance); | 57 *result = actual_data->CreatePPVar(dummy_instance); |
| 58 return true; |
56 } | 59 } |
57 | 60 |
58 // Assumes a ref for var. | 61 // Assumes a ref for var. |
59 bool WriteReadAndCompare(const PP_Var& var) { | 62 bool WriteReadAndCompare(const PP_Var& var) { |
60 ScopedPPVar expected(ScopedPPVar::PassRef(), var); | 63 ScopedPPVar expected(ScopedPPVar::PassRef(), var); |
61 ScopedPPVar actual(ScopedPPVar::PassRef(), WriteAndRead(expected.get())); | 64 PP_Var result; |
| 65 bool success = WriteAndRead(expected.get(), &result); |
| 66 if (!success) |
| 67 return false; |
| 68 ScopedPPVar actual(ScopedPPVar::PassRef(), result); |
62 return TestEqual(expected.get(), actual.get()); | 69 return TestEqual(expected.get(), actual.get()); |
63 } | 70 } |
64 | 71 |
65 } // namespace | 72 } // namespace |
66 | 73 |
67 TEST_F(RawVarDataTest, SimpleTest) { | 74 TEST_F(RawVarDataTest, SimpleTest) { |
68 EXPECT_TRUE(WriteReadAndCompare(PP_MakeUndefined())); | 75 EXPECT_TRUE(WriteReadAndCompare(PP_MakeUndefined())); |
69 EXPECT_TRUE(WriteReadAndCompare(PP_MakeNull())); | 76 EXPECT_TRUE(WriteReadAndCompare(PP_MakeNull())); |
70 EXPECT_TRUE(WriteReadAndCompare(PP_MakeInt32(100))); | 77 EXPECT_TRUE(WriteReadAndCompare(PP_MakeInt32(100))); |
71 EXPECT_TRUE(WriteReadAndCompare(PP_MakeBool(PP_TRUE))); | 78 EXPECT_TRUE(WriteReadAndCompare(PP_MakeBool(PP_TRUE))); |
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
153 array->Set(index++, release_dictionary.get()); | 160 array->Set(index++, release_dictionary.get()); |
154 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); | 161 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); |
155 | 162 |
156 // Array with dictionary with array. | 163 // Array with dictionary with array. |
157 array2->Set(0, PP_MakeInt32(100)); | 164 array2->Set(0, PP_MakeInt32(100)); |
158 dictionary->SetWithStringKey("9", release_array2.get()); | 165 dictionary->SetWithStringKey("9", release_array2.get()); |
159 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); | 166 EXPECT_TRUE(WriteReadAndCompare(array->GetPPVar())); |
160 | 167 |
161 // Array <-> dictionary cycle. | 168 // Array <-> dictionary cycle. |
162 dictionary->SetWithStringKey("10", release_array.get()); | 169 dictionary->SetWithStringKey("10", release_array.get()); |
163 ScopedPPVar result = ScopedPPVar(ScopedPPVar::PassRef(), | 170 PP_Var result; |
164 WriteAndRead(release_dictionary.get())); | 171 ASSERT_FALSE(WriteAndRead(release_dictionary.get(), &result)); |
165 EXPECT_TRUE(TestEqual(release_dictionary.get(), result.get())); | |
166 // Break the cycle. | 172 // Break the cycle. |
167 // TODO(raymes): We need some better machinery for releasing vars with | 173 // TODO(raymes): We need some better machinery for releasing vars with |
168 // cycles. Remove the code below once we have that. | 174 // cycles. Remove the code below once we have that. |
169 dictionary->DeleteWithStringKey("10"); | 175 dictionary->DeleteWithStringKey("10"); |
170 DictionaryVar* result_dictionary = DictionaryVar::FromPPVar(result.get()); | |
171 result_dictionary->DeleteWithStringKey("10"); | |
172 | 176 |
173 // Array with self references. | 177 // Array with self references. |
174 array->Set(index, release_array.get()); | 178 array->Set(index, release_array.get()); |
175 result = ScopedPPVar(ScopedPPVar::PassRef(), | 179 ASSERT_FALSE(WriteAndRead(release_array.get(), &result)); |
176 WriteAndRead(release_array.get())); | |
177 EXPECT_TRUE(TestEqual(release_array.get(), result.get())); | |
178 // Break the self reference. | 180 // Break the self reference. |
179 array->Set(index, PP_MakeUndefined()); | 181 array->Set(index, PP_MakeUndefined()); |
180 ArrayVar* result_array = ArrayVar::FromPPVar(result.get()); | |
181 result_array->Set(index, PP_MakeUndefined()); | |
182 } | 182 } |
183 | 183 |
184 } // namespace proxy | 184 } // namespace proxy |
185 } // namespace ppapi | 185 } // namespace ppapi |
OLD | NEW |