From c033892f2a6d1e5ca9a90ab43c3c8cbc39756a97 Mon Sep 17 00:00:00 2001 From: Rahul Frias Date: Thu, 13 Feb 2020 02:43:56 -0800 Subject: [PATCH] Add policy handling for v16 [ Merge of http://go/wvgerrit/93865 ] This allows for handling of timer and clock values as supported when both the license service and the OEMCrypto on the device support v16. A flag based on a value in the SignedResponse license indicates whether this support should be enabled. A new class PolicyTimerV16 performs the duration value evaluation. Bug: 139372190 Test: Android WV unit/integration tests Change-Id: Iacbbd51ad26c9f29cb5418ff832f8822982644b7 --- libwvdrmengine/cdm/Android.bp | 1 + .../cdm/core/include/policy_engine.h | 6 +- .../cdm/core/include/policy_timers.h | 7 +- .../cdm/core/include/policy_timers_v15.h | 12 +- .../cdm/core/include/policy_timers_v16.h | 111 + .../cdm/core/include/wv_cdm_constants.h | 1 + libwvdrmengine/cdm/core/src/license.cpp | 6 +- libwvdrmengine/cdm/core/src/policy_engine.cpp | 9 +- .../cdm/core/src/policy_timers_v15.cpp | 7 +- .../cdm/core/src/policy_timers_v16.cpp | 123 ++ .../policy_engine_constraints_unittest.cpp | 12 +- .../cdm/core/test/policy_engine_unittest.cpp | 1844 +++++++++++++++-- 12 files changed, 1961 insertions(+), 178 deletions(-) create mode 100644 libwvdrmengine/cdm/core/include/policy_timers_v16.h create mode 100644 libwvdrmengine/cdm/core/src/policy_timers_v16.cpp diff --git a/libwvdrmengine/cdm/Android.bp b/libwvdrmengine/cdm/Android.bp index 1ad45c5b..a095eec5 100644 --- a/libwvdrmengine/cdm/Android.bp +++ b/libwvdrmengine/cdm/Android.bp @@ -46,6 +46,7 @@ cc_library_static { CORE_SRC_DIR + "/policy_engine.cpp", CORE_SRC_DIR + "/policy_timers.cpp", CORE_SRC_DIR + "/policy_timers_v15.cpp", + CORE_SRC_DIR + "/policy_timers_v16.cpp", CORE_SRC_DIR + "/privacy_crypto_boringssl.cpp", CORE_SRC_DIR + "/service_certificate.cpp", CORE_SRC_DIR + "/usage_table_header.cpp", diff --git a/libwvdrmengine/cdm/core/include/policy_engine.h b/libwvdrmengine/cdm/core/include/policy_engine.h index f4e6b622..0e89df64 100644 --- a/libwvdrmengine/cdm/core/include/policy_engine.h +++ b/libwvdrmengine/cdm/core/include/policy_engine.h @@ -58,7 +58,8 @@ class PolicyEngine { // an exact copy of the policy information stored in the license. // The license state transitions to kLicenseStateCanPlay if the license // permits playback. - virtual void SetLicense(const video_widevine::License& license); + virtual void SetLicense(const video_widevine::License& license, + bool supports_core_messages); // Used to update the currently loaded entitled content keys. virtual void SetEntitledLicenseKeys( @@ -66,7 +67,8 @@ class PolicyEngine { // SetLicenseForRelease is used when releasing a license. The keys in this // license will be ignored, and any old keys will be expired. - virtual void SetLicenseForRelease(const video_widevine::License& license); + virtual void SetLicenseForRelease(const video_widevine::License& license, + bool supports_core_messages); // Call this on first decrypt to set the start of playback. virtual bool BeginDecryption(void); diff --git a/libwvdrmengine/cdm/core/include/policy_timers.h b/libwvdrmengine/cdm/core/include/policy_timers.h index ddcf0fa9..c0df728d 100644 --- a/libwvdrmengine/cdm/core/include/policy_timers.h +++ b/libwvdrmengine/cdm/core/include/policy_timers.h @@ -28,9 +28,10 @@ class PolicyTimers { // SetLicense is used in handling the initial license response. virtual void SetLicense(const video_widevine::License& license); - // UpdateLicense is used in handling a license response for a renewal request. - // The response may only contain policy fields that have changed. In this - // case an exact copy is not what we want to happen. + // UpdateLicense is used in handling a license response, a renewal response, + // or when restoring or releasing a persistent license. + // In a renewal the response may only contain policy fields that have + // changed. In this case an exact copy is not what we want to happen. virtual bool UpdateLicense(int64_t current_time, const video_widevine::License& license) = 0; diff --git a/libwvdrmengine/cdm/core/include/policy_timers_v15.h b/libwvdrmengine/cdm/core/include/policy_timers_v15.h index 8d99db7a..c1344d2e 100644 --- a/libwvdrmengine/cdm/core/include/policy_timers_v15.h +++ b/libwvdrmengine/cdm/core/include/policy_timers_v15.h @@ -31,9 +31,15 @@ class PolicyTimersV15 : public PolicyTimers { virtual ~PolicyTimersV15() {} - // UpdateLicense is used in handling a license response for a renewal request. - // The response may only contain any policy fields that have changed. In this - // case an exact copy is not what we want to happen. + // UpdateLicense is used in handling a license response, a renewal response, + // or when restoring or releasing a persistent license. + // In a renewal the response may only contain policy fields that have + // changed. In this case an exact copy is not what we want to happen. + // |license_start_time_| is updated to the time mentioned in the renewal + // response. + // UpdateLicense will return false if |license_start_time| is not + // present or playback is not allowed due to policy or timer duration + // expiration. bool UpdateLicense(int64_t current_time, const video_widevine::License& license) override; diff --git a/libwvdrmengine/cdm/core/include/policy_timers_v16.h b/libwvdrmengine/cdm/core/include/policy_timers_v16.h new file mode 100644 index 00000000..8f21bb6d --- /dev/null +++ b/libwvdrmengine/cdm/core/include/policy_timers_v16.h @@ -0,0 +1,111 @@ +// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary +// source code may only be used and distributed under the Widevine Master +// License Agreement. + +#ifndef WVCDM_CORE_POLICY_TIMERS_V16_H_ +#define WVCDM_CORE_POLICY_TIMERS_V16_H_ + +#include "disallow_copy_and_assign.h" +#include "license_protocol.pb.h" +#include "policy_timers.h" +#include "wv_cdm_types.h" + +namespace wvcdm { + +// OEMCrypto v16 and core messages introduced changes to how duration values +// and clocks should be evaluated. This class provides backward compatibility +// for licenses that do not include a core message. Durations are handled +// in the same way as in earlier releases. +// +// Backward compatibility may be needed if +// * OEMCrypto has not been upgraded to v16 +// * Licenses were persisted before the device was upgraded to v16 +// * License service does not yet support core messages + +class PolicyTimersV16 : public PolicyTimers { + public: + PolicyTimersV16() {} + + virtual ~PolicyTimersV16() {} + + // UpdateLicense is used in handling a license response, a renewal response, + // or when restoring or releasing a persistent license. + // In a renewal the response may only contain policy fields that have + // changed. In this case an exact copy is not what we want to happen. + // |renewal_start_time_| is set to the time mentioned in the renewal + // response. + // UpdateLicense will return false if |license_start_time| is not + // present or playback is not allowed due to policy or timer duration + // expiration. + bool UpdateLicense(int64_t current_time, + const video_widevine::License& license) override; + + // Call this on first decrypt to set the start of playback. + void BeginDecryption(int64_t current_time) override; + + // This is a legacy field for offline licenses. Since no grace period is + // supported return a default value. + int64_t GetGracePeriodEndTime() override { return 0; } + + // For offline save and restore. + void RestorePlaybackTimes(int64_t current_time, int64_t playback_start_time, + int64_t last_playback_time, + int64_t grace_period_end_time) override; + + bool HasPlaybackStarted(int64_t /* current_time */) override { + return playback_start_time_ != 0; + } + // For licenses that support core messages, evaluation of only rental and + // playback durations are needed. + bool HasLicenseOrRentalOrPlaybackDurationExpired( + int64_t current_time) override { + return HasRentalOrPlaybackDurationExpired(current_time); + } + bool HasPassedGracePeriod(int64_t /* current_time */) override { + return true; + } + + // This returns + // * before playback begins: the time remaining on |rental_duration_seconds| + // * after playback begins: + // - |soft_enforce_playback_duration| is true: the time remaining on + // |playback_duration_seconds| + // - |soft_enforce_playback_duration| is false: the minimum + // of the time remaining on |rental_duration_seconds| or + // |playback_duration_seconds| + // + // |license_duration_seconds| is ignored with the introduction of core + // messages + int64_t GetLicenseOrRentalOrPlaybackDurationRemaining( + int64_t current_time) override; + // This is only used in Query. This should return the time remaining on + // |rental_duration_seconds|. + int64_t GetLicenseOrRentalDurationRemaining(int64_t current_time) override { + return GetRentalDurationRemaining(current_time); + }; + + protected: + // Gets the clock time that the license expires based on whether we have + // started playing. This takes into account GetHardLicenseExpiryTime. + int64_t GetExpiryTime(int64_t current_time, + bool ignore_soft_enforce_playback_duration) override; + + int64_t GetRenewalStartTime() override { return renewal_start_time_; } + + private: + // Gets the clock time that the rental duration or playback will expire. + int64_t GetRentalExpiryTime(int64_t current_time); + int64_t GetPlaybackExpiryTime(int64_t current_time, + bool ignore_soft_enforce_playback_duration); + + bool HasRentalOrPlaybackDurationExpired(int64_t current_time); + int64_t GetRentalDurationRemaining(int64_t current_time); + + int64_t renewal_start_time_ = 0; + + CORE_DISALLOW_COPY_AND_ASSIGN(PolicyTimersV16); +}; + +} // namespace wvcdm + +#endif // WVCDM_CORE_POLICY_TIMERS_V16_H_ diff --git a/libwvdrmengine/cdm/core/include/wv_cdm_constants.h b/libwvdrmengine/cdm/core/include/wv_cdm_constants.h index 36fd81d9..5d427e20 100644 --- a/libwvdrmengine/cdm/core/include/wv_cdm_constants.h +++ b/libwvdrmengine/cdm/core/include/wv_cdm_constants.h @@ -25,6 +25,7 @@ static const size_t CERTIFICATE_DATA_SIZE = 4 * 1024; // Use 0 to represent never expired license as specified in EME spec // (NaN in JS translates to 0 in unix timestamp). static const int64_t NEVER_EXPIRES = 0; +static const int64_t UNLIMITED_DURATION = 0; // This is the lower limit. For OEMCrypto v16+ one can query and find how many // are supported diff --git a/libwvdrmengine/cdm/core/src/license.cpp b/libwvdrmengine/cdm/core/src/license.cpp index b4be99de..9549f0cd 100644 --- a/libwvdrmengine/cdm/core/src/license.cpp +++ b/libwvdrmengine/cdm/core/src/license.cpp @@ -944,7 +944,7 @@ CdmResponseType CdmLicense::RestoreLicenseForRelease( // If the policy engine already has keys, they will now expire. // If the policy engine does not already have keys, this will not add any. - policy_engine_->SetLicenseForRelease(license); + policy_engine_->SetLicenseForRelease(license, supports_core_messages()); return NO_ERROR; } @@ -1106,7 +1106,7 @@ CdmResponseType CdmLicense::HandleContentKeyResponse( it != key_array.end(); ++it) { loaded_keys_.insert(it->key_id()); } - policy_engine_->SetLicense(license); + policy_engine_->SetLicense(license, supports_core_messages()); } return resp; } @@ -1135,7 +1135,7 @@ CdmResponseType CdmLicense::HandleEntitlementKeyResponse( // Save the entitlement keys for future use to handle key changes. entitlement_keys_.CopyFrom(license.key()); - policy_engine_->SetLicense(license); + policy_engine_->SetLicense(license, supports_core_messages()); return HandleNewEntitledKeys(wrapped_keys_); } diff --git a/libwvdrmengine/cdm/core/src/policy_engine.cpp b/libwvdrmengine/cdm/core/src/policy_engine.cpp index f247c722..db06d1af 100644 --- a/libwvdrmengine/cdm/core/src/policy_engine.cpp +++ b/libwvdrmengine/cdm/core/src/policy_engine.cpp @@ -9,6 +9,7 @@ #include "clock.h" #include "log.h" #include "policy_timers_v15.h" +#include "policy_timers_v16.h" #include "properties.h" #include "string_conversions.h" #include "wv_cdm_constants.h" @@ -157,7 +158,9 @@ void PolicyEngine::OnTimerEvent() { } } -void PolicyEngine::SetLicense(const License& license) { +void PolicyEngine::SetLicense(const License& license, + bool supports_core_messages) { + if (supports_core_messages) policy_timers_.reset(new PolicyTimersV16()); license_id_.CopyFrom(license.id()); license_keys_->SetFromLicense(license); policy_timers_->SetLicense(license); @@ -169,7 +172,9 @@ void PolicyEngine::SetEntitledLicenseKeys( license_keys_->SetEntitledKeys(entitled_keys); } -void PolicyEngine::SetLicenseForRelease(const License& license) { +void PolicyEngine::SetLicenseForRelease(const License& license, + bool supports_core_messages) { + if (supports_core_messages) policy_timers_.reset(new PolicyTimersV16()); license_id_.CopyFrom(license.id()); // Expire any old keys. diff --git a/libwvdrmengine/cdm/core/src/policy_timers_v15.cpp b/libwvdrmengine/cdm/core/src/policy_timers_v15.cpp index da16f3f2..a8a33f01 100644 --- a/libwvdrmengine/cdm/core/src/policy_timers_v15.cpp +++ b/libwvdrmengine/cdm/core/src/policy_timers_v15.cpp @@ -110,14 +110,15 @@ int64_t PolicyTimersV15::GetLicenseOrRentalDurationRemaining( if (license_expiry_time == NEVER_EXPIRES) return LLONG_MAX; if (license_expiry_time < current_time) return 0; const int64_t policy_license_duration = policy_.license_duration_seconds(); - if (policy_license_duration == NEVER_EXPIRES) + if (policy_license_duration == UNLIMITED_DURATION) return license_expiry_time - current_time; return std::min(license_expiry_time - current_time, policy_license_duration); } // For the policy time fields checked in the following methods, a value of 0 -// indicates that there is no limit to the duration. If the fields are zero -// (including the hard limit) then these methods will return NEVER_EXPIRES. +// (UNLIMITED_DURATION) indicates that there is no limit to the duration. +// If the fields are UNLIMITED_DURATION (including the hard limit) then these +// methods will return NEVER_EXPIRES. int64_t PolicyTimersV15::GetHardLicenseExpiryTime() { return policy_.license_duration_seconds() > 0 ? license_start_time_ + policy_.license_duration_seconds() diff --git a/libwvdrmengine/cdm/core/src/policy_timers_v16.cpp b/libwvdrmengine/cdm/core/src/policy_timers_v16.cpp new file mode 100644 index 00000000..e4d57da2 --- /dev/null +++ b/libwvdrmengine/cdm/core/src/policy_timers_v16.cpp @@ -0,0 +1,123 @@ +// Copyright 2020 Google LLC. All Rights Reserved. This file and proprietary +// source code may only be used and distributed under the Widevine Master +// License Agreement. + +#include "policy_timers_v16.h" + +#include + +#include "log.h" +#include "wv_cdm_constants.h" + +using video_widevine::License; + +namespace wvcdm { + +bool PolicyTimersV16::UpdateLicense(int64_t current_time, + const License& license) { + if (!license.has_policy()) return false; + + policy_.MergeFrom(license.policy()); + + // some basic license validation + // license start time needs to be specified in the initial response + if (!license.has_license_start_time()) return false; + + // Update time information + renewal_start_time_ = license.license_start_time(); + next_renewal_time_ = + license.license_start_time() + policy_.renewal_delay_seconds(); + + if (!policy_.can_play() || + HasLicenseOrRentalOrPlaybackDurationExpired(current_time)) + return false; + + return true; +} + +void PolicyTimersV16::BeginDecryption(int64_t current_time) { + if (playback_start_time_ == 0) { + playback_start_time_ = current_time; + last_playback_time_ = current_time; + } +} + +void PolicyTimersV16::RestorePlaybackTimes( + int64_t current_time, int64_t playback_start_time, + int64_t last_playback_time, int64_t /* grace_period_end_time */) { + playback_start_time_ = (playback_start_time > 0) ? playback_start_time : 0; + last_playback_time_ = (last_playback_time > 0) ? last_playback_time : 0; + + const int64_t expiry_time = GetExpiryTime( + current_time, /* ignore_soft_enforce_playback_duration */ true); + was_expired_on_load_ = + expiry_time != NEVER_EXPIRES && expiry_time < current_time; +} + +bool PolicyTimersV16::HasRentalOrPlaybackDurationExpired(int64_t current_time) { + const int64_t expiry_time = GetExpiryTime( + current_time, /* ignore_soft_enforce_playback_duration */ false); + return expiry_time != NEVER_EXPIRES && expiry_time <= current_time; +} + +int64_t PolicyTimersV16::GetLicenseOrRentalOrPlaybackDurationRemaining( + int64_t current_time) { + const int64_t expiry_time = GetExpiryTime( + current_time, /* ignore_soft_enforce_playback_duration */ false); + if (expiry_time == NEVER_EXPIRES) return LLONG_MAX; + if (expiry_time < current_time) return 0; + return expiry_time - current_time; +} + +int64_t PolicyTimersV16::GetRentalDurationRemaining(int64_t current_time) { + if (HasLicenseOrRentalOrPlaybackDurationExpired(current_time)) return 0; + const int64_t rental_expiry_time = GetRentalExpiryTime(current_time); + if (rental_expiry_time == NEVER_EXPIRES) return LLONG_MAX; + if (rental_expiry_time < current_time) return 0; + return rental_expiry_time - current_time; +} + +// For the policy time fields checked in the following methods, a value of 0 +// (UNLIMITED_DURATION) indicates that there is no limit to the duration. +// If the fields are UNLIMITED_DURATION then these methods will return +// NEVER_EXPIRES. +int64_t PolicyTimersV16::GetRentalExpiryTime(int64_t current_time) { + if (policy_.rental_duration_seconds() == UNLIMITED_DURATION) + return NEVER_EXPIRES; + + if (HasPlaybackStarted(current_time) && + policy_.soft_enforce_rental_duration()) + return NEVER_EXPIRES; + + return license_start_time_ + policy_.rental_duration_seconds(); +} + +int64_t PolicyTimersV16::GetPlaybackExpiryTime( + int64_t current_time, bool ignore_soft_enforce_playback_duration) { + if (policy_.playback_duration_seconds() == UNLIMITED_DURATION) + return NEVER_EXPIRES; + + if (!HasPlaybackStarted(current_time)) return NEVER_EXPIRES; + + if (was_expired_on_load_) return current_time; + + if (!ignore_soft_enforce_playback_duration && + policy_.soft_enforce_playback_duration()) + return NEVER_EXPIRES; + + return playback_start_time_ + policy_.playback_duration_seconds(); +} + +int64_t PolicyTimersV16::GetExpiryTime( + int64_t current_time, bool ignore_soft_enforce_playback_duration) { + const int64_t rental_expiry_time = GetRentalExpiryTime(current_time); + const int64_t playback_expiry_time = GetPlaybackExpiryTime( + current_time, ignore_soft_enforce_playback_duration); + + if (rental_expiry_time == NEVER_EXPIRES) return playback_expiry_time; + if (playback_expiry_time == NEVER_EXPIRES) return rental_expiry_time; + + return std::min(rental_expiry_time, playback_expiry_time); +} + +} // namespace wvcdm diff --git a/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp index 83296e16..eb65d4c3 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_constraints_unittest.cpp @@ -238,7 +238,7 @@ TEST_F(PolicyEngineConstraintsTest, IsPermissiveWithoutAResolution) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId1)); @@ -270,7 +270,7 @@ TEST_F(PolicyEngineConstraintsTest, HandlesResolutionsBasedOnConstraints) { .WillRepeatedly( DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(NO_ERROR))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->NotifyResolution(1, kTargetRes1); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId1)); @@ -334,7 +334,7 @@ TEST_F(PolicyEngineConstraintsTest, } policy_engine_->NotifyResolution(1, kTargetRes1); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); policy_engine_->OnTimerEvent(); policy_engine_->OnTimerEvent(); @@ -367,7 +367,7 @@ TEST_F(PolicyEngineConstraintsTest, HandlesConstraintOverridingHdcp) { EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_V2), Return(NO_ERROR))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->NotifyResolution(1, kTargetRes1); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId1)); @@ -409,7 +409,7 @@ TEST_F(PolicyEngineConstraintsTest, HandlesNoHdcp) { EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NONE), Return(NO_ERROR))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->NotifyResolution(1, kTargetRes1); policy_engine_->OnTimerEvent(); @@ -453,7 +453,7 @@ TEST_F(PolicyEngineConstraintsTest, UsesDefaultHdcpWhenResolutionNotSet) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId1)); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId2)); diff --git a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp index b55a9199..6cfe95eb 100644 --- a/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp +++ b/libwvdrmengine/cdm/core/test/policy_engine_unittest.cpp @@ -24,7 +24,6 @@ namespace wvcdm { using namespace testing; namespace { -const int64_t kDurationUnlimited = 0; const int64_t kLicenseStartTime = 1413517500; // ~ 01/01/2013 const int64_t kPlaybackStartTime = kLicenseStartTime + 5; const int64_t kRentalDuration = 604800; // 7 days @@ -191,7 +190,7 @@ TEST_F(PolicyEngineTest, NoLicense) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackSuccess_OfflineLicense) { +TEST_F(PolicyEngineTest, PlaybackSuccess_OfflineLicense_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kPlaybackStartTime)) @@ -207,7 +206,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_OfflineLicense) { .WillRepeatedly( DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(NO_ERROR))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -215,7 +214,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_OfflineLicense) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicense) { +TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicense_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kPlaybackStartTime)) @@ -235,7 +234,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicense) { key->set_type(License::KeyContainer::ENTITLEMENT); key->set_id(kEntitlementKeyId); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -249,7 +248,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicense) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicenseExpiration) { +TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicenseExpiration_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kPlaybackStartTime)) @@ -267,7 +266,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicenseExpiration) { key->set_type(License::KeyContainer::ENTITLEMENT); key->set_id(kEntitlementKeyId); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -281,7 +280,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicenseExpiration) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackSuccess_StreamingLicense) { +TEST_F(PolicyEngineTest, PlaybackSuccess_StreamingLicense_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_license_duration_seconds(kLowDuration); @@ -298,7 +297,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_StreamingLicense) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -306,7 +305,7 @@ TEST_F(PolicyEngineTest, PlaybackSuccess_StreamingLicense) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFailed_CanPlayFalse) { +TEST_F(PolicyEngineTest, PlaybackFailed_CanPlayFalse_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_play(false); @@ -321,7 +320,7 @@ TEST_F(PolicyEngineTest, PlaybackFailed_CanPlayFalse) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); policy_engine_->OnTimerEvent(); @@ -330,7 +329,8 @@ TEST_F(PolicyEngineTest, PlaybackFailed_CanPlayFalse) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, LicenseExpired_RentalDurationExpiredWithoutPlayback) { +TEST_F(PolicyEngineTest, + LicenseExpired_RentalDurationExpiredWithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kLowDuration); policy->set_license_duration_seconds(kHighDuration); @@ -354,7 +354,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_RentalDurationExpiredWithoutPlayback) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); for (int i = 1; i <= 3; ++i) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -365,7 +365,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_RentalDurationExpiredWithoutPlayback) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RentalDurationPassedWithPlayback) { +TEST_F(PolicyEngineTest, PlaybackOk_RentalDurationPassedWithPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kLowDuration); @@ -388,7 +388,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalDurationPassedWithPlayback) { EXPECT_CALL(check_, Call(1)); EXPECT_CALL(check_, Call(2)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -400,7 +400,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalDurationPassedWithPlayback) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDurationExpired) { +TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDurationExpired_V15) { int64_t playback_start_time = kLicenseStartTime + 10000; EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -423,7 +423,7 @@ TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDurationExpired) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(2)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -435,7 +435,8 @@ TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDurationExpired) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, LicenseExpired_LicenseDurationExpiredWithoutPlayback) { +TEST_F(PolicyEngineTest, + LicenseExpired_LicenseDurationExpiredWithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_license_duration_seconds(kLowDuration); @@ -458,7 +459,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_LicenseDurationExpiredWithoutPlayback) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); for (int i = 1; i <= 3; ++i) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -469,7 +470,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_LicenseDurationExpiredWithoutPlayback) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Offline) { +TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Offline_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_renewal_delay_seconds(kLicenseDuration + 10); policy->set_can_renew(true); @@ -494,7 +495,7 @@ TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Offline) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(2)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -506,7 +507,7 @@ TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Offline) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Streaming) { +TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Streaming_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_rental_duration_seconds(); policy->clear_playback_duration_seconds(); @@ -531,7 +532,7 @@ TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Streaming) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(2)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -543,9 +544,9 @@ TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_Streaming) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RentalDuration0) { +TEST_F(PolicyEngineTest, PlaybackOk_RentalDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) @@ -566,7 +567,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalDuration0) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); for (int i = 1; i <= 3; ++i) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -577,9 +578,9 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalDuration0) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_PlaybackDuration0) { +TEST_F(PolicyEngineTest, PlaybackOk_PlaybackDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_playback_duration_seconds(kDurationUnlimited); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime)) @@ -605,7 +606,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackDuration0) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 4; ++i) { @@ -617,9 +618,9 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackDuration0) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_LicenseDuration0) { +TEST_F(PolicyEngineTest, PlaybackOk_LicenseDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_license_duration_seconds(UNLIMITED_DURATION); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) @@ -641,7 +642,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_LicenseDuration0) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(2)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -653,7 +654,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_LicenseDuration0) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0) { +TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_rental_duration_seconds(); policy->clear_playback_duration_seconds(); @@ -672,7 +673,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -680,7 +681,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithoutPlayback) { +TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_license_duration_seconds(); policy->clear_playback_duration_seconds(); @@ -697,7 +698,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithoutPlayback) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -714,7 +715,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithoutPlayback) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithPlayback) { +TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_license_duration_seconds(); policy->clear_playback_duration_seconds(); @@ -731,7 +732,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithPlayback) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -744,7 +745,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndLicense0_WithPlayback) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithoutPlayback) { +TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_license_duration_seconds(); policy->clear_rental_duration_seconds(); @@ -758,7 +759,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithoutPlayback) { ExpectSessionKeysChange(kKeyStatusUsable, true); EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, 0)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -770,7 +771,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithoutPlayback) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithPlayback) { +TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_license_duration_seconds(); policy->clear_rental_duration_seconds(); @@ -788,7 +789,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithPlayback) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -802,7 +803,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RentalAndLicense0_WithPlayback) { } TEST_F(PolicyEngineTest, - PlaybackOk_RentalAndLicense0_WithPlaybackBeforeLicense) { + PlaybackOk_RentalAndLicense0_WithPlaybackBeforeLicense_V15) { License_Policy* policy = license_.mutable_policy(); policy->clear_license_duration_seconds(); policy->clear_rental_duration_seconds(); @@ -822,7 +823,7 @@ TEST_F(PolicyEngineTest, EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -835,11 +836,11 @@ TEST_F(PolicyEngineTest, EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_Durations0) { +TEST_F(PolicyEngineTest, PlaybackOk_Durations0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); - policy->set_playback_duration_seconds(kDurationUnlimited); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(UNLIMITED_DURATION); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) @@ -858,7 +859,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_Durations0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -869,7 +870,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_Durations0) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_LicenseWithFutureStartTime) { +TEST_F(PolicyEngineTest, PlaybackOk_LicenseWithFutureStartTime_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime - 100)) .WillOnce(Return(kLicenseStartTime - 50)) @@ -888,7 +889,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_LicenseWithFutureStartTime) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -900,7 +901,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_LicenseWithFutureStartTime) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFailed_CanRenewFalse) { +TEST_F(PolicyEngineTest, PlaybackFailed_CanRenewFalse_V15) { License_Policy* policy = license_.mutable_policy(); const int64_t license_renewal_delay = GetLicenseRenewalDelay(kPlaybackDuration); @@ -929,7 +930,7 @@ TEST_F(PolicyEngineTest, PlaybackFailed_CanRenewFalse) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 3; ++i) { @@ -941,7 +942,7 @@ TEST_F(PolicyEngineTest, PlaybackFailed_CanRenewFalse) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess) { +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); policy->set_license_duration_seconds(kLowDuration); @@ -974,7 +975,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess) { OnExpirationUpdate(_, new_license_start_time + kLowDuration)); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -997,7 +998,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_WithFutureStartTime) { +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_WithFutureStartTime_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); policy->set_license_duration_seconds(kLowDuration); @@ -1033,7 +1034,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_WithFutureStartTime) { ExpectSessionKeysChange(kKeyStatusUsable, true); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 2; ++i) { @@ -1057,7 +1058,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_WithFutureStartTime) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, LicenseExpired_RenewFailedVersionNotUpdated) { +TEST_F(PolicyEngineTest, LicenseExpired_RenewFailedVersionNotUpdated_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); policy->set_license_duration_seconds(kLowDuration); @@ -1087,7 +1088,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_RenewFailedVersionNotUpdated) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); for (int i = 1; i <= 2; ++i) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -1112,7 +1113,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_RenewFailedVersionNotUpdated) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackFailed_RepeatedRenewFailures) { +TEST_F(PolicyEngineTest, PlaybackFailed_RepeatedRenewFailures_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); const int64_t license_renewal_delay = @@ -1155,7 +1156,7 @@ TEST_F(PolicyEngineTest, PlaybackFailed_RepeatedRenewFailures) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(8)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 8; ++i) { @@ -1166,7 +1167,7 @@ TEST_F(PolicyEngineTest, PlaybackFailed_RepeatedRenewFailures) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterExpiry) { +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterExpiry_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); policy->set_license_duration_seconds(kLowDuration); @@ -1221,7 +1222,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterExpiry) { OnExpirationUpdate(_, kPlaybackStartTime + new_playback_duration)); EXPECT_CALL(check_, Call(10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 9; ++i) { @@ -1245,7 +1246,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterExpiry) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterFailures) { +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterFailures_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(true); policy->clear_rental_duration_seconds(); @@ -1287,7 +1288,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterFailures) { EXPECT_CALL(check_, Call(6)); EXPECT_CALL(check_, Call(7)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 5; ++i) { @@ -1309,7 +1310,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccessAfterFailures) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_RenewedWithUsage) { +TEST_F(PolicyEngineTest, PlaybackOk_RenewedWithUsage_V15) { int64_t new_license_start_time = kLicenseStartTime + 10; int64_t new_playback_duration = kPlaybackDuration + 100; @@ -1343,7 +1344,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_RenewedWithUsage) { OnExpirationUpdate(_, kPlaybackStartTime + new_playback_duration)); EXPECT_CALL(check_, Call(3)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); check_.Call(1); @@ -1394,14 +1395,14 @@ TEST_F(PolicyEngineTest, MultipleKeysInLicense) { ExpectSessionKeysChange(kKeyStatusUsable, kKeyStatusUsable, true); EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, _)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); EXPECT_TRUE(policy_engine_->CanDecryptContent(kAnotherKeyId)); EXPECT_FALSE(policy_engine_->CanDecryptContent(kSigningKeyId)); EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_SoftEnforcePlaybackDuration) { +TEST_F(PolicyEngineTest, PlaybackOk_SoftEnforcePlaybackDuration_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_soft_enforce_playback_duration(true); @@ -1429,7 +1430,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_SoftEnforcePlaybackDuration) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 4; ++i) { @@ -1441,7 +1442,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_SoftEnforcePlaybackDuration) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadBeforeExpire) { +TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadBeforeExpire_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_soft_enforce_playback_duration(true); @@ -1461,7 +1462,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadBeforeExpire) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kLicenseStartTime + kLicenseDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->RestorePlaybackTimes(kPlaybackStartTime, kPlaybackStartTime, kPlaybackStartTime); policy_engine_->OnTimerEvent(); @@ -1469,7 +1470,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadBeforeExpire) { EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadAfterExpire) { +TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadAfterExpire_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_soft_enforce_playback_duration(true); @@ -1490,7 +1491,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadAfterExpire) { OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); ExpectSessionKeysChange(kKeyStatusExpired, false); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->RestorePlaybackTimes(kPlaybackStartTime, kPlaybackStartTime, kPlaybackStartTime); policy_engine_->OnTimerEvent(); @@ -1498,7 +1499,7 @@ TEST_F(PolicyEngineTest, LicenseExpired_SoftEnforceLoadAfterExpire) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_GracePeriod) { +TEST_F(PolicyEngineTest, PlaybackOk_GracePeriod_V15) { const int64_t kGracePeriod = 300; // 5 minutes License_Policy* policy = license_.mutable_policy(); policy->set_play_start_grace_period_seconds(kGracePeriod); @@ -1527,7 +1528,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriod) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); for (int i = 1; i <= 4; ++i) { @@ -1539,7 +1540,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriod) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithLoad) { +TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithLoad_V15) { const int64_t kGracePeriod = 300; // 5 minutes const int64_t kNewPlaybackStartTime = kPlaybackStartTime + kPlaybackDuration; License_Policy* policy = license_.mutable_policy(); @@ -1570,7 +1571,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithLoad) { ExpectSessionKeysChange(kKeyStatusExpired, false); EXPECT_CALL(check_, Call(4)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->RestorePlaybackTimes(kPlaybackStartTime, kPlaybackStartTime, 0); policy_engine_->BeginDecryption(); @@ -1584,7 +1585,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithLoad) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithExpiredLoad) { +TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithExpiredLoad_V15) { const int64_t kGracePeriod = 300; // 5 minutes const int64_t kNewPlaybackStartTime = kPlaybackStartTime + kPlaybackDuration + 5; @@ -1608,7 +1609,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithExpiredLoad) { OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); ExpectSessionKeysChange(kKeyStatusExpired, false); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->RestorePlaybackTimes(kPlaybackStartTime, kPlaybackStartTime, kPlaybackStartTime); @@ -1616,7 +1617,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_GracePeriodWithExpiredLoad) { EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, PlaybackOk_CanStoreGracePeriod) { +TEST_F(PolicyEngineTest, PlaybackOk_CanStoreGracePeriod_V15) { const int64_t kGracePeriod = 300; // 5 minutes License_Policy* policy = license_.mutable_policy(); policy->set_play_start_grace_period_seconds(kGracePeriod); @@ -1638,7 +1639,7 @@ TEST_F(PolicyEngineTest, PlaybackOk_CanStoreGracePeriod) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -1688,25 +1689,25 @@ TEST_P(PolicyEngineKeySecurityLevelTest, CanUseKeyForSecurityLevel) { EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, _)); SetCdmSecurityLevel(kSecurityLevelL1); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_EQ(param->expect_can_L1_use_key, policy_engine_->CanUseKeyForSecurityLevel(kKeyId)); SetCdmSecurityLevel(kSecurityLevelL2); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_EQ(param->expect_can_L2_use_key, policy_engine_->CanUseKeyForSecurityLevel(kKeyId)); SetCdmSecurityLevel(kSecurityLevelL3); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_EQ(param->expect_can_L3_use_key, policy_engine_->CanUseKeyForSecurityLevel(kKeyId)); SetCdmSecurityLevel(kSecurityLevelUnknown); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_EQ(param->expect_can_level_unknown_use_key, policy_engine_->CanUseKeyForSecurityLevel(kKeyId)); @@ -1847,7 +1848,7 @@ TEST_F(PolicyEngineKeyAllowedUsageTest, AllowedUsageBasic) { ExpectSessionKeysChange(kKeyStatusUsable, kKeyStatusUsable, true); EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, _)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); ExpectSecureContentKey(kKeyId, kHardwareSecureAll); ExpectLessSecureContentKey(kAnotherKeyId, kKeySecurityLevelUnset); @@ -1907,7 +1908,7 @@ TEST_F(PolicyEngineKeyAllowedUsageTest, AllowedUsageGeneric) { ExpectSessionKeysChange(kKeyStatusUsable, kKeyStatusUsable, true); EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, _)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); ExpectSecureContentKey(kKeyId, kHardwareSecureDecode); ExpectLessSecureContentKey(kAnotherKeyId, kHardwareSecureCrypto); @@ -1941,7 +1942,7 @@ class PolicyEngineQueryTest : public PolicyEngineTest { } }; -TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseNotReceived) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseNotReceived_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime)); @@ -1950,20 +1951,20 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseNotReceived) { EXPECT_EQ(0u, query_info.size()); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseStartTimeNotSet) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseStartTimeNotSet_V15) { license_.clear_license_start_time(); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); CdmQueryMap query_info; EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); EXPECT_EQ(0u, query_info.size()); } -TEST_F(PolicyEngineQueryTest, QuerySuccess) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kLicenseStartTime + 100)); @@ -1972,7 +1973,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); CdmQueryMap query_info; EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); @@ -1988,7 +1989,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackNotBegun) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackNotBegun_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kLicenseStartTime + 100)) @@ -1998,7 +1999,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackNotBegun) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); CdmQueryMap query_info; EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); @@ -2026,7 +2027,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackNotBegun) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackBegun) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackBegun_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kLicenseStartTime + 50)) @@ -2038,7 +2039,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackBegun) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); CdmQueryMap query_info; EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); @@ -2071,7 +2072,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackBegun) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_Offline) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_Offline_V15) { LicenseIdentification* id = license_.mutable_id(); id->set_type(OFFLINE); @@ -2091,7 +2092,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Offline) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); @@ -2112,7 +2113,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Offline) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialRentalDurationExpired) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialRentalDurationExpired_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kLowDuration); policy->set_license_duration_seconds(kHighDuration); @@ -2121,7 +2122,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialRentalDurationExpired) { .WillOnce(Return(kLicenseStartTime + kLowDuration + 1)) .WillOnce(Return(kLicenseStartTime + kLowDuration + 5)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2138,12 +2139,12 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialRentalDurationExpired) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialLicenseDurationExpired) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialLicenseDurationExpired_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + kLowDuration + 1)) .WillOnce(Return(kLicenseStartTime + kLowDuration + 5)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2160,7 +2161,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialLicenseDurationExpired) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_CanPlayFalse) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_CanPlayFalse_V15) { LicenseIdentification* id = license_.mutable_id(); id->set_type(OFFLINE); @@ -2178,7 +2179,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_CanPlayFalse) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); policy_engine_->OnTimerEvent(); @@ -2200,7 +2201,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_CanPlayFalse) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDurationExpired) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDurationExpired_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kLowDuration); policy->set_license_duration_seconds(kHighDuration); @@ -2217,7 +2218,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDurationExpired) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2241,7 +2242,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDurationExpired) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDurationExpired) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDurationExpired_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_playback_duration_seconds(kLowDuration); policy->set_license_duration_seconds(kHighDuration); @@ -2259,7 +2260,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDurationExpired) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2282,7 +2283,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDurationExpired) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDurationExpired) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDurationExpired_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_can_renew(false); @@ -2297,7 +2298,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDurationExpired) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2321,9 +2322,9 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDurationExpired) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDuration0) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); int64_t license_renewal_delay = GetLicenseRenewalDelay(kLowDuration); EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2339,7 +2340,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDuration0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2363,9 +2364,9 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDuration0) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDuration0) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_playback_duration_seconds(kDurationUnlimited); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); policy->set_license_duration_seconds(kHighDuration); int64_t license_renewal_delay = GetLicenseRenewalDelay(kHighDuration); policy->set_renewal_delay_seconds(license_renewal_delay); @@ -2384,7 +2385,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDuration0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2423,9 +2424,9 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDuration0) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDuration0) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDuration0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_license_duration_seconds(UNLIMITED_DURATION); EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) @@ -2438,7 +2439,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDuration0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2461,10 +2462,10 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseDuration0) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); - policy->set_playback_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); policy->set_license_duration_seconds(kLowDuration); // Only |license_duration_seconds| set. @@ -2476,7 +2477,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0) { .WillOnce(Return(kLicenseStartTime + kLowDuration + 10)) .WillOnce(Return(kLicenseStartTime + kLowDuration + 10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -2510,11 +2511,11 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0) { } TEST_F(PolicyEngineQueryTest, - QuerySuccess_PlaybackAndLicense0_WithoutPlayback) { + QuerySuccess_PlaybackAndLicense0_WithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kRentalDuration); - policy->set_playback_duration_seconds(kDurationUnlimited); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(UNLIMITED_DURATION); // Only |rental_duration_seconds| set. EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2525,7 +2526,7 @@ TEST_F(PolicyEngineQueryTest, .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)) .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2565,11 +2566,12 @@ TEST_F(PolicyEngineQueryTest, EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndLicense0_WithPlayback) { +TEST_F(PolicyEngineQueryTest, + QuerySuccess_PlaybackAndLicense0_WithPlayback_V15) { License_Policy* policy = license_.mutable_policy(); policy->set_rental_duration_seconds(kRentalDuration); - policy->set_playback_duration_seconds(kDurationUnlimited); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(UNLIMITED_DURATION); // Only |rental_duration_seconds| set. EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2582,7 +2584,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndLicense0_WithPlayback) { .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)) .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -2636,11 +2638,12 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndLicense0_WithPlayback) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithoutPlayback) { +TEST_F(PolicyEngineQueryTest, + QuerySuccess_RentalAndLicense0_WithoutPlayback_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); policy->set_playback_duration_seconds(kPlaybackDuration); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_license_duration_seconds(UNLIMITED_DURATION); // Only |playback_duration_seconds| set. EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2650,7 +2653,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithoutPlayback) { .WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10)) .WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2687,11 +2690,11 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithoutPlayback) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithPlayback) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithPlayback_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); policy->set_playback_duration_seconds(kPlaybackDuration); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_license_duration_seconds(UNLIMITED_DURATION); // Only |playback_duration_seconds| set. EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2704,7 +2707,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithPlayback) { .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 10)) .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 10)); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); @@ -2756,11 +2759,11 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalAndLicense0_WithPlayback) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_Durations0) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_Durations0_V15) { License_Policy* policy = license_.mutable_policy(); - policy->set_rental_duration_seconds(kDurationUnlimited); - policy->set_playback_duration_seconds(kDurationUnlimited); - policy->set_license_duration_seconds(kDurationUnlimited); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(UNLIMITED_DURATION); policy->set_renewal_delay_seconds(kHighDuration + 10); EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2774,7 +2777,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Durations0) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2798,7 +2801,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Durations0) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseWithFutureStartTime) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseWithFutureStartTime_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime - 100)) .WillOnce(Return(kLicenseStartTime - 50)) @@ -2811,7 +2814,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseWithFutureStartTime) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->OnTimerEvent(); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2848,7 +2851,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseWithFutureStartTime) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_Renew) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_Renew_V15) { int64_t license_renewal_delay = license_.policy().renewal_delay_seconds(); EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2866,7 +2869,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Renew) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2901,7 +2904,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_Renew) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineQueryTest, QuerySuccess_RenewWithFutureStartTime) { +TEST_F(PolicyEngineQueryTest, QuerySuccess_RenewWithFutureStartTime_V15) { int64_t license_renewal_delay = license_.policy().renewal_delay_seconds(); EXPECT_CALL(*mock_clock_, GetCurrentTime()) @@ -2923,7 +2926,7 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RenewWithFutureStartTime) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -2974,19 +2977,19 @@ TEST_F(PolicyEngineQueryTest, QuerySuccess_RenewWithFutureStartTime) { EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); } -TEST_F(PolicyEngineTest, SetLicenseForRelease) { +TEST_F(PolicyEngineTest, SetLicenseForRelease_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)); // No key change event will fire. EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); - policy_engine_->SetLicenseForRelease(license_); + policy_engine_->SetLicenseForRelease(license_, false); // No keys were loaded. EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); } -TEST_F(PolicyEngineTest, SetLicenseForReleaseAfterSetLicense) { +TEST_F(PolicyEngineTest, SetLicenseForReleaseAfterSetLicense_V15) { EXPECT_CALL(*mock_clock_, GetCurrentTime()) .WillOnce(Return(kLicenseStartTime + 1)) .WillOnce(Return(kPlaybackStartTime)) @@ -3002,7 +3005,7 @@ TEST_F(PolicyEngineTest, SetLicenseForReleaseAfterSetLicense) { .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(GET_HDCP_CAPABILITY_FAILED))); - policy_engine_->SetLicense(license_); + policy_engine_->SetLicense(license_, false); policy_engine_->BeginDecryption(); policy_engine_->OnTimerEvent(); EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); @@ -3012,7 +3015,1536 @@ TEST_F(PolicyEngineTest, SetLicenseForReleaseAfterSetLicense) { // This would happen when asking the session to generate a release message // on an existing session. ExpectSessionKeysChange(kKeyStatusExpired, false); - policy_engine_->SetLicenseForRelease(license_); + policy_engine_->SetLicenseForRelease(license_, false); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +// These test execise license policy when the license service and client +// both support OEMCrypto v16 + +TEST_F(PolicyEngineTest, PlaybackSuccess_V16) { + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + 10)); + + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly( + DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(NO_ERROR))); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + policy_engine_->OnTimerEvent(); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFailed_CanPlayFalse_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_can_play(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + 5)) + .WillOnce(Return(kLicenseStartTime + 7)); + + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + + policy_engine_->BeginDecryption(); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, + LicenseExpired_RentalDurationExpiredWithoutPlayback_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_soft_enforce_rental_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kLowDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F( + PolicyEngineTest, + LicenseExpired_RentalDurationExpiredWithoutPlayback_SoftEnforceRentalDuration_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_soft_enforce_rental_duration(true); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kLowDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFails_RentalDurationPassedWithPlayback_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 1)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kLowDuration)); + EXPECT_CALL(check_, Call(1)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(2)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F( + PolicyEngineTest, + PlaybackOk_RentalDurationPassedWithPlayback_SoftEnforceRentalDuration_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(true); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 1)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kLowDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDurationExpired_V16) { + const int64_t playback_start_time = kLicenseStartTime + 10000; + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(playback_start_time)) + .WillOnce(Return(playback_start_time + kPlaybackDuration - 2)) + .WillOnce(Return(playback_start_time + kPlaybackDuration + 2)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, playback_start_time + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(2)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, + PlaybackOk_PlaybackDurationExpired_SoftEnforcePlaybackDuration_V16) { + int64_t playback_start_time = kLicenseStartTime + 10000; + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(true); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(playback_start_time)) + .WillOnce(Return(playback_start_time + kPlaybackDuration - 2)) + .WillOnce(Return(playback_start_time + kPlaybackDuration + 2)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +// License duration is not enforced with the policy changes introduced in +// OEMCrypto v16. Rental and Playback durations are used for both streaming and +// offline. Verify that License duration expiry does not cause the license +// to expire. +TEST_F(PolicyEngineTest, LicenseOk_LicenseDurationExpiredWithoutPlayback_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_license_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, LicenseOk_LicenseDurationExpiredWithPlayback_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_license_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime + 10)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFails_ExpiryBeforeRenewalDelay_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_renewal_delay_seconds(kLicenseDuration + 10); + policy->set_can_renew(true); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 1)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 1)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(2)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, LicenseOk_RentalDuration0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)) + .WillOnce(Return(kLicenseStartTime + kLicenseDuration + 1)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, NEVER_EXPIRES)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackOk_RentalDuration0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration + 10)) + .WillOnce(Return(kLicenseStartTime + kLicenseDuration + 1)) + .WillOnce(Return(kLicenseStartTime + kLicenseDuration + 10)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, NEVER_EXPIRES)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kLicenseDuration + 10 + + kPlaybackDuration)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFails_PlaybackDuration0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 2)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 2)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration - 2)) + .WillOnce(Return(kLicenseStartTime + kRentalDuration + 2)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(4)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 4; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, + PlaybackOk_PlaybackDuration0_SoftEnforceRentalDuration_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(true); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 2)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 2)) + .WillOnce(Return(kPlaybackStartTime + kRentalDuration - 2)) + .WillOnce(Return(kPlaybackStartTime + kRentalDuration + 2)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, NEVER_EXPIRES)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + EXPECT_CALL(check_, Call(4)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 4; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackOk_PlaybackAndRental0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + // Only |license_duration_seconds| set. + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 2)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 2)) + .WillOnce(Return(kPlaybackStartTime + kRentalDuration - 2)) + .WillOnce(Return(kPlaybackStartTime + kRentalDuration + 2)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, OnExpirationUpdate(_, NEVER_EXPIRES)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + EXPECT_CALL(check_, Call(4)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 4; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackOk_LicenseWithFutureStartTime_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime - 100)) + .WillOnce(Return(kLicenseStartTime - 50)) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kPlaybackStartTime)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsableInFuture, false); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->OnTimerEvent(); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackFailed_CanRenewFalse_V16) { + License_Policy* policy = license_.mutable_policy(); + const int64_t license_renewal_delay = + GetLicenseRenewalDelay(kPlaybackDuration); + policy->set_renewal_delay_seconds(license_renewal_delay); + policy->set_can_renew(false); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 10)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration - 10)) + .WillOnce(Return(kPlaybackStartTime + kPlaybackDuration + 1)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(check_, Call(2)); + ExpectSessionKeysChange(kKeyStatusExpired, false); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 3; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_can_renew(true); + int64_t license_renewal_delay = GetLicenseRenewalDelay(kPlaybackDuration); + policy->set_renewal_delay_seconds(license_renewal_delay); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + int64_t new_license_start_time = + kLicenseStartTime + license_renewal_delay + 15; + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 15)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 10)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 20)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + + kLicenseRenewalRetryInterval + 10)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(check_, Call(3)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + license_.set_license_start_time(new_license_start_time); + policy->set_renewal_delay_seconds(new_license_start_time); + LicenseIdentification* id = license_.mutable_id(); + id->set_version(2); + policy_engine_->UpdateLicense(license_); + + policy_engine_->OnTimerEvent(); + check_.Call(3); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackOk_RenewSuccess_WithFutureStartTime_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_can_renew(true); + const int64_t license_renewal_delay = + GetLicenseRenewalDelay(kPlaybackDuration); + policy->set_renewal_delay_seconds(license_renewal_delay); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + const int64_t new_license_start_time = + kLicenseStartTime + license_renewal_delay + 50; + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 15)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 10)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 20)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 30)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 60)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(3)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(4)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + license_.set_license_start_time(new_license_start_time); + LicenseIdentification* id = license_.mutable_id(); + id->set_version(2); + policy_engine_->UpdateLicense(license_); + + policy_engine_->OnTimerEvent(); + check_.Call(3); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + check_.Call(4); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, LicenseExpired_RenewFailedVersionNotUpdated_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_can_renew(true); + int64_t license_renewal_delay = GetLicenseRenewalDelay(kPlaybackDuration); + policy->set_renewal_delay_seconds(license_renewal_delay); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 10)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 10)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 40)) + .WillOnce(Return(kLicenseStartTime + kPlaybackDuration + 10)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + InSequence s; + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(check_, Call(1)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(2)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(3)); + EXPECT_CALL(mock_event_listener_, OnSessionRenewalNeeded(_)); + EXPECT_CALL(check_, Call(4)); + + policy_engine_->SetLicense(license_, true); + + for (int i = 1; i <= 2; ++i) { + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->OnTimerEvent(); + check_.Call(i); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + license_.set_license_start_time(kLicenseStartTime + license_renewal_delay + + 30); + policy_engine_->UpdateLicense(license_); + + policy_engine_->OnTimerEvent(); + check_.Call(3); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + check_.Call(4); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, PlaybackSuccess_EntitlementLicense_V16) { + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + 10)); + + ExpectSessionKeysChange(kKeyStatusUsable, true, kEntitlementKeyId); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly( + DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), Return(NO_ERROR))); + + License::KeyContainer* key = license_.mutable_key(0); + key->set_type(License::KeyContainer::ENTITLEMENT); + key->set_id(kEntitlementKeyId); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + policy_engine_->OnTimerEvent(); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + std::vector entitled_keys(1); + entitled_keys[0].set_entitlement_key_id(kEntitlementKeyId); + entitled_keys[0].set_key_id(kKeyId); + policy_engine_->SetEntitledLicenseKeys(entitled_keys); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseNotReceived_V16) { + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(0u, query_info.size()); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseStartTimeNotSet_V16) { + license_.clear_license_start_time(); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)); + + policy_engine_->SetLicense(license_, true); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(0u, query_info.size()); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + 100)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 100, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackNotBegun_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + 100)) + .WillOnce(Return(kLicenseStartTime + 200)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 100, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); + + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 200, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackBegun_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + 50)) + .WillOnce(Return(kLicenseStartTime + 100)) + .WillOnce(Return(kLicenseStartTime + 150)) + .WillOnce(Return(kLicenseStartTime + 200)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 50, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 200, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration - 100, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_InitialRentalDurationExpired_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 5)); + + policy_engine_->SetLicense(license_, true); + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_CanPlayFalse_V16) { + LicenseIdentification* id = license_.mutable_id(); + id->set_type(OFFLINE); + + License_Policy* policy = license_.mutable_policy(); + policy->set_can_play(false); + policy->set_can_persist(true); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kLicenseStartTime + 5)) + .WillOnce(Return(kLicenseStartTime + 7)) + .WillOnce(Return(kLicenseStartTime + 100)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + + policy_engine_->BeginDecryption(); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_OFFLINE, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 100, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDurationExpired_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_renewal_delay_seconds(GetLicenseRenewalDelay(kHighDuration)); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 5)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 2; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration - kLowDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDurationExpired_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_playback_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_renewal_delay_seconds(GetLicenseRenewalDelay(kHighDuration)); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + int64_t playback_start_time = kLicenseStartTime + 10000; + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(playback_start_time)) + .WillOnce(Return(playback_start_time - 2 + kLowDuration)) + .WillOnce(Return(playback_start_time + 2 + kLowDuration)) + .WillOnce(Return(playback_start_time + 5 + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 2; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, + QuerySuccess_RentalDurationExpired_SoftEnforceRentalDuration_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_renewal_delay_seconds(GetLicenseRenewalDelay(kHighDuration)); + policy->set_soft_enforce_rental_duration(true); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime - 2 + kLowDuration)) + .WillOnce(Return(kLicenseStartTime + 2 + kLowDuration)) + .WillOnce(Return(kLicenseStartTime + 5 + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 2; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration - kLicenseStartTime - 5 - kLowDuration + + kPlaybackStartTime, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, + QuerySuccess_PlaybackDurationExpired_SoftEnforcePlaybackDuration_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_playback_duration_seconds(kLowDuration); + policy->set_license_duration_seconds(kHighDuration); + policy->set_renewal_delay_seconds(GetLicenseRenewalDelay(kHighDuration)); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(true); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kPlaybackStartTime - 2 + kLowDuration)) + .WillOnce(Return(kPlaybackStartTime + 2 + kLowDuration)) + .WillOnce(Return(kPlaybackStartTime + 5 + kLowDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 2; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - (kPlaybackStartTime + 5 + kLowDuration) + + kLicenseStartTime, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_RentalDuration0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + int64_t license_renewal_delay = GetLicenseRenewalDelay(kLowDuration); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 1)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 1)) + .WillOnce(Return(kLicenseStartTime + kLowDuration)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 5)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 4; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration - kLowDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackDuration0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(kHighDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + int64_t license_renewal_delay = GetLicenseRenewalDelay(kHighDuration); + policy->set_renewal_delay_seconds(license_renewal_delay); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kLicenseStartTime + 5)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay - 2)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 2)) + .WillOnce(Return(kLicenseStartTime + license_renewal_delay + 5)) + .WillOnce(Return(kLicenseStartTime + kHighDuration - 2)) + .WillOnce(Return(kLicenseStartTime + kHighDuration + 2)) + .WillOnce(Return(kLicenseStartTime + kHighDuration + 5)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->BeginDecryption(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + + for (int i = 1; i <= 2; ++i) { + policy_engine_->OnTimerEvent(); + } + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); + + for (int i = 3; i <= 4; ++i) { + policy_engine_->OnTimerEvent(); + } + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(0, std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_PlaybackAndRental0_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_rental_duration_seconds(UNLIMITED_DURATION); + policy->set_playback_duration_seconds(UNLIMITED_DURATION); + policy->set_license_duration_seconds(kLowDuration); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + // Only |license_duration_seconds| set. + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + 10)) + .WillOnce(Return(kLicenseStartTime + kLowDuration - 10)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 10)) + .WillOnce(Return(kLicenseStartTime + kLowDuration + 10)); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + policy_engine_->OnTimerEvent(); + + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kSomeRandomKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); + + policy_engine_->OnTimerEvent(); + + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(LLONG_MAX, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineQueryTest, QuerySuccess_LicenseWithFutureStartTime_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime - 100)) + .WillOnce(Return(kLicenseStartTime - 50)) + .WillOnce(Return(kLicenseStartTime - 10)) + .WillOnce(Return(kLicenseStartTime)) + .WillOnce(Return(kLicenseStartTime + 10)) + .WillOnce(Return(kLicenseStartTime + 25)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + + policy_engine_->OnTimerEvent(); + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + CdmQueryMap query_info; + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration + 10, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); + + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); + + policy_engine_->OnTimerEvent(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + policy_engine_->BeginDecryption(); + + EXPECT_EQ(NO_ERROR, policy_engine_->Query(&query_info)); + EXPECT_EQ(QUERY_VALUE_STREAMING, query_info[QUERY_KEY_LICENSE_TYPE]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_PLAY_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_FALSE, query_info[QUERY_KEY_PERSIST_ALLOWED]); + EXPECT_EQ(QUERY_VALUE_TRUE, query_info[QUERY_KEY_RENEW_ALLOWED]); + + EXPECT_EQ(kRentalDuration - 25, + std::stoll(query_info[QUERY_KEY_LICENSE_DURATION_REMAINING])); + EXPECT_EQ(kPlaybackDuration - 15, + std::stoll(query_info[QUERY_KEY_PLAYBACK_DURATION_REMAINING])); + EXPECT_EQ(kRenewalServerUrl, query_info[QUERY_KEY_RENEWAL_SERVER_URL]); +} + +TEST_F(PolicyEngineTest, SetLicenseForRelease_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)); + + // No key change event will fire. + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + policy_engine_->SetLicenseForRelease(license_, false); + // No keys were loaded. + EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); +} + +TEST_F(PolicyEngineTest, SetLicenseForReleaseAfterSetLicense_V16) { + License_Policy* policy = license_.mutable_policy(); + policy->set_soft_enforce_rental_duration(false); + policy->set_soft_enforce_playback_duration(false); + + EXPECT_CALL(*mock_clock_, GetCurrentTime()) + .WillOnce(Return(kLicenseStartTime + 1)) + .WillOnce(Return(kPlaybackStartTime)) + .WillOnce(Return(kLicenseStartTime + 10)); + + ExpectSessionKeysChange(kKeyStatusUsable, true); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kLicenseStartTime + kRentalDuration)); + EXPECT_CALL(mock_event_listener_, + OnExpirationUpdate(_, kPlaybackStartTime + kPlaybackDuration)); + + EXPECT_CALL(crypto_session_, GetHdcpCapabilities(_, _)) + .WillRepeatedly(DoAll(SetArgPointee<0>(HDCP_NO_DIGITAL_OUTPUT), + Return(GET_HDCP_CAPABILITY_FAILED))); + + policy_engine_->SetLicense(license_, true); + policy_engine_->BeginDecryption(); + policy_engine_->OnTimerEvent(); + EXPECT_TRUE(policy_engine_->CanDecryptContent(kKeyId)); + ::testing::Mock::VerifyAndClear(&mock_event_listener_); + + // Set the license again with use_keys set to false. + // This would happen when asking the session to generate a release message + // on an existing session. + ExpectSessionKeysChange(kKeyStatusExpired, false); + policy_engine_->SetLicenseForRelease(license_, false); EXPECT_FALSE(policy_engine_->CanDecryptContent(kKeyId)); }