1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "ppapi/tests/test_flash_drm.h"
7 #if defined(PPAPI_OS_WIN)
11 #include "ppapi/c/pp_macros.h"
12 #include "ppapi/c/private/ppb_file_ref_private.h"
13 #include "ppapi/c/private/ppb_flash_drm.h"
14 #include "ppapi/cpp/instance.h"
15 #include "ppapi/cpp/module.h"
16 #include "ppapi/cpp/private/flash_device_id.h"
17 #include "ppapi/cpp/private/flash_drm.h"
18 #include "ppapi/cpp/var.h"
19 #include "ppapi/tests/testing_instance.h"
21 REGISTER_TEST_CASE(FlashDRM
);
23 using pp::flash::DeviceID
;
30 const char kExepectedVoucherFilename
[] = "plugin.vch";
33 TestFlashDRM::TestFlashDRM(TestingInstance
* instance
)
35 PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
38 void TestFlashDRM::RunTests(const std::string
& filter
) {
39 RUN_TEST(GetDeviceID
, filter
);
40 RUN_TEST(GetHmonitor
, filter
);
41 RUN_TEST(GetVoucherFile
, filter
);
44 std::string
TestFlashDRM::TestGetDeviceID() {
45 // Test the old C++ wrapper.
46 // TODO(raymes): Remove this once Flash switches APIs.
48 DeviceID
device_id(instance_
);
49 TestCompletionCallbackWithOutput
<Var
> output_callback(
50 instance_
->pp_instance());
51 int32_t rv
= device_id
.GetDeviceID(output_callback
.GetCallback());
52 output_callback
.WaitForResult(rv
);
53 ASSERT_TRUE(output_callback
.result() == PP_OK
);
54 Var result
= output_callback
.output();
55 ASSERT_TRUE(result
.is_string());
56 std::string id
= result
.AsString();
57 ASSERT_FALSE(id
.empty());
62 TestCompletionCallbackWithOutput
<Var
> output_callback(
63 instance_
->pp_instance());
64 int32_t rv
= drm
.GetDeviceID(output_callback
.GetCallback());
65 output_callback
.WaitForResult(rv
);
66 ASSERT_TRUE(output_callback
.result() == PP_OK
);
67 Var result
= output_callback
.output();
68 ASSERT_TRUE(result
.is_string());
69 std::string id
= result
.AsString();
70 ASSERT_FALSE(id
.empty());
76 std::string
TestFlashDRM::TestGetHmonitor() {
79 #if defined(PPAPI_OS_WIN)
81 if (drm
.GetHmonitor(&hmonitor
)) {
82 MONITORINFO info
= { sizeof(info
) };
84 ::GetMonitorInfo(reinterpret_cast<HMONITOR
>(hmonitor
), &info
));
91 ASSERT_FALSE(drm
.GetHmonitor(&hmonitor
));
97 std::string
TestFlashDRM::TestGetVoucherFile() {
99 TestCompletionCallbackWithOutput
<FileRef
> output_callback(
100 instance_
->pp_instance());
101 int32_t rv
= drm
.GetVoucherFile(output_callback
.GetCallback());
102 output_callback
.WaitForResult(rv
);
103 ASSERT_EQ(PP_OK
, output_callback
.result());
104 FileRef result
= output_callback
.output();
105 ASSERT_EQ(PP_FILESYSTEMTYPE_EXTERNAL
, result
.GetFileSystemType());
107 // The PPB_FileRefPrivate interface doesn't have a C++ wrapper yet, so just
108 // use the C interface.
109 const PPB_FileRefPrivate
* file_ref_private
=
110 static_cast<const PPB_FileRefPrivate
*>(
111 pp::Module::Get()->GetBrowserInterface(PPB_FILEREFPRIVATE_INTERFACE
));
112 ASSERT_TRUE(file_ref_private
);
113 Var
path(PassRef(), file_ref_private
->GetAbsolutePath(result
.pp_resource()));
114 ASSERT_TRUE(path
.is_string());
115 std::string path_string
= path
.AsString();
116 std::string expected_filename
= std::string(kExepectedVoucherFilename
);
117 ASSERT_EQ(expected_filename
,
118 path_string
.substr(path_string
.size() - expected_filename
.size()));