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

Side by Side 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, 9 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_case.h ('k') | ppapi/tests/test_case.html » ('j') | 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_case.h" 5 #include "ppapi/tests/test_case.h"
6 6
7 #include <sstream> 7 #include <sstream>
8 8
9 #include "ppapi/tests/test_utils.h" 9 #include "ppapi/tests/test_utils.h"
10 #include "ppapi/tests/testing_instance.h" 10 #include "ppapi/tests/testing_instance.h"
(...skipping 29 matching lines...) Expand all
40 40
41 std::ostringstream output; 41 std::ostringstream output;
42 output << "Failure in " << file << "(" << line << "): " << cmd; 42 output << "Failure in " << file << "(" << line << "): " << cmd;
43 return output.str(); 43 return output.str();
44 } 44 }
45 45
46 #if !(defined __native_client__) 46 #if !(defined __native_client__)
47 pp::VarPrivate TestCase::GetTestObject() { 47 pp::VarPrivate TestCase::GetTestObject() {
48 if (test_object_.is_undefined()) { 48 if (test_object_.is_undefined()) {
49 pp::deprecated::ScriptableObject* so = CreateTestObject(); 49 pp::deprecated::ScriptableObject* so = CreateTestObject();
50 if (so) 50 if (so) {
51 test_object_ = pp::VarPrivate(instance_, so); // Takes ownership. 51 test_object_ = pp::VarPrivate(instance_, so); // Takes ownership.
52 // CheckResourcesAndVars runs and looks for leaks before we've actually
53 // completely shut down. Ignore the instance object, since it's not a real
54 // leak.
55 IgnoreLeakedVar(test_object_.pp_var().value.as_id);
56 }
52 } 57 }
53 return test_object_; 58 return test_object_;
54 } 59 }
55 #endif 60 #endif
56 61
57 bool TestCase::CheckTestingInterface() { 62 bool TestCase::CheckTestingInterface() {
58 testing_interface_ = GetTestingInterface(); 63 testing_interface_ = GetTestingInterface();
59 if (!testing_interface_) { 64 if (!testing_interface_) {
60 // Give a more helpful error message for the testing interface being gone 65 // Give a more helpful error message for the testing interface being gone
61 // since that needs special enabling in Chrome. 66 // since that needs special enabling in Chrome.
62 instance_->AppendError("This test needs the testing interface, which is " 67 instance_->AppendError("This test needs the testing interface, which is "
63 "not currently available. In Chrome, use " 68 "not currently available. In Chrome, use "
64 "--enable-pepper-testing when launching."); 69 "--enable-pepper-testing when launching.");
65 return false; 70 return false;
66 } 71 }
67 72
68 return true; 73 return true;
69 } 74 }
70 75
71 void TestCase::HandleMessage(const pp::Var& message_data) { 76 void TestCase::HandleMessage(const pp::Var& message_data) {
72 } 77 }
73 78
74 void TestCase::DidChangeView(const pp::View& view) { 79 void TestCase::DidChangeView(const pp::View& view) {
75 } 80 }
76 81
77 bool TestCase::HandleInputEvent(const pp::InputEvent& event) { 82 bool TestCase::HandleInputEvent(const pp::InputEvent& event) {
78 return false; 83 return false;
79 } 84 }
80 85
86 void TestCase::IgnoreLeakedVar(int64_t id) {
87 ignored_leaked_vars_.insert(id);
88 }
89
81 #if !(defined __native_client__) 90 #if !(defined __native_client__)
82 pp::deprecated::ScriptableObject* TestCase::CreateTestObject() { 91 pp::deprecated::ScriptableObject* TestCase::CreateTestObject() {
83 return NULL; 92 return NULL;
84 } 93 }
85 #endif 94 #endif
86 95
87 bool TestCase::EnsureRunningOverHTTP() { 96 bool TestCase::EnsureRunningOverHTTP() {
88 if (instance_->protocol() != "http:") { 97 if (instance_->protocol() != "http:") {
89 instance_->AppendError("This test needs to be run over HTTP."); 98 instance_->AppendError("This test needs to be run over HTTP.");
90 return false; 99 return false;
(...skipping 13 matching lines...) Expand all
104 // TODO(dmichael): Fix tests that leak resources and enable the following: 113 // TODO(dmichael): Fix tests that leak resources and enable the following:
105 /* 114 /*
106 uint32_t leaked_resources = 115 uint32_t leaked_resources =
107 testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance()); 116 testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance());
108 if (leaked_resources) { 117 if (leaked_resources) {
109 std::ostringstream output; 118 std::ostringstream output;
110 output << "FAILED: Test leaked " << leaked_resources << " resources.\n"; 119 output << "FAILED: Test leaked " << leaked_resources << " resources.\n";
111 errors += output.str(); 120 errors += output.str();
112 } 121 }
113 */ 122 */
114 const uint32_t kVarsToPrint = 10; 123 const int kVarsToPrint = 100;
115 PP_Var vars[kVarsToPrint]; 124 PP_Var vars[kVarsToPrint];
116 uint32_t leaked_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint); 125 int found_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint);
117 uint32_t tracked_vars = leaked_vars; 126 // This will undercount if we are told to ignore a Var which is then *not*
118 #if !(defined __native_client__) 127 // leaked. Worst case, we just won't print the little "Test leaked" message,
119 // Don't count test_object_ as a leak. 128 // but we'll still print any non-ignored leaked vars we found.
120 if (test_object_.pp_var().type > PP_VARTYPE_DOUBLE) 129 int leaked_vars =
121 --leaked_vars; 130 found_vars - static_cast<int>(ignored_leaked_vars_.size());
122 #endif 131 if (leaked_vars > 0) {
123 if (leaked_vars) {
124 std::ostringstream output; 132 std::ostringstream output;
125 output << "Test leaked " << leaked_vars << " vars (printing at most " 133 output << "Test leaked " << leaked_vars << " vars (printing at most "
126 << kVarsToPrint <<"):<p>"; 134 << kVarsToPrint <<"):<p>";
127 errors += output.str(); 135 errors += output.str();
128 for (uint32_t i = 0; i < std::min(tracked_vars, kVarsToPrint); ++i) { 136 }
129 pp::Var leaked_var(pp::PASS_REF, vars[i]); 137 for (int i = 0; i < std::min(found_vars, kVarsToPrint); ++i) {
130 #if (defined __native_client__) 138 pp::Var leaked_var(pp::PASS_REF, vars[i]);
139 if (ignored_leaked_vars_.count(leaked_var.pp_var().value.as_id) == 0)
131 errors += leaked_var.DebugString() + "<p>"; 140 errors += leaked_var.DebugString() + "<p>";
132 #else
133 if (!(leaked_var == test_object_))
134 errors += leaked_var.DebugString() + "<p>";
135 #endif
136 }
137 } 141 }
138 } 142 }
139 return errors; 143 return errors;
140 } 144 }
141 145
146
OLDNEW
« 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