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

Side by Side Diff: chrome/browser/chromeos/drive/file_system/create_file_operation_unittest.cc

Issue 380993002: Upstream RunBlockingPoolTask(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fixed. Created 6 years, 5 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
1 // Copyright 2013 The Chromium Authors. All rights reserved. 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 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_system/create_file_operation.h" 5 #include "chrome/browser/chromeos/drive/file_system/create_file_operation.h"
6 6
7 #include "chrome/browser/chromeos/drive/file_change.h" 7 #include "chrome/browser/chromeos/drive/file_change.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h" 8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
9 #include "content/public/test/test_utils.h"
9 #include "google_apis/drive/test_util.h" 10 #include "google_apis/drive/test_util.h"
10 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
11 12
12 namespace drive { 13 namespace drive {
13 namespace file_system { 14 namespace file_system {
14 15
15 typedef OperationTestBase CreateFileOperationTest; 16 typedef OperationTestBase CreateFileOperationTest;
16 17
17 TEST_F(CreateFileOperationTest, CreateFile) { 18 TEST_F(CreateFileOperationTest, CreateFile) {
18 CreateFileOperation operation(blocking_task_runner(), 19 CreateFileOperation operation(blocking_task_runner(),
19 observer(), 20 observer(),
20 metadata()); 21 metadata());
21 22
22 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt")); 23 const base::FilePath kFilePath(FILE_PATH_LITERAL("drive/root/New File.txt"));
23 FileError error = FILE_ERROR_FAILED; 24 FileError error = FILE_ERROR_FAILED;
24 operation.CreateFile( 25 operation.CreateFile(
25 kFilePath, 26 kFilePath,
26 true, // is_exclusive 27 true, // is_exclusive
27 std::string(), // no predetermined mime type 28 std::string(), // no predetermined mime type
28 google_apis::test_util::CreateCopyResultCallback(&error)); 29 google_apis::test_util::CreateCopyResultCallback(&error));
29 test_util::RunBlockingPoolTask(); 30 content::RunAllBlockingPoolTasksUntilIdle();
30 EXPECT_EQ(FILE_ERROR_OK, error); 31 EXPECT_EQ(FILE_ERROR_OK, error);
31 32
32 ResourceEntry entry; 33 ResourceEntry entry;
33 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry)); 34 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kFilePath, &entry));
34 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state()); 35 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state());
35 EXPECT_FALSE(base::Time::FromInternalValue( 36 EXPECT_FALSE(base::Time::FromInternalValue(
36 entry.file_info().last_modified()).is_null()); 37 entry.file_info().last_modified()).is_null());
37 EXPECT_FALSE(base::Time::FromInternalValue( 38 EXPECT_FALSE(base::Time::FromInternalValue(
38 entry.file_info().last_accessed()).is_null()); 39 entry.file_info().last_accessed()).is_null());
39 40
(...skipping 17 matching lines...) Expand all
57 const base::FilePath kFileInNonExistingDirectory( 58 const base::FilePath kFileInNonExistingDirectory(
58 FILE_PATH_LITERAL("drive/root/not exist/not exist.png")); 59 FILE_PATH_LITERAL("drive/root/not exist/not exist.png"));
59 60
60 // Create fails if is_exclusive = true and a file exists. 61 // Create fails if is_exclusive = true and a file exists.
61 FileError error = FILE_ERROR_FAILED; 62 FileError error = FILE_ERROR_FAILED;
62 operation.CreateFile( 63 operation.CreateFile(
63 kExistingFile, 64 kExistingFile,
64 true, // is_exclusive 65 true, // is_exclusive
65 std::string(), // no predetermined mime type 66 std::string(), // no predetermined mime type
66 google_apis::test_util::CreateCopyResultCallback(&error)); 67 google_apis::test_util::CreateCopyResultCallback(&error));
67 test_util::RunBlockingPoolTask(); 68 content::RunAllBlockingPoolTasksUntilIdle();
68 EXPECT_EQ(FILE_ERROR_EXISTS, error); 69 EXPECT_EQ(FILE_ERROR_EXISTS, error);
69 70
70 // Create succeeds if is_exclusive = false and a file exists. 71 // Create succeeds if is_exclusive = false and a file exists.
71 operation.CreateFile( 72 operation.CreateFile(
72 kExistingFile, 73 kExistingFile,
73 false, // is_exclusive 74 false, // is_exclusive
74 std::string(), // no predetermined mime type 75 std::string(), // no predetermined mime type
75 google_apis::test_util::CreateCopyResultCallback(&error)); 76 google_apis::test_util::CreateCopyResultCallback(&error));
76 test_util::RunBlockingPoolTask(); 77 content::RunAllBlockingPoolTasksUntilIdle();
77 EXPECT_EQ(FILE_ERROR_OK, error); 78 EXPECT_EQ(FILE_ERROR_OK, error);
78 79
79 // Create fails if a directory existed even when is_exclusive = false. 80 // Create fails if a directory existed even when is_exclusive = false.
80 operation.CreateFile( 81 operation.CreateFile(
81 kExistingDirectory, 82 kExistingDirectory,
82 false, // is_exclusive 83 false, // is_exclusive
83 std::string(), // no predetermined mime type 84 std::string(), // no predetermined mime type
84 google_apis::test_util::CreateCopyResultCallback(&error)); 85 google_apis::test_util::CreateCopyResultCallback(&error));
85 test_util::RunBlockingPoolTask(); 86 content::RunAllBlockingPoolTasksUntilIdle();
86 EXPECT_EQ(FILE_ERROR_EXISTS, error); 87 EXPECT_EQ(FILE_ERROR_EXISTS, error);
87 88
88 // Create succeeds if no entry exists. 89 // Create succeeds if no entry exists.
89 operation.CreateFile( 90 operation.CreateFile(
90 kNonExistingFile, 91 kNonExistingFile,
91 true, // is_exclusive 92 true, // is_exclusive
92 std::string(), // no predetermined mime type 93 std::string(), // no predetermined mime type
93 google_apis::test_util::CreateCopyResultCallback(&error)); 94 google_apis::test_util::CreateCopyResultCallback(&error));
94 test_util::RunBlockingPoolTask(); 95 content::RunAllBlockingPoolTasksUntilIdle();
95 EXPECT_EQ(FILE_ERROR_OK, error); 96 EXPECT_EQ(FILE_ERROR_OK, error);
96 97
97 // Create fails if the parent directory does not exist. 98 // Create fails if the parent directory does not exist.
98 operation.CreateFile( 99 operation.CreateFile(
99 kFileInNonExistingDirectory, 100 kFileInNonExistingDirectory,
100 false, // is_exclusive 101 false, // is_exclusive
101 std::string(), // no predetermined mime type 102 std::string(), // no predetermined mime type
102 google_apis::test_util::CreateCopyResultCallback(&error)); 103 google_apis::test_util::CreateCopyResultCallback(&error));
103 test_util::RunBlockingPoolTask(); 104 content::RunAllBlockingPoolTasksUntilIdle();
104 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error); 105 EXPECT_EQ(FILE_ERROR_NOT_A_DIRECTORY, error);
105 } 106 }
106 107
107 TEST_F(CreateFileOperationTest, CreateFileMimeType) { 108 TEST_F(CreateFileOperationTest, CreateFileMimeType) {
108 CreateFileOperation operation(blocking_task_runner(), 109 CreateFileOperation operation(blocking_task_runner(),
109 observer(), 110 observer(),
110 metadata()); 111 metadata());
111 112
112 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png")); 113 const base::FilePath kPng1(FILE_PATH_LITERAL("drive/root/1.png"));
113 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png")); 114 const base::FilePath kPng2(FILE_PATH_LITERAL("drive/root/2.png"));
114 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown")); 115 const base::FilePath kUnknown(FILE_PATH_LITERAL("drive/root/3.unknown"));
115 const std::string kSpecialMimeType("application/x-createfile-test"); 116 const std::string kSpecialMimeType("application/x-createfile-test");
116 117
117 FileError error = FILE_ERROR_FAILED; 118 FileError error = FILE_ERROR_FAILED;
118 operation.CreateFile( 119 operation.CreateFile(
119 kPng1, 120 kPng1,
120 false, // is_exclusive 121 false, // is_exclusive
121 std::string(), // no predetermined mime type 122 std::string(), // no predetermined mime type
122 google_apis::test_util::CreateCopyResultCallback(&error)); 123 google_apis::test_util::CreateCopyResultCallback(&error));
123 test_util::RunBlockingPoolTask(); 124 content::RunAllBlockingPoolTasksUntilIdle();
124 EXPECT_EQ(FILE_ERROR_OK, error); 125 EXPECT_EQ(FILE_ERROR_OK, error);
125 126
126 // If no mime type is specified, it is guessed from the file name. 127 // If no mime type is specified, it is guessed from the file name.
127 ResourceEntry entry; 128 ResourceEntry entry;
128 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng1, &entry)); 129 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng1, &entry));
129 EXPECT_EQ("image/png", entry.file_specific_info().content_mime_type()); 130 EXPECT_EQ("image/png", entry.file_specific_info().content_mime_type());
130 131
131 error = FILE_ERROR_FAILED; 132 error = FILE_ERROR_FAILED;
132 operation.CreateFile( 133 operation.CreateFile(
133 kPng2, 134 kPng2,
134 false, // is_exclusive 135 false, // is_exclusive
135 kSpecialMimeType, 136 kSpecialMimeType,
136 google_apis::test_util::CreateCopyResultCallback(&error)); 137 google_apis::test_util::CreateCopyResultCallback(&error));
137 test_util::RunBlockingPoolTask(); 138 content::RunAllBlockingPoolTasksUntilIdle();
138 EXPECT_EQ(FILE_ERROR_OK, error); 139 EXPECT_EQ(FILE_ERROR_OK, error);
139 140
140 // If the mime type is explicitly set, respect it. 141 // If the mime type is explicitly set, respect it.
141 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng2, &entry)); 142 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kPng2, &entry));
142 EXPECT_EQ(kSpecialMimeType, entry.file_specific_info().content_mime_type()); 143 EXPECT_EQ(kSpecialMimeType, entry.file_specific_info().content_mime_type());
143 144
144 error = FILE_ERROR_FAILED; 145 error = FILE_ERROR_FAILED;
145 operation.CreateFile( 146 operation.CreateFile(
146 kUnknown, 147 kUnknown,
147 false, // is_exclusive 148 false, // is_exclusive
148 std::string(), // no predetermined mime type 149 std::string(), // no predetermined mime type
149 google_apis::test_util::CreateCopyResultCallback(&error)); 150 google_apis::test_util::CreateCopyResultCallback(&error));
150 test_util::RunBlockingPoolTask(); 151 content::RunAllBlockingPoolTasksUntilIdle();
151 EXPECT_EQ(FILE_ERROR_OK, error); 152 EXPECT_EQ(FILE_ERROR_OK, error);
152 153
153 // If the mime type is not set and unknown, default to octet-stream. 154 // If the mime type is not set and unknown, default to octet-stream.
154 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry)); 155 ASSERT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(kUnknown, &entry));
155 EXPECT_EQ("application/octet-stream", 156 EXPECT_EQ("application/octet-stream",
156 entry.file_specific_info().content_mime_type()); 157 entry.file_specific_info().content_mime_type());
157 } 158 }
158 159
159 } // namespace file_system 160 } // namespace file_system
160 } // namespace drive 161 } // namespace drive
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698