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 "chrome/browser/extensions/api/developer_private/developer_private_api.
h" | 5 #include "chrome/browser/extensions/api/developer_private/developer_private_api.
h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 #include <utility> | 8 #include <utility> |
9 | 9 |
10 #include "base/files/file_util.h" | 10 #include "base/files/file_util.h" |
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
131 test_extension_dirs_.push_back(base::MakeUnique<TestExtensionDir>()); | 131 test_extension_dirs_.push_back(base::MakeUnique<TestExtensionDir>()); |
132 TestExtensionDir* dir = test_extension_dirs_.back().get(); | 132 TestExtensionDir* dir = test_extension_dirs_.back().get(); |
133 dir->WriteManifest(kManifest); | 133 dir->WriteManifest(kManifest); |
134 | 134 |
135 // TODO(devlin): We should extract out methods to load an unpacked extension | 135 // TODO(devlin): We should extract out methods to load an unpacked extension |
136 // synchronously. We do it in ExtensionBrowserTest, but that's not helpful | 136 // synchronously. We do it in ExtensionBrowserTest, but that's not helpful |
137 // for unittests. | 137 // for unittests. |
138 TestExtensionRegistryObserver registry_observer(registry()); | 138 TestExtensionRegistryObserver registry_observer(registry()); |
139 scoped_refptr<UnpackedInstaller> installer( | 139 scoped_refptr<UnpackedInstaller> installer( |
140 UnpackedInstaller::Create(service())); | 140 UnpackedInstaller::Create(service())); |
141 installer->Load(dir->unpacked_path()); | 141 installer->Load(dir->UnpackedPath()); |
142 base::FilePath extension_path = | 142 base::FilePath extension_path = |
143 base::MakeAbsoluteFilePath(dir->unpacked_path()); | 143 base::MakeAbsoluteFilePath(dir->UnpackedPath()); |
144 const Extension* extension = nullptr; | 144 const Extension* extension = nullptr; |
145 do { | 145 do { |
146 extension = registry_observer.WaitForExtensionLoaded(); | 146 extension = registry_observer.WaitForExtensionLoaded(); |
147 } while (extension->path() != extension_path); | 147 } while (extension->path() != extension_path); |
148 // The fact that unpacked extensions get file access by default is an | 148 // The fact that unpacked extensions get file access by default is an |
149 // irrelevant detail to these tests. Disable it. | 149 // irrelevant detail to these tests. Disable it. |
150 ExtensionPrefs::Get(browser_context())->SetAllowFileAccess(extension->id(), | 150 ExtensionPrefs::Get(browser_context())->SetAllowFileAccess(extension->id(), |
151 false); | 151 false); |
152 return extension; | 152 return extension; |
153 } | 153 } |
(...skipping 142 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
296 registry_observer.WaitForExtensionLoaded(); | 296 registry_observer.WaitForExtensionLoaded(); |
297 EXPECT_EQ(extension_id, reloaded_extension->id()); | 297 EXPECT_EQ(extension_id, reloaded_extension->id()); |
298 } | 298 } |
299 | 299 |
300 // Test developerPrivate.packDirectory. | 300 // Test developerPrivate.packDirectory. |
301 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivatePackFunction) { | 301 TEST_F(DeveloperPrivateApiUnitTest, DeveloperPrivatePackFunction) { |
302 // Use a temp dir isolating the extension dir and its generated files. | 302 // Use a temp dir isolating the extension dir and its generated files. |
303 base::ScopedTempDir temp_dir; | 303 base::ScopedTempDir temp_dir; |
304 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 304 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
305 base::FilePath root_path = data_dir().AppendASCII("good_unpacked"); | 305 base::FilePath root_path = data_dir().AppendASCII("good_unpacked"); |
306 ASSERT_TRUE(base::CopyDirectory(root_path, temp_dir.path(), true)); | 306 ASSERT_TRUE(base::CopyDirectory(root_path, temp_dir.GetPath(), true)); |
307 | 307 |
308 base::FilePath temp_root_path = temp_dir.path().Append(root_path.BaseName()); | 308 base::FilePath temp_root_path = |
309 base::FilePath crx_path = temp_dir.path().AppendASCII("good_unpacked.crx"); | 309 temp_dir.GetPath().Append(root_path.BaseName()); |
310 base::FilePath pem_path = temp_dir.path().AppendASCII("good_unpacked.pem"); | 310 base::FilePath crx_path = temp_dir.GetPath().AppendASCII("good_unpacked.crx"); |
| 311 base::FilePath pem_path = temp_dir.GetPath().AppendASCII("good_unpacked.pem"); |
311 | 312 |
312 EXPECT_FALSE(base::PathExists(crx_path)) | 313 EXPECT_FALSE(base::PathExists(crx_path)) |
313 << "crx should not exist before the test is run!"; | 314 << "crx should not exist before the test is run!"; |
314 EXPECT_FALSE(base::PathExists(pem_path)) | 315 EXPECT_FALSE(base::PathExists(pem_path)) |
315 << "pem should not exist before the test is run!"; | 316 << "pem should not exist before the test is run!"; |
316 | 317 |
317 // First, test a directory that should pack properly. | 318 // First, test a directory that should pack properly. |
318 base::ListValue pack_args; | 319 base::ListValue pack_args; |
319 pack_args.AppendString(temp_root_path.AsUTF8Unsafe()); | 320 pack_args.AppendString(temp_root_path.AsUTF8Unsafe()); |
320 EXPECT_TRUE(TestPackExtensionFunction( | 321 EXPECT_TRUE(TestPackExtensionFunction( |
(...skipping 238 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
559 .Append( | 560 .Append( |
560 DictionaryBuilder().Set("extensionId", extension->id()).Build()) | 561 DictionaryBuilder().Set("extensionId", extension->id()).Build()) |
561 .Build(); | 562 .Build(); |
562 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); | 563 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); |
563 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); | 564 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); |
564 // No more errors! | 565 // No more errors! |
565 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); | 566 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); |
566 } | 567 } |
567 | 568 |
568 } // namespace extensions | 569 } // namespace extensions |
OLD | NEW |