Commit 85dc7849 authored by Xiaohan Wang's avatar Xiaohan Wang Committed by Commit Bot

media: Use NiceMock<MockCdm> in MockCdmFactory

The MockCdmFactory just creates the MockCdm and should not expect what
calls will be made on the MockCdm. Hence, replace StrictMock with
NiceMock. Test cases that expect calls on MockCdm should get the MockCdm
via MockCdmFactory::GetCreatedCdm() and explicitly specify expectations
using EXPECT_CALL.

This is also consistent with googlemock guidelines [1]:
"""
Our general recommendation is to use nice mocks (not yet the default)
most of the time, use naggy mocks (the current default) when developing
or debugging tests, and use strict mocks only as the last resort.
"""

[1] https://github.com/google/googletest/blob/master/googlemock/docs/cook_book.md#the-nice-the-strict-and-the-naggy-nicestrictnaggy

Bug: 1018854
Test: Update test helper classes. No functionality change.
Change-Id: I197f83b221296beccd05b82d2b6ae030381178e8
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1890970
Commit-Queue: Xiaohan Wang <xhwang@chromium.org>
Reviewed-by: default avatarJohn Rummell <jrummell@chromium.org>
Cr-Commit-Position: refs/heads/master@{#710980}
parent 7063ac9f
...@@ -7,9 +7,9 @@ ...@@ -7,9 +7,9 @@
#include "base/logging.h" #include "base/logging.h"
using ::testing::_; using ::testing::_;
using ::testing::NiceMock;
using ::testing::Return; using ::testing::Return;
using ::testing::SaveArg; using ::testing::SaveArg;
using ::testing::StrictMock;
MATCHER(NotEmpty, "") { MATCHER(NotEmpty, "") {
return !arg.empty(); return !arg.empty();
...@@ -244,12 +244,13 @@ void MockCdmFactory::Create( ...@@ -244,12 +244,13 @@ void MockCdmFactory::Create(
before_creation_cb_.Run(); before_creation_cb_.Run();
// Create and return a new MockCdm. Keep a pointer to the created CDM so // Create and return a new MockCdm. Keep a pointer to the created CDM so
// that tests can access it. Calls to GetCdmContext() can be ignored. // that tests can access it. Test cases that expect calls on MockCdm should
scoped_refptr<MockCdm> cdm = new StrictMock<MockCdm>( // get the MockCdm via MockCdmFactory::GetCreatedCdm() and explicitly specify
// expectations using EXPECT_CALL.
scoped_refptr<MockCdm> cdm = new NiceMock<MockCdm>(
key_system, security_origin, session_message_cb, session_closed_cb, key_system, security_origin, session_message_cb, session_closed_cb,
session_keys_change_cb, session_expiration_update_cb); session_keys_change_cb, session_expiration_update_cb);
created_cdm_ = cdm.get(); created_cdm_ = cdm.get();
EXPECT_CALL(*created_cdm_.get(), GetCdmContext());
cdm_created_cb.Run(std::move(cdm), ""); cdm_created_cb.Run(std::move(cdm), "");
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment