Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(73)

Side by Side Diff: media/mojo/clients/mojo_cdm_unittest.cc

Issue 2551333002: media: Avoid access violation in MojoCdm after connection error (Closed)
Patch Set: add unittests Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « media/mojo/clients/mojo_cdm.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright 2016 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include <stdint.h>
6
7 #include "base/bind.h"
8 #include "base/macros.h"
9 #include "base/memory/ptr_util.h"
10 #include "base/run_loop.h"
11 #include "base/test/test_message_loop.h"
12 #include "media/base/cdm_config.h"
13 #include "media/base/mock_filters.h"
14 #include "media/cdm/default_cdm_factory.h"
15 #include "media/mojo/clients/mojo_cdm.h"
16 #include "media/mojo/interfaces/content_decryption_module.mojom.h"
17 #include "media/mojo/services/mojo_cdm_service.h"
18 #include "media/mojo/services/mojo_cdm_service_context.h"
19 #include "mojo/public/cpp/bindings/interface_request.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 using ::testing::StrictMock;
23
24 namespace media {
25
26 namespace {
27
28 const char kClearKeyKeySystem[] = "org.w3.clearkey";
29 const char kTestSecurityOrigin[] = "https://www.test.com";
30
31 } // namespace
32
33 class MojoCdmTest : public ::testing::Test {
34 public:
35 enum ExpectedResult { SUCCESS, CONNECTION_ERROR };
36
37 MojoCdmTest()
38 : mojo_cdm_service_(base::MakeUnique<MojoCdmService>(
39 mojo_cdm_service_context_.GetWeakPtr(),
40 &cdm_factory_)),
41 cdm_binding_(mojo_cdm_service_.get()) {}
42
43 virtual ~MojoCdmTest() {}
44
45 void Initialize(ExpectedResult expected_result) {
46 mojom::ContentDecryptionModulePtr remote_cdm;
47 auto cdm_request = mojo::GetProxy(&remote_cdm);
48
49 switch (expected_result) {
50 case SUCCESS:
51 cdm_binding_.Bind(std::move(cdm_request));
52 break;
53 case CONNECTION_ERROR:
54 cdm_request.ResetWithReason(0, "Request dropped for testing.");
55 break;
56 }
57
58 MojoCdm::Create(
59 kClearKeyKeySystem, GURL(kTestSecurityOrigin), CdmConfig(),
60 std::move(remote_cdm), base::Bind(&MockCdmClient::OnSessionMessage,
61 base::Unretained(&cdm_client_)),
62 base::Bind(&MockCdmClient::OnSessionClosed,
63 base::Unretained(&cdm_client_)),
64 base::Bind(&MockCdmClient::OnSessionKeysChange,
65 base::Unretained(&cdm_client_)),
66 base::Bind(&MockCdmClient::OnSessionExpirationUpdate,
67 base::Unretained(&cdm_client_)),
68 base::Bind(&MojoCdmTest::OnCdmCreated, base::Unretained(this)));
69
70 base::RunLoop().RunUntilIdle();
71
72 if (expected_result == SUCCESS) {
73 EXPECT_TRUE(mojo_cdm_);
74 } else {
75 EXPECT_FALSE(mojo_cdm_);
76 }
77 }
78
79 void OnCdmCreated(const scoped_refptr<MediaKeys>& cdm,
80 const std::string& error_message) {
jrummell 2016/12/06 21:07:07 Maybe pass expected_result in the Bind() above, an
xhwang 2016/12/06 21:33:43 In the future we may have other types of failures,
81 if (!cdm) {
82 LOG(ERROR) << error_message;
jrummell 2016/12/06 21:07:07 I think it would be better if this simply did EXPE
xhwang 2016/12/06 21:33:43 We don't "force" all impls to provide a non-empty
83 return;
84 }
85
86 mojo_cdm_ = cdm;
87 }
88
89 // Fixture members.
90 base::TestMessageLoop message_loop_;
91
92 MojoCdmServiceContext mojo_cdm_service_context_;
93 StrictMock<MockCdmClient> cdm_client_;
94
95 // TODO(jrummell): Use a MockCdmFactory to create a MockCdm here to more test
jrummell 2016/12/06 21:07:07 s/to more/for more/
xhwang 2016/12/06 21:33:43 Done.
96 // coverage.
97 DefaultCdmFactory cdm_factory_;
98
99 std::unique_ptr<MojoCdmService> mojo_cdm_service_;
100 mojo::Binding<mojom::ContentDecryptionModule> cdm_binding_;
101 scoped_refptr<MediaKeys> mojo_cdm_;
102
103 private:
104 DISALLOW_COPY_AND_ASSIGN(MojoCdmTest);
105 };
106
107 TEST_F(MojoCdmTest, Create_Success) {
108 Initialize(SUCCESS);
109 }
110
111 TEST_F(MojoCdmTest, Create_ConnectionError) {
112 Initialize(CONNECTION_ERROR);
113 }
114
115 // TODO(xhwang): Add more test cases!
116
117 } // namespace media
OLDNEW
« no previous file with comments | « media/mojo/clients/mojo_cdm.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698