Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(900)

Side by Side Diff: chrome/common/extensions/manifest_tests/extension_manifests_options_unittest.cc

Issue 518653002: Add the "options_ui" extension manifest field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fix build issue? Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "chrome/common/extensions/manifest_tests/extension_manifest_test.h" 6 #include "chrome/common/extensions/manifest_tests/extension_manifest_test.h"
6 #include "chrome/common/extensions/manifest_url_handler.h" 7 #include "extensions/common/error_utils.h"
8 #include "extensions/common/feature_switch.h"
7 #include "extensions/common/manifest_constants.h" 9 #include "extensions/common/manifest_constants.h"
10 #include "extensions/common/manifest_handlers/options_page_info.h"
8 #include "testing/gtest/include/gtest/gtest.h" 11 #include "testing/gtest/include/gtest/gtest.h"
9 12
13 using namespace extensions;
14
10 namespace errors = extensions::manifest_errors; 15 namespace errors = extensions::manifest_errors;
11 16
12 class OptionsPageManifestTest : public ExtensionManifestTest { 17 class OptionsPageManifestTest : public ExtensionManifestTest {
13 }; 18 };
14 19
15 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { 20 TEST_F(OptionsPageManifestTest, OptionsPageInApps) {
16 scoped_refptr<extensions::Extension> extension;
17
18 // Allow options page with absolute URL in hosted apps. 21 // Allow options page with absolute URL in hosted apps.
19 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); 22 scoped_refptr<Extension> extension =
20 EXPECT_STREQ("http", 23 LoadAndExpectSuccess("hosted_app_absolute_options.json");
21 extensions::ManifestURL::GetOptionsPage(extension.get()) 24 EXPECT_EQ("http://example.com/options.html",
22 .scheme().c_str()); 25 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
23 EXPECT_STREQ(
24 "example.com",
25 extensions::ManifestURL::GetOptionsPage(extension.get()).host().c_str());
26 EXPECT_STREQ("options.html",
27 extensions::ManifestURL::GetOptionsPage(extension.get())
28 .ExtractFileName().c_str());
29 26
30 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); 27 extension = LoadAndExpectSuccess("platform_app_with_options_page.json");
31 EXPECT_TRUE(extensions::ManifestURL::GetOptionsPage(extension.get()) 28 EXPECT_TRUE(!OptionsPageInfo::HasOptionsPage(extension.get()));
32 .is_empty());
33 29
34 Testcase testcases[] = { 30 Testcase testcases[] = {
35 // Forbid options page with relative URL in hosted apps. 31 // Forbid options page with relative URL in hosted apps.
36 Testcase("hosted_app_relative_options.json", 32 Testcase("hosted_app_relative_options.json",
37 errors::kInvalidOptionsPageInHostedApp), 33 errors::kInvalidOptionsPageInHostedApp),
38 34
39 // Forbid options page with non-(http|https) scheme in hosted app. 35 // Forbid options page with non-(http|https) scheme in hosted app.
40 Testcase("hosted_app_file_options.json", 36 Testcase("hosted_app_file_options.json",
41 errors::kInvalidOptionsPageInHostedApp), 37 errors::kInvalidOptionsPageInHostedApp),
42 38
43 // Forbid absolute URL for options page in packaged apps. 39 // Forbid absolute URL for options page in packaged apps.
44 Testcase("packaged_app_absolute_options.json", 40 Testcase("packaged_app_absolute_options.json",
45 errors::kInvalidOptionsPageExpectUrlInPackage) 41 errors::kInvalidOptionsPageExpectUrlInPackage)
46 }; 42 };
47 RunTestcases(testcases, arraysize(testcases), 43 RunTestcases(testcases, arraysize(testcases),
48 EXPECT_TYPE_ERROR); 44 EXPECT_TYPE_ERROR);
49 } 45 }
46
47 // Tests for the options_ui.page manifest field.
48 TEST_F(OptionsPageManifestTest, OptionsUIPage) {
49 FeatureSwitch::ScopedOverride enable_flag(
50 FeatureSwitch::embedded_extension_options(), true);
51
52 scoped_refptr<Extension> extension =
53 LoadAndExpectSuccess("options_ui_page_basic.json");
54 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html",
55 extension.get()->id().c_str()),
56 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
57
58 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json");
59 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html",
60 extension.get()->id().c_str()),
61 OptionsPageInfo::GetOptionsPage(extension.get()).spec());
62
63 Testcase testcases[] = {Testcase("options_ui_page_bad_url.json",
64 "'page': expected page, got null")};
65 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING);
66 }
67
68 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields.
69 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) {
70 FeatureSwitch::ScopedOverride enable_flag(
71 FeatureSwitch::embedded_extension_options(), true);
72
73 scoped_refptr<Extension> extension =
74 LoadAndExpectSuccess("options_ui_flags_true.json");
75 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
76 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
77
78 extension = LoadAndExpectSuccess("options_ui_flags_false.json");
79 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
80 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
81
82 // If chrome_style and open_in_tab are not set, they should be false.
83 extension = LoadAndExpectSuccess("options_ui_page_basic.json");
84 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get()));
85 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get()));
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 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698