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

Side by Side Diff: chrome/browser/chromeos/drive/drive_file_stream_reader_unittest.cc

Issue 14237004: Add an utility interface ReaderProxy and its implementation for local file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebase Created 7 years, 8 months 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 "chrome/browser/chromeos/drive/drive_file_stream_reader.h"
6
7 #include <string>
8
9 #include "base/file_util.h"
10 #include "base/files/file_path.h"
11 #include "base/message_loop.h"
12 #include "chrome/browser/google_apis/test_util.h"
13 #include "content/public/test/test_browser_thread.h"
14 #include "net/base/file_stream.h"
15 #include "net/base/io_buffer.h"
16 #include "net/base/net_errors.h"
17 #include "net/base/test_completion_callback.h"
18 #include "testing/gtest/include/gtest/gtest.h"
19
20 using content::BrowserThread;
21
22 namespace drive {
23 namespace internal {
24
25 TEST(LocalReaderProxyTest, Read) {
26 // Prepare the test content.
27 const base::FilePath kTestFile(
28 google_apis::test_util::GetTestFilePath("chromeos/drive/applist.json"));
29 std::string expected_content;
30 ASSERT_TRUE(file_util::ReadFileToString(kTestFile, &expected_content));
31
32 // The LocaReaderProxy should live on IO thread.
33 MessageLoopForIO io_loop;
34 content::TestBrowserThread io_thread(BrowserThread::IO, &io_loop);
35
36 // Open the file first.
37 scoped_ptr<net::FileStream> file_stream(new net::FileStream(NULL));
38 net::TestCompletionCallback callback;
39 int result = file_stream->Open(
40 google_apis::test_util::GetTestFilePath("chromeos/drive/applist.json"),
41 base::PLATFORM_FILE_OPEN | base::PLATFORM_FILE_READ |
42 base::PLATFORM_FILE_ASYNC,
43 callback.callback());
44 ASSERT_EQ(net::OK, callback.GetResult(result));
45
46 // Test instance.
47 LocalReaderProxy proxy(file_stream.Pass());
48
49 // Prepare the buffer, whose size is smaller than the whole data size.
50 const int kBufferSize = 10;
51 ASSERT_LE(static_cast<size_t>(kBufferSize), expected_content.size());
52 scoped_refptr<net::IOBuffer> buffer(new net::IOBuffer(kBufferSize));
53
54 // Read repeatedly, until it is finished.
55 std::string concatenated_content;
56 while (concatenated_content.size() < expected_content.size()) {
57 result = proxy.Read(buffer.get(), kBufferSize, callback.callback());
58 result = callback.GetResult(result);
59
60 // The read content size should be smaller than the buffer size.
61 ASSERT_GT(result, 0);
62 ASSERT_LE(result, kBufferSize);
63 concatenated_content.append(buffer->data(), result);
64 }
65
66 // Make sure the read contant is as same as the file.
67 EXPECT_EQ(expected_content, concatenated_content);
68 }
69
70 } // namespace internal
71 } // namespace drive
OLDNEW
« no previous file with comments | « chrome/browser/chromeos/drive/drive_file_stream_reader.cc ('k') | chrome/chrome_tests_unit.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698