190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved. 290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)// found in the LICENSE file. 490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/tests/test_flash_drm.h" 690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 77d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(PPAPI_OS_WIN) 87d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include <Windows.h> 97d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/c/pp_macros.h" 127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "ppapi/c/private/ppb_file_ref_private.h" 1390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/c/private/ppb_flash_drm.h" 1490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/cpp/instance.h" 1590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/cpp/module.h" 1690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/cpp/private/flash_device_id.h" 1790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/cpp/private/flash_drm.h" 1890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/cpp/var.h" 1990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)#include "ppapi/tests/testing_instance.h" 2090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)REGISTER_TEST_CASE(FlashDRM); 2290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 2390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using pp::flash::DeviceID; 2490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using pp::flash::DRM; 257d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using pp::FileRef; 267d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)using pp::PassRef; 2790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)using pp::Var; 2890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 297d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)namespace { 307d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const char kExepectedVoucherFilename[] = "plugin.vch"; 317d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 327d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 3390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)TestFlashDRM::TestFlashDRM(TestingInstance* instance) 3490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) : TestCase(instance), 3590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) { 3690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 3790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 3890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)void TestFlashDRM::RunTests(const std::string& filter) { 3990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) RUN_TEST(GetDeviceID, filter); 407d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RUN_TEST(GetHmonitor, filter); 417d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) RUN_TEST(GetVoucherFile, filter); 4290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 4390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 4490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)std::string TestFlashDRM::TestGetDeviceID() { 4590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // Test the old C++ wrapper. 4690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) // TODO(raymes): Remove this once Flash switches APIs. 4790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) { 4890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DeviceID device_id(instance_); 4990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TestCompletionCallbackWithOutput<Var> output_callback( 5090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) instance_->pp_instance()); 5190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int32_t rv = device_id.GetDeviceID(output_callback.GetCallback()); 5290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) output_callback.WaitForResult(rv); 5390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(output_callback.result() == PP_OK); 5490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Var result = output_callback.output(); 5590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(result.is_string()); 5690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::string id = result.AsString(); 5790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_FALSE(id.empty()); 5890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 5990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 6090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) { 6190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) DRM drm(instance_); 6290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) TestCompletionCallbackWithOutput<Var> output_callback( 6390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) instance_->pp_instance()); 6490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) int32_t rv = drm.GetDeviceID(output_callback.GetCallback()); 6590dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) output_callback.WaitForResult(rv); 6690dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(output_callback.result() == PP_OK); 6790dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) Var result = output_callback.output(); 6890dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_TRUE(result.is_string()); 6990dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) std::string id = result.AsString(); 7090dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) ASSERT_FALSE(id.empty()); 7190dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) } 7290dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) 7390dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles) PASS(); 7490dce4d38c5ff5333bea97d859d4e484e27edf0cTorne (Richard Coles)} 757d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 767d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)std::string TestFlashDRM::TestGetHmonitor() { 777d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DRM drm(instance_); 787d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int64_t hmonitor; 797d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#if defined(PPAPI_OS_WIN) 807dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch while (true) { 817dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch if (drm.GetHmonitor(&hmonitor)) { 827dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch MONITORINFO info = { sizeof(info) }; 837dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ASSERT_EQ(TRUE, 847dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ::GetMonitorInfo(reinterpret_cast<HMONITOR>(hmonitor), &info)); 857dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch break; 867dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } else { 877dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ::Sleep(30); 887dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 897dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch } 907d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#else 917dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch ASSERT_FALSE(drm.GetHmonitor(&hmonitor)); 927d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#endif 937d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 947d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PASS(); 957d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 967d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 977d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)std::string TestFlashDRM::TestGetVoucherFile() { 987d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) DRM drm(instance_); 997d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) TestCompletionCallbackWithOutput<FileRef> output_callback( 1007d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) instance_->pp_instance()); 1017d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) int32_t rv = drm.GetVoucherFile(output_callback.GetCallback()); 1027d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) output_callback.WaitForResult(rv); 1037d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_EQ(PP_OK, output_callback.result()); 1047d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) FileRef result = output_callback.output(); 1057d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_EQ(PP_FILESYSTEMTYPE_EXTERNAL, result.GetFileSystemType()); 1067d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1077d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // The PPB_FileRefPrivate interface doesn't have a C++ wrapper yet, so just 1087d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) // use the C interface. 1097d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) const PPB_FileRefPrivate* file_ref_private = 1107d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) static_cast<const PPB_FileRefPrivate*>( 1117d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) pp::Module::Get()->GetBrowserInterface(PPB_FILEREFPRIVATE_INTERFACE)); 1127d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_TRUE(file_ref_private); 1137d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) Var path(PassRef(), file_ref_private->GetAbsolutePath(result.pp_resource())); 1147d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_TRUE(path.is_string()); 1157d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string path_string = path.AsString(); 1167d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) std::string expected_filename = std::string(kExepectedVoucherFilename); 1177d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) ASSERT_EQ(expected_filename, 1187d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) path_string.substr(path_string.size() - expected_filename.size())); 1197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) 1207d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles) PASS(); 1217d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)} 122