| 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" | 11 #include "base/command_line.h" |
| 12 #include "base/file_path.h" | 12 #include "base/file_path.h" |
| 13 #include "base/file_util.h" | 13 #include "base/file_util.h" |
| 14 #include "base/i18n/rtl.h" | 14 #include "base/i18n/rtl.h" |
| 15 #include "base/json/json_value_serializer.h" | 15 #include "base/json/json_value_serializer.h" |
| 16 #include "base/memory/scoped_ptr.h" | 16 #include "base/memory/scoped_ptr.h" |
| 17 #include "base/path_service.h" | 17 #include "base/path_service.h" |
| 18 #include "base/string_number_conversions.h" | 18 #include "base/string_number_conversions.h" |
| 19 #include "base/string_util.h" | 19 #include "base/string_util.h" |
| 20 #include "base/stringprintf.h" | 20 #include "base/stringprintf.h" |
| 21 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
| 22 #include "chrome/common/chrome_paths.h" | 22 #include "chrome/common/chrome_paths.h" |
| 23 #include "chrome/common/chrome_switches.h" | 23 #include "chrome/common/chrome_switches.h" |
| 24 #include "chrome/common/extensions/extension.h" | 24 #include "chrome/common/extensions/extension.h" |
| 25 #include "chrome/common/extensions/extension_constants.h" | 25 #include "chrome/common/extensions/extension_constants.h" |
| 26 #include "chrome/common/extensions/extension_error_utils.h" | 26 #include "chrome/common/extensions/extension_error_utils.h" |
| 27 #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" |
| 30 #include "testing/gtest/include/gtest/gtest.h" | 29 #include "testing/gtest/include/gtest/gtest.h" |
| 31 #include "ui/base/l10n/l10n_util.h" | 30 #include "ui/base/l10n/l10n_util.h" |
| 32 #include "webkit/glue/web_intent_service_data.h" | 31 #include "webkit/glue/web_intent_service_data.h" |
| 33 | 32 |
| 34 namespace { | 33 namespace { |
| 35 | 34 |
| 36 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { | 35 static void AddPattern(URLPatternSet* extent, const std::string& pattern) { |
| 37 int schemes = URLPattern::SCHEME_ALL; | 36 int schemes = URLPattern::SCHEME_ALL; |
| (...skipping 491 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 529 | 528 |
| 530 CommandLine::ForCurrentProcess()->AppendSwitch( | 529 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 531 switches::kEnableExperimentalExtensionApis); | 530 switches::kEnableExperimentalExtensionApis); |
| 532 scoped_refptr<Extension> extension; | 531 scoped_refptr<Extension> extension; |
| 533 extension = LoadAndExpectSuccess("devtools_extension.json"); | 532 extension = LoadAndExpectSuccess("devtools_extension.json"); |
| 534 EXPECT_EQ(extension->url().spec() + "devtools.html", | 533 EXPECT_EQ(extension->url().spec() + "devtools.html", |
| 535 extension->devtools_url().spec()); | 534 extension->devtools_url().spec()); |
| 536 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); | 535 EXPECT_TRUE(extension->HasEffectiveAccessToAllHosts()); |
| 537 } | 536 } |
| 538 | 537 |
| 539 TEST_F(ExtensionManifestTest, Sidebar) { | |
| 540 LoadAndExpectError("sidebar.json", | |
| 541 errors::kExperimentalFlagRequired); | |
| 542 | |
| 543 CommandLine::ForCurrentProcess()->AppendSwitch( | |
| 544 switches::kEnableExperimentalExtensionApis); | |
| 545 | |
| 546 LoadAndExpectError("sidebar_no_permissions.json", | |
| 547 errors::kSidebarExperimental); | |
| 548 | |
| 549 LoadAndExpectError("sidebar_icon_empty.json", | |
| 550 errors::kInvalidSidebarDefaultIconPath); | |
| 551 LoadAndExpectError("sidebar_icon_invalid_type.json", | |
| 552 errors::kInvalidSidebarDefaultIconPath); | |
| 553 LoadAndExpectError("sidebar_page_empty.json", | |
| 554 errors::kInvalidSidebarDefaultPage); | |
| 555 LoadAndExpectError("sidebar_page_invalid_type.json", | |
| 556 errors::kInvalidSidebarDefaultPage); | |
| 557 LoadAndExpectError("sidebar_title_invalid_type.json", | |
| 558 errors::kInvalidSidebarDefaultTitle); | |
| 559 | |
| 560 scoped_refptr<Extension> extension(LoadAndExpectSuccess("sidebar.json")); | |
| 561 ASSERT_TRUE(extension->sidebar_defaults() != NULL); | |
| 562 EXPECT_EQ(extension->sidebar_defaults()->default_title(), | |
| 563 ASCIIToUTF16("Default title")); | |
| 564 EXPECT_EQ(extension->sidebar_defaults()->default_icon_path(), | |
| 565 "icon.png"); | |
| 566 EXPECT_EQ(extension->url().spec() + "sidebar.html", | |
| 567 extension->sidebar_defaults()->default_page().spec()); | |
| 568 } | |
| 569 | |
| 570 TEST_F(ExtensionManifestTest, BackgroundPermission) { | 538 TEST_F(ExtensionManifestTest, BackgroundPermission) { |
| 571 LoadAndExpectError("background_permission.json", | 539 LoadAndExpectError("background_permission.json", |
| 572 errors::kBackgroundPermissionNeeded); | 540 errors::kBackgroundPermissionNeeded); |
| 573 } | 541 } |
| 574 | 542 |
| 575 TEST_F(ExtensionManifestTest, OptionsPageInApps) { | 543 TEST_F(ExtensionManifestTest, OptionsPageInApps) { |
| 576 scoped_refptr<Extension> extension; | 544 scoped_refptr<Extension> extension; |
| 577 | 545 |
| 578 // Allow options page with absolute URL in hosted apps. | 546 // Allow options page with absolute URL in hosted apps. |
| 579 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); | 547 extension = LoadAndExpectSuccess("hosted_app_absolute_options.json"); |
| (...skipping 380 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 960 // This guy is identical to the previous but doesn't ask for any | 928 // This guy is identical to the previous but doesn't ask for any |
| 961 // platform-app-only permissions. We should be able to load him and ask | 929 // platform-app-only permissions. We should be able to load him and ask |
| 962 // questions about his permissions. | 930 // questions about his permissions. |
| 963 scoped_refptr<Extension> extension( | 931 scoped_refptr<Extension> extension( |
| 964 LoadAndExpectSuccess("not_platform_app.json")); | 932 LoadAndExpectSuccess("not_platform_app.json")); |
| 965 ExtensionAPIPermissionSet apis = extension->GetActivePermissions()->apis(); | 933 ExtensionAPIPermissionSet apis = extension->GetActivePermissions()->apis(); |
| 966 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin(); | 934 for (ExtensionAPIPermissionSet::const_iterator i = apis.begin(); |
| 967 i != apis.end(); ++i) | 935 i != apis.end(); ++i) |
| 968 EXPECT_NE(platform_app, info->GetByID(*i)->type_restrictions()); | 936 EXPECT_NE(platform_app, info->GetByID(*i)->type_restrictions()); |
| 969 } | 937 } |
| OLD | NEW |