| 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 279 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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::UnlimitedStorage())); |
| 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 std::set<ExtensionAPIPermission> api_perms = ExtensionAPIPermission::GetAll(); |
| 624 const char* name = Extension::kPermissions[i].name; | 624 for (std::set<ExtensionAPIPermission>::iterator i = api_perms.begin(); |
| 625 i != api_perms.end(); ++i) { |
| 626 const char* name = i->name(); |
| 625 StringValue* p = new StringValue(name); | 627 StringValue* p = new StringValue(name); |
| 626 permissions->Clear(); | 628 permissions->Clear(); |
| 627 permissions->Append(p); | 629 permissions->Append(p); |
| 628 std::string message_name = base::StringPrintf("permission-%s", name); | 630 std::string message_name = base::StringPrintf("permission-%s", name); |
| 629 | 631 |
| 630 if (name == Extension::kExperimentalPermission) { | 632 if (*i == ExtensionAPIPermission::Experimental()) { |
| 631 // Experimental permission is allowed, but requires this switch. | 633 // Experimental permission is allowed, but requires this switch. |
| 632 CommandLine::ForCurrentProcess()->AppendSwitch( | 634 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 633 switches::kEnableExperimentalExtensionApis); | 635 switches::kEnableExperimentalExtensionApis); |
| 634 } | 636 } |
| 635 | 637 |
| 636 // Extensions are allowed to contain unrecognized API permissions, | 638 // Extensions are allowed to contain unrecognized API permissions, |
| 637 // so there shouldn't be any errors. | 639 // so there shouldn't be any errors. |
| 638 scoped_refptr<Extension> extension; | 640 scoped_refptr<Extension> extension; |
| 639 extension = LoadAndExpectSuccess(manifest.get(), message_name); | 641 extension = LoadAndExpectSuccess(manifest.get(), message_name); |
| 640 } | 642 } |
| (...skipping 138 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 779 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); | 781 ASSERT_EQ(extension->file_browser_handlers()->size(), 1U); |
| 780 const FileBrowserHandler* action = | 782 const FileBrowserHandler* action = |
| 781 extension->file_browser_handlers()->at(0).get(); | 783 extension->file_browser_handlers()->at(0).get(); |
| 782 EXPECT_EQ(action->title(), "Default title"); | 784 EXPECT_EQ(action->title(), "Default title"); |
| 783 EXPECT_EQ(action->icon_path(), "icon.png"); | 785 EXPECT_EQ(action->icon_path(), "icon.png"); |
| 784 const URLPatternList& patterns = action->file_url_patterns(); | 786 const URLPatternList& patterns = action->file_url_patterns(); |
| 785 ASSERT_EQ(patterns.size(), 1U); | 787 ASSERT_EQ(patterns.size(), 1U); |
| 786 ASSERT_TRUE(action->MatchesURL( | 788 ASSERT_TRUE(action->MatchesURL( |
| 787 GURL("filesystem:chrome-extension://foo/local/test.txt"))); | 789 GURL("filesystem:chrome-extension://foo/local/test.txt"))); |
| 788 } | 790 } |
| OLD | NEW |