| 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 <utility> | 5 #include <utility> |
| 6 | 6 |
| 7 #include "base/files/file_util.h" | 7 #include "base/files/file_util.h" |
| 8 #include "base/macros.h" | 8 #include "base/macros.h" |
| 9 #include "base/memory/scoped_ptr.h" | 9 #include "base/memory/scoped_ptr.h" |
| 10 #include "base/strings/utf_string_conversions.h" | 10 #include "base/strings/utf_string_conversions.h" |
| (...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 145 const char kName[] = "extension name"; | 145 const char kName[] = "extension name"; |
| 146 const char kVersion[] = "1.0.0.1"; | 146 const char kVersion[] = "1.0.0.1"; |
| 147 std::string id = crx_file::id_util::GenerateId(kName); | 147 std::string id = crx_file::id_util::GenerateId(kName); |
| 148 DictionaryBuilder manifest; | 148 DictionaryBuilder manifest; |
| 149 manifest.Set("name", kName) | 149 manifest.Set("name", kName) |
| 150 .Set("version", kVersion) | 150 .Set("version", kVersion) |
| 151 .Set("manifest_version", 2) | 151 .Set("manifest_version", 2) |
| 152 .Set("description", "an extension"); | 152 .Set("description", "an extension"); |
| 153 scoped_refptr<const Extension> extension = | 153 scoped_refptr<const Extension> extension = |
| 154 ExtensionBuilder() | 154 ExtensionBuilder() |
| 155 .SetManifest(std::move(manifest)) | 155 .SetManifest(manifest.Build()) |
| 156 .SetLocation(Manifest::INTERNAL) | 156 .SetLocation(Manifest::INTERNAL) |
| 157 .SetID(id) | 157 .SetID(id) |
| 158 .Build(); | 158 .Build(); |
| 159 service()->AddExtension(extension.get()); | 159 service()->AddExtension(extension.get()); |
| 160 return extension.get(); | 160 return extension.get(); |
| 161 } | 161 } |
| 162 | 162 |
| 163 void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting( | 163 void DeveloperPrivateApiUnitTest::TestExtensionPrefSetting( |
| 164 bool (*has_pref)(const std::string&, content::BrowserContext*), | 164 bool (*has_pref)(const std::string&, content::BrowserContext*), |
| 165 const std::string& key, | 165 const std::string& key, |
| (...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 509 error_test_util::CreateNewRuntimeError(extension->id(), "bar")); | 509 error_test_util::CreateNewRuntimeError(extension->id(), "bar")); |
| 510 error_console->ReportError( | 510 error_console->ReportError( |
| 511 error_test_util::CreateNewManifestError(extension->id(), "baz")); | 511 error_test_util::CreateNewManifestError(extension->id(), "baz")); |
| 512 EXPECT_EQ(3u, error_console->GetErrorsForExtension(extension->id()).size()); | 512 EXPECT_EQ(3u, error_console->GetErrorsForExtension(extension->id()).size()); |
| 513 | 513 |
| 514 // Start by removing all errors for the extension of a given type (manifest). | 514 // Start by removing all errors for the extension of a given type (manifest). |
| 515 std::string type_string = api::developer_private::ToString( | 515 std::string type_string = api::developer_private::ToString( |
| 516 api::developer_private::ERROR_TYPE_MANIFEST); | 516 api::developer_private::ERROR_TYPE_MANIFEST); |
| 517 scoped_ptr<base::ListValue> args = | 517 scoped_ptr<base::ListValue> args = |
| 518 ListBuilder() | 518 ListBuilder() |
| 519 .Append(std::move(DictionaryBuilder() | 519 .Append(DictionaryBuilder() |
| 520 .Set("extensionId", extension->id()) | 520 .Set("extensionId", extension->id()) |
| 521 .Set("type", type_string))) | 521 .Set("type", type_string) |
| 522 .Build()) |
| 522 .Build(); | 523 .Build(); |
| 523 scoped_refptr<UIThreadExtensionFunction> function = | 524 scoped_refptr<UIThreadExtensionFunction> function = |
| 524 new api::DeveloperPrivateDeleteExtensionErrorsFunction(); | 525 new api::DeveloperPrivateDeleteExtensionErrorsFunction(); |
| 525 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); | 526 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); |
| 526 // Two errors should remain. | 527 // Two errors should remain. |
| 527 const ErrorList& error_list = | 528 const ErrorList& error_list = |
| 528 error_console->GetErrorsForExtension(extension->id()); | 529 error_console->GetErrorsForExtension(extension->id()); |
| 529 ASSERT_EQ(2u, error_list.size()); | 530 ASSERT_EQ(2u, error_list.size()); |
| 530 | 531 |
| 531 // Next remove errors by id. | 532 // Next remove errors by id. |
| 532 int error_id = error_list[0]->id(); | 533 int error_id = error_list[0]->id(); |
| 533 args = | 534 args = |
| 534 ListBuilder() | 535 ListBuilder() |
| 535 .Append(std::move( | 536 .Append(DictionaryBuilder() |
| 536 DictionaryBuilder() | 537 .Set("extensionId", extension->id()) |
| 537 .Set("extensionId", extension->id()) | 538 .Set("errorIds", ListBuilder().Append(error_id).Build()) |
| 538 .Set("errorIds", std::move(ListBuilder().Append(error_id))))) | 539 .Build()) |
| 539 .Build(); | 540 .Build(); |
| 540 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); | 541 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); |
| 541 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); | 542 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); |
| 542 // And then there was one. | 543 // And then there was one. |
| 543 EXPECT_EQ(1u, error_console->GetErrorsForExtension(extension->id()).size()); | 544 EXPECT_EQ(1u, error_console->GetErrorsForExtension(extension->id()).size()); |
| 544 | 545 |
| 545 // Finally remove all errors for the extension. | 546 // Finally remove all errors for the extension. |
| 546 args = ListBuilder() | 547 args = |
| 547 .Append(std::move( | 548 ListBuilder() |
| 548 DictionaryBuilder().Set("extensionId", extension->id()))) | 549 .Append( |
| 549 .Build(); | 550 DictionaryBuilder().Set("extensionId", extension->id()).Build()) |
| 551 .Build(); |
| 550 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); | 552 function = new api::DeveloperPrivateDeleteExtensionErrorsFunction(); |
| 551 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); | 553 EXPECT_TRUE(RunFunction(function, *args)) << function->GetError(); |
| 552 // No more errors! | 554 // No more errors! |
| 553 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); | 555 EXPECT_TRUE(error_console->GetErrorsForExtension(extension->id()).empty()); |
| 554 } | 556 } |
| 555 | 557 |
| 556 } // namespace extensions | 558 } // namespace extensions |
| OLD | NEW |