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

Side by Side Diff: media/cdm/ppapi/cdm_file_io_test.cc

Issue 93243003: Add CDM FileIO tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: comments addressed Created 7 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright 2013 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 "media/cdm/ppapi/cdm_file_io_test.h"
6
7 #include "base/callback_helpers.h"
8 #include "media/base/bind_to_loop.h"
9
10 namespace media {
11
12 #define RETURN_IF_FAILURE(success, log) \
ddorwin 2013/12/11 21:16:17 It's really "return if false" now or "log failure
ddorwin 2013/12/11 21:16:17 Not in this CL, but bonus points if you can figure
xhwang 2013/12/13 02:51:47 This Macro is Removed.
xhwang 2013/12/13 02:51:47 This Macro is Removed.
13 do { \
14 if (!(success)) { \
15 DVLOG(1) << "CDM File IO Test failure: " << log; \
ddorwin 2013/12/11 21:16:17 DLOG
xhwang 2013/12/13 02:51:47 This Macro is Removed.
16 OnTestComplete(false); \
17 return; \
18 } \
19 } while (0)
20
21 const char kTestFileName[] = "cdm_file_io_test_file";
22
23 // TODO(xhwang): Add tests that test multiple reads (needs large data to read).
ddorwin 2013/12/11 21:16:17 Just a thought for future tests: Is there a thresh
xhwang 2013/12/13 02:51:47 There WAS no limit. I filed a bug and now (as of t
xhwang 2013/12/13 05:03:06 FYI: I tested writing and reading ~33M data and I
24 const uint8_t kTestData[] = { 0x00, 0x01, 0x02, 0x03, 0x04, 0x05, 0x06, 0x07,
25 0x08, 0x09, 0x0a, 0x0b, 0x0c, 0x0d, 0x0e, 0x0f };
26
27 // TODO(xhwang): Add more test cases.
28
29 CdmFileIOTest::CdmFileIOTest(ClearKeyCdmHost* cdm_host)
30 : cdm_host_(cdm_host),
31 cdm_file_io_(NULL),
32 test_data_(kTestData, kTestData + arraysize(kTestData)) {}
33
34 CdmFileIOTest::~CdmFileIOTest() {}
35
36 void CdmFileIOTest::OnOpenComplete(Status status) {
37 RETURN_IF_FAILURE(status == kSuccess, "Open failed.");
38 cdm_file_io_->Write(&test_data_[0], test_data_.size());
39 }
40
41 void CdmFileIOTest::OnReadComplete(Status status,
42 const uint8_t* data, uint32_t data_size) {
43 RETURN_IF_FAILURE(status == kSuccess, "Read failed.");
44
45 std::vector<uint8_t> data_read(data, data + data_size);
46 RETURN_IF_FAILURE(test_data_ == data_read, "Read data mismatch.");
47
48 OnTestComplete(true);
49 }
50
51 void CdmFileIOTest::OnWriteComplete(Status status) {
52 RETURN_IF_FAILURE(status == kSuccess, "Write failed.");
53 cdm_file_io_->Read();
54 }
55
56 void CdmFileIOTest::Run(CompletionCB completion_cb) {
57 cdm::FileIO* cdm_file_io = cdm_host_->CreateFileIO(this);
ddorwin 2013/12/11 21:16:17 We could separate this class from CK by passing in
xhwang 2013/12/13 02:51:47 Done.
58 RETURN_IF_FAILURE(cdm_file_io, "Cannot get CDM File IO interface.");
59
60 cdm_file_io_ = cdm_file_io;
61 completion_cb_ = BindToCurrentLoop(completion_cb);
62 cdm_file_io_->Open(kTestFileName, arraysize(kTestFileName));
63 }
64
65 void CdmFileIOTest::OnTestComplete(bool success) {
66 base::ResetAndReturn(&completion_cb_).Run(success);
67 cdm_file_io_->Close();
ddorwin 2013/12/11 21:16:17 Delete the file to clean up after the test.
xhwang 2013/12/13 02:51:47 There's no "delete" in FileIO. The closest thing i
68 cdm_file_io_ = NULL;
69 }
70
71 } // namespace media
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698