| OLD | NEW |
| 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" |
| 11 | 11 |
| 12 TestCase::TestCase(TestingInstance* instance) | 12 TestCase::TestCase(TestingInstance* instance) |
| 13 : instance_(instance), | 13 : instance_(instance), |
| 14 testing_interface_(NULL), | 14 testing_interface_(NULL), |
| 15 force_async_(false) { | 15 force_async_(false) { |
| 16 // Get the testing_interface_ if it is available, so that we can do Resource |
| 17 // and Var checks on shutdown (see CheckResourcesAndVars). If it is not |
| 18 // available, testing_interface_ will be NULL. Some tests do not require it. |
| 19 testing_interface_ = GetTestingInterface(); |
| 16 } | 20 } |
| 17 | 21 |
| 18 TestCase::~TestCase() { | 22 TestCase::~TestCase() { |
| 19 } | 23 } |
| 20 | 24 |
| 21 bool TestCase::Init() { | 25 bool TestCase::Init() { |
| 22 return true; | 26 return true; |
| 23 } | 27 } |
| 24 | 28 |
| 25 // static | 29 // static |
| (...skipping 17 matching lines...) Expand all Loading... |
| 43 pp::VarPrivate TestCase::GetTestObject() { | 47 pp::VarPrivate TestCase::GetTestObject() { |
| 44 if (test_object_.is_undefined()) { | 48 if (test_object_.is_undefined()) { |
| 45 pp::deprecated::ScriptableObject* so = CreateTestObject(); | 49 pp::deprecated::ScriptableObject* so = CreateTestObject(); |
| 46 if (so) | 50 if (so) |
| 47 test_object_ = pp::VarPrivate(instance_, so); // Takes ownership. | 51 test_object_ = pp::VarPrivate(instance_, so); // Takes ownership. |
| 48 } | 52 } |
| 49 return test_object_; | 53 return test_object_; |
| 50 } | 54 } |
| 51 #endif | 55 #endif |
| 52 | 56 |
| 57 bool TestCase::CheckTestingInterface() { |
| 58 testing_interface_ = GetTestingInterface(); |
| 59 if (!testing_interface_) { |
| 60 // Give a more helpful error message for the testing interface being gone |
| 61 // since that needs special enabling in Chrome. |
| 62 instance_->AppendError("This test needs the testing interface, which is " |
| 63 "not currently available. In Chrome, use " |
| 64 "--enable-pepper-testing when launching."); |
| 65 return false; |
| 66 } |
| 67 |
| 68 return true; |
| 69 } |
| 70 |
| 53 void TestCase::HandleMessage(const pp::Var& message_data) { | 71 void TestCase::HandleMessage(const pp::Var& message_data) { |
| 54 } | 72 } |
| 55 | 73 |
| 56 void TestCase::DidChangeView(const pp::Rect& position, const pp::Rect& clip) { | 74 void TestCase::DidChangeView(const pp::Rect& position, const pp::Rect& clip) { |
| 57 } | 75 } |
| 58 | 76 |
| 59 bool TestCase::HandleInputEvent(const pp::InputEvent& event) { | 77 bool TestCase::HandleInputEvent(const pp::InputEvent& event) { |
| 60 return false; | 78 return false; |
| 61 } | 79 } |
| 62 | 80 |
| 63 #if !(defined __native_client__) | 81 #if !(defined __native_client__) |
| 64 pp::deprecated::ScriptableObject* TestCase::CreateTestObject() { | 82 pp::deprecated::ScriptableObject* TestCase::CreateTestObject() { |
| 65 return NULL; | 83 return NULL; |
| 66 } | 84 } |
| 67 #endif | 85 #endif |
| 68 | 86 |
| 69 bool TestCase::InitTestingInterface() { | |
| 70 testing_interface_ = GetTestingInterface(); | |
| 71 if (!testing_interface_) { | |
| 72 // Give a more helpful error message for the testing interface being gone | |
| 73 // since that needs special enabling in Chrome. | |
| 74 instance_->AppendError("This test needs the testing interface, which is " | |
| 75 "not currently available. In Chrome, use " | |
| 76 "--enable-pepper-testing when launching."); | |
| 77 return false; | |
| 78 } | |
| 79 | |
| 80 return true; | |
| 81 } | |
| 82 | |
| 83 bool TestCase::EnsureRunningOverHTTP() { | 87 bool TestCase::EnsureRunningOverHTTP() { |
| 84 if (instance_->protocol() != "http:") { | 88 if (instance_->protocol() != "http:") { |
| 85 instance_->AppendError("This test needs to be run over HTTP."); | 89 instance_->AppendError("This test needs to be run over HTTP."); |
| 86 return false; | 90 return false; |
| 87 } | 91 } |
| 88 | 92 |
| 89 return true; | 93 return true; |
| 90 } | 94 } |
| 91 | 95 |
| 92 bool TestCase::MatchesFilter(const std::string& test_name, | 96 bool TestCase::MatchesFilter(const std::string& test_name, |
| 93 const std::string& filter) { | 97 const std::string& filter) { |
| 94 return filter.empty() || (test_name == filter); | 98 return filter.empty() || (test_name == filter); |
| 95 } | 99 } |
| 96 | 100 |
| 101 std::string TestCase::CheckResourcesAndVars() { |
| 102 std::string errors; |
| 103 if (testing_interface_) { |
| 104 // TODO(dmichael): Init the testing interface for all tests. |
| 105 // TODO(dmichael): Fix tests that leak resources and enable the following: |
| 106 /* |
| 107 uint32_t leaked_resources = |
| 108 testing_interface_->GetLiveObjectsForInstance(instance_->pp_instance()); |
| 109 if (leaked_resources) { |
| 110 std::ostringstream output; |
| 111 output << "FAILED: Test leaked " << leaked_resources << " resources.\n"; |
| 112 errors += output.str(); |
| 113 } |
| 114 */ |
| 115 const uint32_t kVarsToPrint = 10; |
| 116 PP_Var vars[kVarsToPrint]; |
| 117 uint32_t leaked_vars = testing_interface_->GetLiveVars(vars, kVarsToPrint); |
| 118 uint32_t tracked_vars = leaked_vars; |
| 119 // Don't count test_object_ as a leak. |
| 120 if (test_object_.pp_var().type > PP_VARTYPE_DOUBLE) |
| 121 --leaked_vars; |
| 122 if (leaked_vars) { |
| 123 std::ostringstream output; |
| 124 output << "Test leaked " << leaked_vars << " vars (printing at most " |
| 125 << kVarsToPrint <<"):<p>"; |
| 126 errors += output.str(); |
| 127 for (uint32_t i = 0; i < std::min(tracked_vars, kVarsToPrint); ++i) { |
| 128 pp::Var leaked_var(pp::Var::PassRef(), vars[i]); |
| 129 if (!(leaked_var == test_object_)) |
| 130 errors += leaked_var.DebugString() + "<p>"; |
| 131 } |
| 132 } |
| 133 } |
| 134 return errors; |
| 135 } |
| 136 |
| OLD | NEW |