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 <string> | 5 #include <string> |
6 #include <vector> | 6 #include <vector> |
7 | 7 |
8 #include "base/bind.h" | 8 #include "base/bind.h" |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
11 #include "base/json/json_file_value_serializer.h" | 11 #include "base/json/json_file_value_serializer.h" |
12 #include "base/memory/scoped_ptr.h" | 12 #include "base/memory/scoped_ptr.h" |
13 #include "base/message_loop.h" | 13 #include "base/message_loop.h" |
14 #include "base/path_service.h" | 14 #include "base/path_service.h" |
15 #include "base/scoped_temp_dir.h" | 15 #include "base/scoped_temp_dir.h" |
16 #include "base/stringprintf.h" | 16 #include "base/stringprintf.h" |
17 #include "base/threading/sequenced_worker_pool.h" | 17 #include "base/threading/sequenced_worker_pool.h" |
18 #include "base/values.h" | 18 #include "base/values.h" |
19 #include "chrome/browser/chromeos/cros/cros_library.h" | 19 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 20 #include "chrome/browser/chromeos/gdata/drive_api_parser.h" |
20 #include "chrome/browser/chromeos/gdata/drive_webapps_registry.h" | 21 #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.pb.h" |
22 #include "chrome/browser/chromeos/gdata/gdata_file_system.h" | 23 #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_test_util.h" |
24 #include "chrome/browser/chromeos/gdata/gdata_util.h" | 25 #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_directory_change_observer.h" |
26 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h" | 27 #include "chrome/browser/chromeos/gdata/mock_gdata_cache_observer.h" |
27 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h" | 28 #include "chrome/browser/chromeos/gdata/mock_gdata_documents_service.h" |
28 #include "chrome/common/chrome_paths.h" | 29 #include "chrome/common/chrome_paths.h" |
29 #include "chrome/test/base/testing_profile.h" | 30 #include "chrome/test/base/testing_profile.h" |
(...skipping 155 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 | 186 |
186 class MockDriveWebAppsRegistry : public DriveWebAppsRegistryInterface { | 187 class MockDriveWebAppsRegistry : public DriveWebAppsRegistryInterface { |
187 public: | 188 public: |
188 virtual ~MockDriveWebAppsRegistry() {} | 189 virtual ~MockDriveWebAppsRegistry() {} |
189 | 190 |
190 MOCK_METHOD3(GetWebAppsForFile, void(const FilePath& file, | 191 MOCK_METHOD3(GetWebAppsForFile, void(const FilePath& file, |
191 const std::string& mime_type, | 192 const std::string& mime_type, |
192 ScopedVector<DriveWebAppInfo>* apps)); | 193 ScopedVector<DriveWebAppInfo>* apps)); |
193 MOCK_METHOD1(GetExtensionsForWebStoreApp, | 194 MOCK_METHOD1(GetExtensionsForWebStoreApp, |
194 std::set<std::string>(const std::string& web_store_id)); | 195 std::set<std::string>(const std::string& web_store_id)); |
195 MOCK_METHOD1(UpdateFromFeed, void(AccountMetadataFeed* metadata)); | 196 MOCK_METHOD1(UpdateFromFeed, void(const AccountMetadataFeed& metadata)); |
| 197 MOCK_METHOD1(UpdateFromApplicationList, void(const AppList& applist)); |
196 }; | 198 }; |
197 | 199 |
198 class GDataFileSystemTest : public testing::Test { | 200 class GDataFileSystemTest : public testing::Test { |
199 protected: | 201 protected: |
200 GDataFileSystemTest() | 202 GDataFileSystemTest() |
201 : ui_thread_(content::BrowserThread::UI, &message_loop_), | 203 : ui_thread_(content::BrowserThread::UI, &message_loop_), |
202 io_thread_(content::BrowserThread::IO), | 204 io_thread_(content::BrowserThread::IO), |
203 cache_(NULL), | 205 cache_(NULL), |
204 file_system_(NULL), | 206 file_system_(NULL), |
205 mock_doc_service_(NULL), | 207 mock_doc_service_(NULL), |
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
879 &AsyncInitializationCallback, | 881 &AsyncInitializationCallback, |
880 &counter, | 882 &counter, |
881 2, | 883 2, |
882 FilePath(FILE_PATH_LITERAL("drive")), | 884 FilePath(FILE_PATH_LITERAL("drive")), |
883 &message_loop_); | 885 &message_loop_); |
884 | 886 |
885 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | 887 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
886 EXPECT_CALL(*mock_doc_service_, | 888 EXPECT_CALL(*mock_doc_service_, |
887 GetDocuments(Eq(GURL()), _, _, _, _)).Times(1); | 889 GetDocuments(Eq(GURL()), _, _, _, _)).Times(1); |
888 | 890 |
889 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | 891 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
890 | 892 |
891 file_system_->GetEntryInfoByPath( | 893 file_system_->GetEntryInfoByPath( |
892 FilePath(FILE_PATH_LITERAL("drive")), callback); | 894 FilePath(FILE_PATH_LITERAL("drive")), callback); |
893 file_system_->GetEntryInfoByPath( | 895 file_system_->GetEntryInfoByPath( |
894 FilePath(FILE_PATH_LITERAL("drive")), callback); | 896 FilePath(FILE_PATH_LITERAL("drive")), callback); |
895 message_loop_.Run(); // Wait to get our result | 897 message_loop_.Run(); // Wait to get our result |
896 EXPECT_EQ(2, counter); | 898 EXPECT_EQ(2, counter); |
897 } | 899 } |
898 | 900 |
899 TEST_F(GDataFileSystemTest, SearchRootDirectory) { | 901 TEST_F(GDataFileSystemTest, SearchRootDirectory) { |
(...skipping 316 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1216 } | 1218 } |
1217 | 1219 |
1218 TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) { | 1220 TEST_F(GDataFileSystemTest, CachedFeadLoadingThenServerFeedLoading) { |
1219 SaveTestFileSystem(); | 1221 SaveTestFileSystem(); |
1220 | 1222 |
1221 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, | 1223 // SaveTestFileSystem and "account_metadata.json" have the same changestamp, |
1222 // so no request for new feeds (i.e., call to GetDocuments) should happen. | 1224 // so no request for new feeds (i.e., call to GetDocuments) should happen. |
1223 mock_doc_service_->set_account_metadata( | 1225 mock_doc_service_->set_account_metadata( |
1224 LoadJSONFile("account_metadata.json")); | 1226 LoadJSONFile("account_metadata.json")); |
1225 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | 1227 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
1226 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | 1228 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
1227 EXPECT_CALL(*mock_doc_service_, GetDocuments(_, _, _, _, _)).Times(0); | 1229 EXPECT_CALL(*mock_doc_service_, GetDocuments(_, _, _, _, _)).Times(0); |
1228 | 1230 |
1229 // Kicks loading of cached file system and query for server update. | 1231 // Kicks loading of cached file system and query for server update. |
1230 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); | 1232 EXPECT_TRUE(EntryExists(FilePath(FILE_PATH_LITERAL("drive/File1")))); |
1231 | 1233 |
1232 // Since the file system has verified that it holds the latest snapshot, | 1234 // Since the file system has verified that it holds the latest snapshot, |
1233 // it should change its state to FROM_SERVER, which admits periodic refresh. | 1235 // it should change its state to FROM_SERVER, which admits periodic refresh. |
1234 // To test it, call CheckForUpdates and verify it does try to check updates. | 1236 // To test it, call CheckForUpdates and verify it does try to check updates. |
1235 mock_doc_service_->set_account_metadata( | 1237 mock_doc_service_->set_account_metadata( |
1236 LoadJSONFile("account_metadata.json")); | 1238 LoadJSONFile("account_metadata.json")); |
1237 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | 1239 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
1238 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | 1240 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
1239 | 1241 |
1240 file_system_->CheckForUpdates(); | 1242 file_system_->CheckForUpdates(); |
1241 test_util::RunBlockingPoolTask(); | 1243 test_util::RunBlockingPoolTask(); |
1242 } | 1244 } |
1243 | 1245 |
1244 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { | 1246 TEST_F(GDataFileSystemTest, TransferFileFromLocalToRemote_RegularFile) { |
1245 LoadRootFeedDocument("root_feed.json"); | 1247 LoadRootFeedDocument("root_feed.json"); |
1246 | 1248 |
1247 // We'll add a file to the Drive root directory. | 1249 // We'll add a file to the Drive root directory. |
1248 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( | 1250 EXPECT_CALL(*mock_directory_observer_, OnDirectoryChanged( |
(...skipping 1222 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2471 const SearchResultPair kExpectedResults[] = { | 2473 const SearchResultPair kExpectedResults[] = { |
2472 { "drive/Directory 1", true } | 2474 { "drive/Directory 1", true } |
2473 }; | 2475 }; |
2474 | 2476 |
2475 // At the same time, unknown entry should trigger delta feed request. | 2477 // At the same time, unknown entry should trigger delta feed request. |
2476 // This will cause notification to observers (e.g., File Browser) so that | 2478 // This will cause notification to observers (e.g., File Browser) so that |
2477 // they can request search again. | 2479 // they can request search again. |
2478 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); | 2480 EXPECT_CALL(*mock_doc_service_, GetAccountMetadata(_)).Times(1); |
2479 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) | 2481 EXPECT_CALL(*mock_doc_service_, GetDocuments(Eq(GURL()), _, "", _, _)) |
2480 .Times(1); | 2482 .Times(1); |
2481 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(NotNull())).Times(1); | 2483 EXPECT_CALL(*mock_webapps_registry_, UpdateFromFeed(_)).Times(1); |
2482 | 2484 |
2483 SearchCallback callback = base::Bind(&DriveSearchCallback, | 2485 SearchCallback callback = base::Bind(&DriveSearchCallback, |
2484 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults)); | 2486 &message_loop_, kExpectedResults, ARRAYSIZE_UNSAFE(kExpectedResults)); |
2485 | 2487 |
2486 file_system_->Search("foo", GURL(), callback); | 2488 file_system_->Search("foo", GURL(), callback); |
2487 message_loop_.Run(); // Wait to get our result. | 2489 message_loop_.Run(); // Wait to get our result. |
2488 } | 2490 } |
2489 | 2491 |
2490 TEST_F(GDataFileSystemTest, ContentSearchEmptyResult) { | 2492 TEST_F(GDataFileSystemTest, ContentSearchEmptyResult) { |
2491 LoadRootFeedDocument("root_feed.json"); | 2493 LoadRootFeedDocument("root_feed.json"); |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2616 | 2618 |
2617 // Try to close the same file twice. | 2619 // Try to close the same file twice. |
2618 file_system_->CloseFile(kFileInRoot, close_file_callback); | 2620 file_system_->CloseFile(kFileInRoot, close_file_callback); |
2619 message_loop_.Run(); | 2621 message_loop_.Run(); |
2620 | 2622 |
2621 // It must fail. | 2623 // It must fail. |
2622 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); | 2624 EXPECT_EQ(GDATA_FILE_ERROR_NOT_FOUND, callback_helper_->last_error_); |
2623 } | 2625 } |
2624 | 2626 |
2625 } // namespace gdata | 2627 } // namespace gdata |
OLD | NEW |