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 "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 |
10 namespace errors = extensions::manifest_errors; | 13 namespace errors = extensions::manifest_errors; |
11 | 14 |
15 using extensions::FeatureSwitch; | |
16 using extensions::OptionsPageInfo; | |
17 | |
12 class OptionsPageManifestTest : public ExtensionManifestTest { | 18 class OptionsPageManifestTest : public ExtensionManifestTest { |
13 }; | 19 }; |
14 | 20 |
15 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { | 21 TEST_F(OptionsPageManifestTest, OptionsPageInApps) { |
16 scoped_refptr<extensions::Extension> extension; | 22 scoped_refptr<extensions::Extension> extension; |
17 | |
18 // Allow options page with absolute URL in hosted apps. | 23 // Allow options page with absolute URL in hosted apps. |
19 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); | 24 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); |
20 EXPECT_STREQ("http", | 25 EXPECT_EQ("http://example.com/options.html", |
21 extensions::ManifestURL::GetOptionsPage(extension.get()) | 26 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); |
22 .scheme().c_str()); | |
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 | 27 |
30 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); | 28 extension = LoadAndExpectSuccess("platform_app_with_options_page.json"); |
31 EXPECT_TRUE(extensions::ManifestURL::GetOptionsPage(extension.get()) | 29 EXPECT_TRUE(OptionsPageInfo::GetOptionsPage(extension.get()).is_empty()); |
32 .is_empty()); | |
33 | 30 |
34 Testcase testcases[] = { | 31 Testcase testcases[] = { |
35 // Forbid options page with relative URL in hosted apps. | 32 // Forbid options page with relative URL in hosted apps. |
36 Testcase("hosted_app_relative_options.json", | 33 Testcase("hosted_app_relative_options.json", |
37 errors::kInvalidOptionsPageInHostedApp), | 34 errors::kInvalidOptionsPageInHostedApp), |
38 | 35 |
39 // Forbid options page with non-(http|https) scheme in hosted app. | 36 // Forbid options page with non-(http|https) scheme in hosted app. |
40 Testcase("hosted_app_file_options.json", | 37 Testcase("hosted_app_file_options.json", |
41 errors::kInvalidOptionsPageInHostedApp), | 38 errors::kInvalidOptionsPageInHostedApp), |
42 | 39 |
43 // Forbid absolute URL for options page in packaged apps. | 40 // Forbid absolute URL for options page in packaged apps. |
44 Testcase("packaged_app_absolute_options.json", | 41 Testcase("packaged_app_absolute_options.json", |
45 errors::kInvalidOptionsPageExpectUrlInPackage) | 42 errors::kInvalidOptionsPageExpectUrlInPackage) |
46 }; | 43 }; |
47 RunTestcases(testcases, arraysize(testcases), | 44 RunTestcases(testcases, arraysize(testcases), |
48 EXPECT_TYPE_ERROR); | 45 EXPECT_TYPE_ERROR); |
49 } | 46 } |
47 | |
48 // 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.
| |
49 TEST_F(OptionsPageManifestTest, OptionsUIPage) { | |
50 scoped_refptr<extensions::Extension> extension; | |
51 | |
52 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
53 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/options.html", | |
54 extension.get()->id().c_str()), | |
55 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | |
56 | |
57 extension = LoadAndExpectSuccess("options_ui_page_with_legacy_page.json"); | |
58 EXPECT_EQ(base::StringPrintf("chrome-extension://%s/newoptions.html", | |
59 extension.get()->id().c_str()), | |
60 OptionsPageInfo::GetOptionsPage(extension.get()).spec()); | |
61 | |
62 Testcase testcases[] = { | |
63 Testcase("options_ui_page_bad_url.json", | |
64 extensions::ErrorUtils::FormatErrorMessage( | |
65 errors::kInvalidOptionsPage, "options_ui"))}; | |
66 RunTestcases(testcases, arraysize(testcases), EXPECT_TYPE_WARNING); | |
67 } | |
68 | |
69 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields | |
70 TEST_F(OptionsPageManifestTest, OptionsUIChromeStyleAndOpenInTab) { | |
71 scoped_ptr<FeatureSwitch::ScopedOverride> enable_flag( | |
72 new FeatureSwitch::ScopedOverride( | |
73 FeatureSwitch::embedded_extension_options(), true)); | |
74 | |
75 scoped_refptr<extensions::Extension> extension; | |
76 | |
77 extension = LoadAndExpectSuccess("options_ui_flags_true.json"); | |
78 EXPECT_TRUE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
79 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
80 | |
81 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | |
82 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
83 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
84 | |
85 // If chrome_style and open_in_tab are not set, they should be false | |
86 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
87 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
88 EXPECT_FALSE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
89 } | |
90 | |
91 // Tests for the options_ui.chrome_style and options_ui.open_in_tab fields when | |
92 // the flag for embedded extension options is turned off. chrome_style should | |
93 // always be false, open_in_tab should always be true. | |
94 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.
| |
95 scoped_refptr<extensions::Extension> extension; | |
96 | |
97 extension = LoadAndExpectSuccess("options_ui_flags_true.json"); | |
98 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
99 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
100 | |
101 extension = LoadAndExpectSuccess("options_ui_flags_false.json"); | |
102 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
103 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
104 | |
105 extension = LoadAndExpectSuccess("options_ui_page_basic.json"); | |
106 EXPECT_FALSE(OptionsPageInfo::ShouldUseChromeStyle(extension.get())); | |
107 EXPECT_TRUE(OptionsPageInfo::ShouldOpenInTab(extension.get())); | |
108 } | |
OLD | NEW |