| 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 "chrome/browser/chromeos/drive/drive_prefetcher.h" | 5 #include "chrome/browser/chromeos/drive/drive_prefetcher.h" |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <vector> | 8 #include <vector> |
| 9 | 9 |
| 10 #include "base/bind.h" | 10 #include "base/bind.h" |
| (...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 80 const ReadDirectoryWithSettingCallback& callback = arg1; | 80 const ReadDirectoryWithSettingCallback& callback = arg1; |
| 81 | 81 |
| 82 scoped_ptr<DriveEntryProtoVector> entries(new DriveEntryProtoVector); | 82 scoped_ptr<DriveEntryProtoVector> entries(new DriveEntryProtoVector); |
| 83 for (size_t i = 0; i < test_entries.size(); ++i) { | 83 for (size_t i = 0; i < test_entries.size(); ++i) { |
| 84 if (test_entries[i].IsDirectChildOf(directory)) | 84 if (test_entries[i].IsDirectChildOf(directory)) |
| 85 entries->push_back(test_entries[i].ToDriveEntryProto()); | 85 entries->push_back(test_entries[i].ToDriveEntryProto()); |
| 86 } | 86 } |
| 87 callback.Run(DRIVE_FILE_OK, false /* hide_hosted_document */, entries.Pass()); | 87 callback.Run(DRIVE_FILE_OK, false /* hide_hosted_document */, entries.Pass()); |
| 88 } | 88 } |
| 89 | 89 |
| 90 #define FPL FILE_PATH_LITERAL |
| 91 |
| 90 const TestEntry kEmptyDrive[] = { | 92 const TestEntry kEmptyDrive[] = { |
| 91 { FILE_PATH_LITERAL("drive"), TYPE_DIRECTORY, 0, 0, "id:drive" }, | 93 { FPL("drive/root"), TYPE_DIRECTORY, 0, 0, "id:drive" }, |
| 92 }; | 94 }; |
| 93 | 95 |
| 94 const TestEntry kOneFileDrive[] = { | 96 const TestEntry kOneFileDrive[] = { |
| 95 { FILE_PATH_LITERAL("drive"), TYPE_DIRECTORY, 0, 0, "id:drive" }, | 97 { FPL("drive/root"), TYPE_DIRECTORY, 0, 0, "id:drive" }, |
| 96 { FILE_PATH_LITERAL("drive/abc.txt"), TYPE_REGULAR_FILE, 1, 0, "id:abc" }, | 98 { FPL("drive/root/abc.txt"), TYPE_REGULAR_FILE, 1, 0, |
| 99 "id:abc" }, |
| 97 }; | 100 }; |
| 98 | 101 |
| 99 const char* kExpectedOneFile[] = { "id:abc" }; | 102 const char* kExpectedOneFile[] = { "id:abc" }; |
| 100 | 103 |
| 101 const TestEntry kComplexDrive[] = { | 104 const TestEntry kComplexDrive[] = { |
| 102 // Path Type Access Modify ID | 105 // Path Type Access Modify ID |
| 103 { FILE_PATH_LITERAL("drive"), TYPE_DIRECTORY, 0, 0, "id:root" }, | 106 { FPL("drive/root"), TYPE_DIRECTORY, 0, 0, "id:root" }, |
| 104 { FILE_PATH_LITERAL("drive/a"), TYPE_DIRECTORY, 0, 0, "id:a" }, | 107 { FPL("drive/root/a"), TYPE_DIRECTORY, 0, 0, "id:a" }, |
| 105 { FILE_PATH_LITERAL("drive/a/foo.txt"), TYPE_REGULAR_FILE, 3, 2, "id:foo1" }, | 108 { FPL("drive/root/a/foo.txt"), TYPE_REGULAR_FILE, 3, 2, "id:foo1" }, |
| 106 { FILE_PATH_LITERAL("drive/a/b"), TYPE_DIRECTORY, 8, 0, "id:b" }, | 109 { FPL("drive/root/a/b"), TYPE_DIRECTORY, 8, 0, "id:b" }, |
| 107 { FILE_PATH_LITERAL("drive/a/bar.jpg"), TYPE_REGULAR_FILE, 5, 0, "id:bar1", | 110 { FPL("drive/root/a/bar.jpg"), TYPE_REGULAR_FILE, 5, 0, "id:bar1", |
| 108 999 }, | 111 999 }, |
| 109 { FILE_PATH_LITERAL("drive/a/b/x.gdoc"), TYPE_HOSTED_FILE, 7, 0, "id:new" }, | 112 { FPL("drive/root/a/b/x.gdoc"), TYPE_HOSTED_FILE, 7, 0, "id:new" }, |
| 110 { FILE_PATH_LITERAL("drive/a/buz.zip"), TYPE_REGULAR_FILE, 4, 0, "id:buz1" }, | 113 { FPL("drive/root/a/buz.zip"), TYPE_REGULAR_FILE, 4, 0, "id:buz1" }, |
| 111 { FILE_PATH_LITERAL("drive/a/old.gdoc"), TYPE_HOSTED_FILE, 1, 0, "id:old" }, | 114 { FPL("drive/root/a/old.gdoc"), TYPE_HOSTED_FILE, 1, 0, "id:old" }, |
| 112 { FILE_PATH_LITERAL("drive/c"), TYPE_DIRECTORY, 0, 0, "id:c" }, | 115 { FPL("drive/root/c"), TYPE_DIRECTORY, 0, 0, "id:c" }, |
| 113 { FILE_PATH_LITERAL("drive/c/foo.txt"), TYPE_REGULAR_FILE, 3, 1, "id:foo2" }, | 116 { FPL("drive/root/c/foo.txt"), TYPE_REGULAR_FILE, 3, 1, "id:foo2" }, |
| 114 { FILE_PATH_LITERAL("drive/c/buz.zip"), TYPE_REGULAR_FILE, 1, 0, "id:buz2" }, | 117 { FPL("drive/root/c/buz.zip"), TYPE_REGULAR_FILE, 1, 0, "id:buz2" }, |
| 115 { FILE_PATH_LITERAL("drive/bar.jpg"), TYPE_REGULAR_FILE, 6, 0, "id:bar2" }, | 118 { FPL("drive/root/bar.jpg"), TYPE_REGULAR_FILE, 6, 0, "id:bar2" }, |
| 116 }; | 119 }; |
| 117 | 120 |
| 121 #undef FPL |
| 122 |
| 118 const char* kTop3Files[] = { | 123 const char* kTop3Files[] = { |
| 119 "id:bar2", // The file with the largest timestamp | 124 "id:bar2", // The file with the largest timestamp |
| 120 // "bar1" is the second latest, but its file size is over limit. | 125 // "bar1" is the second latest, but its file size is over limit. |
| 121 "id:buz1", // The third latest file. | 126 "id:buz1", // The third latest file. |
| 122 "id:foo1" // 4th. Has same access time with id:foo2, so the one with the | 127 "id:foo1" // 4th. Has same access time with id:foo2, so the one with the |
| 123 // newer modified time wins. | 128 // newer modified time wins. |
| 124 }; | 129 }; |
| 125 | 130 |
| 126 const char* kAllRegularFiles[] = { | 131 const char* kAllRegularFiles[] = { |
| 127 "id:bar2", "id:bar1", "id:buz1", "id:foo1", "id:foo2", "id:buz2", | 132 "id:bar2", "id:bar1", "id:buz1", "id:foo1", "id:foo2", "id:buz2", |
| (...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 218 // This is checked by setting the fetch limit larger than the number of files. | 223 // This is checked by setting the fetch limit larger than the number of files. |
| 219 InitPrefetcher(100, 99999999); | 224 InitPrefetcher(100, 99999999); |
| 220 VerifyFullScan( | 225 VerifyFullScan( |
| 221 std::vector<TestEntry>(kComplexDrive, | 226 std::vector<TestEntry>(kComplexDrive, |
| 222 kComplexDrive + arraysize(kComplexDrive)), | 227 kComplexDrive + arraysize(kComplexDrive)), |
| 223 std::vector<std::string>(kAllRegularFiles, | 228 std::vector<std::string>(kAllRegularFiles, |
| 224 kAllRegularFiles + arraysize(kAllRegularFiles))); | 229 kAllRegularFiles + arraysize(kAllRegularFiles))); |
| 225 } | 230 } |
| 226 | 231 |
| 227 } // namespace drive | 232 } // namespace drive |
| OLD | NEW |