| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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/common/extensions/manifest_handlers/ui_overrides_handler.h" | 5 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h" |
| 6 | 6 |
| 7 #include <memory> |
| 8 |
| 7 #include "base/command_line.h" | 9 #include "base/command_line.h" |
| 8 #include "base/json/json_string_value_serializer.h" | 10 #include "base/json/json_string_value_serializer.h" |
| 9 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
| 10 #include "chrome/common/extensions/features/feature_channel.h" | 12 #include "chrome/common/extensions/features/feature_channel.h" |
| 11 #include "components/version_info/version_info.h" | 13 #include "components/version_info/version_info.h" |
| 12 #include "extensions/common/error_utils.h" | 14 #include "extensions/common/error_utils.h" |
| 13 #include "extensions/common/extension.h" | 15 #include "extensions/common/extension.h" |
| 14 #include "extensions/common/manifest_constants.h" | 16 #include "extensions/common/manifest_constants.h" |
| 15 #include "extensions/common/manifest_url_handlers.h" | 17 #include "extensions/common/manifest_url_handlers.h" |
| 16 #include "testing/gtest/include/gtest/gtest.h" | 18 #include "testing/gtest/include/gtest/gtest.h" |
| (...skipping 29 matching lines...) Expand all Loading... |
| 46 | 48 |
| 47 | 49 |
| 48 TEST_F(UIOverrideTest, ParseManifest) { | 50 TEST_F(UIOverrideTest, ParseManifest) { |
| 49 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); | 51 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 50 // This functionality requires a feature flag. | 52 // This functionality requires a feature flag. |
| 51 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 53 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 52 "--enable-override-bookmarks-ui", "1"); | 54 "--enable-override-bookmarks-ui", "1"); |
| 53 std::string manifest(kManifest); | 55 std::string manifest(kManifest); |
| 54 JSONStringValueDeserializer json(manifest); | 56 JSONStringValueDeserializer json(manifest); |
| 55 std::string error; | 57 std::string error; |
| 56 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); | 58 std::unique_ptr<base::Value> root(json.Deserialize(NULL, &error)); |
| 57 ASSERT_TRUE(root); | 59 ASSERT_TRUE(root); |
| 58 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 60 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
| 59 scoped_refptr<Extension> extension = Extension::Create( | 61 scoped_refptr<Extension> extension = Extension::Create( |
| 60 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 62 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
| 61 Manifest::INVALID_LOCATION, | 63 Manifest::INVALID_LOCATION, |
| 62 *static_cast<base::DictionaryValue*>(root.get()), | 64 *static_cast<base::DictionaryValue*>(root.get()), |
| 63 Extension::NO_FLAGS, | 65 Extension::NO_FLAGS, |
| 64 &error); | 66 &error); |
| 65 ASSERT_TRUE(extension.get()) << error; | 67 ASSERT_TRUE(extension.get()) << error; |
| 66 ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride)); | 68 ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride)); |
| 67 | 69 |
| 68 UIOverrides* ui_override = static_cast<UIOverrides*>( | 70 UIOverrides* ui_override = static_cast<UIOverrides*>( |
| 69 extension->GetManifestData(manifest_keys::kUIOverride)); | 71 extension->GetManifestData(manifest_keys::kUIOverride)); |
| 70 ASSERT_TRUE(ui_override); | 72 ASSERT_TRUE(ui_override); |
| 71 ASSERT_TRUE(ui_override->bookmarks_ui); | 73 ASSERT_TRUE(ui_override->bookmarks_ui); |
| 72 EXPECT_TRUE(ui_override->bookmarks_ui->remove_button); | 74 EXPECT_TRUE(ui_override->bookmarks_ui->remove_button); |
| 73 EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut); | 75 EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut); |
| 74 } | 76 } |
| 75 | 77 |
| 76 TEST_F(UIOverrideTest, ParseBrokenManifest) { | 78 TEST_F(UIOverrideTest, ParseBrokenManifest) { |
| 77 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); | 79 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
| 78 // This functionality requires a feature flag. | 80 // This functionality requires a feature flag. |
| 79 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 81 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
| 80 "--enable-override-bookmarks-ui", "1"); | 82 "--enable-override-bookmarks-ui", "1"); |
| 81 std::string manifest(kBrokenManifest); | 83 std::string manifest(kBrokenManifest); |
| 82 JSONStringValueDeserializer json(manifest); | 84 JSONStringValueDeserializer json(manifest); |
| 83 std::string error; | 85 std::string error; |
| 84 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); | 86 std::unique_ptr<base::Value> root(json.Deserialize(NULL, &error)); |
| 85 ASSERT_TRUE(root); | 87 ASSERT_TRUE(root); |
| 86 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 88 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
| 87 scoped_refptr<Extension> extension = Extension::Create( | 89 scoped_refptr<Extension> extension = Extension::Create( |
| 88 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 90 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
| 89 Manifest::INVALID_LOCATION, | 91 Manifest::INVALID_LOCATION, |
| 90 *static_cast<base::DictionaryValue*>(root.get()), | 92 *static_cast<base::DictionaryValue*>(root.get()), |
| 91 Extension::NO_FLAGS, | 93 Extension::NO_FLAGS, |
| 92 &error); | 94 &error); |
| 93 EXPECT_FALSE(extension.get()); | 95 EXPECT_FALSE(extension.get()); |
| 94 EXPECT_EQ( | 96 EXPECT_EQ( |
| 95 extensions::ErrorUtils::FormatErrorMessage( | 97 extensions::ErrorUtils::FormatErrorMessage( |
| 96 extensions::manifest_errors::kInvalidEmptyDictionary, | 98 extensions::manifest_errors::kInvalidEmptyDictionary, |
| 97 extensions::manifest_keys::kUIOverride), | 99 extensions::manifest_keys::kUIOverride), |
| 98 error); | 100 error); |
| 99 } | 101 } |
| 100 | 102 |
| 101 } // namespace | 103 } // namespace |
| OLD | NEW |