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

Side by Side Diff: chrome/browser/chromeos/gdata/gdata_file_writing_unittest.cc

Issue 10827068: gdata: Fix "save as pdf" to work on Google Drive. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Split from GDataFileSystem, add test. Created 8 years, 4 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 (c) 2012 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 <string>
6 #include <vector>
7 /*
8 #include "base/bind.h"
9 #include "base/file_path.h"
10 #include "base/file_util.h"
11 #include "base/json/json_file_value_serializer.h"
12 #include "base/memory/scoped_ptr.h"
13 #include "base/message_loop.h"
14 #include "base/path_service.h"
15 #include "base/scoped_temp_dir.h"
16 #include "base/stringprintf.h"
17 #include "base/threading/sequenced_worker_pool.h"
18 #include "base/values.h"
19 #include "chrome/browser/chromeos/cros/cros_library.h"
20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h"
21 #include "chrome/browser/chromeos/gdata/gdata.pb.h"
22 #include "chrome/browser/chromeos/gdata/gdata_file_system.h"
23 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
24 #include "chrome/browser/chromeos/gdata/gdata_util.h"
25 #include "chrome/browser/chromeos/gdata/mock_directory_change_observer.h"
26 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h"
27 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h"
28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/test/base/testing_profile.h"
30 */
31 #include "base/bind.h"
32 #include "base/message_loop.h"
33 #include "base/threading/thread_restrictions.h"
34 #include "chrome/browser/chromeos/gdata/gdata_file_writing.h"
35 #include "chrome/browser/chromeos/gdata/gdata_test_util.h"
36 #include "chrome/browser/chromeos/gdata/mock_gdata_file_system.h"
37 #include "content/public/browser/browser_thread.h"
38 #include "content/public/test/test_browser_thread.h"
39 #include "testing/gmock/include/gmock/gmock.h"
40 #include "testing/gtest/include/gtest/gtest.h"
41
42 using ::testing::StrictMock;
43 using ::testing::_;
44
45 namespace gdata {
46
47 namespace {
48
49 ACTION_P(MockCreateFile, error) {
50 if (!arg2.is_null())
51 arg2.Run(error);
52 }
53
54 ACTION_P2(MockOpenFile, error, local_path) {
55 if (!arg1.is_null())
56 arg1.Run(error, local_path);
57 }
58
59 ACTION_P(MockCloseFile, error) {
60 if (!arg1.is_null())
61 arg1.Run(error);
62 }
63
64 void RecordOpenFileCallbackArguments(GDataFileError* error,
65 FilePath* path,
66 GDataFileError error_arg,
67 const FilePath& path_arg) {
68 base::ThreadRestrictions::AssertIOAllowed();
69 *error = error_arg;
70 *path = path_arg;
71 }
72
73 } // namespace
74
75 class GDataFileWritingTest : public testing::Test {
76 public:
77 GDataFileWritingTest()
78 : ui_thread_(content::BrowserThread::UI, &message_loop_),
79 mock_file_system_(new StrictMock<MockGDataFileSystem>) {
80 }
81
82 protected:
83 MessageLoopForUI message_loop_;
84 content::TestBrowserThread ui_thread_;
85 scoped_ptr< StrictMock<MockGDataFileSystem> > mock_file_system_;
86 };
87
88 TEST_F(GDataFileWritingTest, PrepareFileForWritingSuccess) {
89 const FilePath kDrivePath("/drive/file.txt");
90 const FilePath kLocalPath("/tmp/dummy.txt");
91
92 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _))
93 .WillOnce(MockCreateFile(GDATA_FILE_OK));
94 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _))
95 .WillOnce(MockOpenFile(GDATA_FILE_OK, kLocalPath));
96 EXPECT_CALL(*mock_file_system_, CloseFile(kDrivePath, _))
97 .WillOnce(MockCloseFile(GDATA_FILE_OK));
98
99 GDataFileWriting file_writing(mock_file_system_.get());
100 GDataFileError error = GDATA_FILE_ERROR_FAILED;
101 FilePath path;
102 file_writing.PrepareWritableFileAndRun(
103 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path));
104 test_util::RunBlockingPoolTask();
105
106 EXPECT_EQ(GDATA_FILE_OK, error);
107 EXPECT_EQ(kLocalPath, path);
108 }
109
110 TEST_F(GDataFileWritingTest, PrepareFileForWritingCreateFail) {
111 const FilePath kDrivePath("/drive/file.txt");
112
113 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _))
114 .WillOnce(MockCreateFile(GDATA_FILE_ERROR_ACCESS_DENIED));
115 EXPECT_CALL(*mock_file_system_, OpenFile(_, _)).Times(0);
116 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0);
117
118 GDataFileWriting file_writing(mock_file_system_.get());
119 GDataFileError error = GDATA_FILE_ERROR_FAILED;
120 FilePath path;
121 file_writing.PrepareWritableFileAndRun(
122 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path));
123 test_util::RunBlockingPoolTask();
124
125 EXPECT_EQ(GDATA_FILE_ERROR_ACCESS_DENIED, error);
126 EXPECT_EQ(FilePath(), path);
127 }
128
129 TEST_F(GDataFileWritingTest, PrepareFileForWritingOpenFail) {
130 const FilePath kDrivePath("/drive/file.txt");
131
132 EXPECT_CALL(*mock_file_system_, CreateFile(kDrivePath, false, _))
133 .WillOnce(MockCreateFile(GDATA_FILE_OK));
134 EXPECT_CALL(*mock_file_system_, OpenFile(kDrivePath, _))
135 .WillOnce(MockOpenFile(GDATA_FILE_ERROR_IN_USE, FilePath()));
136 EXPECT_CALL(*mock_file_system_, CloseFile(_, _)).Times(0);
137
138 GDataFileWriting file_writing(mock_file_system_.get());
139 GDataFileError error = GDATA_FILE_ERROR_FAILED;
140 FilePath path;
141 file_writing.PrepareWritableFileAndRun(
142 kDrivePath, base::Bind(&RecordOpenFileCallbackArguments, &error, &path));
143 test_util::RunBlockingPoolTask();
144
145 EXPECT_EQ(GDATA_FILE_ERROR_IN_USE, error);
146 EXPECT_EQ(FilePath(), path);
147 }
148
149 } // namespace gdata
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698