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

Side by Side Diff: chrome/common/extensions/extension_manifests_unittest.cc

Issue 8561031: Replace ScopedCommandLineOverride with TestSuite listener. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Simplify per Pawel's suggestions. Created 9 years, 1 month 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 | Annotate | Revision Log
OLDNEW
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"
11 #include "base/file_path.h" 12 #include "base/file_path.h"
12 #include "base/file_util.h" 13 #include "base/file_util.h"
13 #include "base/i18n/rtl.h" 14 #include "base/i18n/rtl.h"
14 #include "base/json/json_value_serializer.h" 15 #include "base/json/json_value_serializer.h"
15 #include "base/memory/scoped_ptr.h" 16 #include "base/memory/scoped_ptr.h"
16 #include "base/path_service.h" 17 #include "base/path_service.h"
17 #include "base/string_number_conversions.h" 18 #include "base/string_number_conversions.h"
18 #include "base/string_util.h" 19 #include "base/string_util.h"
19 #include "base/stringprintf.h" 20 #include "base/stringprintf.h"
20 #include "base/utf_string_conversions.h" 21 #include "base/utf_string_conversions.h"
21 #include "chrome/common/chrome_paths.h" 22 #include "chrome/common/chrome_paths.h"
22 #include "chrome/common/chrome_switches.h" 23 #include "chrome/common/chrome_switches.h"
23 #include "chrome/common/extensions/extension.h" 24 #include "chrome/common/extensions/extension.h"
24 #include "chrome/common/extensions/extension_constants.h" 25 #include "chrome/common/extensions/extension_constants.h"
25 #include "chrome/common/extensions/extension_error_utils.h" 26 #include "chrome/common/extensions/extension_error_utils.h"
26 #include "chrome/common/extensions/extension_sidebar_defaults.h" 27 #include "chrome/common/extensions/extension_sidebar_defaults.h"
27 #include "chrome/common/extensions/file_browser_handler.h" 28 #include "chrome/common/extensions/file_browser_handler.h"
28 #include "chrome/common/extensions/url_pattern.h" 29 #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 330 matching lines...) Expand 10 before | Expand all | Expand 10 after
370 370
371 scoped_refptr<Extension> extension( 371 scoped_refptr<Extension> extension(
372 LoadAndExpectSuccess("web_urls_default.json")); 372 LoadAndExpectSuccess("web_urls_default.json"));
373 ASSERT_EQ(1u, extension->web_extent().patterns().size()); 373 ASSERT_EQ(1u, extension->web_extent().patterns().size());
374 EXPECT_EQ("*://www.google.com/*", 374 EXPECT_EQ("*://www.google.com/*",
375 extension->web_extent().patterns().begin()->GetAsString()); 375 extension->web_extent().patterns().begin()->GetAsString());
376 } 376 }
377 377
378 TEST_F(ExtensionManifestTest, AppLaunchContainer) { 378 TEST_F(ExtensionManifestTest, AppLaunchContainer) {
379 scoped_refptr<Extension> extension; 379 scoped_refptr<Extension> extension;
380 CommandLine::ForCurrentProcess()->AppendSwitch(
381 switches::kEnablePlatformApps);
380 382
381 extension = LoadAndExpectSuccess("launch_tab.json"); 383 extension = LoadAndExpectSuccess("launch_tab.json");
382 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); 384 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container());
383 385
384 extension = LoadAndExpectSuccess("launch_panel.json"); 386 extension = LoadAndExpectSuccess("launch_panel.json");
385 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container()); 387 EXPECT_EQ(extension_misc::LAUNCH_PANEL, extension->launch_container());
386 388
387 extension = LoadAndExpectSuccess("launch_default.json"); 389 extension = LoadAndExpectSuccess("launch_default.json");
388 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); 390 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container());
389 391
390 extension = LoadAndExpectSuccess("launch_width.json"); 392 extension = LoadAndExpectSuccess("launch_width.json");
391 EXPECT_EQ(640, extension->launch_width()); 393 EXPECT_EQ(640, extension->launch_width());
392 394
393 extension = LoadAndExpectSuccess("launch_height.json"); 395 extension = LoadAndExpectSuccess("launch_height.json");
394 EXPECT_EQ(480, extension->launch_height()); 396 EXPECT_EQ(480, extension->launch_height());
395 397
396 LoadAndExpectError("launch_window.json", 398 LoadAndExpectError("launch_window.json",
397 errors::kInvalidLaunchContainer); 399 errors::kInvalidLaunchContainer);
398 LoadAndExpectError("launch_container_invalid_type.json", 400 LoadAndExpectError("launch_container_invalid_type.json",
399 errors::kInvalidLaunchContainer); 401 errors::kInvalidLaunchContainer);
400 { 402 LoadAndExpectError("launch_container_invalid_type_for_platform.json",
401 ScopedCommandLineOverride override(switches::kEnablePlatformApps); 403 errors::kInvalidLaunchContainerForPlatform);
402 LoadAndExpectError("launch_container_invalid_type_for_platform.json",
403 errors::kInvalidLaunchContainerForPlatform);
404 }
405 LoadAndExpectError("launch_container_invalid_value.json", 404 LoadAndExpectError("launch_container_invalid_value.json",
406 errors::kInvalidLaunchContainer); 405 errors::kInvalidLaunchContainer);
407 LoadAndExpectError("launch_container_without_launch_url.json", 406 LoadAndExpectError("launch_container_without_launch_url.json",
408 errors::kLaunchURLRequired); 407 errors::kLaunchURLRequired);
409 LoadAndExpectError("launch_width_invalid.json", 408 LoadAndExpectError("launch_width_invalid.json",
410 errors::kInvalidLaunchWidthContainer); 409 errors::kInvalidLaunchWidthContainer);
411 LoadAndExpectError("launch_width_negative.json", 410 LoadAndExpectError("launch_width_negative.json",
412 errors::kInvalidLaunchWidth); 411 errors::kInvalidLaunchWidth);
413 LoadAndExpectError("launch_height_invalid.json", 412 LoadAndExpectError("launch_height_invalid.json",
414 errors::kInvalidLaunchHeightContainer); 413 errors::kInvalidLaunchHeightContainer);
(...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after
529 "Invalid value for " 528 "Invalid value for "
530 "'content_scripts[0].exclude_matches[0]': " 529 "'content_scripts[0].exclude_matches[0]': "
531 "Invalid host wildcard."); 530 "Invalid host wildcard.");
532 } 531 }
533 532
534 TEST_F(ExtensionManifestTest, ExperimentalPermission) { 533 TEST_F(ExtensionManifestTest, ExperimentalPermission) {
535 LoadAndExpectError("experimental.json", errors::kExperimentalFlagRequired); 534 LoadAndExpectError("experimental.json", errors::kExperimentalFlagRequired);
536 LoadAndExpectSuccess("experimental.json", Extension::COMPONENT); 535 LoadAndExpectSuccess("experimental.json", Extension::COMPONENT);
537 LoadAndExpectSuccess("experimental.json", Extension::INTERNAL, 536 LoadAndExpectSuccess("experimental.json", Extension::INTERNAL,
538 Extension::FROM_WEBSTORE); 537 Extension::FROM_WEBSTORE);
539 ScopedCommandLineOverride override( 538 CommandLine::ForCurrentProcess()->AppendSwitch(
540 switches::kEnableExperimentalExtensionApis); 539 switches::kEnableExperimentalExtensionApis);
541 LoadAndExpectSuccess("experimental.json"); 540 LoadAndExpectSuccess("experimental.json");
542 } 541 }
543 542
544 TEST_F(ExtensionManifestTest, DevToolsExtensions) { 543 TEST_F(ExtensionManifestTest, DevToolsExtensions) {
545 LoadAndExpectError("devtools_extension_no_permissions.json", 544 LoadAndExpectError("devtools_extension_no_permissions.json",
546 errors::kDevToolsExperimental); 545 errors::kDevToolsExperimental);
547 LoadAndExpectError("devtools_extension_url_invalid_type.json", 546 LoadAndExpectError("devtools_extension_url_invalid_type.json",
548 errors::kInvalidDevToolsPage); 547 errors::kInvalidDevToolsPage);
549 548
550 ScopedCommandLineOverride override( 549 CommandLine::ForCurrentProcess()->AppendSwitch(
551 switches::kEnableExperimentalExtensionApis); 550 switches::kEnableExperimentalExtensionApis);
552 scoped_refptr<Extension> extension; 551 scoped_refptr<Extension> extension;
553 extension = LoadAndExpectSuccess("devtools_extension.json"); 552 extension = LoadAndExpectSuccess("devtools_extension.json");
554 EXPECT_EQ(extension->url().spec() + "devtools.html", 553 EXPECT_EQ(extension->url().spec() + "devtools.html",
555 extension->devtools_url().spec()); 554 extension->devtools_url().spec());
556 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); 555 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts());
557 } 556 }
558 557
559 TEST_F(ExtensionManifestTest, Sidebar) { 558 TEST_F(ExtensionManifestTest, Sidebar) {
560 LoadAndExpectError("sidebar.json", 559 LoadAndExpectError("sidebar.json",
561 errors::kExperimentalFlagRequired); 560 errors::kExperimentalFlagRequired);
562 561
563 ScopedCommandLineOverride override( 562 CommandLine::ForCurrentProcess()->AppendSwitch(
564 switches::kEnableExperimentalExtensionApis); 563 switches::kEnableExperimentalExtensionApis);
565 564
566 LoadAndExpectError("sidebar_no_permissions.json", 565 LoadAndExpectError("sidebar_no_permissions.json",
567 errors::kSidebarExperimental); 566 errors::kSidebarExperimental);
568 567
569 LoadAndExpectError("sidebar_icon_empty.json", 568 LoadAndExpectError("sidebar_icon_empty.json",
570 errors::kInvalidSidebarDefaultIconPath); 569 errors::kInvalidSidebarDefaultIconPath);
571 LoadAndExpectError("sidebar_icon_invalid_type.json", 570 LoadAndExpectError("sidebar_icon_invalid_type.json",
572 errors::kInvalidSidebarDefaultIconPath); 571 errors::kInvalidSidebarDefaultIconPath);
573 LoadAndExpectError("sidebar_page_empty.json", 572 LoadAndExpectError("sidebar_page_empty.json",
(...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after
810 LoadAndExpectSuccess("tts_engine_valid.json")); 809 LoadAndExpectSuccess("tts_engine_valid.json"));
811 810
812 ASSERT_EQ(1u, extension->tts_voices().size()); 811 ASSERT_EQ(1u, extension->tts_voices().size());
813 EXPECT_EQ("name", extension->tts_voices()[0].voice_name); 812 EXPECT_EQ("name", extension->tts_voices()[0].voice_name);
814 EXPECT_EQ("en-US", extension->tts_voices()[0].lang); 813 EXPECT_EQ("en-US", extension->tts_voices()[0].lang);
815 EXPECT_EQ("female", extension->tts_voices()[0].gender); 814 EXPECT_EQ("female", extension->tts_voices()[0].gender);
816 EXPECT_EQ(3U, extension->tts_voices()[0].event_types.size()); 815 EXPECT_EQ(3U, extension->tts_voices()[0].event_types.size());
817 } 816 }
818 817
819 TEST_F(ExtensionManifestTest, WebIntents) { 818 TEST_F(ExtensionManifestTest, WebIntents) {
820 ScopedCommandLineOverride override("--enable-web-intents"); 819 CommandLine::ForCurrentProcess()->AppendSwitch("--enable-web-intents");
821 820
822 LoadAndExpectError("intent_invalid_1.json", 821 LoadAndExpectError("intent_invalid_1.json",
823 extension_manifest_errors::kInvalidIntents); 822 extension_manifest_errors::kInvalidIntents);
824 LoadAndExpectError("intent_invalid_2.json", 823 LoadAndExpectError("intent_invalid_2.json",
825 extension_manifest_errors::kInvalidIntent); 824 extension_manifest_errors::kInvalidIntent);
826 LoadAndExpectError("intent_invalid_3.json", 825 LoadAndExpectError("intent_invalid_3.json",
827 extension_manifest_errors::kInvalidIntentPath); 826 extension_manifest_errors::kInvalidIntentPath);
828 LoadAndExpectError("intent_invalid_4.json", 827 LoadAndExpectError("intent_invalid_4.json",
829 extension_manifest_errors::kInvalidIntentDisposition); 828 extension_manifest_errors::kInvalidIntentDisposition);
830 LoadAndExpectError("intent_invalid_5.json", 829 LoadAndExpectError("intent_invalid_5.json",
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
873 // to flag this case. 872 // to flag this case.
874 LoadAndExpectSuccess("forbid_ports_in_permissions.json", 873 LoadAndExpectSuccess("forbid_ports_in_permissions.json",
875 Extension::INTERNAL, Extension::STRICT_ERROR_CHECKS); 874 Extension::INTERNAL, Extension::STRICT_ERROR_CHECKS);
876 } 875 }
877 876
878 TEST_F(ExtensionManifestTest, IsolatedApps) { 877 TEST_F(ExtensionManifestTest, IsolatedApps) {
879 // Requires --enable-experimental-extension-apis 878 // Requires --enable-experimental-extension-apis
880 LoadAndExpectError("isolated_app_valid.json", 879 LoadAndExpectError("isolated_app_valid.json",
881 errors::kExperimentalFlagRequired); 880 errors::kExperimentalFlagRequired);
882 881
883 ScopedCommandLineOverride override( 882 CommandLine::ForCurrentProcess()->AppendSwitch(
884 switches::kEnableExperimentalExtensionApis); 883 switches::kEnableExperimentalExtensionApis);
885 scoped_refptr<Extension> extension2( 884 scoped_refptr<Extension> extension2(
886 LoadAndExpectSuccess("isolated_app_valid.json")); 885 LoadAndExpectSuccess("isolated_app_valid.json"));
887 EXPECT_TRUE(extension2->is_storage_isolated()); 886 EXPECT_TRUE(extension2->is_storage_isolated());
888 } 887 }
889 888
890 889
891 TEST_F(ExtensionManifestTest, FileBrowserHandlers) { 890 TEST_F(ExtensionManifestTest, FileBrowserHandlers) {
892 LoadAndExpectError("filebrowser_invalid_actions_1.json", 891 LoadAndExpectError("filebrowser_invalid_actions_1.json",
893 errors::kInvalidFileBrowserHandler); 892 errors::kInvalidFileBrowserHandler);
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after
954 scoped_refptr<Extension> extension_2( 953 scoped_refptr<Extension> extension_2(
955 LoadAndExpectSuccess("offline_disabled_packaged_app.json")); 954 LoadAndExpectSuccess("offline_disabled_packaged_app.json"));
956 EXPECT_FALSE(extension_2->offline_enabled()); 955 EXPECT_FALSE(extension_2->offline_enabled());
957 scoped_refptr<Extension> extension_3( 956 scoped_refptr<Extension> extension_3(
958 LoadAndExpectSuccess("offline_default_packaged_app.json")); 957 LoadAndExpectSuccess("offline_default_packaged_app.json"));
959 EXPECT_FALSE(extension_3->offline_enabled()); 958 EXPECT_FALSE(extension_3->offline_enabled());
960 scoped_refptr<Extension> extension_4( 959 scoped_refptr<Extension> extension_4(
961 LoadAndExpectSuccess("offline_enabled_hosted_app.json")); 960 LoadAndExpectSuccess("offline_enabled_hosted_app.json"));
962 EXPECT_TRUE(extension_4->offline_enabled()); 961 EXPECT_TRUE(extension_4->offline_enabled());
963 } 962 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698