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 "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/json/json_string_value_serializer.h" | 8 #include "base/json/json_string_value_serializer.h" |
9 #include "base/strings/utf_string_conversions.h" | 9 #include "base/strings/utf_string_conversions.h" |
10 #include "chrome/common/extensions/features/feature_channel.h" | 10 #include "chrome/common/extensions/features/feature_channel.h" |
(...skipping 27 matching lines...) Expand all Loading... |
38 using extensions::Extension; | 38 using extensions::Extension; |
39 using extensions::Manifest; | 39 using extensions::Manifest; |
40 using extensions::UIOverrides; | 40 using extensions::UIOverrides; |
41 namespace manifest_keys = extensions::manifest_keys; | 41 namespace manifest_keys = extensions::manifest_keys; |
42 | 42 |
43 class UIOverrideTest : public testing::Test { | 43 class UIOverrideTest : public testing::Test { |
44 }; | 44 }; |
45 | 45 |
46 | 46 |
47 TEST_F(UIOverrideTest, ParseManifest) { | 47 TEST_F(UIOverrideTest, ParseManifest) { |
48 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 48 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
49 // This functionality requires a feature flag. | 49 // This functionality requires a feature flag. |
50 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 50 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
51 "--enable-override-bookmarks-ui", "1"); | 51 "--enable-override-bookmarks-ui", "1"); |
52 std::string manifest(kManifest); | 52 std::string manifest(kManifest); |
53 JSONStringValueDeserializer json(manifest); | 53 JSONStringValueDeserializer json(manifest); |
54 std::string error; | 54 std::string error; |
55 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); | 55 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); |
56 ASSERT_TRUE(root); | 56 ASSERT_TRUE(root); |
57 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 57 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
58 scoped_refptr<Extension> extension = Extension::Create( | 58 scoped_refptr<Extension> extension = Extension::Create( |
59 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 59 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
60 Manifest::INVALID_LOCATION, | 60 Manifest::INVALID_LOCATION, |
61 *static_cast<base::DictionaryValue*>(root.get()), | 61 *static_cast<base::DictionaryValue*>(root.get()), |
62 Extension::NO_FLAGS, | 62 Extension::NO_FLAGS, |
63 &error); | 63 &error); |
64 ASSERT_TRUE(extension.get()) << error; | 64 ASSERT_TRUE(extension.get()) << error; |
65 ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride)); | 65 ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride)); |
66 | 66 |
67 UIOverrides* ui_override = static_cast<UIOverrides*>( | 67 UIOverrides* ui_override = static_cast<UIOverrides*>( |
68 extension->GetManifestData(manifest_keys::kUIOverride)); | 68 extension->GetManifestData(manifest_keys::kUIOverride)); |
69 ASSERT_TRUE(ui_override); | 69 ASSERT_TRUE(ui_override); |
70 ASSERT_TRUE(ui_override->bookmarks_ui); | 70 ASSERT_TRUE(ui_override->bookmarks_ui); |
71 EXPECT_TRUE(ui_override->bookmarks_ui->remove_button); | 71 EXPECT_TRUE(ui_override->bookmarks_ui->remove_button); |
72 EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut); | 72 EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut); |
73 } | 73 } |
74 | 74 |
75 TEST_F(UIOverrideTest, ParseBrokenManifest) { | 75 TEST_F(UIOverrideTest, ParseBrokenManifest) { |
76 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV); | 76 extensions::ScopedCurrentChannel channel(version_info::Channel::DEV); |
77 // This functionality requires a feature flag. | 77 // This functionality requires a feature flag. |
78 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( | 78 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII( |
79 "--enable-override-bookmarks-ui", "1"); | 79 "--enable-override-bookmarks-ui", "1"); |
80 std::string manifest(kBrokenManifest); | 80 std::string manifest(kBrokenManifest); |
81 JSONStringValueDeserializer json(manifest); | 81 JSONStringValueDeserializer json(manifest); |
82 std::string error; | 82 std::string error; |
83 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); | 83 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error)); |
84 ASSERT_TRUE(root); | 84 ASSERT_TRUE(root); |
85 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); | 85 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY)); |
86 scoped_refptr<Extension> extension = Extension::Create( | 86 scoped_refptr<Extension> extension = Extension::Create( |
87 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), | 87 base::FilePath(FILE_PATH_LITERAL("//nonexistent")), |
88 Manifest::INVALID_LOCATION, | 88 Manifest::INVALID_LOCATION, |
89 *static_cast<base::DictionaryValue*>(root.get()), | 89 *static_cast<base::DictionaryValue*>(root.get()), |
90 Extension::NO_FLAGS, | 90 Extension::NO_FLAGS, |
91 &error); | 91 &error); |
92 EXPECT_FALSE(extension.get()); | 92 EXPECT_FALSE(extension.get()); |
93 EXPECT_EQ( | 93 EXPECT_EQ( |
94 extensions::ErrorUtils::FormatErrorMessage( | 94 extensions::ErrorUtils::FormatErrorMessage( |
95 extensions::manifest_errors::kInvalidEmptyDictionary, | 95 extensions::manifest_errors::kInvalidEmptyDictionary, |
96 extensions::manifest_keys::kUIOverride), | 96 extensions::manifest_keys::kUIOverride), |
97 error); | 97 error); |
98 } | 98 } |
99 | 99 |
100 } // namespace | 100 } // namespace |
OLD | NEW |