Chromium Code Reviews| Index: chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc |
| diff --git a/chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc b/chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc |
| index f7b5c3b7a7322a07252404853ff239ad161e517f..1b2ef1a81efd38fa76a3c20d08c730bfab2179d5 100644 |
| --- a/chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc |
| +++ b/chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc |
| @@ -2,34 +2,31 @@ |
| // Use of this source code is governed by a BSD-style license that can be |
| // found in the LICENSE file. |
| +#include "base/strings/stringprintf.h" |
| #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h" |
| -#include "chrome/common/extensions/manifest_url_handler.h" |
| +#include "extensions/common/error_utils.h" |
| +#include "extensions/common/feature_switch.h" |
| #include "extensions/common/manifest_constants.h" |
| +#include "extensions/common/manifest_handlers/options_page_info.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| namespace errors = extensions::manifest_errors; |
| +using extensions::FeatureSwitch; |
| +using extensions::OptionsPageInfo; |
| + |
| class OptionsPageManifestTest : public ExtensionManifestTest { |
| }; |
| TEST_F(OptionsPageManifestTest, OptionsPageInApps) { |
| scoped_refptr<extensions::Extension> extension; |
| - |
| // Allow options page with absolute URL in hosted apps. |
| extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); |
| - EXPECT_STREQ("http", |
| - extensions::ManifestURL::GetOptionsPage(extension.get()) |
| - .scheme().c_str()); |
| - EXPECT_STREQ( |
| - "example.com", |
| - extensions::ManifestURL::GetOptionsPage(extension.get()).host().c_str()); |
| - EXPECT_STREQ("options.html", |
| - extensions::ManifestURL::GetOptionsPage(extension.get()) |
| - .ExtractFileName().c_str()); |
| + EXPECT_EQ("http://example.com/options.html", |
| + OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
| extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); |
| - EXPECT_TRUE(extensions::ManifestURL::GetOptionsPage(extension.get()) |
| - .is_empty()); |
| + EXPECT_TRUE(OptionsPageInfo::GetOptionsPage(extension.get()).is_empty()); |
| Testcase testcases[] = { |
| // Forbid options page with relative URL in hosted apps. |
| @@ -47,3 +44,65 @@ TEST_F(OptionsPageManifestTest, OptionsPageInApps) { |
| RunTestcases(testcases, arraysize(testcases), |
| EXPECT_TYPE_ERROR); |
| } |
| + |
| +// Tests for the options_ui.page manifest field |
|
Yoyo Zhou
2014/08/29 23:06:27
nit: comments should end in .
ericzeng
2014/09/02 18:23:37
Done.
|
| +TEST_F(OptionsPageManifestTest, OptionsUIPage) { |
| + scoped_refptr<extensions::Extension> extension; |
| + |
| + extension = LoadAndExpectSuccess("options_ui_page_basic.json"); |
| + EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html", |
| + extension.get()->id().c_str()), |
| + OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
| + |
| + extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); |
| + EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", |
| + extension.get()->id().c_str()), |
| + OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
| + |
| + Testcase testcases[] = { |
| + Testcase("options_ui_page_bad_url.json", |
| + extensions::ErrorUtils::FormatErrorMessage( |
| + errors::kInvalidOptionsPage, "options_ui"))}; |
| + RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); |
| +} |
| + |
| +// Tests for the options_ui.chrome_style and options_ui.open_in_tab fields |
| +TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { |
| + scoped_ptr<FeatureSwitch::ScopedOverride> enable_flag( |
| + new FeatureSwitch::ScopedOverride( |
| + FeatureSwitch::embedded_extension_options(), true)); |
| + |
| + scoped_refptr<extensions::Extension> extension; |
| + |
| + extension = LoadAndExpectSuccess("options_ui_flags_true.json"); |
| + EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| + |
| + extension = LoadAndExpectSuccess("options_ui_flags_false.json"); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| + |
| + // If chrome_style and open_in_tab are not set, they should be false |
| + extension = LoadAndExpectSuccess("options_ui_page_basic.json"); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| +} |
| + |
| +// Tests for the options_ui.chrome_style and options_ui.open_in_tab fields when |
| +// the flag for embedded extension options is turned off. chrome_style should |
| +// always be false, open_in_tab should always be true. |
| +TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTabNoFlag) { |
|
not at google - send to devlin
2014/08/29 22:33:37
You should ASSERT_TRUE that the flag is actually o
ericzeng
2014/08/29 23:54:03
Done.
|
| + scoped_refptr<extensions::Extension> extension; |
| + |
| + extension = LoadAndExpectSuccess("options_ui_flags_true.json"); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| + |
| + extension = LoadAndExpectSuccess("options_ui_flags_false.json"); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| + |
| + extension = LoadAndExpectSuccess("options_ui_page_basic.json"); |
| + EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); |
| + EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); |
| +} |