OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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 "chrome/common/extensions/extension.h" | 5 #include "chrome/common/extensions/extension.h" |
6 | 6 |
7 #if defined(TOOLKIT_GTK) | 7 #if defined(TOOLKIT_GTK) |
8 #include <gtk/gtk.h> | 8 #include <gtk/gtk.h> |
9 #endif | 9 #endif |
10 | 10 |
11 #include "base/command_line.h" | |
12 #include "base/file_path.h" | 11 #include "base/file_path.h" |
13 #include "base/file_util.h" | 12 #include "base/file_util.h" |
14 #include "base/i18n/rtl.h" | 13 #include "base/i18n/rtl.h" |
15 #include "base/json/json_value_serializer.h" | 14 #include "base/json/json_value_serializer.h" |
16 #include "base/memory/scoped_ptr.h" | 15 #include "base/memory/scoped_ptr.h" |
17 #include "base/path_service.h" | 16 #include "base/path_service.h" |
18 #include "base/stringprintf.h" | |
19 #include "base/string_number_conversions.h" | 17 #include "base/string_number_conversions.h" |
20 #include "base/string_util.h" | 18 #include "base/string_util.h" |
| 19 #include "base/stringprintf.h" |
21 #include "base/utf_string_conversions.h" | 20 #include "base/utf_string_conversions.h" |
22 #include "chrome/common/chrome_paths.h" | 21 #include "chrome/common/chrome_paths.h" |
23 #include "chrome/common/chrome_switches.h" | 22 #include "chrome/common/chrome_switches.h" |
24 #include "chrome/common/extensions/extension.h" | 23 #include "chrome/common/extensions/extension.h" |
25 #include "chrome/common/extensions/extension_constants.h" | 24 #include "chrome/common/extensions/extension_constants.h" |
26 #include "chrome/common/extensions/extension_error_utils.h" | 25 #include "chrome/common/extensions/extension_error_utils.h" |
27 #include "chrome/common/extensions/extension_sidebar_defaults.h" | 26 #include "chrome/common/extensions/extension_sidebar_defaults.h" |
28 #include "chrome/common/extensions/file_browser_handler.h" | 27 #include "chrome/common/extensions/file_browser_handler.h" |
29 #include "chrome/common/extensions/url_pattern.h" | 28 #include "chrome/common/extensions/url_pattern.h" |
| 29 #include "chrome/test/base/scoped_command_line_override.h" |
30 #include "testing/gtest/include/gtest/gtest.h" | 30 #include "testing/gtest/include/gtest/gtest.h" |
31 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
32 | 32 |
33 | 33 |
34 namespace { | 34 namespace { |
35 | 35 |
36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
37 int schemes = URLPattern::SCHEME_ALL; | 37 int schemes = URLPattern::SCHEME_ALL; |
38 extent->AddPattern(URLPattern(schemes, pattern)); | 38 extent->AddPattern(URLPattern(schemes, pattern)); |
39 } | 39 } |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
214 // distinguish between API and host permissions. | 214 // distinguish between API and host permissions. |
215 extension = LoadAndExpectSuccess("init_valid_permissions.json"); | 215 extension = LoadAndExpectSuccess("init_valid_permissions.json"); |
216 | 216 |
217 // Test with an options page. | 217 // Test with an options page. |
218 extension = LoadAndExpectSuccess("init_valid_options.json"); | 218 extension = LoadAndExpectSuccess("init_valid_options.json"); |
219 EXPECT_EQ("chrome-extension", extension->options_url().scheme()); | 219 EXPECT_EQ("chrome-extension", extension->options_url().scheme()); |
220 EXPECT_EQ("/options.html", extension->options_url().path()); | 220 EXPECT_EQ("/options.html", extension->options_url().path()); |
221 | 221 |
222 // Test that an empty list of page actions does not stop a browser action | 222 // Test that an empty list of page actions does not stop a browser action |
223 // from being loaded. | 223 // from being loaded. |
224 extension = LoadAndExpectSuccess("init_valid_empty_page_actions.json"); | 224 LoadAndExpectSuccess("init_valid_empty_page_actions.json"); |
225 | 225 |
226 // Test with a minimum_chrome_version. | 226 // Test with a minimum_chrome_version. |
227 extension = LoadAndExpectSuccess("init_valid_minimum_chrome.json"); | 227 LoadAndExpectSuccess("init_valid_minimum_chrome.json"); |
228 | 228 |
229 // Test a hosted app with a minimum_chrome_version. | 229 // Test a hosted app with a minimum_chrome_version. |
230 extension = LoadAndExpectSuccess("init_valid_app_minimum_chrome.json"); | 230 LoadAndExpectSuccess("init_valid_app_minimum_chrome.json"); |
231 | 231 |
232 // Test a hosted app with a requirements section. | 232 // Test a hosted app with a requirements section. |
233 extension = LoadAndExpectSuccess("init_valid_app_requirements.json"); | 233 LoadAndExpectSuccess("init_valid_app_requirements.json"); |
234 | 234 |
235 // Verify empty permission settings are considered valid. | 235 // Verify empty permission settings are considered valid. |
236 LoadAndExpectSuccess("init_valid_permissions_empty.json"); | 236 LoadAndExpectSuccess("init_valid_permissions_empty.json"); |
237 | 237 |
238 // We allow unknown API permissions, so this will be valid until we better | 238 // We allow unknown API permissions, so this will be valid until we better |
239 // distinguish between API and host permissions. | 239 // distinguish between API and host permissions. |
240 LoadAndExpectSuccess("init_valid_permissions_unknown.json"); | 240 LoadAndExpectSuccess("init_valid_permissions_unknown.json"); |
241 } | 241 } |
242 | 242 |
| 243 TEST_F(ExtensionManifestTest, PlatformApps) { |
| 244 // A minimal platform app. |
| 245 LoadAndExpectSuccess("init_valid_platform_app.json"); |
| 246 } |
| 247 |
243 TEST_F(ExtensionManifestTest, InitFromValueValidNameInRTL) { | 248 TEST_F(ExtensionManifestTest, InitFromValueValidNameInRTL) { |
244 #if defined(TOOLKIT_GTK) | 249 #if defined(TOOLKIT_GTK) |
245 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); | 250 GtkTextDirection gtk_dir = gtk_widget_get_default_direction(); |
246 gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); | 251 gtk_widget_set_default_direction(GTK_TEXT_DIR_RTL); |
247 #else | 252 #else |
248 std::string locale = l10n_util::GetApplicationLocale(""); | 253 std::string locale = l10n_util::GetApplicationLocale(""); |
249 base::i18n::SetICUDefaultLocale("he"); | 254 base::i18n::SetICUDefaultLocale("he"); |
250 #endif | 255 #endif |
251 | 256 |
252 // No strong RTL characters in name. | 257 // No strong RTL characters in name. |
(...skipping 132 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
385 extension = LoadAndExpectSuccess("launch_width.json"); | 390 extension = LoadAndExpectSuccess("launch_width.json"); |
386 EXPECT_EQ(640, extension->launch_width()); | 391 EXPECT_EQ(640, extension->launch_width()); |
387 | 392 |
388 extension = LoadAndExpectSuccess("launch_height.json"); | 393 extension = LoadAndExpectSuccess("launch_height.json"); |
389 EXPECT_EQ(480, extension->launch_height()); | 394 EXPECT_EQ(480, extension->launch_height()); |
390 | 395 |
391 LoadAndExpectError("launch_window.json", | 396 LoadAndExpectError("launch_window.json", |
392 errors::kInvalidLaunchContainer); | 397 errors::kInvalidLaunchContainer); |
393 LoadAndExpectError("launch_container_invalid_type.json", | 398 LoadAndExpectError("launch_container_invalid_type.json", |
394 errors::kInvalidLaunchContainer); | 399 errors::kInvalidLaunchContainer); |
| 400 { |
| 401 ScopedCommandLineOverride override(switches::kEnablePlatformApps); |
| 402 LoadAndExpectError("launch_container_invalid_type_for_platform.json", |
| 403 errors::kInvalidLaunchContainerForPlatform); |
| 404 } |
395 LoadAndExpectError("launch_container_invalid_value.json", | 405 LoadAndExpectError("launch_container_invalid_value.json", |
396 errors::kInvalidLaunchContainer); | 406 errors::kInvalidLaunchContainer); |
397 LoadAndExpectError("launch_container_without_launch_url.json", | 407 LoadAndExpectError("launch_container_without_launch_url.json", |
398 errors::kLaunchURLRequired); | 408 errors::kLaunchURLRequired); |
399 LoadAndExpectError("launch_width_invalid.json", | 409 LoadAndExpectError("launch_width_invalid.json", |
400 errors::kInvalidLaunchWidthContainer); | 410 errors::kInvalidLaunchWidthContainer); |
401 LoadAndExpectError("launch_width_negative.json", | 411 LoadAndExpectError("launch_width_negative.json", |
402 errors::kInvalidLaunchWidth); | 412 errors::kInvalidLaunchWidth); |
403 LoadAndExpectError("launch_height_invalid.json", | 413 LoadAndExpectError("launch_height_invalid.json", |
404 errors::kInvalidLaunchHeightContainer); | 414 errors::kInvalidLaunchHeightContainer); |
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
519 "Invalid value for " | 529 "Invalid value for " |
520 "'content_scripts[0].exclude_matches[0]': " | 530 "'content_scripts[0].exclude_matches[0]': " |
521 "Invalid host wildcard."); | 531 "Invalid host wildcard."); |
522 } | 532 } |
523 | 533 |
524 TEST_F(ExtensionManifestTest, ExperimentalPermission) { | 534 TEST_F(ExtensionManifestTest, ExperimentalPermission) { |
525 LoadAndExpectError("experimental.json", errors::kExperimentalFlagRequired); | 535 LoadAndExpectError("experimental.json", errors::kExperimentalFlagRequired); |
526 LoadAndExpectSuccess("experimental.json", Extension::COMPONENT); | 536 LoadAndExpectSuccess("experimental.json", Extension::COMPONENT); |
527 LoadAndExpectSuccess("experimental.json", Extension::INTERNAL, | 537 LoadAndExpectSuccess("experimental.json", Extension::INTERNAL, |
528 Extension::FROM_WEBSTORE); | 538 Extension::FROM_WEBSTORE); |
529 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); | 539 ScopedCommandLineOverride override( |
530 CommandLine::ForCurrentProcess()->AppendSwitch( | |
531 switches::kEnableExperimentalExtensionApis); | 540 switches::kEnableExperimentalExtensionApis); |
532 LoadAndExpectSuccess("experimental.json"); | 541 LoadAndExpectSuccess("experimental.json"); |
533 *CommandLine::ForCurrentProcess() = old_command_line; | |
534 } | 542 } |
535 | 543 |
536 TEST_F(ExtensionManifestTest, DevToolsExtensions) { | 544 TEST_F(ExtensionManifestTest, DevToolsExtensions) { |
537 LoadAndExpectError("devtools_extension_no_permissions.json", | 545 LoadAndExpectError("devtools_extension_no_permissions.json", |
538 errors::kDevToolsExperimental); | 546 errors::kDevToolsExperimental); |
539 LoadAndExpectError("devtools_extension_url_invalid_type.json", | 547 LoadAndExpectError("devtools_extension_url_invalid_type.json", |
540 errors::kInvalidDevToolsPage); | 548 errors::kInvalidDevToolsPage); |
541 | 549 |
542 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); | 550 ScopedCommandLineOverride override( |
543 CommandLine::ForCurrentProcess()->AppendSwitch( | |
544 switches::kEnableExperimentalExtensionApis); | 551 switches::kEnableExperimentalExtensionApis); |
545 | |
546 scoped_refptr<Extension> extension; | 552 scoped_refptr<Extension> extension; |
547 extension = LoadAndExpectSuccess("devtools_extension.json"); | 553 extension = LoadAndExpectSuccess("devtools_extension.json"); |
548 EXPECT_EQ(extension->url().spec() + "devtools.html", | 554 EXPECT_EQ(extension->url().spec() + "devtools.html", |
549 extension->devtools_url().spec()); | 555 extension->devtools_url().spec()); |
550 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); | 556 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); |
551 | |
552 *CommandLine::ForCurrentProcess() = old_command_line; | |
553 } | 557 } |
554 | 558 |
555 TEST_F(ExtensionManifestTest, Sidebar) { | 559 TEST_F(ExtensionManifestTest, Sidebar) { |
556 LoadAndExpectError("sidebar.json", | 560 LoadAndExpectError("sidebar.json", |
557 errors::kExperimentalFlagRequired); | 561 errors::kExperimentalFlagRequired); |
558 | 562 |
559 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); | 563 ScopedCommandLineOverride override( |
560 CommandLine::ForCurrentProcess()->AppendSwitch( | |
561 switches::kEnableExperimentalExtensionApis); | 564 switches::kEnableExperimentalExtensionApis); |
562 | 565 |
563 LoadAndExpectError("sidebar_no_permissions.json", | 566 LoadAndExpectError("sidebar_no_permissions.json", |
564 errors::kSidebarExperimental); | 567 errors::kSidebarExperimental); |
565 | 568 |
566 LoadAndExpectError("sidebar_icon_empty.json", | 569 LoadAndExpectError("sidebar_icon_empty.json", |
567 errors::kInvalidSidebarDefaultIconPath); | 570 errors::kInvalidSidebarDefaultIconPath); |
568 LoadAndExpectError("sidebar_icon_invalid_type.json", | 571 LoadAndExpectError("sidebar_icon_invalid_type.json", |
569 errors::kInvalidSidebarDefaultIconPath); | 572 errors::kInvalidSidebarDefaultIconPath); |
570 LoadAndExpectError("sidebar_page_empty.json", | 573 LoadAndExpectError("sidebar_page_empty.json", |
571 errors::kInvalidSidebarDefaultPage); | 574 errors::kInvalidSidebarDefaultPage); |
572 LoadAndExpectError("sidebar_page_invalid_type.json", | 575 LoadAndExpectError("sidebar_page_invalid_type.json", |
573 errors::kInvalidSidebarDefaultPage); | 576 errors::kInvalidSidebarDefaultPage); |
574 LoadAndExpectError("sidebar_title_invalid_type.json", | 577 LoadAndExpectError("sidebar_title_invalid_type.json", |
575 errors::kInvalidSidebarDefaultTitle); | 578 errors::kInvalidSidebarDefaultTitle); |
576 | 579 |
577 scoped_refptr<Extension> extension(LoadAndExpectSuccess("sidebar.json")); | 580 scoped_refptr<Extension> extension(LoadAndExpectSuccess("sidebar.json")); |
578 ASSERT_TRUE(extension->sidebar_defaults() != NULL); | 581 ASSERT_TRUE(extension->sidebar_defaults() != NULL); |
579 EXPECT_EQ(extension->sidebar_defaults()->default_title(), | 582 EXPECT_EQ(extension->sidebar_defaults()->default_title(), |
580 ASCIIToUTF16("Default title")); | 583 ASCIIToUTF16("Default title")); |
581 EXPECT_EQ(extension->sidebar_defaults()->default_icon_path(), | 584 EXPECT_EQ(extension->sidebar_defaults()->default_icon_path(), |
582 "icon.png"); | 585 "icon.png"); |
583 EXPECT_EQ(extension->url().spec() + "sidebar.html", | 586 EXPECT_EQ(extension->url().spec() + "sidebar.html", |
584 extension->sidebar_defaults()->default_page().spec()); | 587 extension->sidebar_defaults()->default_page().spec()); |
585 | |
586 *CommandLine::ForCurrentProcess() = old_command_line; | |
587 } | 588 } |
588 | 589 |
589 TEST_F(ExtensionManifestTest, DisallowHybridApps) { | 590 TEST_F(ExtensionManifestTest, DisallowHybridApps) { |
590 LoadAndExpectError("disallow_hybrid_1.json", | 591 LoadAndExpectError("disallow_hybrid_1.json", |
591 ExtensionErrorUtils::FormatErrorMessage( | 592 ExtensionErrorUtils::FormatErrorMessage( |
592 errors::kHostedAppsCannotIncludeExtensionFeatures, | 593 errors::kHostedAppsCannotIncludeExtensionFeatures, |
593 keys::kBrowserAction)); | 594 keys::kBrowserAction)); |
594 LoadAndExpectError("disallow_hybrid_2.json", | 595 LoadAndExpectError("disallow_hybrid_2.json", |
595 errors::kBackgroundPermissionNeeded); | 596 errors::kBackgroundPermissionNeeded); |
596 } | 597 } |
(...skipping 212 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
809 LoadAndExpectSuccess("tts_engine_valid.json")); | 810 LoadAndExpectSuccess("tts_engine_valid.json")); |
810 | 811 |
811 ASSERT_EQ(1u, extension->tts_voices().size()); | 812 ASSERT_EQ(1u, extension->tts_voices().size()); |
812 EXPECT_EQ("name", extension->tts_voices()[0].voice_name); | 813 EXPECT_EQ("name", extension->tts_voices()[0].voice_name); |
813 EXPECT_EQ("en-US", extension->tts_voices()[0].lang); | 814 EXPECT_EQ("en-US", extension->tts_voices()[0].lang); |
814 EXPECT_EQ("female", extension->tts_voices()[0].gender); | 815 EXPECT_EQ("female", extension->tts_voices()[0].gender); |
815 EXPECT_EQ(3U, extension->tts_voices()[0].event_types.size()); | 816 EXPECT_EQ(3U, extension->tts_voices()[0].event_types.size()); |
816 } | 817 } |
817 | 818 |
818 TEST_F(ExtensionManifestTest, WebIntents) { | 819 TEST_F(ExtensionManifestTest, WebIntents) { |
819 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents"); | 820 ScopedCommandLineOverride override("--enable-web-intents"); |
820 | 821 |
821 LoadAndExpectError("intent_invalid_1.json", | 822 LoadAndExpectError("intent_invalid_1.json", |
822 extension_manifest_errors::kInvalidIntents); | 823 extension_manifest_errors::kInvalidIntents); |
823 LoadAndExpectError("intent_invalid_2.json", | 824 LoadAndExpectError("intent_invalid_2.json", |
824 extension_manifest_errors::kInvalidIntent); | 825 extension_manifest_errors::kInvalidIntent); |
825 LoadAndExpectError("intent_invalid_3.json", | 826 LoadAndExpectError("intent_invalid_3.json", |
826 extension_manifest_errors::kInvalidIntentPath); | 827 extension_manifest_errors::kInvalidIntentPath); |
827 LoadAndExpectError("intent_invalid_4.json", | 828 LoadAndExpectError("intent_invalid_4.json", |
828 extension_manifest_errors::kInvalidIntentDisposition); | 829 extension_manifest_errors::kInvalidIntentDisposition); |
829 LoadAndExpectError("intent_invalid_5.json", | 830 LoadAndExpectError("intent_invalid_5.json", |
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
872 // to flag this case. | 873 // to flag this case. |
873 LoadAndExpectSuccess("forbid_ports_in_permissions.json", | 874 LoadAndExpectSuccess("forbid_ports_in_permissions.json", |
874 Extension::INTERNAL, Extension::STRICT_ERROR_CHECKS); | 875 Extension::INTERNAL, Extension::STRICT_ERROR_CHECKS); |
875 } | 876 } |
876 | 877 |
877 TEST_F(ExtensionManifestTest, IsolatedApps) { | 878 TEST_F(ExtensionManifestTest, IsolatedApps) { |
878 // Requires --enable-experimental-extension-apis | 879 // Requires --enable-experimental-extension-apis |
879 LoadAndExpectError("isolated_app_valid.json", | 880 LoadAndExpectError("isolated_app_valid.json", |
880 errors::kExperimentalFlagRequired); | 881 errors::kExperimentalFlagRequired); |
881 | 882 |
882 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); | 883 ScopedCommandLineOverride override( |
883 CommandLine::ForCurrentProcess()->AppendSwitch( | |
884 switches::kEnableExperimentalExtensionApis); | 884 switches::kEnableExperimentalExtensionApis); |
885 scoped_refptr<Extension> extension2( | 885 scoped_refptr<Extension> extension2( |
886 LoadAndExpectSuccess("isolated_app_valid.json")); | 886 LoadAndExpectSuccess("isolated_app_valid.json")); |
887 EXPECT_TRUE(extension2->is_storage_isolated()); | 887 EXPECT_TRUE(extension2->is_storage_isolated()); |
888 *CommandLine::ForCurrentProcess() = old_command_line; | |
889 } | 888 } |
890 | 889 |
891 | 890 |
892 TEST_F(ExtensionManifestTest, FileBrowserHandlers) { | 891 TEST_F(ExtensionManifestTest, FileBrowserHandlers) { |
893 LoadAndExpectError("filebrowser_invalid_actions_1.json", | 892 LoadAndExpectError("filebrowser_invalid_actions_1.json", |
894 errors::kInvalidFileBrowserHandler); | 893 errors::kInvalidFileBrowserHandler); |
895 LoadAndExpectError("filebrowser_invalid_actions_2.json", | 894 LoadAndExpectError("filebrowser_invalid_actions_2.json", |
896 errors::kInvalidFileBrowserHandler); | 895 errors::kInvalidFileBrowserHandler); |
897 LoadAndExpectError("filebrowser_invalid_action_id.json", | 896 LoadAndExpectError("filebrowser_invalid_action_id.json", |
898 errors::kInvalidPageActionId); | 897 errors::kInvalidPageActionId); |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
955 scoped_refptr<Extension> extension_2( | 954 scoped_refptr<Extension> extension_2( |
956 LoadAndExpectSuccess("offline_disabled_packaged_app.json")); | 955 LoadAndExpectSuccess("offline_disabled_packaged_app.json")); |
957 EXPECT_FALSE(extension_2->offline_enabled()); | 956 EXPECT_FALSE(extension_2->offline_enabled()); |
958 scoped_refptr<Extension> extension_3( | 957 scoped_refptr<Extension> extension_3( |
959 LoadAndExpectSuccess("offline_default_packaged_app.json")); | 958 LoadAndExpectSuccess("offline_default_packaged_app.json")); |
960 EXPECT_FALSE(extension_3->offline_enabled()); | 959 EXPECT_FALSE(extension_3->offline_enabled()); |
961 scoped_refptr<Extension> extension_4( | 960 scoped_refptr<Extension> extension_4( |
962 LoadAndExpectSuccess("offline_enabled_hosted_app.json")); | 961 LoadAndExpectSuccess("offline_enabled_hosted_app.json")); |
963 EXPECT_TRUE(extension_4->offline_enabled()); | 962 EXPECT_TRUE(extension_4->offline_enabled()); |
964 } | 963 } |
OLD | NEW |