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

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: comments addressed 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(kClearKeyKeySystem, GURL(kTestSecurityOrigin), CdmConfig(),
59 std::move(remote_cdm),
60 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,
69 base::Unretained(this), expected_result));
70
71 base::RunLoop().RunUntilIdle();
72
73 if (expected_result == SUCCESS) {
74 EXPECT_TRUE(mojo_cdm_);
75 } else {
76 EXPECT_FALSE(mojo_cdm_);
77 }
78 }
79
80 void OnCdmCreated(ExpectedResult expected_result,
81 const scoped_refptr<MediaKeys>& cdm,
82 const std::string& error_message) {
83 if (!cdm) {
84 DVLOG(1) << error_message;
85 return;
86 }
87
88 EXPECT_EQ(SUCCESS, expected_result);
89 mojo_cdm_ = cdm;
90 }
91
92 // Fixture members.
93 base::TestMessageLoop message_loop_;
94
95 MojoCdmServiceContext mojo_cdm_service_context_;
96 StrictMock<MockCdmClient> cdm_client_;
97
98 // TODO(jrummell): Use a MockCdmFactory to create a MockCdm here for more test
99 // coverage.
100 DefaultCdmFactory cdm_factory_;
101
102 std::unique_ptr<MojoCdmService> mojo_cdm_service_;
103 mojo::Binding<mojom::ContentDecryptionModule> cdm_binding_;
104 scoped_refptr<MediaKeys> mojo_cdm_;
105
106 private:
107 DISALLOW_COPY_AND_ASSIGN(MojoCdmTest);
108 };
109
110 TEST_F(MojoCdmTest, Create_Success) {
111 Initialize(SUCCESS);
112 }
113
114 TEST_F(MojoCdmTest, Create_ConnectionError) {
115 Initialize(CONNECTION_ERROR);
116 }
117
118 // TODO(xhwang): Add more test cases!
119
120 } // 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