Update CrOS OOBE throbber to MD throbber; delete old asset
[chromium-blink-merge.git] / chrome / common / extensions / manifest_tests / extension_manifests_options_unittest.cc
blobe14abf6ddea3a20f44a86245820e13cd61296d4b
1 // Copyright (c) 2012 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 "base/strings/stringprintf.h"
6 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h"
7 #include "extensions/common/error_utils.h"
8 #include "extensions/common/feature_switch.h"
9 #include "extensions/common/manifest_constants.h"
10 #include "extensions/common/manifest_handlers/options_page_info.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 using namespace extensions;
15 namespace errors = extensions::manifest_errors;
17 namespace {
19 class OptionsPageManifestTest : public ChromeManifestTest {
20 protected:
21 // Tests how the options_ui manifest key affects the open-in-tab and
22 // chromes-style behaviour.
23 testing::AssertionResult TestOptionsUIChromeStyleAndOpenInTab() {
24 // Explicitly specifying true in the manifest for options_ui.chrome_style
25 // and options_ui.open_in_tab sets them both to true.
26 scoped_refptr<Extension> extension =
27 LoadAndExpectSuccess("options_ui_flags_true.json");
28 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
29 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
31 // Explicitly specifying false in the manifest for options_ui.chrome_style
32 // and options_ui.open_in_tab sets them both to false.
33 extension = LoadAndExpectSuccess("options_ui_flags_false.json");
34 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
35 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
37 // Specifying an options_ui key but neither options_ui.chrome_style nor
38 // options_ui.open_in_tab uses the default values: false for open-in-tab,
39 // false for use-chrome-style.
40 extension = LoadAndExpectSuccess("options_ui_page_basic.json");
41 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
42 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
44 // This extension has both options_page and options_ui specified. The
45 // options_ui key should take precedence.
46 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json");
47 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
48 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
50 return testing::AssertionSuccess();
53 // Tests how the options_page manifest key affects the open-in-tab and
54 // chromes-style behaviour.
55 testing::AssertionResult TestOptionsPageChromeStyleAndOpenInTab(
56 bool expect_open_in_tab) {
57 scoped_refptr<Extension> extension =
58 LoadAndExpectSuccess("init_valid_options.json");
59 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
60 if (expect_open_in_tab) {
61 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
62 } else {
63 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
65 return testing::AssertionSuccess();
69 TEST_F(OptionsPageManifestTest, OptionsPageInApps) {
70 // Allow options page with absolute URL in hosted apps.
71 scoped_refptr<Extension> extension =
72 LoadAndExpectSuccess("hosted_app_absolute_options.json");
73 EXPECT_EQ("http://example.com/options.html",
74 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
76 extension = LoadAndExpectSuccess("platform_app_with_options_page.json");
77 EXPECT_TRUE(!OptionsPageInfo::HasOptionsPage(extension.get()));
79 Testcase testcases[] = {
80 // Forbid options page with relative URL in hosted apps.
81 Testcase("hosted_app_relative_options.json",
82 errors::kInvalidOptionsPageInHostedApp),
84 // Forbid options page with non-(http|https) scheme in hosted app.
85 Testcase("hosted_app_file_options.json",
86 errors::kInvalidOptionsPageInHostedApp),
88 // Forbid absolute URL for options page in packaged apps.
89 Testcase("packaged_app_absolute_options.json",
90 errors::kInvalidOptionsPageExpectUrlInPackage)
92 RunTestcases(testcases, arraysize(testcases),
93 EXPECT_TYPE_ERROR);
96 // Tests for the options_ui.page manifest field.
97 TEST_F(OptionsPageManifestTest, OptionsUIPage) {
98 FeatureSwitch::ScopedOverride enable_flag(
99 FeatureSwitch::embedded_extension_options(), true);
101 scoped_refptr<Extension> extension =
102 LoadAndExpectSuccess("options_ui_page_basic.json");
103 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html",
104 extension.get()->id().c_str()),
105 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
107 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json");
108 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html",
109 extension.get()->id().c_str()),
110 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
112 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json",
113 "'page': expected page, got null")};
114 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING);
117 // Runs TestOptionsUIChromeStyleAndOpenInTab with and without the
118 // embedded-extension-options flag. The results should always be the same.
119 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) {
120 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled());
121 EXPECT_TRUE(TestOptionsUIChromeStyleAndOpenInTab());
123 FeatureSwitch::ScopedOverride enable_flag(
124 FeatureSwitch::embedded_extension_options(), true);
125 EXPECT_TRUE(TestOptionsUIChromeStyleAndOpenInTab());
129 // Runs TestOptionsPageChromeStyleAndOpenInTab with and without the
130 // embedded-extension-options flag. The default value of open-in-tab differs
131 // depending on the flag's value.
132 TEST_F(OptionsPageManifestTest, OptionsPageChromeStyleAndOpenInTab) {
133 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled());
134 EXPECT_TRUE(TestOptionsPageChromeStyleAndOpenInTab(true));
136 FeatureSwitch::ScopedOverride enable_flag(
137 FeatureSwitch::embedded_extension_options(), true);
138 EXPECT_TRUE(TestOptionsPageChromeStyleAndOpenInTab(false));
142 } // namespace