Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / sync_file_system / drive_backend / drive_backend_test_util.cc
blob3cad47c4c1e96b11e1e62053f5a1a7c7bc4d1937
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
3 // found in the LICENSE file.
5 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_test_util.h"
7 #include <set>
8 #include <string>
10 #include "chrome/browser/drive/drive_api_util.h"
11 #include "chrome/browser/sync_file_system/drive_backend/drive_backend_constants.h"
12 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.h"
13 #include "chrome/browser/sync_file_system/drive_backend/metadata_database.pb.h"
14 #include "google_apis/drive/drive_api_parser.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace sync_file_system {
18 namespace drive_backend {
19 namespace test_util {
21 void ExpectEquivalentDetails(const FileDetails& left,
22 const FileDetails& right) {
23 std::set<std::string> parents;
24 for (int i = 0; i < left.parent_folder_ids_size(); ++i)
25 EXPECT_TRUE(parents.insert(left.parent_folder_ids(i)).second);
27 for (int i = 0; i < right.parent_folder_ids_size(); ++i)
28 EXPECT_EQ(1u, parents.erase(left.parent_folder_ids(i)));
29 EXPECT_TRUE(parents.empty());
31 EXPECT_EQ(left.title(), right.title());
32 EXPECT_EQ(left.file_kind(), right.file_kind());
33 EXPECT_EQ(left.md5(), right.md5());
34 EXPECT_EQ(left.etag(), right.etag());
35 EXPECT_EQ(left.creation_time(), right.creation_time());
36 EXPECT_EQ(left.modification_time(), right.modification_time());
37 EXPECT_EQ(left.missing(), right.missing());
38 EXPECT_EQ(left.change_id(), right.change_id());
41 void ExpectEquivalentMetadata(const FileMetadata& left,
42 const FileMetadata& right) {
43 EXPECT_EQ(left.file_id(), right.file_id());
44 ExpectEquivalentDetails(left.details(), right.details());
47 void ExpectEquivalentTrackers(const FileTracker& left,
48 const FileTracker& right) {
49 EXPECT_EQ(left.tracker_id(), right.tracker_id());
50 EXPECT_EQ(left.parent_tracker_id(), right.parent_tracker_id());
51 EXPECT_EQ(left.file_id(), right.file_id());
52 EXPECT_EQ(left.app_id(), right.app_id());
53 EXPECT_EQ(left.tracker_kind(), right.tracker_kind());
54 ExpectEquivalentDetails(left.synced_details(), right.synced_details());
55 EXPECT_EQ(left.dirty(), right.dirty());
56 EXPECT_EQ(left.active(), right.active());
57 EXPECT_EQ(left.needs_folder_listing(), right.needs_folder_listing());
60 scoped_ptr<FileMetadata> CreateFolderMetadata(const std::string& file_id,
61 const std::string& title) {
62 FileDetails details;
63 details.set_title(title);
64 details.set_file_kind(FILE_KIND_FOLDER);
65 details.set_missing(false);
67 scoped_ptr<FileMetadata> metadata(new FileMetadata);
68 metadata->set_file_id(file_id);
69 *metadata->mutable_details() = details;
71 return metadata.Pass();
74 scoped_ptr<FileMetadata> CreateFileMetadata(const std::string& file_id,
75 const std::string& title,
76 const std::string& md5) {
77 FileDetails details;
78 details.set_title(title);
79 details.set_file_kind(FILE_KIND_FILE);
80 details.set_missing(false);
81 details.set_md5(md5);
83 scoped_ptr<FileMetadata> metadata(new FileMetadata);
84 metadata->set_file_id(file_id);
85 *metadata->mutable_details() = details;
87 return metadata.Pass();
90 scoped_ptr<FileTracker> CreateTracker(const FileMetadata& metadata,
91 int64 tracker_id,
92 const FileTracker* parent_tracker) {
93 scoped_ptr<FileTracker> tracker(new FileTracker);
94 tracker->set_tracker_id(tracker_id);
95 int64 parent_id = parent_tracker ?
96 parent_tracker->tracker_id() : kInvalidTrackerID;
97 tracker->set_parent_tracker_id(parent_id);
98 tracker->set_file_id(metadata.file_id());
99 if (parent_tracker)
100 tracker->set_app_id(parent_tracker->app_id());
101 tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
102 *tracker->mutable_synced_details() = metadata.details();
103 tracker->set_dirty(false);
104 tracker->set_active(true);
105 tracker->set_needs_folder_listing(false);
106 return tracker.Pass();
109 scoped_ptr<FileTracker> CreatePlaceholderTracker(
110 const std::string& file_id,
111 int64 tracker_id,
112 const FileTracker* parent_tracker) {
113 scoped_ptr<FileTracker> tracker(new FileTracker);
114 tracker->set_tracker_id(tracker_id);
115 if (parent_tracker)
116 tracker->set_parent_tracker_id(parent_tracker->tracker_id());
117 tracker->set_file_id(file_id);
118 if (parent_tracker)
119 tracker->set_app_id(parent_tracker->app_id());
120 tracker->set_tracker_kind(TRACKER_KIND_REGULAR);
121 tracker->set_dirty(true);
122 tracker->set_active(false);
123 tracker->set_needs_folder_listing(false);
124 return tracker.Pass();
127 FileResourceKind GetFileResourceKind(
128 const google_apis::FileResource& resource) {
129 if (resource.IsDirectory())
130 return RESOURCE_KIND_FOLDER;
131 else
132 return RESOURCE_KIND_FILE;
135 } // namespace test_util
136 } // namespace drive_backend
137 } // namespace sync_file_system