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/extension_manifest_test.h" | 6 #include "chrome/common/extensions/manifest_tests/extension_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" |
(...skipping 28 matching lines...) Expand all Loading... |
39 // Forbid absolute URL for options page in packaged apps. | 39 // Forbid absolute URL for options page in packaged apps. |
40 Testcase("packaged_app_absolute_options.json", | 40 Testcase("packaged_app_absolute_options.json", |
41 errors::kInvalidOptionsPageExpectUrlInPackage) | 41 errors::kInvalidOptionsPageExpectUrlInPackage) |
42 }; | 42 }; |
43 RunTestcases(testcases, arraysize(testcases), | 43 RunTestcases(testcases, arraysize(testcases), |
44 EXPECT_TYPE_ERROR); | 44 EXPECT_TYPE_ERROR); |
45 } | 45 } |
46 | 46 |
47 // Tests for the options_ui.page manifest field. | 47 // Tests for the options_ui.page manifest field. |
48 TEST_F(OptionsPageManifestTest, OptionsUIPage) { | 48 TEST_F(OptionsPageManifestTest, OptionsUIPage) { |
| 49 FeatureSwitch::ScopedOverride enable_flag( |
| 50 FeatureSwitch::embedded_extension_options(), true); |
| 51 |
49 scoped_refptr<Extension> extension = | 52 scoped_refptr<Extension> extension = |
50 LoadAndExpectSuccess("options_ui_page_basic.json"); | 53 LoadAndExpectSuccess("options_ui_page_basic.json"); |
51 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html", | 54 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html", |
52 extension.get()->id().c_str()), | 55 extension.get()->id().c_str()), |
53 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | 56 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
54 | 57 |
55 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); | 58 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); |
56 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", | 59 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", |
57 extension.get()->id().c_str()), | 60 extension.get()->id().c_str()), |
58 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | 61 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
59 | 62 |
60 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json", | 63 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json", |
61 "'page': expected page, got null")}; | 64 "'page': expected page, got null")}; |
62 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); | 65 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); |
63 } | 66 } |
64 | 67 |
65 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields. | 68 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields. |
66 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { | 69 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { |
| 70 FeatureSwitch::ScopedOverride enable_flag( |
| 71 FeatureSwitch::embedded_extension_options(), true); |
| 72 |
67 scoped_refptr<Extension> extension = | 73 scoped_refptr<Extension> extension = |
68 LoadAndExpectSuccess("options_ui_flags_true.json"); | 74 LoadAndExpectSuccess("options_ui_flags_true.json"); |
69 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | 75 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
70 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | 76 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
71 | 77 |
72 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | 78 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); |
73 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | 79 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
74 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | 80 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
75 | 81 |
76 // If chrome_style and open_in_tab are not set, they should be false. | 82 // If chrome_style and open_in_tab are not set, they should be false. |
77 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | 83 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); |
78 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | 84 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
79 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | 85 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
80 } | 86 } |
| 87 |
| 88 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields when |
| 89 // the flag for embedded extension options is turned off. chrome_style should |
| 90 // always be false, open_in_tab should always be true. |
| 91 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTabNoFlag) { |
| 92 ASSERT_FALSE(FeatureSwitch::embedded_extension_options()->IsEnabled()); |
| 93 |
| 94 scoped_refptr<Extension> extension = |
| 95 LoadAndExpectSuccess("options_ui_flags_true.json"); |
| 96 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| 97 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| 98 |
| 99 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); |
| 100 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| 101 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| 102 |
| 103 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); |
| 104 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| 105 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| 106 } |
OLD | NEW |