| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/file_system_provider/operations/get_metadata.h
" | 5 #include "chrome/browser/chromeos/file_system_provider/operations/get_metadata.h
" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 | 8 |
| 9 #include "base/files/file.h" | 9 #include "base/files/file.h" |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 85 const ScopedVector<Event>& events() const { return events_; } | 85 const ScopedVector<Event>& events() const { return events_; } |
| 86 | 86 |
| 87 private: | 87 private: |
| 88 ScopedVector<Event> events_; | 88 ScopedVector<Event> events_; |
| 89 | 89 |
| 90 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); | 90 DISALLOW_COPY_AND_ASSIGN(CallbackLogger); |
| 91 }; | 91 }; |
| 92 | 92 |
| 93 } // namespace | 93 } // namespace |
| 94 | 94 |
| 95 using ModificationTime = |
| 96 extensions::api::file_system_provider::EntryMetadata::ModificationTime; |
| 97 |
| 95 class FileSystemProviderOperationsGetMetadataTest : public testing::Test { | 98 class FileSystemProviderOperationsGetMetadataTest : public testing::Test { |
| 96 protected: | 99 protected: |
| 97 FileSystemProviderOperationsGetMetadataTest() {} | 100 FileSystemProviderOperationsGetMetadataTest() {} |
| 98 ~FileSystemProviderOperationsGetMetadataTest() override {} | 101 ~FileSystemProviderOperationsGetMetadataTest() override {} |
| 99 | 102 |
| 100 void SetUp() override { | 103 void SetUp() override { |
| 101 file_system_info_ = ProvidedFileSystemInfo( | 104 file_system_info_ = ProvidedFileSystemInfo( |
| 102 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), | 105 kExtensionId, MountOptions(kFileSystemId, "" /* display_name */), |
| 103 base::FilePath(), false /* configurable */, true /* watchable */, | 106 base::FilePath(), false /* configurable */, true /* watchable */, |
| 104 extensions::SOURCE_FILE); | 107 extensions::SOURCE_FILE); |
| (...skipping 15 matching lines...) Expand all Loading... |
| 120 | 123 |
| 121 TEST_F(FileSystemProviderOperationsGetMetadataTest, ValidateIDLEntryMetadata) { | 124 TEST_F(FileSystemProviderOperationsGetMetadataTest, ValidateIDLEntryMetadata) { |
| 122 using extensions::api::file_system_provider::EntryMetadata; | 125 using extensions::api::file_system_provider::EntryMetadata; |
| 123 const std::string kValidFileName = "hello-world"; | 126 const std::string kValidFileName = "hello-world"; |
| 124 const std::string kValidThumbnailUrl = "data:something"; | 127 const std::string kValidThumbnailUrl = "data:something"; |
| 125 | 128 |
| 126 // Correct metadata for non-root. | 129 // Correct metadata for non-root. |
| 127 { | 130 { |
| 128 EntryMetadata metadata; | 131 EntryMetadata metadata; |
| 129 metadata.name = kValidFileName; | 132 metadata.name = kValidFileName; |
| 130 metadata.modification_time.additional_properties.SetString( | 133 metadata.modification_time.reset(new ModificationTime()); |
| 134 metadata.modification_time->additional_properties.SetString( |
| 131 "value", "invalid-date-time"); // Invalid modification time is OK. | 135 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 132 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); | 136 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); |
| 133 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 137 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 134 } | 138 } |
| 135 | 139 |
| 136 // Correct metadata for non-root (without thumbnail). | 140 // Correct metadata for non-root (without thumbnail). |
| 137 { | 141 { |
| 138 EntryMetadata metadata; | 142 EntryMetadata metadata; |
| 139 metadata.name = kValidFileName; | 143 metadata.name = kValidFileName; |
| 140 metadata.modification_time.additional_properties.SetString( | 144 metadata.modification_time.reset(new ModificationTime()); |
| 145 metadata.modification_time->additional_properties.SetString( |
| 141 "value", "invalid-date-time"); // Invalid modification time is OK. | 146 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 142 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 147 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 143 } | 148 } |
| 144 | 149 |
| 145 // Correct metadata for root. | 150 // Correct metadata for root. |
| 146 { | 151 { |
| 147 EntryMetadata metadata; | 152 EntryMetadata metadata; |
| 148 metadata.name = ""; | 153 metadata.name = ""; |
| 149 metadata.modification_time.additional_properties.SetString( | 154 metadata.modification_time.reset(new ModificationTime()); |
| 155 metadata.modification_time->additional_properties.SetString( |
| 150 "value", "invalid-date-time"); // Invalid modification time is OK. | 156 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 151 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, true /* root_path */)); | 157 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, true /* root_path */)); |
| 152 } | 158 } |
| 153 | 159 |
| 154 // Invalid characters in the name. | 160 // Invalid characters in the name. |
| 155 { | 161 { |
| 156 EntryMetadata metadata; | 162 EntryMetadata metadata; |
| 157 metadata.name = "hello/world"; | 163 metadata.name = "hello/world"; |
| 158 metadata.modification_time.additional_properties.SetString( | 164 metadata.modification_time.reset(new ModificationTime()); |
| 165 metadata.modification_time->additional_properties.SetString( |
| 159 "value", "invalid-date-time"); // Invalid modification time is OK. | 166 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 160 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); | 167 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); |
| 161 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 168 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 162 } | 169 } |
| 163 | 170 |
| 164 // Empty name for non-root. | 171 // Empty name for non-root. |
| 165 { | 172 { |
| 166 EntryMetadata metadata; | 173 EntryMetadata metadata; |
| 167 metadata.name = ""; | 174 metadata.name = ""; |
| 168 metadata.modification_time.additional_properties.SetString( | 175 metadata.modification_time.reset(new ModificationTime()); |
| 176 metadata.modification_time->additional_properties.SetString( |
| 169 "value", "invalid-date-time"); // Invalid modification time is OK. | 177 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 170 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); | 178 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); |
| 171 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 179 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 172 } | 180 } |
| 173 | 181 |
| 174 // Missing date time. | 182 // Missing last modification time is allowed. |
| 175 { | 183 { |
| 176 EntryMetadata metadata; | 184 EntryMetadata metadata; |
| 177 metadata.name = kValidFileName; | 185 metadata.name = kValidFileName; |
| 178 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); | 186 metadata.thumbnail.reset(new std::string(kValidThumbnailUrl)); |
| 179 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 187 EXPECT_TRUE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 180 } | 188 } |
| 181 | 189 |
| 182 // Invalid thumbnail. | 190 // Invalid thumbnail. |
| 183 { | 191 { |
| 184 EntryMetadata metadata; | 192 EntryMetadata metadata; |
| 185 metadata.name = kValidFileName; | 193 metadata.name = kValidFileName; |
| 186 metadata.modification_time.additional_properties.SetString( | 194 metadata.modification_time.reset(new ModificationTime()); |
| 195 metadata.modification_time->additional_properties.SetString( |
| 187 "value", "invalid-date-time"); // Invalid modification time is OK. | 196 "value", "invalid-date-time"); // Invalid modification time is OK. |
| 188 metadata.thumbnail.reset(new std::string("http://invalid-scheme")); | 197 metadata.thumbnail.reset(new std::string("http://invalid-scheme")); |
| 189 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); | 198 EXPECT_FALSE(ValidateIDLEntryMetadata(metadata, false /* root_path */)); |
| 190 } | 199 } |
| 191 } | 200 } |
| 192 | 201 |
| 193 TEST_F(FileSystemProviderOperationsGetMetadataTest, Execute) { | 202 TEST_F(FileSystemProviderOperationsGetMetadataTest, Execute) { |
| 194 using extensions::api::file_system_provider::GetMetadataRequestedOptions; | 203 using extensions::api::file_system_provider::GetMetadataRequestedOptions; |
| 195 | 204 |
| 196 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); | 205 util::LoggingDispatchEventImpl dispatcher(true /* dispatch_reply */); |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 367 base::File::FILE_ERROR_TOO_MANY_OPENED); | 376 base::File::FILE_ERROR_TOO_MANY_OPENED); |
| 368 | 377 |
| 369 ASSERT_EQ(1u, callback_logger.events().size()); | 378 ASSERT_EQ(1u, callback_logger.events().size()); |
| 370 CallbackLogger::Event* event = callback_logger.events()[0]; | 379 CallbackLogger::Event* event = callback_logger.events()[0]; |
| 371 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); | 380 EXPECT_EQ(base::File::FILE_ERROR_TOO_MANY_OPENED, event->result()); |
| 372 } | 381 } |
| 373 | 382 |
| 374 } // namespace operations | 383 } // namespace operations |
| 375 } // namespace file_system_provider | 384 } // namespace file_system_provider |
| 376 } // namespace chromeos | 385 } // namespace chromeos |
| OLD | NEW |