Update broken references to image assets
[chromium-blink-merge.git] / chrome / browser / chromeos / drive / file_system / set_property_operation_unittest.cc
blob402de2344f54db4c0781d34344dc2620499254b0
1 // Copyright 2015 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/chromeos/drive/file_system/set_property_operation.h"
7 #include "base/files/file_path.h"
8 #include "chrome/browser/chromeos/drive/file_system/operation_test_base.h"
9 #include "components/drive/drive.pb.h"
10 #include "components/drive/file_errors.h"
11 #include "content/public/test/test_utils.h"
12 #include "google_apis/drive/drive_api_requests.h"
13 #include "google_apis/drive/test_util.h"
14 #include "testing/gtest/include/gtest/gtest.h"
16 namespace drive {
17 namespace file_system {
18 namespace {
20 const base::FilePath::CharType kTestPath[] =
21 FILE_PATH_LITERAL("drive/root/File 1.txt");
22 const char kTestKey[] = "key";
23 const char kTestValue[] = "value";
24 const char kTestAnotherValue[] = "another-value";
26 } // namespace
28 typedef OperationTestBase SetPropertyOperationTest;
30 TEST_F(SetPropertyOperationTest, SetProperty) {
31 SetPropertyOperation operation(blocking_task_runner(), delegate(),
32 metadata());
34 const base::FilePath test_path(kTestPath);
35 FileError result = FILE_ERROR_FAILED;
36 operation.SetProperty(
37 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PRIVATE,
38 kTestKey, kTestValue,
39 google_apis::test_util::CreateCopyResultCallback(&result));
40 content::RunAllBlockingPoolTasksUntilIdle();
41 EXPECT_EQ(FILE_ERROR_OK, result);
43 ResourceEntry entry;
44 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(test_path, &entry));
45 EXPECT_EQ(ResourceEntry::DIRTY, entry.metadata_edit_state());
46 ASSERT_EQ(1, entry.new_properties().size());
47 const drive::Property property = entry.new_properties().Get(0);
48 EXPECT_EQ(Property_Visibility_PRIVATE, property.visibility());
49 EXPECT_EQ(kTestKey, property.key());
50 EXPECT_EQ(kTestValue, property.value());
52 EXPECT_EQ(0u, delegate()->get_changed_files().size());
53 EXPECT_FALSE(delegate()->get_changed_files().count(test_path));
55 EXPECT_EQ(1u, delegate()->updated_local_ids().size());
56 EXPECT_TRUE(delegate()->updated_local_ids().count(entry.local_id()));
59 TEST_F(SetPropertyOperationTest, SetProperty_Duplicate) {
60 SetPropertyOperation operation(blocking_task_runner(), delegate(),
61 metadata());
63 const base::FilePath test_path(kTestPath);
64 FileError result = FILE_ERROR_FAILED;
65 operation.SetProperty(
66 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PRIVATE,
67 kTestKey, kTestValue,
68 google_apis::test_util::CreateCopyResultCallback(&result));
69 operation.SetProperty(
70 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PRIVATE,
71 kTestKey, kTestValue,
72 google_apis::test_util::CreateCopyResultCallback(&result));
73 content::RunAllBlockingPoolTasksUntilIdle();
74 EXPECT_EQ(FILE_ERROR_OK, result);
76 ResourceEntry entry;
77 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(test_path, &entry));
78 EXPECT_EQ(1, entry.new_properties().size());
81 TEST_F(SetPropertyOperationTest, SetProperty_Overwrite) {
82 SetPropertyOperation operation(blocking_task_runner(), delegate(),
83 metadata());
85 const base::FilePath test_path(kTestPath);
86 FileError result = FILE_ERROR_FAILED;
87 operation.SetProperty(
88 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PUBLIC,
89 kTestKey, kTestValue,
90 google_apis::test_util::CreateCopyResultCallback(&result));
91 operation.SetProperty(
92 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PUBLIC,
93 kTestKey, kTestAnotherValue,
94 google_apis::test_util::CreateCopyResultCallback(&result));
95 content::RunAllBlockingPoolTasksUntilIdle();
96 EXPECT_EQ(FILE_ERROR_OK, result);
98 ResourceEntry entry;
99 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(test_path, &entry));
100 ASSERT_EQ(1, entry.new_properties().size());
101 const drive::Property property = entry.new_properties().Get(0);
102 EXPECT_EQ(Property_Visibility_PUBLIC, property.visibility());
103 EXPECT_EQ(kTestKey, property.key());
104 EXPECT_EQ(kTestAnotherValue, property.value());
107 TEST_F(SetPropertyOperationTest, SetProperty_DifferentVisibilities) {
108 SetPropertyOperation operation(blocking_task_runner(), delegate(),
109 metadata());
112 const base::FilePath test_path(kTestPath);
113 FileError result = FILE_ERROR_FAILED;
114 operation.SetProperty(
115 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PRIVATE,
116 kTestKey, kTestValue,
117 google_apis::test_util::CreateCopyResultCallback(&result));
118 content::RunAllBlockingPoolTasksUntilIdle();
119 EXPECT_EQ(FILE_ERROR_OK, result);
121 ResourceEntry entry;
122 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(test_path, &entry));
123 ASSERT_EQ(1, entry.new_properties().size());
124 const drive::Property property = entry.new_properties().Get(0);
125 EXPECT_EQ(Property_Visibility_PRIVATE, property.visibility());
126 EXPECT_EQ(kTestKey, property.key());
127 EXPECT_EQ(kTestValue, property.value());
130 // Insert another property with the same key, same value but different
131 // visibility.
133 const base::FilePath test_path(kTestPath);
134 FileError result = FILE_ERROR_FAILED;
135 operation.SetProperty(
136 test_path, google_apis::drive::Property::Visibility::VISIBILITY_PUBLIC,
137 kTestKey, kTestAnotherValue,
138 google_apis::test_util::CreateCopyResultCallback(&result));
139 content::RunAllBlockingPoolTasksUntilIdle();
140 EXPECT_EQ(FILE_ERROR_OK, result);
142 ResourceEntry entry;
143 EXPECT_EQ(FILE_ERROR_OK, GetLocalResourceEntry(test_path, &entry));
144 ASSERT_EQ(2, entry.new_properties().size());
145 const drive::Property property = entry.new_properties().Get(1);
146 EXPECT_EQ(Property_Visibility_PUBLIC, property.visibility());
147 EXPECT_EQ(kTestKey, property.key());
148 EXPECT_EQ(kTestAnotherValue, property.value());
152 } // namespace file_system
153 } // namespace drive