Delete chrome.mediaGalleriesPrivate because the functionality unique to it has since...
[chromium-blink-merge.git] / chrome / common / extensions / manifest_handlers / ui_overrides_handler_unittest.cc
blob007d102b82880f4006875a205310dec5ec5dd6f7
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
3 // found in the LICENSE file.
5 #include "chrome/common/extensions/manifest_handlers/ui_overrides_handler.h"
7 #include "base/command_line.h"
8 #include "base/json/json_string_value_serializer.h"
9 #include "base/strings/utf_string_conversions.h"
10 #include "chrome/common/extensions/features/feature_channel.h"
11 #include "extensions/common/error_utils.h"
12 #include "extensions/common/extension.h"
13 #include "extensions/common/manifest_constants.h"
14 #include "extensions/common/manifest_url_handlers.h"
15 #include "testing/gtest/include/gtest/gtest.h"
17 namespace {
19 const char kManifest[] = "{"
20 " \"version\" : \"1.0.0.0\","
21 " \"name\" : \"Test\","
22 " \"chrome_ui_overrides\" : {"
23 " \"bookmarks_ui\" : {"
24 " \"remove_button\" : true,"
25 " \"remove_bookmark_shortcut\" : true"
26 " }"
27 " }"
28 "}";
30 const char kBrokenManifest[] = "{"
31 " \"version\" : \"1.0.0.0\","
32 " \"name\" : \"Test\","
33 " \"chrome_ui_overrides\" : {"
34 " }"
35 "}";
37 using extensions::api::manifest_types::ChromeUIOverrides;
38 using extensions::Extension;
39 using extensions::Manifest;
40 using extensions::UIOverrides;
41 namespace manifest_keys = extensions::manifest_keys;
43 class UIOverrideTest : public testing::Test {
47 TEST_F(UIOverrideTest, ParseManifest) {
48 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
49 // This functionality requires a feature flag.
50 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
51 "--enable-override-bookmarks-ui", "1");
52 std::string manifest(kManifest);
53 JSONStringValueSerializer json(&manifest);
54 std::string error;
55 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
56 ASSERT_TRUE(root);
57 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
58 scoped_refptr<Extension> extension = Extension::Create(
59 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
60 Manifest::INVALID_LOCATION,
61 *static_cast<base::DictionaryValue*>(root.get()),
62 Extension::NO_FLAGS,
63 &error);
64 ASSERT_TRUE(extension.get()) << error;
65 ASSERT_TRUE(extension->manifest()->HasPath(manifest_keys::kUIOverride));
67 UIOverrides* ui_override = static_cast<UIOverrides*>(
68 extension->GetManifestData(manifest_keys::kUIOverride));
69 ASSERT_TRUE(ui_override);
70 ASSERT_TRUE(ui_override->bookmarks_ui);
71 EXPECT_TRUE(ui_override->bookmarks_ui->remove_button);
72 EXPECT_TRUE(ui_override->bookmarks_ui->remove_bookmark_shortcut);
75 TEST_F(UIOverrideTest, ParseBrokenManifest) {
76 extensions::ScopedCurrentChannel channel(chrome::VersionInfo::CHANNEL_DEV);
77 // This functionality requires a feature flag.
78 base::CommandLine::ForCurrentProcess()->AppendSwitchASCII(
79 "--enable-override-bookmarks-ui", "1");
80 std::string manifest(kBrokenManifest);
81 JSONStringValueSerializer json(&manifest);
82 std::string error;
83 scoped_ptr<base::Value> root(json.Deserialize(NULL, &error));
84 ASSERT_TRUE(root);
85 ASSERT_TRUE(root->IsType(base::Value::TYPE_DICTIONARY));
86 scoped_refptr<Extension> extension = Extension::Create(
87 base::FilePath(FILE_PATH_LITERAL("//nonexistent")),
88 Manifest::INVALID_LOCATION,
89 *static_cast<base::DictionaryValue*>(root.get()),
90 Extension::NO_FLAGS,
91 &error);
92 EXPECT_FALSE(extension.get());
93 EXPECT_EQ(
94 extensions::ErrorUtils::FormatErrorMessage(
95 extensions::manifest_errors::kInvalidEmptyDictionary,
96 extensions::manifest_keys::kUIOverride),
97 error);
100 } // namespace