14e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
24e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
34e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)// found in the LICENSE file.
44e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ppapi/tests/test_output_protection_private.h"
64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
74e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#include "ppapi/tests/testing_instance.h"
84e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
94e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)REGISTER_TEST_CASE(OutputProtectionPrivate);
104e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
114e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)TestOutputProtectionPrivate::TestOutputProtectionPrivate(
124e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    TestingInstance* instance)
134e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)    : TestCase(instance) {
144e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
154e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
164e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)bool TestOutputProtectionPrivate::Init() {
174e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  output_protection_interface_ =
184e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      static_cast<const PPB_OutputProtection_Private*>(
194e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          pp::Module::Get()->GetBrowserInterface(
204e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)              PPB_OUTPUTPROTECTION_PRIVATE_INTERFACE_0_1));
214e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  return output_protection_interface_ && CheckTestingInterface();
224e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
234e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
244e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)void TestOutputProtectionPrivate::RunTests(const std::string& filter) {
254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RUN_TEST(QueryStatus, filter);
264e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  RUN_TEST(EnableProtection, filter);
274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
284e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
294e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)std::string TestOutputProtectionPrivate::TestQueryStatus() {
304e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  TestCompletionCallback callback(instance_->pp_instance(), callback_type());
314e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
324e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PP_Resource output_protection_resource = output_protection_interface_->
334e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      Create(instance_->pp_instance());
344e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  uint32_t link_mask;
354e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  uint32_t protection_mask;
364e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  callback.WaitForResult(
374e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      output_protection_interface_->QueryStatus(
384e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          output_protection_resource,
394e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          &link_mask,
404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          &protection_mask,
414e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          callback.GetCallback().pp_completion_callback()));
424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  CHECK_CALLBACK_BEHAVIOR(callback);
434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
444e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PASS();
454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
474e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)std::string TestOutputProtectionPrivate::TestEnableProtection() {
484e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  TestCompletionCallback callback(instance_->pp_instance(), callback_type());
494e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
504e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PP_Resource output_protection_resource = output_protection_interface_->
514e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      Create(instance_->pp_instance());
524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  callback.WaitForResult(
534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)      output_protection_interface_->EnableProtection(
544e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          output_protection_resource,
554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          PP_OUTPUT_PROTECTION_METHOD_PRIVATE_NONE,
564e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)          callback.GetCallback().pp_completion_callback()));
574e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  CHECK_CALLBACK_BEHAVIOR(callback);
584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)
594e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)  PASS();
604e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)}
61