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

Unified Diff: ppapi/tests/test_case.cc

Issue 9403039: PPAPI: Really force-free NPObjects on Instance destruction. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years, 10 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 | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_case.html » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ppapi/tests/test_case.cc
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc
index 90e7d721e05e3cbb49bf86a29e1fcae4b660a612..e2d9d76f706e87402946da6ebe89c0997a71f27d 100644
--- a/ppapi/tests/test_case.cc
+++ b/ppapi/tests/test_case.cc
@@ -47,8 +47,13 @@ std::string TestCase::MakeFailureMessage(const char* file,
pp::VarPrivate TestCase::GetTestObject() {
if (test_object_.is_undefined()) {
pp::deprecated::ScriptableObject* so = CreateTestObject();
- if (so)
+ if (so) {
test_object_ = pp::VarPrivate(instance_, so); // Takes ownership.
+ // CheckResourcesAndVars runs and looks for leaks before we've actually
+ // completely shut down. Ignore the instance object, since it's not a real
+ // leak.
+ IgnoreLeakedVar(test_object_.pp_var().value.as_id);
+ }
}
return test_object_;
}
@@ -78,6 +83,10 @@ bool TestCase::HandleInputEvent(const pp::InputEvent& event) {
return false;
}
+void TestCase::IgnoreLeakedVar(int64_t id) {
+ ignored_leaked_vars_.insert(id);
+}
+
#if !(defined __native_client__)
pp::deprecated::ScriptableObject* TestCase::CreateTestObject() {
return NULL;
@@ -111,31 +120,27 @@ std::string TestCase::CheckResourcesAndVars() {
errors += output.str();
}
*/
- const uint32_t kVarsToPrint = 10;
+ const int kVarsToPrint = 100;
PP_Var vars[kVarsToPrint];
- uint32_t leaked_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint);
- uint32_t tracked_vars = leaked_vars;
-#if !(defined __native_client__)
- // Don't count test_object_ as a leak.
- if (test_object_.pp_var().type > PP_VARTYPE_DOUBLE)
- --leaked_vars;
-#endif
- if (leaked_vars) {
+ int found_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint);
+ // This will undercount if we are told to ignore a Var which is then *not*
+ // leaked. Worst case, we just won't print the little "Test leaked" message,
+ // but we'll still print any non-ignored leaked vars we found.
+ int leaked_vars =
+ found_vars - static_cast<int>(ignored_leaked_vars_.size());
+ if (leaked_vars > 0) {
std::ostringstream output;
output << "Test leaked " << leaked_vars << " vars (printing at most "
<< kVarsToPrint <<"):<p>";
errors += output.str();
- for (uint32_t i = 0; i < std::min(tracked_vars, kVarsToPrint); ++i) {
- pp::Var leaked_var(pp::PASS_REF, vars[i]);
-#if (defined __native_client__)
+ }
+ for (int i = 0; i < std::min(found_vars, kVarsToPrint); ++i) {
+ pp::Var leaked_var(pp::PASS_REF, vars[i]);
+ if (ignored_leaked_vars_.count(leaked_var.pp_var().value.as_id) == 0)
errors += leaked_var.DebugString() + "<p>";
-#else
- if (!(leaked_var == test_object_))
- errors += leaked_var.DebugString() + "<p>";
-#endif
- }
}
}
return errors;
}
+
« no previous file with comments | « ppapi/tests/test_case.h ('k') | ppapi/tests/test_case.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698