OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/apps/app_browsertest_util.h" | 5 #include "chrome/browser/apps/app_browsertest_util.h" |
6 #include "chrome/browser/chromeos/drive/drive_integration_service.h" | 6 #include "chrome/browser/chromeos/drive/drive_integration_service.h" |
7 #include "chrome/browser/chromeos/drive/file_system_interface.h" | 7 #include "chrome/browser/chromeos/drive/file_system_interface.h" |
8 #include "chrome/browser/chromeos/drive/file_system_util.h" | 8 #include "chrome/browser/chromeos/drive/file_system_util.h" |
9 #include "chrome/browser/chromeos/drive/test_util.h" | 9 #include "chrome/browser/chromeos/drive/test_util.h" |
10 #include "chrome/browser/drive/fake_drive_service.h" | 10 #include "chrome/browser/drive/fake_drive_service.h" |
(...skipping 59 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 SetUpTestFileHierarchy(); | 70 SetUpTestFileHierarchy(); |
71 | 71 |
72 integration_service_ = new drive::DriveIntegrationService( | 72 integration_service_ = new drive::DriveIntegrationService( |
73 profile, NULL, fake_drive_service_, test_cache_root_.path(), NULL); | 73 profile, NULL, fake_drive_service_, test_cache_root_.path(), NULL); |
74 return integration_service_; | 74 return integration_service_; |
75 } | 75 } |
76 | 76 |
77 void SetUpTestFileHierarchy() { | 77 void SetUpTestFileHierarchy() { |
78 const std::string root = fake_drive_service_->GetRootResourceId(); | 78 const std::string root = fake_drive_service_->GetRootResourceId(); |
79 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root)); | 79 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", root)); |
| 80 const std::string subdir = AddTestDirectory("subdir", root); |
| 81 ASSERT_FALSE(subdir.empty()); |
| 82 ASSERT_TRUE(AddTestFile("open_existing.txt", "Can you see me?", subdir)); |
80 } | 83 } |
81 | 84 |
82 bool AddTestFile(const std::string& title, | 85 bool AddTestFile(const std::string& title, |
83 const std::string& data, | 86 const std::string& data, |
84 const std::string& parent_id) { | 87 const std::string& parent_id) { |
85 scoped_ptr<google_apis::ResourceEntry> resource_entry; | 88 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
86 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; | 89 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
87 fake_drive_service_->AddNewFile( | 90 fake_drive_service_->AddNewFile( |
88 "text/plain", data, parent_id, title, false, | 91 "text/plain", data, parent_id, title, false, |
89 google_apis::test_util::CreateCopyResultCallback(&error, | 92 google_apis::test_util::CreateCopyResultCallback(&error, |
90 &resource_entry)); | 93 &resource_entry)); |
91 content::RunAllPendingInMessageLoop(); | 94 content::RunAllPendingInMessageLoop(); |
92 return error == google_apis::HTTP_CREATED && resource_entry; | 95 return error == google_apis::HTTP_CREATED && resource_entry; |
93 } | 96 } |
94 | 97 |
| 98 std::string AddTestDirectory(const std::string& title, |
| 99 const std::string& parent_id) { |
| 100 scoped_ptr<google_apis::ResourceEntry> resource_entry; |
| 101 google_apis::GDataErrorCode error = google_apis::GDATA_OTHER_ERROR; |
| 102 fake_drive_service_->AddNewDirectory( |
| 103 parent_id, title, |
| 104 google_apis::test_util::CreateCopyResultCallback(&error, |
| 105 &resource_entry)); |
| 106 content::RunAllPendingInMessageLoop(); |
| 107 return error == google_apis::HTTP_CREATED && resource_entry ? |
| 108 resource_entry->resource_id() : ""; |
| 109 } |
| 110 |
95 base::ScopedTempDir test_cache_root_; | 111 base::ScopedTempDir test_cache_root_; |
96 drive::FakeDriveService* fake_drive_service_; | 112 drive::FakeDriveService* fake_drive_service_; |
97 drive::DriveIntegrationService* integration_service_; | 113 drive::DriveIntegrationService* integration_service_; |
98 drive::DriveIntegrationServiceFactory::FactoryCallback | 114 drive::DriveIntegrationServiceFactory::FactoryCallback |
99 create_drive_integration_service_; | 115 create_drive_integration_service_; |
100 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> | 116 scoped_ptr<drive::DriveIntegrationServiceFactory::ScopedFactoryForTest> |
101 service_factory_for_test_; | 117 service_factory_for_test_; |
102 }; | 118 }; |
103 | 119 |
104 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, | 120 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
105 FileSystemApiOpenExistingFileTest) { | 121 FileSystemApiOpenExistingFileTest) { |
106 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII( | 122 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII( |
107 "root/open_existing.txt"); | 123 "root/open_existing.txt"); |
108 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 124 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
109 &test_file); | 125 &test_file); |
110 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) | 126 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_existing")) |
111 << message_; | 127 << message_; |
112 } | 128 } |
113 | 129 |
114 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, | 130 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
115 FileSystemApiOpenExistingFileWithWriteTest) { | 131 FileSystemApiOpenExistingFileWithWriteTest) { |
116 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII( | 132 base::FilePath test_file = drive::util::GetDriveMountPointPath().AppendASCII( |
117 "root/open_existing.txt"); | 133 "root/open_existing.txt"); |
118 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( | 134 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
119 &test_file); | 135 &test_file); |
120 ASSERT_TRUE(RunPlatformAppTest( | 136 ASSERT_TRUE(RunPlatformAppTest( |
121 "api_test/file_system/open_existing_with_write")) << message_; | 137 "api_test/file_system/open_existing_with_write")) << message_; |
122 } | 138 } |
123 | 139 |
| 140 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
| 141 FileSystemApiOpenDirectoryTest) { |
| 142 base::FilePath test_directory = |
| 143 drive::util::GetDriveMountPointPath().AppendASCII("root/subdir"); |
| 144 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 145 &test_directory); |
| 146 ASSERT_TRUE(RunPlatformAppTest("api_test/file_system/open_directory")) |
| 147 << message_; |
| 148 } |
| 149 |
| 150 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
| 151 FileSystemApiOpenDirectoryWithWriteTest) { |
| 152 base::FilePath test_directory = |
| 153 drive::util::GetDriveMountPointPath().AppendASCII("root/subdir"); |
| 154 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 155 &test_directory); |
| 156 ASSERT_TRUE( |
| 157 RunPlatformAppTest("api_test/file_system/open_directory_with_write")) |
| 158 << message_; |
| 159 } |
| 160 |
| 161 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
| 162 FileSystemApiOpenDirectoryWithoutPermissionTest) { |
| 163 base::FilePath test_directory = |
| 164 drive::util::GetDriveMountPointPath().AppendASCII("root/subdir"); |
| 165 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 166 &test_directory); |
| 167 ASSERT_TRUE(RunPlatformAppTest( |
| 168 "api_test/file_system/open_directory_without_permission")) |
| 169 << message_; |
| 170 } |
| 171 |
| 172 IN_PROC_BROWSER_TEST_F(FileSystemApiTestForDrive, |
| 173 FileSystemApiOpenDirectoryWithOnlyWritePermissionTest) { |
| 174 base::FilePath test_directory = |
| 175 drive::util::GetDriveMountPointPath().AppendASCII("root/subdir"); |
| 176 FileSystemChooseEntryFunction::SkipPickerAndAlwaysSelectPathForTest( |
| 177 &test_directory); |
| 178 ASSERT_TRUE(RunPlatformAppTest( |
| 179 "api_test/file_system/open_directory_with_only_write")) |
| 180 << message_; |
| 181 } |
| 182 |
124 } // namespace extensions | 183 } // namespace extensions |
OLD | NEW |