| 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/tests/test_instance_deprecated.h" | 5 #include "ppapi/tests/test_instance_deprecated.h" |
| 6 | 6 |
| 7 #include <assert.h> | 7 #include <assert.h> |
| 8 #include <iostream> | |
| 9 | 8 |
| 10 #include "ppapi/c/ppb_var.h" | 9 #include "ppapi/c/ppb_var.h" |
| 11 #include "ppapi/cpp/module.h" | 10 #include "ppapi/cpp/module.h" |
| 12 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" | 11 #include "ppapi/cpp/dev/scriptable_object_deprecated.h" |
| 13 #include "ppapi/tests/testing_instance.h" | 12 #include "ppapi/tests/testing_instance.h" |
| 14 | 13 |
| 15 namespace { | 14 namespace { |
| 16 | 15 |
| 17 static const char kSetValueFunction[] = "SetValue"; | 16 static const char kSetValueFunction[] = "SetValue"; |
| 18 static const char kSetExceptionFunction[] = "SetException"; | 17 static const char kSetExceptionFunction[] = "SetException"; |
| (...skipping 100 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 119 REGISTER_TEST_CASE(Instance); | 118 REGISTER_TEST_CASE(Instance); |
| 120 | 119 |
| 121 TestInstance::TestInstance(TestingInstance* instance) : TestCase(instance) { | 120 TestInstance::TestInstance(TestingInstance* instance) : TestCase(instance) { |
| 122 } | 121 } |
| 123 | 122 |
| 124 bool TestInstance::Init() { | 123 bool TestInstance::Init() { |
| 125 return true; | 124 return true; |
| 126 } | 125 } |
| 127 | 126 |
| 128 TestInstance::~TestInstance() { | 127 TestInstance::~TestInstance() { |
| 128 ResetTestObject(); |
| 129 // When running tests in process, some post conditions check that teardown |
| 130 // happened successfully. We need to run the garbage collector to ensure that |
| 131 // vars get released. |
| 132 if (testing_interface_->IsOutOfProcess() == PP_FALSE) |
| 133 testing_interface_->RunV8GC(instance_->pp_instance()); |
| 129 // Save the fact that we were destroyed in sessionStorage. This tests that | 134 // Save the fact that we were destroyed in sessionStorage. This tests that |
| 130 // we can ExecuteScript at instance destruction without crashing. It also | 135 // we can ExecuteScript at instance destruction without crashing. It also |
| 131 // allows us to check that ExecuteScript will run and succeed in certain | 136 // allows us to check that ExecuteScript will run and succeed in certain |
| 132 // cases. In particular, when the instance is destroyed by normal DOM | 137 // cases. In particular, when the instance is destroyed by normal DOM |
| 133 // deletion, ExecuteScript will actually work. See | 138 // deletion, ExecuteScript will actually work. See |
| 134 // TestExecuteScriptInInstanceShutdown for that test. Note, however, that | 139 // TestExecuteScriptInInstanceShutdown for that test. Note, however, that |
| 135 // ExecuteScript will *not* have an effect when the instance is destroyed | 140 // ExecuteScript will *not* have an effect when the instance is destroyed |
| 136 // because the renderer was shut down. | 141 // because the renderer was shut down. |
| 137 pp::Var ret = instance()->ExecuteScript( | 142 pp::Var ret = instance()->ExecuteScript( |
| 138 "sessionStorage.setItem('instance_destroyed', 'true');"); | 143 "sessionStorage.setItem('instance_destroyed', 'true');"); |
| (...skipping 72 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 211 new ObjectWithChildren(i, num_descendents - 1, | 216 new ObjectWithChildren(i, num_descendents - 1, |
| 212 IgnoreLeaks())); | 217 IgnoreLeaks())); |
| 213 i->IgnoreLeakedVar(child_.pp_var().value.as_id); | 218 i->IgnoreLeakedVar(child_.pp_var().value.as_id); |
| 214 } | 219 } |
| 215 } | 220 } |
| 216 private: | 221 private: |
| 217 pp::VarPrivate child_; | 222 pp::VarPrivate child_; |
| 218 }; | 223 }; |
| 219 | 224 |
| 220 std::string TestInstance::TestRecursiveObjects() { | 225 std::string TestInstance::TestRecursiveObjects() { |
| 221 // These should be deleted when we exit scope, so should not leak. | 226 const int kNumChildren = 20; |
| 222 pp::VarPrivate not_leaked(instance(), new ObjectWithChildren(this, 50)); | 227 { |
| 228 // These should be deleted when we exit scope, so should not leak. |
| 229 pp::VarPrivate not_leaked(instance(), new ObjectWithChildren(this, |
| 230 kNumChildren)); |
| 231 } |
| 232 // We need to run the GC multiple times until all of the vars are released. |
| 233 // Each GC invocation will result in releasing a var, which will result in its |
| 234 // children not having any references, allowing them also to be collected. |
| 235 for (int i = 0; i < kNumChildren; ++i) |
| 236 testing_interface_->RunV8GC(instance_->pp_instance()); |
| 223 | 237 |
| 224 // Leak some, but tell TestCase to ignore the leaks. This test is run and then | 238 // Leak some, but tell TestCase to ignore the leaks. This test is run and then |
| 225 // reloaded (see ppapi_uitest.cc). If these aren't cleaned up when the first | 239 // reloaded (see ppapi_uitest.cc). If these aren't cleaned up when the first |
| 226 // run is torn down, they will show up as leaks in the second run. | 240 // run is torn down, they will show up as leaks in the second run. |
| 227 // NOTE: The ScriptableObjects are actually leaked, but they should be removed | 241 // NOTE: The ScriptableObjects are actually leaked, but they should be removed |
| 228 // from the tracker. See below for a test that verifies that the | 242 // from the tracker. See below for a test that verifies that the |
| 229 // destructor is not run. | 243 // destructor is not run. |
| 230 pp::VarPrivate leaked( | 244 pp::VarPrivate leaked( |
| 231 instance(), | 245 instance(), |
| 232 new ObjectWithChildren(this, 50, ObjectWithChildren::IgnoreLeaks())); | 246 new ObjectWithChildren(this, kNumChildren, |
| 247 ObjectWithChildren::IgnoreLeaks())); |
| 233 // Now leak a reference to the root object. This should force the root and | 248 // Now leak a reference to the root object. This should force the root and |
| 234 // all its descendents to stay in the tracker. | 249 // all its descendents to stay in the tracker. |
| 235 LeakReferenceAndIgnore(leaked); | 250 LeakReferenceAndIgnore(leaked); |
| 236 | 251 |
| 237 PASS(); | 252 PASS(); |
| 238 } | 253 } |
| 239 | 254 |
| 240 // A scriptable object that should cause a crash if its destructor is run. We | 255 // A scriptable object that should cause a crash if its destructor is run. We |
| 241 // don't run the destructor for objects which the plugin leaks. This is to | 256 // don't run the destructor for objects which the plugin leaks. This is to |
| 242 // prevent them doing dangerous things at cleanup time, such as executing script | 257 // prevent them doing dangerous things at cleanup time, such as executing script |
| (...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 277 // that it was set as expected. | 292 // that it was set as expected. |
| 278 pp::Var result = instance()->ExecuteScript( | 293 pp::Var result = instance()->ExecuteScript( |
| 279 "sessionStorage.getItem('instance_destroyed');"); | 294 "sessionStorage.getItem('instance_destroyed');"); |
| 280 ASSERT_TRUE(result.is_string()); | 295 ASSERT_TRUE(result.is_string()); |
| 281 ASSERT_EQ(std::string("true"), result.AsString()); | 296 ASSERT_EQ(std::string("true"), result.AsString()); |
| 282 instance()->ExecuteScript("sessionStorage.removeItem('instance_destroyed');"); | 297 instance()->ExecuteScript("sessionStorage.removeItem('instance_destroyed');"); |
| 283 | 298 |
| 284 PASS(); | 299 PASS(); |
| 285 } | 300 } |
| 286 | 301 |
| OLD | NEW |