15d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)// Copyright 2014 The Chromium Authors. All rights reserved.
2a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
3a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)// found in the LICENSE file.
4a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
55d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)#include "chrome/browser/chromeos/drive/fileapi/webkit_file_stream_reader_impl.h"
6a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
7a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include <string>
8a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
9a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/bind.h"
10a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/bind_helpers.h"
11a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/memory/scoped_ptr.h"
125c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "base/run_loop.h"
13a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "base/threading/thread.h"
14eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch#include "base/time/time.h"
15a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/chromeos/drive/fake_file_system.h"
16a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/chromeos/drive/file_system_interface.h"
17a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/chromeos/drive/file_system_util.h"
18a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "chrome/browser/chromeos/drive/test_util.h"
197d4cd473f85ac64c3747c96c277f9e506a0d2246Torne (Richard Coles)#include "chrome/browser/drive/fake_drive_service.h"
205c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu#include "chrome/browser/drive/test_util.h"
21868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)#include "content/public/test/test_browser_thread_bundle.h"
2246d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)#include "google_apis/drive/drive_api_parser.h"
23a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "google_apis/drive/time_util.h"
24a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "net/base/io_buffer.h"
25a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "net/base/net_errors.h"
26a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "net/base/test_completion_callback.h"
27a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)#include "testing/gtest/include/gtest/gtest.h"
28a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
29a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace drive {
30a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)namespace internal {
31a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
32a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)class WebkitFileStreamReaderImplTest : public ::testing::Test {
33a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles) protected:
34a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // Because the testee should live on IO thread, the main thread is
35a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  // reused as IO thread, and UI thread will be run on background.
36a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  WebkitFileStreamReaderImplTest()
37868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)      : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) {
38a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
39a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
40a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  virtual void SetUp() OVERRIDE {
41a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    worker_thread_.reset(new base::Thread("WebkitFileStreamReaderImplTest"));
42a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    ASSERT_TRUE(worker_thread_->Start());
43a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
44a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Initialize FakeDriveService.
45eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch    fake_drive_service_.reset(new FakeDriveService);
465c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu    ASSERT_TRUE(test_util::SetUpTestEntries(fake_drive_service_.get()));
47a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
48a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    // Create a testee instance.
49a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    fake_file_system_.reset(
50a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)        new test_util::FakeFileSystem(fake_drive_service_.get()));
51a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
52a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
53a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  FileSystemInterface* GetFileSystem() {
54a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return fake_file_system_.get();
55a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
56a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
57a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  DriveFileStreamReader::FileSystemGetter GetFileSystemGetter() {
58a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)    return base::Bind(&WebkitFileStreamReaderImplTest::GetFileSystem,
59a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)                      base::Unretained(this));
60a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  }
61a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
62868fa2fe829687343ffae624259930155e16dbd8Torne (Richard Coles)  content::TestBrowserThreadBundle thread_bundle_;
63a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
64a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<base::Thread> worker_thread_;
65a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
66eb525c5499e34cc9c4b825d6d9e75bb07cc06aceBen Murdoch  scoped_ptr<FakeDriveService> fake_drive_service_;
67a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<test_util::FakeFileSystem> fake_file_system_;
68a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)};
69a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
70a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, ReadThenGetLength) {
71a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
72a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
73a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
747dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl(
757dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetFileSystemGetter(),
767dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      worker_thread_->message_loop_proxy().get(),
777dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kDriveFile,
787dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      0,               // offset
797dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::Time()));  // expected modification time
80a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
81a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string content;
82a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content));
83a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
84a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
85a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 length = reader->GetLength(callback.callback());
86a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  length = callback.GetResult(length);
87a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(content.size(), static_cast<size_t>(length));
88a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
89a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
90a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, GetLengthThenRead) {
91a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
92a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
93a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
947dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl(
957dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetFileSystemGetter(),
967dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      worker_thread_->message_loop_proxy().get(),
977dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kDriveFile,
987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      0,               // offset
997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::Time()));  // expected modification time
100a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
101a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
102a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 length = reader->GetLength(callback.callback());
103a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  length = callback.GetResult(length);
104a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
105a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string content;
106a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content));
107a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(content.size(), static_cast<size_t>(length));
108a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
109a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
110a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, ReadWithOffset) {
111a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
112a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
113a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const int kOffset = 5;
114a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1157dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl(
1167dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetFileSystemGetter(),
1177dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      worker_thread_->message_loop_proxy().get(),
1187dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kDriveFile,
1197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kOffset,
1207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::Time()));  // expected modification time
121a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
122a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string content;
123a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content));
124a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
125a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
126a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 length = reader->GetLength(callback.callback());
127a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  length = callback.GetResult(length);
128a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(content.size() + kOffset, static_cast<size_t>(length));
129a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
130a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
131a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, ReadError) {
132a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
133a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt");
134a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1357dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl(
1367dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetFileSystemGetter(),
1377dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      worker_thread_->message_loop_proxy().get(),
1387dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kDriveFile,
1397dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      0,               // offset
1407dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::Time()));  // expected modification time
141a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
142a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const int kBufferSize = 10;
143a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_refptr<net::IOBuffer> io_buffer(new net::IOBuffer(kBufferSize));
144a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestCompletionCallback callback;
145a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int result = reader->Read(io_buffer.get(), kBufferSize, callback.callback());
146a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  result = callback.GetResult(result);
147a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result);
148a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
149a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
150a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, GetLengthError) {
151a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
152a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("non-existing.txt");
153a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
1547dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch  scoped_ptr<WebkitFileStreamReaderImpl> reader(new WebkitFileStreamReaderImpl(
1557dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      GetFileSystemGetter(),
1567dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      worker_thread_->message_loop_proxy().get(),
1577dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      kDriveFile,
1587dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      0,               // offset
1597dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      base::Time()));  // expected modification time
160a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
161a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
162a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 result = reader->GetLength(callback.callback());
163a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  result = callback.GetResult(result);
164a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(net::ERR_FILE_NOT_FOUND, result);
165a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
166a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
167a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)TEST_F(WebkitFileStreamReaderImplTest, LastModification) {
168a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
169a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
170a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
171a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  base::Time expected_modification_time;
172a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ASSERT_TRUE(google_apis::util::GetTimeFromString(
173a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      "2011-12-14T00:40:47.330Z", &expected_modification_time));
1745c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1755c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  FileError error = FILE_ERROR_FAILED;
1765c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  scoped_ptr<ResourceEntry> entry;
1775c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  fake_file_system_->GetResourceEntry(
1785c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      kDriveFile,
1795c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      google_apis::test_util::CreateCopyResultCallback(&error, &entry));
1805c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  base::RunLoop().RunUntilIdle();
1815c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(FILE_ERROR_OK, error);
1825c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  ASSERT_TRUE(entry);
1835c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
1845c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  google_apis::GDataErrorCode status = google_apis::GDATA_OTHER_ERROR;
18546d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)  scoped_ptr<google_apis::FileResource> server_entry;
1865c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  fake_drive_service_->UpdateResource(
1875c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      entry->resource_id(),
1885c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      std::string(),  // parent_resource_id
1895c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      std::string(),  // title
1905c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      expected_modification_time,
1915c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      base::Time(),
1925c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu      google_apis::test_util::CreateCopyResultCallback(&status,
19346d4c2bc3267f3f028f39e7e311b0f89aba2e4fdTorne (Richard Coles)                                                       &server_entry));
1945c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  base::RunLoop().RunUntilIdle();
1955c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu  EXPECT_EQ(google_apis::HTTP_SUCCESS, status);
1965c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu
197a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<WebkitFileStreamReaderImpl> reader(
1987dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      new WebkitFileStreamReaderImpl(GetFileSystemGetter(),
1997dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     worker_thread_->message_loop_proxy().get(),
2007dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     kDriveFile,
2017dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     0,  // offset
2027dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     expected_modification_time));
203a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
204a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
205a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 result = reader->GetLength(callback.callback());
206a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  result = callback.GetResult(result);
207a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
208a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  std::string content;
209a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  ASSERT_EQ(net::OK, test_util::ReadAllData(reader.get(), &content));
210a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_GE(content.size(), static_cast<size_t>(result));
211a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
212a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
2135c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo Liu// TODO(hashimoto): Enable this test. crbug.com/346625
2145c02ac1a9c1b504631c0a3d2b6e737b5d738bae1Bo LiuTEST_F(WebkitFileStreamReaderImplTest, DISABLED_LastModificationError) {
215a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  const base::FilePath kDriveFile =
216a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)      util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt");
217a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
218a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  scoped_ptr<WebkitFileStreamReaderImpl> reader(
2197dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch      new WebkitFileStreamReaderImpl(GetFileSystemGetter(),
2207dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     worker_thread_->message_loop_proxy().get(),
2217dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     kDriveFile,
2227dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     0,  // offset
2237dbb3d5cf0c15f500944d211057644d6a2f37371Ben Murdoch                                     base::Time::FromInternalValue(1)));
224a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
225a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  net::TestInt64CompletionCallback callback;
226a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  int64 result = reader->GetLength(callback.callback());
227a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  result = callback.GetResult(result);
228a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)  EXPECT_EQ(net::ERR_UPLOAD_FILE_CHANGED, result);
229a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}
230a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)
231a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace internal
232a93a17c8d99d686bd4a1511e5504e5e6cc9fcadfTorne (Richard Coles)}  // namespace drive
233