| 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 |
| (...skipping 278 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 289 errors::kInvalidUpdateURL); | 289 errors::kInvalidUpdateURL); |
| 290 LoadAndExpectErrorStrict("update_url_invalid_3.json", | 290 LoadAndExpectErrorStrict("update_url_invalid_3.json", |
| 291 errors::kInvalidUpdateURL); | 291 errors::kInvalidUpdateURL); |
| 292 } | 292 } |
| 293 | 293 |
| 294 // Tests that the old permission name "unlimited_storage" still works for | 294 // Tests that the old permission name "unlimited_storage" still works for |
| 295 // backwards compatibility (we renamed it to "unlimitedStorage"). | 295 // backwards compatibility (we renamed it to "unlimitedStorage"). |
| 296 TEST_F(ExtensionManifestTest, OldUnlimitedStoragePermission) { | 296 TEST_F(ExtensionManifestTest, OldUnlimitedStoragePermission) { |
| 297 scoped_refptr<Extension> extension = LoadStrictAndExpectSuccess( | 297 scoped_refptr<Extension> extension = LoadStrictAndExpectSuccess( |
| 298 "old_unlimited_storage.json"); | 298 "old_unlimited_storage.json"); |
| 299 EXPECT_TRUE(extension->HasApiPermission( | 299 EXPECT_TRUE(extension->HasAPIPermission( |
| 300 Extension::kUnlimitedStoragePermission)); | 300 ExtensionAPIPermission::kUnlimitedStorage)); |
| 301 } | 301 } |
| 302 | 302 |
| 303 TEST_F(ExtensionManifestTest, ValidApp) { | 303 TEST_F(ExtensionManifestTest, ValidApp) { |
| 304 scoped_refptr<Extension> extension(LoadAndExpectSuccess("valid_app.json")); | 304 scoped_refptr<Extension> extension(LoadAndExpectSuccess("valid_app.json")); |
| 305 ASSERT_EQ(2u, extension->web_extent().patterns().size()); | 305 ASSERT_EQ(2u, extension->web_extent().patterns().size()); |
| 306 EXPECT_EQ("http://www.google.com/mail/*", | 306 EXPECT_EQ("http://www.google.com/mail/*", |
| 307 extension->web_extent().patterns()[0].GetAsString()); | 307 extension->web_extent().patterns()[0].GetAsString()); |
| 308 EXPECT_EQ("http://www.google.com/foobar/*", | 308 EXPECT_EQ("http://www.google.com/foobar/*", |
| 309 extension->web_extent().patterns()[1].GetAsString()); | 309 extension->web_extent().patterns()[1].GetAsString()); |
| 310 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); | 310 EXPECT_EQ(extension_misc::LAUNCH_TAB, extension->launch_container()); |
| (...skipping 302 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 613 | 613 |
| 614 TEST_F(ExtensionManifestTest, AllowUnrecognizedPermissions) { | 614 TEST_F(ExtensionManifestTest, AllowUnrecognizedPermissions) { |
| 615 std::string error; | 615 std::string error; |
| 616 scoped_ptr<DictionaryValue> manifest( | 616 scoped_ptr<DictionaryValue> manifest( |
| 617 LoadManifestFile("valid_app.json", &error)); | 617 LoadManifestFile("valid_app.json", &error)); |
| 618 ASSERT_TRUE(manifest.get()); | 618 ASSERT_TRUE(manifest.get()); |
| 619 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); | 619 CommandLine old_command_line = *CommandLine::ForCurrentProcess(); |
| 620 | 620 |
| 621 ListValue *permissions = new ListValue(); | 621 ListValue *permissions = new ListValue(); |
| 622 manifest->Set(keys::kPermissions, permissions); | 622 manifest->Set(keys::kPermissions, permissions); |
| 623 for (size_t i = 0; i < Extension::kNumPermissions; i++) { | 623 ExtensionPermissionsInfo* info = ExtensionPermissionsInfo::GetInstance(); |
| 624 const char* name = Extension::kPermissions[i].name; | 624 ExtensionAPIPermissionSet api_perms = info->GetAll(); |
| 625 for (ExtensionAPIPermissionSet::iterator i = api_perms.begin(); |
| 626 i != api_perms.end(); ++i) { |
| 627 ExtensionAPIPermission* permission = info->GetByID(*i); |
| 628 const char* name = permission->name(); |
| 625 StringValue* p = new StringValue(name); | 629 StringValue* p = new StringValue(name); |
| 626 permissions->Clear(); | 630 permissions->Clear(); |
| 627 permissions->Append(p); | 631 permissions->Append(p); |
| 628 std::string message_name = base::StringPrintf("permission-%s", name); | 632 std::string message_name = base::StringPrintf("permission-%s", name); |
| 629 | 633 |
| 630 if (name == Extension::kExperimentalPermission) { | 634 if (*i == ExtensionAPIPermission::kExperimental) { |
| 631 // Experimental permission is allowed, but requires this switch. | 635 // Experimental permission is allowed, but requires this switch. |
| 632 CommandLine::ForCurrentProcess()->AppendSwitch( | 636 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 633 switches::kEnableExperimentalExtensionApis); | 637 switches::kEnableExperimentalExtensionApis); |
| 634 } | 638 } |
| 635 | 639 |
| 636 // Extensions are allowed to contain unrecognized API permissions, | 640 // Extensions are allowed to contain unrecognized API permissions, |
| 637 // so there shouldn't be any errors. | 641 // so there shouldn't be any errors. |
| 638 scoped_refptr<Extension> extension; | 642 scoped_refptr<Extension> extension; |
| 639 extension = LoadAndExpectSuccess(manifest.get(), message_name); | 643 extension = LoadAndExpectSuccess(manifest.get(), message_name); |
| 640 } | 644 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); | 783 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); |
| 780 const FileBrowserHandler* action = | 784 const FileBrowserHandler* action = |
| 781 extension->file_browser_handlers()->at(0).get(); | 785 extension->file_browser_handlers()->at(0).get(); |
| 782 EXPECT_EQ(action->title(), "Default title"); | 786 EXPECT_EQ(action->title(), "Default title"); |
| 783 EXPECT_EQ(action->icon_path(), "icon.png"); | 787 EXPECT_EQ(action->icon_path(), "icon.png"); |
| 784 const URLPatternList& patterns = action->file_url_patterns(); | 788 const URLPatternList& patterns = action->file_url_patterns(); |
| 785 ASSERT_EQ(patterns.size(), 1U); | 789 ASSERT_EQ(patterns.size(), 1U); |
| 786 ASSERT_TRUE(action->MatchesURL( | 790 ASSERT_TRUE(action->MatchesURL( |
| 787 GURL("filesystem:chrome-extension://foo/local/test.txt"))); | 791 GURL("filesystem:chrome-extension://foo/local/test.txt"))); |
| 788 } | 792 } |
| OLD | NEW |