Index: ppapi/tests/test_case.cc |
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc |
index bcee6c3b73dc0af22253a9184f4123087ddacfc5..1dfe4a9ababe5ebd09ed9f4946c5068ad033a07c 100644 |
--- a/ppapi/tests/test_case.cc |
+++ b/ppapi/tests/test_case.cc |
@@ -13,6 +13,10 @@ TestCase::TestCase(TestingInstance* instance) |
: instance_(instance), |
testing_interface_(NULL), |
force_async_(false) { |
+ // Get the testing_interface_ if it is available, so that we can do Resource |
+ // and Var checks on shutdown (see CheckResourcesAndVars). If it is not |
+ // available, testing_interface_ will be NULL. Some tests do not require it. |
+ testing_interface_ = GetTestingInterface(); |
} |
TestCase::~TestCase() { |
@@ -50,6 +54,20 @@ pp::VarPrivate TestCase::GetTestObject() { |
} |
#endif |
+bool TestCase::CheckTestingInterface() { |
+ testing_interface_ = GetTestingInterface(); |
+ if (!testing_interface_) { |
+ // Give a more helpful error message for the testing interface being gone |
+ // since that needs special enabling in Chrome. |
+ instance_->AppendError("This test needs the testing interface, which is " |
+ "not currently available. In Chrome, use " |
+ "--enable-pepper-testing when launching."); |
+ return false; |
+ } |
+ |
+ return true; |
+} |
+ |
void TestCase::HandleMessage(const pp::Var& message_data) { |
} |
@@ -66,20 +84,6 @@ pp::deprecated::ScriptableObject* TestCase::CreateTestObject() { |
} |
#endif |
-bool TestCase::InitTestingInterface() { |
- testing_interface_ = GetTestingInterface(); |
- if (!testing_interface_) { |
- // Give a more helpful error message for the testing interface being gone |
- // since that needs special enabling in Chrome. |
- instance_->AppendError("This test needs the testing interface, which is " |
- "not currently available. In Chrome, use " |
- "--enable-pepper-testing when launching."); |
- return false; |
- } |
- |
- return true; |
-} |
- |
bool TestCase::EnsureRunningOverHTTP() { |
if (instance_->protocol() != "http:") { |
instance_->AppendError("This test needs to be run over HTTP."); |
@@ -94,3 +98,39 @@ bool TestCase::MatchesFilter(const std::string& test_name, |
return filter.empty() || (test_name == filter); |
} |
+std::string TestCase::CheckResourcesAndVars() { |
+ std::string errors; |
+ if (testing_interface_) { |
+ // TODO(dmichael): Init the testing interface for all tests. |
+ // TODO(dmichael): Fix tests that leak resources and enable the following: |
+ /* |
+ uint32_t leaked_resources = |
+ testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance()); |
+ if (leaked_resources) { |
+ std::ostringstream output; |
+ output << "FAILED: Test leaked " << leaked_resources << " resources.\n"; |
+ errors += output.str(); |
+ } |
+ */ |
+ const uint32_t kVarsToPrint = 10; |
+ PP_Var vars[kVarsToPrint]; |
+ uint32_t leaked_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint); |
+ uint32_t tracked_vars = leaked_vars; |
+ // Don't count test_object_ as a leak. |
+ if (test_object_.pp_var().type > PP_VARTYPE_DOUBLE) |
+ --leaked_vars; |
+ if (leaked_vars) { |
+ 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::Var::PassRef(), vars[i]); |
+ if (!(leaked_var == test_object_)) |
+ errors += leaked_var.DebugString() + "<p>"; |
+ } |
+ } |
+ } |
+ return errors; |
+} |
+ |