OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/drive/file_write_helper.h" | 5 #include "chrome/browser/chromeos/drive/file_write_helper.h" |
6 | 6 |
7 #include "base/bind.h" | 7 #include "base/bind.h" |
8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
9 #include "base/threading/thread_restrictions.h" | 9 #include "base/threading/thread_restrictions.h" |
10 #include "chrome/browser/chromeos/drive/drive_test_util.h" | 10 #include "chrome/browser/chromeos/drive/drive_test_util.h" |
11 #include "chrome/browser/chromeos/drive/mock_drive_file_system.h" | 11 #include "chrome/browser/chromeos/drive/mock_drive_file_system.h" |
12 #include "content/public/browser/browser_thread.h" | 12 #include "content/public/browser/browser_thread.h" |
13 #include "content/public/test/test_browser_thread.h" | 13 #include "content/public/test/test_browser_thread.h" |
14 #include "testing/gmock/include/gmock/gmock.h" | 14 #include "testing/gmock/include/gmock/gmock.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using ::testing::StrictMock; | 17 using ::testing::StrictMock; |
18 using ::testing::_; | 18 using ::testing::_; |
19 | 19 |
20 namespace gdata { | 20 namespace drive { |
21 | 21 |
22 namespace { | 22 namespace { |
23 | 23 |
24 ACTION_P(MockCreateFile, error) { | 24 ACTION_P(MockCreateFile, error) { |
25 DCHECK(!arg2.is_null()); | 25 DCHECK(!arg2.is_null()); |
26 arg2.Run(error); | 26 arg2.Run(error); |
27 } | 27 } |
28 | 28 |
29 ACTION_P2(MockOpenFile, error, local_path) { | 29 ACTION_P2(MockOpenFile, error, local_path) { |
30 DCHECK(!arg1.is_null()); | 30 DCHECK(!arg1.is_null()); |
(...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
69 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _)) | 69 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _)) |
70 .WillOnce(MockOpenFile(DRIVE_FILE_OK, kLocalPath)); | 70 .WillOnce(MockOpenFile(DRIVE_FILE_OK, kLocalPath)); |
71 EXPECT_CALL(*mock_file_system_, CloseFile(kDrivePath, _)) | 71 EXPECT_CALL(*mock_file_system_, CloseFile(kDrivePath, _)) |
72 .WillOnce(MockCloseFile(DRIVE_FILE_OK)); | 72 .WillOnce(MockCloseFile(DRIVE_FILE_OK)); |
73 | 73 |
74 FileWriteHelper file_write_helper(mock_file_system_.get()); | 74 FileWriteHelper file_write_helper(mock_file_system_.get()); |
75 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 75 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
76 FilePath path; | 76 FilePath path; |
77 file_write_helper.PrepareWritableFileAndRun( | 77 file_write_helper.PrepareWritableFileAndRun( |
78 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); | 78 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); |
79 test_util::RunBlockingPoolTask(); | 79 gdata::test_util::RunBlockingPoolTask(); |
80 | 80 |
81 EXPECT_EQ(DRIVE_FILE_OK, error); | 81 EXPECT_EQ(DRIVE_FILE_OK, error); |
82 EXPECT_EQ(kLocalPath, path); | 82 EXPECT_EQ(kLocalPath, path); |
83 } | 83 } |
84 | 84 |
85 TEST_F(FileWriteHelperTest, PrepareFileForWritingCreateFail) { | 85 TEST_F(FileWriteHelperTest, PrepareFileForWritingCreateFail) { |
86 const FilePath kDrivePath("/drive/file.txt"); | 86 const FilePath kDrivePath("/drive/file.txt"); |
87 | 87 |
88 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _)) | 88 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _)) |
89 .WillOnce(MockCreateFile(DRIVE_FILE_ERROR_ACCESS_DENIED)); | 89 .WillOnce(MockCreateFile(DRIVE_FILE_ERROR_ACCESS_DENIED)); |
90 EXPECT_CALL(*mock_file_system_, OpenFile(_, _)).Times(0); | 90 EXPECT_CALL(*mock_file_system_, OpenFile(_, _)).Times(0); |
91 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0); | 91 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0); |
92 | 92 |
93 FileWriteHelper file_write_helper(mock_file_system_.get()); | 93 FileWriteHelper file_write_helper(mock_file_system_.get()); |
94 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 94 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
95 FilePath path; | 95 FilePath path; |
96 file_write_helper.PrepareWritableFileAndRun( | 96 file_write_helper.PrepareWritableFileAndRun( |
97 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); | 97 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); |
98 test_util::RunBlockingPoolTask(); | 98 gdata::test_util::RunBlockingPoolTask(); |
99 | 99 |
100 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error); | 100 EXPECT_EQ(DRIVE_FILE_ERROR_ACCESS_DENIED, error); |
101 EXPECT_EQ(FilePath(), path); | 101 EXPECT_EQ(FilePath(), path); |
102 } | 102 } |
103 | 103 |
104 TEST_F(FileWriteHelperTest, PrepareFileForWritingOpenFail) { | 104 TEST_F(FileWriteHelperTest, PrepareFileForWritingOpenFail) { |
105 const FilePath kDrivePath("/drive/file.txt"); | 105 const FilePath kDrivePath("/drive/file.txt"); |
106 | 106 |
107 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _)) | 107 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _)) |
108 .WillOnce(MockCreateFile(DRIVE_FILE_OK)); | 108 .WillOnce(MockCreateFile(DRIVE_FILE_OK)); |
109 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _)) | 109 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _)) |
110 .WillOnce(MockOpenFile(DRIVE_FILE_ERROR_IN_USE, FilePath())); | 110 .WillOnce(MockOpenFile(DRIVE_FILE_ERROR_IN_USE, FilePath())); |
111 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0); | 111 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0); |
112 | 112 |
113 FileWriteHelper file_write_helper(mock_file_system_.get()); | 113 FileWriteHelper file_write_helper(mock_file_system_.get()); |
114 DriveFileError error = DRIVE_FILE_ERROR_FAILED; | 114 DriveFileError error = DRIVE_FILE_ERROR_FAILED; |
115 FilePath path; | 115 FilePath path; |
116 file_write_helper.PrepareWritableFileAndRun( | 116 file_write_helper.PrepareWritableFileAndRun( |
117 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); | 117 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path)); |
118 test_util::RunBlockingPoolTask(); | 118 gdata::test_util::RunBlockingPoolTask(); |
119 | 119 |
120 EXPECT_EQ(DRIVE_FILE_ERROR_IN_USE, error); | 120 EXPECT_EQ(DRIVE_FILE_ERROR_IN_USE, error); |
121 EXPECT_EQ(FilePath(), path); | 121 EXPECT_EQ(FilePath(), path); |
122 } | 122 } |
123 | 123 |
124 } // namespace gdata | 124 } // namespace drive |
OLD | NEW |