Home | History | Annotate | Download | only in tests
      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.
      4 
      5 #include "ppapi/tests/test_flash_drm.h"
      6 
      7 #if defined(PPAPI_OS_WIN)
      8 #include <Windows.h>
      9 #endif
     10 
     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"
     20 
     21 REGISTER_TEST_CASE(FlashDRM);
     22 
     23 using pp::flash::DeviceID;
     24 using pp::flash::DRM;
     25 using pp::FileRef;
     26 using pp::PassRef;
     27 using pp::Var;
     28 
     29 namespace {
     30   const char kExepectedVoucherFilename[] = "plugin.vch";
     31 }
     32 
     33 TestFlashDRM::TestFlashDRM(TestingInstance* instance)
     34     : TestCase(instance),
     35       PP_ALLOW_THIS_IN_INITIALIZER_LIST(callback_factory_(this)) {
     36 }
     37 
     38 void TestFlashDRM::RunTests(const std::string& filter) {
     39   RUN_TEST(GetDeviceID, filter);
     40   RUN_TEST(GetHmonitor, filter);
     41   RUN_TEST(GetVoucherFile, filter);
     42 }
     43 
     44 std::string TestFlashDRM::TestGetDeviceID() {
     45   // Test the old C++ wrapper.
     46   // TODO(raymes): Remove this once Flash switches APIs.
     47   {
     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());
     58   }
     59 
     60   {
     61     DRM drm(instance_);
     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());
     71   }
     72 
     73   PASS();
     74 }
     75 
     76 std::string TestFlashDRM::TestGetHmonitor() {
     77   DRM drm(instance_);
     78   int64_t hmonitor;
     79 #if defined(PPAPI_OS_WIN)
     80   while (true) {
     81     if (drm.GetHmonitor(&hmonitor)) {
     82       MONITORINFO info = { sizeof(info) };
     83       ASSERT_EQ(TRUE,
     84                 ::GetMonitorInfo(reinterpret_cast<HMONITOR>(hmonitor), &info));
     85       break;
     86     } else {
     87       ::Sleep(30);
     88     }
     89   }
     90 #else
     91   ASSERT_FALSE(drm.GetHmonitor(&hmonitor));
     92 #endif
     93 
     94   PASS();
     95 }
     96 
     97 std::string TestFlashDRM::TestGetVoucherFile() {
     98   DRM drm(instance_);
     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());
    106 
    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()));
    119 
    120   PASS();
    121 }
    122