diff options
Diffstat (limited to 'ppapi/tests')
-rw-r--r-- | ppapi/tests/test_case.cc | 73 | ||||
-rw-r--r-- | ppapi/tests/test_case.h | 16 | ||||
-rw-r--r-- | ppapi/tests/test_directory_reader.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_file_io.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_file_ref.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_file_system.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_flash_fullscreen.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_fullscreen.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_graphics_2d.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_graphics_3d.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_input_event.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_memory.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_post_message.cc | 13 | ||||
-rw-r--r-- | ppapi/tests/test_scrollbar.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_tcp_socket_private_shared.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_transport.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_udp_socket_private_shared.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_url_loader.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_var.cc | 3 | ||||
-rw-r--r-- | ppapi/tests/test_var_deprecated.cc | 7 | ||||
-rw-r--r-- | ppapi/tests/test_video_decoder.cc | 2 | ||||
-rw-r--r-- | ppapi/tests/test_websocket.cc | 2 |
22 files changed, 109 insertions, 37 deletions
diff --git a/ppapi/tests/test_case.cc b/ppapi/tests/test_case.cc index bcee6c3..e6164e0 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,44 @@ 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): 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; +#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) { + 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 (defined __native_client__) + errors += leaked_var.DebugString() + "<p>"; +#else + if (!(leaked_var == test_object_)) + errors += leaked_var.DebugString() + "<p>"; +#endif + } + } + } + return errors; +} + diff --git a/ppapi/tests/test_case.h b/ppapi/tests/test_case.h index 8ea3aef..75cafda 100644 --- a/ppapi/tests/test_case.h +++ b/ppapi/tests/test_case.h @@ -80,8 +80,10 @@ class TestCase { virtual pp::deprecated::ScriptableObject* CreateTestObject(); #endif - // Initializes the testing interface. - bool InitTestingInterface(); + // Checks whether the testing interface is available. Returns true if it is, + // false otherwise. If it is not available, adds a descriptive error. This is + // for use by tests that require the testing interface. + bool CheckTestingInterface(); // Makes sure the test is run over HTTP. bool EnsureRunningOverHTTP(); @@ -90,6 +92,11 @@ class TestCase { // (a) filter is empty or (b) test_name and filter match exactly. bool MatchesFilter(const std::string& test_name, const std::string& filter); + // Check for leaked resources and vars at the end of the test. If any exist, + // return a string with some information about the error. Otherwise, return + // an empty string. + std::string CheckResourcesAndVars(); + // Pointer to the instance that owns us. TestingInstance* instance_; @@ -150,7 +157,10 @@ class TestCaseFactory { #define RUN_TEST(name, test_filter) \ if (MatchesFilter(#name, test_filter)) { \ force_async_ = false; \ - instance_->LogTest(#name, Test##name()); \ + std::string error_message = Test##name(); \ + if (error_message.empty()) \ + error_message = CheckResourcesAndVars(); \ + instance_->LogTest(#name, error_message); \ } #define RUN_TEST_WITH_REFERENCE_CHECK(name, test_filter) \ diff --git a/ppapi/tests/test_directory_reader.cc b/ppapi/tests/test_directory_reader.cc index 3823f29..254a355 100644 --- a/ppapi/tests/test_directory_reader.cc +++ b/ppapi/tests/test_directory_reader.cc @@ -72,7 +72,7 @@ int32_t DeleteDirectoryRecursively(pp::FileRef* dir, } // namespace bool TestDirectoryReader::Init() { - return InitTestingInterface() && EnsureRunningOverHTTP(); + return CheckTestingInterface() && EnsureRunningOverHTTP(); } void TestDirectoryReader::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_file_io.cc b/ppapi/tests/test_file_io.cc index 057fdef..f5235e1 100644 --- a/ppapi/tests/test_file_io.cc +++ b/ppapi/tests/test_file_io.cc @@ -109,7 +109,7 @@ int32_t WriteEntireBuffer(PP_Instance instance, } // namespace bool TestFileIO::Init() { - return InitTestingInterface() && EnsureRunningOverHTTP(); + return CheckTestingInterface() && EnsureRunningOverHTTP(); } void TestFileIO::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_file_ref.cc b/ppapi/tests/test_file_ref.cc index b17450d..0e42d1c 100644 --- a/ppapi/tests/test_file_ref.cc +++ b/ppapi/tests/test_file_ref.cc @@ -41,7 +41,7 @@ std::string ReportMismatch(const std::string& method_name, } // namespace bool TestFileRef::Init() { - return InitTestingInterface() && EnsureRunningOverHTTP(); + return CheckTestingInterface() && EnsureRunningOverHTTP(); } void TestFileRef::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_file_system.cc b/ppapi/tests/test_file_system.cc index 2b5a0c5..8c05d42 100644 --- a/ppapi/tests/test_file_system.cc +++ b/ppapi/tests/test_file_system.cc @@ -14,7 +14,7 @@ REGISTER_TEST_CASE(FileSystem); bool TestFileSystem::Init() { - return InitTestingInterface() && EnsureRunningOverHTTP(); + return CheckTestingInterface() && EnsureRunningOverHTTP(); } void TestFileSystem::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_flash_fullscreen.cc b/ppapi/tests/test_flash_fullscreen.cc index f7f122b..0d49605 100644 --- a/ppapi/tests/test_flash_fullscreen.cc +++ b/ppapi/tests/test_flash_fullscreen.cc @@ -46,7 +46,7 @@ TestFlashFullscreen::TestFlashFullscreen(TestingInstance* instance) } bool TestFlashFullscreen::Init() { - return InitTestingInterface(); + return CheckTestingInterface(); } void TestFlashFullscreen::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_fullscreen.cc b/ppapi/tests/test_fullscreen.cc index c531c02..f2b204e 100644 --- a/ppapi/tests/test_fullscreen.cc +++ b/ppapi/tests/test_fullscreen.cc @@ -71,7 +71,7 @@ bool TestFullscreen::Init() { instance_->AppendError("Failed to initialize graphics2d_"); return false; } - return InitTestingInterface(); + return CheckTestingInterface(); } void TestFullscreen::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_graphics_2d.cc b/ppapi/tests/test_graphics_2d.cc index 63cfc42..86de406 100644 --- a/ppapi/tests/test_graphics_2d.cc +++ b/ppapi/tests/test_graphics_2d.cc @@ -38,7 +38,7 @@ bool TestGraphics2D::Init() { image_data_interface_ = static_cast<const PPB_ImageData*>( pp::Module::Get()->GetBrowserInterface(PPB_IMAGEDATA_INTERFACE)); return graphics_2d_interface_ && image_data_interface_ && - InitTestingInterface(); + CheckTestingInterface(); } void TestGraphics2D::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_graphics_3d.cc b/ppapi/tests/test_graphics_3d.cc index 75b4d68..aa26dff 100644 --- a/ppapi/tests/test_graphics_3d.cc +++ b/ppapi/tests/test_graphics_3d.cc @@ -18,7 +18,7 @@ REGISTER_TEST_CASE(Graphics3D); bool TestGraphics3D::Init() { opengl_es2_ = static_cast<const PPB_OpenGLES2*>( pp::Module::Get()->GetBrowserInterface(PPB_OPENGLES2_INTERFACE)); - return opengl_es2_ && InitTestingInterface(); + return opengl_es2_ && CheckTestingInterface(); } void TestGraphics3D::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_input_event.cc b/ppapi/tests/test_input_event.cc index cdd4939..8ac9a8fd 100644 --- a/ppapi/tests/test_input_event.cc +++ b/ppapi/tests/test_input_event.cc @@ -73,7 +73,7 @@ bool TestInputEvent::Init() { mouse_input_event_interface_ && wheel_input_event_interface_ && keyboard_input_event_interface_ && - InitTestingInterface(); + CheckTestingInterface(); // Set up a listener for our message that signals that all input events have // been received. diff --git a/ppapi/tests/test_memory.cc b/ppapi/tests/test_memory.cc index 4acbd5f..ea612a4 100644 --- a/ppapi/tests/test_memory.cc +++ b/ppapi/tests/test_memory.cc @@ -21,7 +21,7 @@ REGISTER_TEST_CASE(Memory); bool TestMemory::Init() { memory_dev_interface_ = static_cast<const PPB_Memory_Dev*>( pp::Module::Get()->GetBrowserInterface(PPB_MEMORY_DEV_INTERFACE)); - return memory_dev_interface_ && InitTestingInterface(); + return memory_dev_interface_ && CheckTestingInterface(); } void TestMemory::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_post_message.cc b/ppapi/tests/test_post_message.cc index 665dad7..6edd422 100644 --- a/ppapi/tests/test_post_message.cc +++ b/ppapi/tests/test_post_message.cc @@ -69,7 +69,7 @@ TestPostMessage::~TestPostMessage() { } bool TestPostMessage::Init() { - bool success = InitTestingInterface(); + bool success = CheckTestingInterface(); // Set up a special listener that only responds to a FINISHED_WAITING string. // This is for use by WaitForMessages. @@ -179,6 +179,7 @@ std::string TestPostMessage::TestSendInInit() { ASSERT_EQ(message_data_.size(), 1); ASSERT_TRUE(message_data_.back().is_string()); ASSERT_EQ(message_data_.back().AsString(), kTestString); + message_data_.clear(); PASS(); } @@ -236,6 +237,7 @@ std::string TestPostMessage::TestSendingData() { ASSERT_EQ(WaitForMessages(), 1); ASSERT_TRUE(message_data_.back().is_null()); + message_data_.clear(); ASSERT_TRUE(ClearListeners()); PASS(); @@ -296,6 +298,7 @@ std::string TestPostMessage::TestSendingArrayBuffer() { for (size_t i = 0; i < test_data.ByteLength(); ++i) ASSERT_EQ(buff[i], received_buff[i]); + message_data_.clear(); ASSERT_TRUE(ClearListeners()); PASS(); @@ -361,6 +364,9 @@ std::string TestPostMessage::TestMessageEvent() { ASSERT_DOUBLE_EQ(double_vec[1], 2.0); ASSERT_DOUBLE_EQ(double_vec[2], 3.0); + message_data_.clear(); + ASSERT_TRUE(ClearListeners()); + PASS(); } @@ -392,6 +398,8 @@ std::string TestPostMessage::TestExtraParam() { ASSERT_EQ(WaitForMessages(), 0); ASSERT_TRUE(message_data_.empty()); + ASSERT_TRUE(ClearListeners()); + PASS(); } @@ -448,6 +456,9 @@ std::string TestPostMessage::TestNonMainThread() { } ASSERT_EQ(received_counts, expected_counts); + message_data_.clear(); + ASSERT_TRUE(ClearListeners()); + PASS(); } diff --git a/ppapi/tests/test_scrollbar.cc b/ppapi/tests/test_scrollbar.cc index 61345d0..b005db7 100644 --- a/ppapi/tests/test_scrollbar.cc +++ b/ppapi/tests/test_scrollbar.cc @@ -23,7 +23,7 @@ TestScrollbar::TestScrollbar(TestingInstance* instance) } bool TestScrollbar::Init() { - return InitTestingInterface(); + return CheckTestingInterface(); } void TestScrollbar::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_tcp_socket_private_shared.cc b/ppapi/tests/test_tcp_socket_private_shared.cc index 013aa89..6df6cd5 100644 --- a/ppapi/tests/test_tcp_socket_private_shared.cc +++ b/ppapi/tests/test_tcp_socket_private_shared.cc @@ -31,7 +31,7 @@ bool TestTCPSocketPrivateShared::Init() { return tcp_socket_private_interface_ && init_host_port && - InitTestingInterface(); + CheckTestingInterface(); } void TestTCPSocketPrivateShared::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_transport.cc b/ppapi/tests/test_transport.cc index c5ea69c..52d072e 100644 --- a/ppapi/tests/test_transport.cc +++ b/ppapi/tests/test_transport.cc @@ -105,7 +105,7 @@ TestTransport::~TestTransport() { bool TestTransport::Init() { transport_interface_ = static_cast<const PPB_Transport_Dev*>( pp::Module::Get()->GetBrowserInterface(PPB_TRANSPORT_DEV_INTERFACE)); - return transport_interface_ && InitTestingInterface(); + return transport_interface_ && CheckTestingInterface(); } void TestTransport::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_udp_socket_private_shared.cc b/ppapi/tests/test_udp_socket_private_shared.cc index da97cae..2de64778 100644 --- a/ppapi/tests/test_udp_socket_private_shared.cc +++ b/ppapi/tests/test_udp_socket_private_shared.cc @@ -38,7 +38,7 @@ bool TestUDPSocketPrivateShared::Init() { return tcp_socket_private_interface_ && udp_socket_private_interface_ && init_host_port && - InitTestingInterface(); + CheckTestingInterface(); } void TestUDPSocketPrivateShared::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_url_loader.cc b/ppapi/tests/test_url_loader.cc index 630d00f..741d415 100644 --- a/ppapi/tests/test_url_loader.cc +++ b/ppapi/tests/test_url_loader.cc @@ -63,7 +63,7 @@ TestURLLoader::TestURLLoader(TestingInstance* instance) } bool TestURLLoader::Init() { - if (!InitTestingInterface()) { + if (!CheckTestingInterface()) { instance_->AppendError("Testing interface not available"); return false; } diff --git a/ppapi/tests/test_var.cc b/ppapi/tests/test_var.cc index 27c4882..0fedb13 100644 --- a/ppapi/tests/test_var.cc +++ b/ppapi/tests/test_var.cc @@ -27,7 +27,7 @@ REGISTER_TEST_CASE(Var); bool TestVar::Init() { var_interface_ = static_cast<const PPB_Var*>( pp::Module::Get()->GetBrowserInterface(PPB_VAR_INTERFACE)); - return var_interface_ && InitTestingInterface(); + return var_interface_ && CheckTestingInterface(); } void TestVar::RunTests(const std::string& filter) { @@ -136,6 +136,7 @@ std::string TestVar::TestNullInputInUtf8Conversion() { if (result == NULL) { return "Expected a non-null result for 0-lengthed string from VarToUtf8."; } + var_interface_->Release(converted_string); // Should not crash, and make an empty string. const char* null_string = NULL; diff --git a/ppapi/tests/test_var_deprecated.cc b/ppapi/tests/test_var_deprecated.cc index 00585e6..23633ac 100644 --- a/ppapi/tests/test_var_deprecated.cc +++ b/ppapi/tests/test_var_deprecated.cc @@ -69,7 +69,7 @@ REGISTER_TEST_CASE(VarDeprecated); bool TestVarDeprecated::Init() { var_interface_ = static_cast<const PPB_Var_Deprecated*>( pp::Module::Get()->GetBrowserInterface(PPB_VAR_DEPRECATED_INTERFACE)); - return var_interface_ && InitTestingInterface(); + return var_interface_ && CheckTestingInterface(); } void TestVarDeprecated::RunTests(const std::string& filter) { @@ -179,6 +179,7 @@ std::string TestVarDeprecated::TestNullInputInUtf8Conversion() { if (result == NULL) { return "Expected a non-null result for 0-lengthed string from VarToUtf8."; } + var_interface_->Release(converted_string); // Should not crash, and make an empty string. const char* null_string = NULL; @@ -386,6 +387,10 @@ std::string TestVarDeprecated::TestPassReference() { ASSERT_TRUE(result.is_string()); ASSERT_TRUE(result.AsString() == "worksnice"); + // Reset var_from_page_ so it doesn't seem like a leak to the var leak + // checking code. + var_from_page_ = pp::Var(); + PASS(); } diff --git a/ppapi/tests/test_video_decoder.cc b/ppapi/tests/test_video_decoder.cc index eed14d8..0cee794 100644 --- a/ppapi/tests/test_video_decoder.cc +++ b/ppapi/tests/test_video_decoder.cc @@ -15,7 +15,7 @@ REGISTER_TEST_CASE(VideoDecoder); bool TestVideoDecoder::Init() { video_decoder_interface_ = static_cast<const PPB_VideoDecoder_Dev*>( pp::Module::Get()->GetBrowserInterface(PPB_VIDEODECODER_DEV_INTERFACE)); - return video_decoder_interface_ && InitTestingInterface(); + return video_decoder_interface_ && CheckTestingInterface(); } void TestVideoDecoder::RunTests(const std::string& filter) { diff --git a/ppapi/tests/test_websocket.cc b/ppapi/tests/test_websocket.cc index ae1db54..223331e 100644 --- a/ppapi/tests/test_websocket.cc +++ b/ppapi/tests/test_websocket.cc @@ -53,7 +53,7 @@ bool TestWebSocket::Init() { if (!websocket_interface_ || !var_interface_ || !core_interface_) return false; - return InitTestingInterface(); + return CheckTestingInterface(); } void TestWebSocket::RunTests(const std::string& filter) { |