| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 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 | 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 <stdint.h> | 5 #include <stdint.h> |
| 6 | 6 |
| 7 #include <string> | 7 #include <string> |
| 8 #include <utility> | 8 #include <utility> |
| 9 | 9 |
| 10 #include "base/callback_forward.h" | 10 #include "base/callback_forward.h" |
| 11 #include "base/run_loop.h" |
| 11 #include "base/threading/sequenced_worker_pool.h" | 12 #include "base/threading/sequenced_worker_pool.h" |
| 12 #include "base/threading/thread_task_runner_handle.h" | 13 #include "base/threading/thread_task_runner_handle.h" |
| 13 #include "chrome/browser/extensions/app_data_migrator.h" | 14 #include "chrome/browser/extensions/app_data_migrator.h" |
| 14 #include "chrome/browser/extensions/extension_special_storage_policy.h" | 15 #include "chrome/browser/extensions/extension_special_storage_policy.h" |
| 15 #include "chrome/test/base/testing_profile.h" | 16 #include "chrome/test/base/testing_profile.h" |
| 16 #include "content/public/browser/browser_thread.h" | 17 #include "content/public/browser/browser_thread.h" |
| 17 #include "content/public/browser/indexed_db_context.h" | 18 #include "content/public/browser/indexed_db_context.h" |
| 18 #include "content/public/browser/storage_partition.h" | 19 #include "content/public/browser/storage_partition.h" |
| 19 #include "content/public/test/mock_blob_url_request_context.h" | 20 #include "content/public/test/mock_blob_url_request_context.h" |
| 20 #include "content/public/test/test_browser_thread_bundle.h" | 21 #include "content/public/test/test_browser_thread_bundle.h" |
| (...skipping 110 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 131 | 132 |
| 132 void OpenFileSystems(storage::FileSystemContext* fs_context, | 133 void OpenFileSystems(storage::FileSystemContext* fs_context, |
| 133 GURL extension_url) { | 134 GURL extension_url) { |
| 134 fs_context->OpenFileSystem(extension_url, storage::kFileSystemTypeTemporary, | 135 fs_context->OpenFileSystem(extension_url, storage::kFileSystemTypeTemporary, |
| 135 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 136 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 136 base::Bind(&DidOpenFileSystem)); | 137 base::Bind(&DidOpenFileSystem)); |
| 137 | 138 |
| 138 fs_context->OpenFileSystem(extension_url, storage::kFileSystemTypePersistent, | 139 fs_context->OpenFileSystem(extension_url, storage::kFileSystemTypePersistent, |
| 139 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, | 140 storage::OPEN_FILE_SYSTEM_CREATE_IF_NONEXISTENT, |
| 140 base::Bind(&DidOpenFileSystem)); | 141 base::Bind(&DidOpenFileSystem)); |
| 141 base::MessageLoop::current()->RunUntilIdle(); | 142 base::RunLoop().RunUntilIdle(); |
| 142 } | 143 } |
| 143 | 144 |
| 144 void GenerateTestFiles(content::MockBlobURLRequestContext* url_request_context, | 145 void GenerateTestFiles(content::MockBlobURLRequestContext* url_request_context, |
| 145 const Extension* ext, | 146 const Extension* ext, |
| 146 storage::FileSystemContext* fs_context, | 147 storage::FileSystemContext* fs_context, |
| 147 Profile* profile) { | 148 Profile* profile) { |
| 148 profile->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(ext, | 149 profile->GetExtensionSpecialStoragePolicy()->GrantRightsForExtension(ext, |
| 149 profile); | 150 profile); |
| 150 | 151 |
| 151 base::FilePath path(FILE_PATH_LITERAL("test.txt")); | 152 base::FilePath path(FILE_PATH_LITERAL("test.txt")); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 162 extension_url, storage::kFileSystemTypePersistent, path); | 163 extension_url, storage::kFileSystemTypePersistent, path); |
| 163 | 164 |
| 164 content::ScopedTextBlob blob1(*url_request_context, "blob-id:success1", | 165 content::ScopedTextBlob blob1(*url_request_context, "blob-id:success1", |
| 165 "Hello, world!\n"); | 166 "Hello, world!\n"); |
| 166 | 167 |
| 167 fs_context->operation_runner()->CreateFile(fs_temp_url, false, | 168 fs_context->operation_runner()->CreateFile(fs_temp_url, false, |
| 168 base::Bind(&DidCreate)); | 169 base::Bind(&DidCreate)); |
| 169 | 170 |
| 170 fs_context->operation_runner()->CreateFile(fs_persistent_url, false, | 171 fs_context->operation_runner()->CreateFile(fs_persistent_url, false, |
| 171 base::Bind(&DidCreate)); | 172 base::Bind(&DidCreate)); |
| 172 base::MessageLoop::current()->RunUntilIdle(); | 173 base::RunLoop().RunUntilIdle(); |
| 173 | 174 |
| 174 fs_context->operation_runner()->Write(url_request_context, fs_temp_url, | 175 fs_context->operation_runner()->Write(url_request_context, fs_temp_url, |
| 175 blob1.GetBlobDataHandle(), 0, | 176 blob1.GetBlobDataHandle(), 0, |
| 176 base::Bind(&DidWrite)); | 177 base::Bind(&DidWrite)); |
| 177 base::MessageLoop::current()->Run(); | 178 base::RunLoop().Run(); |
| 178 fs_context->operation_runner()->Write(url_request_context, fs_persistent_url, | 179 fs_context->operation_runner()->Write(url_request_context, fs_persistent_url, |
| 179 blob1.GetBlobDataHandle(), 0, | 180 blob1.GetBlobDataHandle(), 0, |
| 180 base::Bind(&DidWrite)); | 181 base::Bind(&DidWrite)); |
| 181 base::MessageLoop::current()->Run(); | 182 base::RunLoop().Run(); |
| 182 } | 183 } |
| 183 | 184 |
| 184 void VerifyFileContents(base::File file, | 185 void VerifyFileContents(base::File file, |
| 185 const base::Closure& on_close_callback) { | 186 const base::Closure& on_close_callback) { |
| 186 ASSERT_EQ(14, file.GetLength()); | 187 ASSERT_EQ(14, file.GetLength()); |
| 187 std::unique_ptr<char[]> buffer(new char[15]); | 188 std::unique_ptr<char[]> buffer(new char[15]); |
| 188 | 189 |
| 189 file.Read(0, buffer.get(), 14); | 190 file.Read(0, buffer.get(), 14); |
| 190 buffer.get()[14] = 0; | 191 buffer.get()[14] = 0; |
| 191 | 192 |
| (...skipping 21 matching lines...) Expand all Loading... |
| 213 storage::FileSystemURL fs_temp_url = | 214 storage::FileSystemURL fs_temp_url = |
| 214 new_fs_context->CreateCrackedFileSystemURL( | 215 new_fs_context->CreateCrackedFileSystemURL( |
| 215 extension_url, storage::kFileSystemTypeTemporary, path); | 216 extension_url, storage::kFileSystemTypeTemporary, path); |
| 216 storage::FileSystemURL fs_persistent_url = | 217 storage::FileSystemURL fs_persistent_url = |
| 217 new_fs_context->CreateCrackedFileSystemURL( | 218 new_fs_context->CreateCrackedFileSystemURL( |
| 218 extension_url, storage::kFileSystemTypePersistent, path); | 219 extension_url, storage::kFileSystemTypePersistent, path); |
| 219 | 220 |
| 220 new_fs_context->operation_runner()->OpenFile( | 221 new_fs_context->operation_runner()->OpenFile( |
| 221 fs_temp_url, base::File::FLAG_READ | base::File::FLAG_OPEN, | 222 fs_temp_url, base::File::FLAG_READ | base::File::FLAG_OPEN, |
| 222 base::Bind(&VerifyFileContents)); | 223 base::Bind(&VerifyFileContents)); |
| 223 base::MessageLoop::current()->Run(); | 224 base::RunLoop().Run(); |
| 224 new_fs_context->operation_runner()->OpenFile( | 225 new_fs_context->operation_runner()->OpenFile( |
| 225 fs_persistent_url, base::File::FLAG_READ | base::File::FLAG_OPEN, | 226 fs_persistent_url, base::File::FLAG_READ | base::File::FLAG_OPEN, |
| 226 base::Bind(&VerifyFileContents)); | 227 base::Bind(&VerifyFileContents)); |
| 227 base::MessageLoop::current()->Run(); | 228 base::RunLoop().Run(); |
| 228 } | 229 } |
| 229 | 230 |
| 230 TEST_F(AppDataMigratorTest, ShouldMigrate) { | 231 TEST_F(AppDataMigratorTest, ShouldMigrate) { |
| 231 scoped_refptr<const Extension> old_ext = GetTestExtension(false); | 232 scoped_refptr<const Extension> old_ext = GetTestExtension(false); |
| 232 scoped_refptr<const Extension> new_ext = GetTestExtension(true); | 233 scoped_refptr<const Extension> new_ext = GetTestExtension(true); |
| 233 | 234 |
| 234 EXPECT_TRUE(AppDataMigrator::NeedsMigration(old_ext.get(), new_ext.get())); | 235 EXPECT_TRUE(AppDataMigrator::NeedsMigration(old_ext.get(), new_ext.get())); |
| 235 } | 236 } |
| 236 | 237 |
| 237 TEST_F(AppDataMigratorTest, ShouldNotMigratePlatformApp) { | 238 TEST_F(AppDataMigratorTest, ShouldNotMigratePlatformApp) { |
| (...skipping 22 matching lines...) Expand all Loading... |
| 260 TEST_F(AppDataMigratorTest, FileSystemMigration) { | 261 TEST_F(AppDataMigratorTest, FileSystemMigration) { |
| 261 scoped_refptr<const Extension> old_ext = GetTestExtension(false); | 262 scoped_refptr<const Extension> old_ext = GetTestExtension(false); |
| 262 scoped_refptr<const Extension> new_ext = GetTestExtension(true); | 263 scoped_refptr<const Extension> new_ext = GetTestExtension(true); |
| 263 | 264 |
| 264 GenerateTestFiles(url_request_context_.get(), old_ext.get(), | 265 GenerateTestFiles(url_request_context_.get(), old_ext.get(), |
| 265 default_fs_context_, profile_.get()); | 266 default_fs_context_, profile_.get()); |
| 266 | 267 |
| 267 migrator_->DoMigrationAndReply(old_ext.get(), new_ext.get(), | 268 migrator_->DoMigrationAndReply(old_ext.get(), new_ext.get(), |
| 268 base::Bind(&MigrationCallback)); | 269 base::Bind(&MigrationCallback)); |
| 269 | 270 |
| 270 base::MessageLoop::current()->RunUntilIdle(); | 271 base::RunLoop().RunUntilIdle(); |
| 271 | 272 |
| 272 registry_->AddEnabled(new_ext); | 273 registry_->AddEnabled(new_ext); |
| 273 GURL extension_url = | 274 GURL extension_url = |
| 274 extensions::Extension::GetBaseURLFromExtensionId(new_ext->id()); | 275 extensions::Extension::GetBaseURLFromExtensionId(new_ext->id()); |
| 275 | 276 |
| 276 content::StoragePartition* new_partition = | 277 content::StoragePartition* new_partition = |
| 277 content::BrowserContext::GetStoragePartitionForSite(profile_.get(), | 278 content::BrowserContext::GetStoragePartitionForSite(profile_.get(), |
| 278 extension_url); | 279 extension_url); |
| 279 | 280 |
| 280 ASSERT_NE(new_partition->GetPath(), default_partition_->GetPath()); | 281 ASSERT_NE(new_partition->GetPath(), default_partition_->GetPath()); |
| 281 | 282 |
| 282 VerifyTestFilesMigrated(new_partition, new_ext.get()); | 283 VerifyTestFilesMigrated(new_partition, new_ext.get()); |
| 283 } | 284 } |
| 284 | 285 |
| 285 } // namespace extensions | 286 } // namespace extensions |
| OLD | NEW |