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
;
31 const char kExepectedVoucherFilename
[] = "plugin.vch";
33 // Check that the Hmonitor value is what it is expected to be for each platform.
34 bool CheckExpectedHmonitorValue(bool success
, int64_t hmonitor
) {
35 #if defined(PPAPI_OS_MACOSX)
36 // TODO(raymes): Verify the expected |hmonitor| value on Mac.
38 #elif defined(PPAPI_OS_WIN)
39 MONITORINFO info
= { sizeof(info
) };
41 ::GetMonitorInfo(reinterpret_cast<HMONITOR
>(hmonitor
), &info
) == TRUE
;
43 // Not implemented for other platforms, should return false.
50 TestFlashDRM::TestFlashDRM(TestingInstance
* instance
)
52 callback_factory_(this) {
55 void TestFlashDRM::RunTests(const std::string
& filter
) {
56 RUN_TEST(GetDeviceID
, filter
);
57 RUN_TEST(GetHmonitor
, filter
);
58 RUN_TEST(GetVoucherFile
, filter
);
61 std::string
TestFlashDRM::TestGetDeviceID() {
62 // Test the old C++ wrapper.
63 // TODO(raymes): Remove this once Flash switches APIs.
65 DeviceID
device_id(instance_
);
66 TestCompletionCallbackWithOutput
<Var
> output_callback(
67 instance_
->pp_instance());
68 int32_t rv
= device_id
.GetDeviceID(output_callback
.GetCallback());
69 output_callback
.WaitForResult(rv
);
70 ASSERT_TRUE(output_callback
.result() == PP_OK
);
71 Var result
= output_callback
.output();
72 ASSERT_TRUE(result
.is_string());
73 std::string id
= result
.AsString();
74 ASSERT_FALSE(id
.empty());
79 TestCompletionCallbackWithOutput
<Var
> output_callback(
80 instance_
->pp_instance());
81 int32_t rv
= drm
.GetDeviceID(output_callback
.GetCallback());
82 output_callback
.WaitForResult(rv
);
83 ASSERT_TRUE(output_callback
.result() == PP_OK
);
84 Var result
= output_callback
.output();
85 ASSERT_TRUE(result
.is_string());
86 std::string id
= result
.AsString();
87 ASSERT_FALSE(id
.empty());
93 std::string
TestFlashDRM::TestGetHmonitor() {
97 bool success
= drm
.GetHmonitor(&hmonitor
);
98 if (CheckExpectedHmonitorValue(success
, hmonitor
))
107 std::string
TestFlashDRM::TestGetVoucherFile() {
109 TestCompletionCallbackWithOutput
<FileRef
> output_callback(
110 instance_
->pp_instance());
111 int32_t rv
= drm
.GetVoucherFile(output_callback
.GetCallback());
112 output_callback
.WaitForResult(rv
);
113 ASSERT_EQ(PP_OK
, output_callback
.result());
114 FileRef result
= output_callback
.output();
115 ASSERT_EQ(PP_FILESYSTEMTYPE_EXTERNAL
, result
.GetFileSystemType());
117 // The PPB_FileRefPrivate interface doesn't have a C++ wrapper yet, so just
118 // use the C interface.
119 const PPB_FileRefPrivate
* file_ref_private
=
120 static_cast<const PPB_FileRefPrivate
*>(
121 pp::Module::Get()->GetBrowserInterface(PPB_FILEREFPRIVATE_INTERFACE
));
122 ASSERT_TRUE(file_ref_private
);
123 Var
path(PassRef(), file_ref_private
->GetAbsolutePath(result
.pp_resource()));
124 ASSERT_TRUE(path
.is_string());
125 std::string path_string
= path
.AsString();
126 std::string expected_filename
= std::string(kExepectedVoucherFilename
);
127 ASSERT_EQ(expected_filename
,
128 path_string
.substr(path_string
.size() - expected_filename
.size()));