OLD | NEW |
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/fake_file_system.h" | 5 #include "chrome/browser/chromeos/drive/fake_file_system.h" |
6 | 6 |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "chrome/browser/chromeos/drive/file_system_util.h" | 9 #include "chrome/browser/chromeos/drive/file_system_util.h" |
10 #include "chrome/browser/drive/fake_drive_service.h" | 10 #include "chrome/browser/drive/fake_drive_service.h" |
(...skipping 20 matching lines...) Expand all Loading... |
31 | 31 |
32 content::TestBrowserThreadBundle thread_bundle_; | 32 content::TestBrowserThreadBundle thread_bundle_; |
33 scoped_ptr<FakeDriveService> fake_drive_service_; | 33 scoped_ptr<FakeDriveService> fake_drive_service_; |
34 scoped_ptr<FakeFileSystem> fake_file_system_; | 34 scoped_ptr<FakeFileSystem> fake_file_system_; |
35 }; | 35 }; |
36 | 36 |
37 TEST_F(FakeFileSystemTest, GetFileContent) { | 37 TEST_F(FakeFileSystemTest, GetFileContent) { |
38 FileError initialize_error = FILE_ERROR_FAILED; | 38 FileError initialize_error = FILE_ERROR_FAILED; |
39 scoped_ptr<ResourceEntry> entry; | 39 scoped_ptr<ResourceEntry> entry; |
40 base::FilePath cache_file_path; | 40 base::FilePath cache_file_path; |
41 base::Closure cancel_download; | |
42 google_apis::test_util::TestGetContentCallback get_content_callback; | 41 google_apis::test_util::TestGetContentCallback get_content_callback; |
43 FileError completion_error = FILE_ERROR_FAILED; | 42 FileError completion_error = FILE_ERROR_FAILED; |
44 | 43 |
45 const base::FilePath kDriveFile = | 44 const base::FilePath kDriveFile = |
46 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); | 45 util::GetDriveMyDriveRootPath().AppendASCII("File 1.txt"); |
47 | 46 |
48 // For the first time, the file should be downloaded from the service. | 47 // For the first time, the file should be downloaded from the service. |
49 fake_file_system_->GetFileContent( | 48 base::Closure cancel_download = fake_file_system_->GetFileContent( |
50 kDriveFile, | 49 kDriveFile, |
51 google_apis::test_util::CreateCopyResultCallback( | 50 google_apis::test_util::CreateCopyResultCallback( |
52 &initialize_error, &entry, &cache_file_path, &cancel_download), | 51 &initialize_error, &cache_file_path, &entry), |
53 get_content_callback.callback(), | 52 get_content_callback.callback(), |
54 google_apis::test_util::CreateCopyResultCallback(&completion_error)); | 53 google_apis::test_util::CreateCopyResultCallback(&completion_error)); |
55 base::RunLoop().RunUntilIdle(); | 54 base::RunLoop().RunUntilIdle(); |
56 | 55 |
57 EXPECT_EQ(FILE_ERROR_OK, initialize_error); | 56 EXPECT_EQ(FILE_ERROR_OK, initialize_error); |
58 EXPECT_TRUE(entry); | 57 EXPECT_TRUE(entry); |
59 | 58 |
60 // No cache file is available yet. | 59 // No cache file is available yet. |
61 EXPECT_TRUE(cache_file_path.empty()); | 60 EXPECT_TRUE(cache_file_path.empty()); |
62 | 61 |
63 // The download should be happened so the |get_content_callback| | 62 // The download should be happened so the |get_content_callback| |
64 // should have the actual data. | 63 // should have the actual data. |
65 std::string content = get_content_callback.GetConcatenatedData(); | 64 std::string content = get_content_callback.GetConcatenatedData(); |
66 EXPECT_EQ(26U, content.size()); | 65 EXPECT_EQ(26U, content.size()); |
67 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 66 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
68 | 67 |
69 initialize_error = FILE_ERROR_FAILED; | 68 initialize_error = FILE_ERROR_FAILED; |
70 entry.reset(); | 69 entry.reset(); |
71 get_content_callback.mutable_data()->clear(); | 70 get_content_callback.mutable_data()->clear(); |
72 completion_error = FILE_ERROR_FAILED; | 71 completion_error = FILE_ERROR_FAILED; |
73 | 72 |
74 // For the second time, the cache file should be found. | 73 // For the second time, the cache file should be found. |
75 fake_file_system_->GetFileContent( | 74 cancel_download = fake_file_system_->GetFileContent( |
76 kDriveFile, | 75 kDriveFile, |
77 google_apis::test_util::CreateCopyResultCallback( | 76 google_apis::test_util::CreateCopyResultCallback( |
78 &initialize_error, &entry, &cache_file_path, &cancel_download), | 77 &initialize_error, &cache_file_path, &entry), |
79 get_content_callback.callback(), | 78 get_content_callback.callback(), |
80 google_apis::test_util::CreateCopyResultCallback(&completion_error)); | 79 google_apis::test_util::CreateCopyResultCallback(&completion_error)); |
81 base::RunLoop().RunUntilIdle(); | 80 base::RunLoop().RunUntilIdle(); |
82 | 81 |
83 EXPECT_EQ(FILE_ERROR_OK, initialize_error); | 82 EXPECT_EQ(FILE_ERROR_OK, initialize_error); |
84 EXPECT_TRUE(entry); | 83 EXPECT_TRUE(entry); |
85 | 84 |
86 // Cache file should be available. | 85 // Cache file should be available. |
87 ASSERT_FALSE(cache_file_path.empty()); | 86 ASSERT_FALSE(cache_file_path.empty()); |
88 | 87 |
89 // There should be a cache file so no data should be downloaded. | 88 // There should be a cache file so no data should be downloaded. |
90 EXPECT_TRUE(get_content_callback.data().empty()); | 89 EXPECT_TRUE(get_content_callback.data().empty()); |
91 EXPECT_EQ(FILE_ERROR_OK, completion_error); | 90 EXPECT_EQ(FILE_ERROR_OK, completion_error); |
92 | 91 |
93 // Make sure the cached file's content. | 92 // Make sure the cached file's content. |
94 std::string cache_file_content; | 93 std::string cache_file_content; |
95 ASSERT_TRUE( | 94 ASSERT_TRUE( |
96 base::ReadFileToString(cache_file_path, &cache_file_content)); | 95 base::ReadFileToString(cache_file_path, &cache_file_content)); |
97 EXPECT_EQ(content, cache_file_content); | 96 EXPECT_EQ(content, cache_file_content); |
98 } | 97 } |
99 | 98 |
100 TEST_F(FakeFileSystemTest, GetFileContent_Directory) { | 99 TEST_F(FakeFileSystemTest, GetFileContent_Directory) { |
101 FileError initialize_error = FILE_ERROR_FAILED; | 100 FileError initialize_error = FILE_ERROR_FAILED; |
102 scoped_ptr<ResourceEntry> entry; | 101 scoped_ptr<ResourceEntry> entry; |
103 base::FilePath cache_file_path; | 102 base::FilePath cache_file_path; |
104 google_apis::test_util::TestGetContentCallback get_content_callback; | 103 google_apis::test_util::TestGetContentCallback get_content_callback; |
105 FileError completion_error = FILE_ERROR_FAILED; | 104 FileError completion_error = FILE_ERROR_FAILED; |
106 base::Closure cancel_download; | 105 base::Closure cancel_download = fake_file_system_->GetFileContent( |
107 | |
108 fake_file_system_->GetFileContent( | |
109 util::GetDriveMyDriveRootPath(), | 106 util::GetDriveMyDriveRootPath(), |
110 google_apis::test_util::CreateCopyResultCallback( | 107 google_apis::test_util::CreateCopyResultCallback( |
111 &initialize_error, &entry, &cache_file_path, &cancel_download), | 108 &initialize_error, &cache_file_path, &entry), |
112 get_content_callback.callback(), | 109 get_content_callback.callback(), |
113 google_apis::test_util::CreateCopyResultCallback(&completion_error)); | 110 google_apis::test_util::CreateCopyResultCallback(&completion_error)); |
114 base::RunLoop().RunUntilIdle(); | 111 base::RunLoop().RunUntilIdle(); |
115 | 112 |
116 EXPECT_EQ(FILE_ERROR_NOT_A_FILE, completion_error); | 113 EXPECT_EQ(FILE_ERROR_NOT_A_FILE, completion_error); |
117 } | 114 } |
118 | 115 |
119 TEST_F(FakeFileSystemTest, GetResourceEntry) { | 116 TEST_F(FakeFileSystemTest, GetResourceEntry) { |
120 FileError error = FILE_ERROR_FAILED; | 117 FileError error = FILE_ERROR_FAILED; |
121 scoped_ptr<ResourceEntry> entry; | 118 scoped_ptr<ResourceEntry> entry; |
(...skipping 30 matching lines...) Expand all Loading... |
152 util::GetDriveMyDriveRootPath().AppendASCII("Invalid File Name"), | 149 util::GetDriveMyDriveRootPath().AppendASCII("Invalid File Name"), |
153 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); | 150 google_apis::test_util::CreateCopyResultCallback(&error, &entry)); |
154 base::RunLoop().RunUntilIdle(); | 151 base::RunLoop().RunUntilIdle(); |
155 | 152 |
156 ASSERT_EQ(FILE_ERROR_NOT_FOUND, error); | 153 ASSERT_EQ(FILE_ERROR_NOT_FOUND, error); |
157 ASSERT_FALSE(entry); | 154 ASSERT_FALSE(entry); |
158 } | 155 } |
159 | 156 |
160 } // namespace test_util | 157 } // namespace test_util |
161 } // namespace drive | 158 } // namespace drive |
OLD | NEW |