OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" | 6 #include "chrome/common/extensions/manifest_tests/chrome_manifest_test.h" |
7 #include "extensions/common/error_utils.h" | 7 #include "extensions/common/error_utils.h" |
8 #include "extensions/common/feature_switch.h" | 8 #include "extensions/common/feature_switch.h" |
9 #include "extensions/common/manifest_constants.h" | 9 #include "extensions/common/manifest_constants.h" |
10 #include "extensions/common/manifest_handlers/options_page_info.h" | 10 #include "extensions/common/manifest_handlers/options_page_info.h" |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 using namespace extensions; | 13 using namespace extensions; |
14 | 14 |
15 namespace errors = extensions::manifest_errors; | 15 namespace errors = extensions::manifest_errors; |
16 | 16 |
| 17 namespace { |
| 18 |
17 class OptionsPageManifestTest : public ChromeManifestTest { | 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())); |
| 30 |
| 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())); |
| 36 |
| 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())); |
| 43 |
| 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())); |
| 49 |
| 50 return testing::AssertionSuccess(); |
| 51 } |
| 52 |
| 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())); |
| 64 } |
| 65 return testing::AssertionSuccess(); |
| 66 } |
18 }; | 67 }; |
19 | 68 |
20 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { | 69 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { |
21 // Allow options page with absolute URL in hosted apps. | 70 // Allow options page with absolute URL in hosted apps. |
22 scoped_refptr<Extension> extension = | 71 scoped_refptr<Extension> extension = |
23 LoadAndExpectSuccess("hosted_app_absolute_options.json"); | 72 LoadAndExpectSuccess("hosted_app_absolute_options.json"); |
24 EXPECT_EQ("http://example.com/options.html", | 73 EXPECT_EQ("http://example.com/options.html", |
25 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | 74 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
26 | 75 |
27 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); | 76 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); |
(...skipping 30 matching lines...) Expand all Loading... |
58 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); | 107 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); |
59 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", | 108 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", |
60 extension.get()->id().c_str()), | 109 extension.get()->id().c_str()), |
61 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | 110 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
62 | 111 |
63 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json", | 112 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json", |
64 "'page': expected page, got null")}; | 113 "'page': expected page, got null")}; |
65 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); | 114 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); |
66 } | 115 } |
67 | 116 |
68 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields with | 117 // Runs TestOptionsUIChromeStyleAndOpenInTab with and without the |
69 // the flag enabled. This makes open_in_tab default to true if unspecified. | 118 // embedded-extension-options flag. The results should always be the same. |
70 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { | 119 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { |
71 FeatureSwitch::ScopedOverride enable_flag( | 120 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled()); |
72 FeatureSwitch::embedded_extension_options(), true); | 121 EXPECT_TRUE(TestOptionsUIChromeStyleAndOpenInTab()); |
73 | 122 { |
74 // Explicitly specifying true in the manifest for options_ui.chrome_style and | 123 FeatureSwitch::ScopedOverride enable_flag( |
75 // options_ui.open_in_tab sets them both to true. | 124 FeatureSwitch::embedded_extension_options(), true); |
76 scoped_refptr<Extension> extension = | 125 EXPECT_TRUE(TestOptionsUIChromeStyleAndOpenInTab()); |
77 LoadAndExpectSuccess("options_ui_flags_true.json"); | 126 } |
78 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
79 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
80 | |
81 // Explicitly specifying false in the manifest for options_ui.chrome_style | |
82 // and options_ui.open_in_tab sets them both to false. | |
83 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | |
84 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
85 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
86 | |
87 // Specifying an options_ui key but neither options_ui.chrome_style nor | |
88 // options_ui.open_in_tab uses the default values: false for open-in-tab, | |
89 // false for use-chrome-style. | |
90 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
91 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
92 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
93 | |
94 // Likewise specifying no options_ui key at all. | |
95 extension = LoadAndExpectSuccess("init_valid_options.json"); | |
96 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
97 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
98 } | 127 } |
99 | 128 |
100 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields when | 129 // Runs TestOptionsPageChromeStyleAndOpenInTab with and without the |
101 // the flag for embedded extension options is turned off. This makes | 130 // embedded-extension-options flag. The default value of open-in-tab differs |
102 // open_in_tab default to false. | 131 // depending on the flag's value. |
103 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTabNoFlag) { | 132 TEST_F(OptionsPageManifestTest, OptionsPageChromeStyleAndOpenInTab) { |
104 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled()); | 133 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled()); |
| 134 EXPECT_TRUE(TestOptionsPageChromeStyleAndOpenInTab(true)); |
| 135 { |
| 136 FeatureSwitch::ScopedOverride enable_flag( |
| 137 FeatureSwitch::embedded_extension_options(), true); |
| 138 EXPECT_TRUE(TestOptionsPageChromeStyleAndOpenInTab(false)); |
| 139 } |
| 140 } |
105 | 141 |
106 // These conditions are the same as OptionsUIChromeStyleAndOpenInTab, except | 142 } // namespace |
107 // when the flag is off the default for open-in-tab is true. | |
108 | |
109 scoped_refptr<Extension> extension = | |
110 LoadAndExpectSuccess("options_ui_flags_true.json"); | |
111 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
112 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
113 | |
114 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | |
115 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
116 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
117 | |
118 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
119 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
120 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
121 | |
122 extension = LoadAndExpectSuccess("init_valid_options.json"); | |
123 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
124 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
125 } | |
OLD | NEW |