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

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

Issue 11588004: Move ScriptBadge, ActionInfo out of Extension; preparation for BrowserAction (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Latest master for CQ Created 7 years, 11 months 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
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 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 #include "base/file_path.h" 7 #include "base/file_path.h"
8 #include "base/file_util.h" 8 #include "base/file_util.h"
9 #include "base/format_macros.h" 9 #include "base/format_macros.h"
10 #include "base/json/json_file_value_serializer.h" 10 #include "base/json/json_file_value_serializer.h"
11 #include "base/path_service.h" 11 #include "base/path_service.h"
12 #include "base/string_number_conversions.h" 12 #include "base/string_number_conversions.h"
13 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
14 #include "base/utf_string_conversions.h" 14 #include "base/utf_string_conversions.h"
15 #include "chrome/common/chrome_paths.h" 15 #include "chrome/common/chrome_paths.h"
16 #include "chrome/common/extensions/api/extension_action/action_info.h"
16 #include "chrome/common/extensions/command.h" 17 #include "chrome/common/extensions/command.h"
17 #include "chrome/common/extensions/extension_file_util.h" 18 #include "chrome/common/extensions/extension_file_util.h"
18 #include "chrome/common/extensions/extension_manifest_constants.h" 19 #include "chrome/common/extensions/extension_manifest_constants.h"
19 #include "chrome/common/extensions/extension_resource.h" 20 #include "chrome/common/extensions/extension_resource.h"
20 #include "chrome/common/extensions/features/feature.h" 21 #include "chrome/common/extensions/features/feature.h"
21 #include "chrome/common/extensions/permissions/api_permission.h" 22 #include "chrome/common/extensions/permissions/api_permission.h"
22 #include "chrome/common/extensions/permissions/permission_set.h" 23 #include "chrome/common/extensions/permissions/permission_set.h"
23 #include "chrome/common/extensions/permissions/socket_permission.h" 24 #include "chrome/common/extensions/permissions/socket_permission.h"
24 #include "chrome/common/extensions/permissions/usb_device_permission.h" 25 #include "chrome/common/extensions/permissions/usb_device_permission.h"
25 #include "chrome/common/url_constants.h" 26 #include "chrome/common/url_constants.h"
26 #include "extensions/common/error_utils.h" 27 #include "extensions/common/error_utils.h"
27 #include "googleurl/src/gurl.h" 28 #include "googleurl/src/gurl.h"
28 #include "net/base/mime_sniffer.h" 29 #include "net/base/mime_sniffer.h"
29 #include "net/base/mock_host_resolver.h" 30 #include "net/base/mock_host_resolver.h"
30 #include "skia/ext/image_operations.h" 31 #include "skia/ext/image_operations.h"
31 #include "testing/gtest/include/gtest/gtest.h" 32 #include "testing/gtest/include/gtest/gtest.h"
32 #include "third_party/skia/include/core/SkBitmap.h" 33 #include "third_party/skia/include/core/SkBitmap.h"
33 #include "ui/gfx/codec/png_codec.h" 34 #include "ui/gfx/codec/png_codec.h"
34 35
35 using content::SocketPermissionRequest; 36 using content::SocketPermissionRequest;
36 using extensions::APIPermission;
37 using extensions::APIPermissionSet;
38 using extensions::ErrorUtils;
39 using extensions::Extension;
40 using extensions::Feature;
41 using extensions::PermissionSet;
42 using extensions::SocketPermission;
43 using extensions::URLPatternSet;
44 using extensions::UsbDevicePermission;
45 37
46 namespace keys = extension_manifest_keys; 38 namespace keys = extension_manifest_keys;
47 namespace values = extension_manifest_values; 39 namespace values = extension_manifest_values;
48 namespace errors = extension_manifest_errors; 40 namespace errors = extension_manifest_errors;
49 41
42 namespace extensions {
50 namespace { 43 namespace {
51 44
52 scoped_refptr<Extension> LoadManifestUnchecked( 45 scoped_refptr<Extension> LoadManifestUnchecked(
53 const std::string& dir, 46 const std::string& dir,
54 const std::string& test_file, 47 const std::string& test_file,
55 Extension::Location location, 48 Extension::Location location,
56 int extra_flags, 49 int extra_flags,
57 std::string* error) { 50 std::string* error) {
58 FilePath path; 51 FilePath path;
59 PathService::Get(chrome::DIR_TEST_DATA, &path); 52 PathService::Get(chrome::DIR_TEST_DATA, &path);
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
94 const std::string& test_file) { 87 const std::string& test_file) {
95 return LoadManifest(dir, test_file, Extension::NO_FLAGS); 88 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
96 } 89 }
97 90
98 static scoped_refptr<Extension> LoadManifestStrict( 91 static scoped_refptr<Extension> LoadManifestStrict(
99 const std::string& dir, 92 const std::string& dir,
100 const std::string& test_file) { 93 const std::string& test_file) {
101 return LoadManifest(dir, test_file, Extension::NO_FLAGS); 94 return LoadManifest(dir, test_file, Extension::NO_FLAGS);
102 } 95 }
103 96
104 static scoped_ptr<Extension::ActionInfo> LoadAction( 97 static scoped_ptr<ActionInfo> LoadAction(
105 const std::string& manifest) { 98 const std::string& manifest) {
106 scoped_refptr<Extension> extension = LoadManifest("page_action", 99 scoped_refptr<Extension> extension = LoadManifest("page_action",
107 manifest); 100 manifest);
108 EXPECT_TRUE(extension->page_action_info()); 101 EXPECT_TRUE(extension->page_action_info());
109 if (extension->page_action_info()) { 102 if (extension->page_action_info()) {
110 return make_scoped_ptr(new Extension::ActionInfo( 103 return make_scoped_ptr(new ActionInfo(
111 *extension->page_action_info())); 104 *extension->page_action_info()));
112 } 105 }
113 ADD_FAILURE() << "Expected manifest in " << manifest 106 ADD_FAILURE() << "Expected manifest in " << manifest
114 << " to include a page_action section."; 107 << " to include a page_action section.";
115 return scoped_ptr<Extension::ActionInfo>(); 108 return scoped_ptr<ActionInfo>();
116 } 109 }
117 110
118 static void LoadActionAndExpectError(const std::string& manifest, 111 static void LoadActionAndExpectError(const std::string& manifest,
119 const std::string& expected_error) { 112 const std::string& expected_error) {
120 std::string error; 113 std::string error;
121 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action", 114 scoped_refptr<Extension> extension = LoadManifestUnchecked("page_action",
122 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error); 115 manifest, Extension::INTERNAL, Extension::NO_FLAGS, &error);
123 EXPECT_FALSE(extension); 116 EXPECT_FALSE(extension);
124 EXPECT_EQ(expected_error, error); 117 EXPECT_EQ(expected_error, error);
125 } 118 }
(...skipping 81 matching lines...) Expand 10 before | Expand all | Expand 10 after
207 &err, &warnings)); 200 &err, &warnings));
208 EXPECT_EQ(0U, warnings.size()); 201 EXPECT_EQ(0U, warnings.size());
209 202
210 EXPECT_EQ(extension->path().AppendASCII("test.html").value(), 203 EXPECT_EQ(extension->path().AppendASCII("test.html").value(),
211 extension->GetResource("test.html").GetFilePath().value()); 204 extension->GetResource("test.html").GetFilePath().value());
212 EXPECT_EQ(extension->path().AppendASCII("test.js").value(), 205 EXPECT_EQ(extension->path().AppendASCII("test.js").value(),
213 extension->GetResource("test.js").GetFilePath().value()); 206 extension->GetResource("test.js").GetFilePath().value());
214 } 207 }
215 208
216 TEST(ExtensionTest, LoadPageActionHelper) { 209 TEST(ExtensionTest, LoadPageActionHelper) {
217 scoped_ptr<Extension::ActionInfo> action; 210 scoped_ptr<ActionInfo> action;
218 211
219 // First try with an empty dictionary. 212 // First try with an empty dictionary.
220 action = LoadAction("page_action_empty.json"); 213 action = LoadAction("page_action_empty.json");
221 ASSERT_TRUE(action != NULL); 214 ASSERT_TRUE(action != NULL);
222 215
223 // Now setup some values to use in the action. 216 // Now setup some values to use in the action.
224 const std::string id("MyExtensionActionId"); 217 const std::string id("MyExtensionActionId");
225 const std::string name("MyExtensionActionName"); 218 const std::string name("MyExtensionActionName");
226 std::string img1("image1.png"); 219 std::string img1("image1.png");
227 220
(...skipping 521 matching lines...) Expand 10 before | Expand all | Expand 10 after
749 EXPECT_FALSE(extension->from_webstore()); 742 EXPECT_FALSE(extension->from_webstore());
750 } 743 }
751 744
752 TEST(ExtensionTest, BrowserActionSynthesizesCommand) { 745 TEST(ExtensionTest, BrowserActionSynthesizesCommand) {
753 scoped_refptr<Extension> extension; 746 scoped_refptr<Extension> extension;
754 747
755 extension = LoadManifest("api_test/browser_action/synthesized", 748 extension = LoadManifest("api_test/browser_action/synthesized",
756 "manifest.json"); 749 "manifest.json");
757 // An extension with a browser action but no extension command specified 750 // An extension with a browser action but no extension command specified
758 // should get a command assigned to it. 751 // should get a command assigned to it.
759 const extensions::Command* command = extension->browser_action_command(); 752 const Command* command = extension->browser_action_command();
760 ASSERT_TRUE(command != NULL); 753 ASSERT_TRUE(command != NULL);
761 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code()); 754 ASSERT_EQ(ui::VKEY_UNKNOWN, command->accelerator().key_code());
762 } 755 }
763 756
764 // Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage 757 // Base class for testing the CanExecuteScriptOnPage and CanCaptureVisiblePage
765 // methods of Extension for extensions with various permissions. 758 // methods of Extension for extensions with various permissions.
766 class ExtensionScriptAndCaptureVisibleTest : public testing::Test { 759 class ExtensionScriptAndCaptureVisibleTest : public testing::Test {
767 protected: 760 protected:
768 ExtensionScriptAndCaptureVisibleTest() 761 ExtensionScriptAndCaptureVisibleTest()
769 : http_url("http://www.google.com"), 762 : http_url("http://www.google.com"),
(...skipping 517 matching lines...) Expand 10 before | Expand all | Expand 10 after
1287 1280
1288 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) { 1281 TEST(ExtensionTest, GetSyncTypeExtensionWithTwoPlugins) {
1289 scoped_refptr<Extension> extension( 1282 scoped_refptr<Extension> extension(
1290 MakeSyncTestExtension(EXTENSION, GURL(), GURL(), 1283 MakeSyncTestExtension(EXTENSION, GURL(), GURL(),
1291 Extension::INTERNAL, 2, FilePath(), 1284 Extension::INTERNAL, 2, FilePath(),
1292 Extension::NO_FLAGS)); 1285 Extension::NO_FLAGS));
1293 if (extension) 1286 if (extension)
1294 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE); 1287 EXPECT_EQ(extension->GetSyncType(), Extension::SYNC_TYPE_NONE);
1295 } 1288 }
1296 #endif // !defined(OS_CHROMEOS) 1289 #endif // !defined(OS_CHROMEOS)
1290
1291 } // namespace extensions
OLDNEW
« no previous file with comments | « chrome/common/extensions/extension_file_util.cc ('k') | chrome/common/extensions/manifest_handler_helpers.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698