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

Side by Side Diff: chrome/browser/extensions/extension_info_map_unittest.cc

Issue 7024056: Handle extension webrequest API on the IO thread. This speeds up blocking event (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: review Created 9 years, 6 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 | 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 "base/message_loop.h" 5 #include "base/message_loop.h"
6 #include "base/path_service.h" 6 #include "base/path_service.h"
7 #include "chrome/browser/extensions/extension_info_map.h" 7 #include "chrome/browser/extensions/extension_info_map.h"
8 #include "chrome/common/chrome_paths.h" 8 #include "chrome/common/chrome_paths.h"
9 #include "chrome/common/extensions/extension.h" 9 #include "chrome/common/extensions/extension.h"
10 #include "content/browser/browser_thread.h" 10 #include "content/browser/browser_thread.h"
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after
77 77
78 // New extensions should have a single reference holding onto them. 78 // New extensions should have a single reference holding onto them.
79 scoped_refptr<Extension> extension1(CreateExtension("extension1")); 79 scoped_refptr<Extension> extension1(CreateExtension("extension1"));
80 scoped_refptr<Extension> extension2(CreateExtension("extension2")); 80 scoped_refptr<Extension> extension2(CreateExtension("extension2"));
81 scoped_refptr<Extension> extension3(CreateExtension("extension3")); 81 scoped_refptr<Extension> extension3(CreateExtension("extension3"));
82 EXPECT_TRUE(extension1->HasOneRef()); 82 EXPECT_TRUE(extension1->HasOneRef());
83 EXPECT_TRUE(extension2->HasOneRef()); 83 EXPECT_TRUE(extension2->HasOneRef());
84 EXPECT_TRUE(extension3->HasOneRef()); 84 EXPECT_TRUE(extension3->HasOneRef());
85 85
86 // Add a ref to each extension and give it to the info map. 86 // Add a ref to each extension and give it to the info map.
87 info_map->AddExtension(extension1); 87 info_map->AddExtension(extension1, base::Time(), false);
88 info_map->AddExtension(extension2); 88 info_map->AddExtension(extension2, base::Time(), false);
89 info_map->AddExtension(extension3); 89 info_map->AddExtension(extension3, base::Time(), false);
90 90
91 // Release extension1, and the info map should have the only ref. 91 // Release extension1, and the info map should have the only ref.
92 const Extension* weak_extension1 = extension1; 92 const Extension* weak_extension1 = extension1;
93 extension1 = NULL; 93 extension1 = NULL;
94 EXPECT_TRUE(weak_extension1->HasOneRef()); 94 EXPECT_TRUE(weak_extension1->HasOneRef());
95 95
96 // Remove extension2, and the extension2 object should have the only ref. 96 // Remove extension2, and the extension2 object should have the only ref.
97 info_map->RemoveExtension(extension2->id(), UnloadedExtensionInfo::UNINSTALL); 97 info_map->RemoveExtension(extension2->id(), UnloadedExtensionInfo::UNINSTALL);
98 EXPECT_TRUE(extension2->HasOneRef()); 98 EXPECT_TRUE(extension2->HasOneRef());
99 99
100 // Delete the info map, and the extension3 object should have the only ref. 100 // Delete the info map, and the extension3 object should have the only ref.
101 info_map = NULL; 101 info_map = NULL;
102 EXPECT_TRUE(extension3->HasOneRef()); 102 EXPECT_TRUE(extension3->HasOneRef());
103 } 103 }
104 104
105 // Tests that we can query a few extension properties from the ExtensionInfoMap. 105 // Tests that we can query a few extension properties from the ExtensionInfoMap.
106 TEST_F(ExtensionInfoMapTest, Properties) { 106 TEST_F(ExtensionInfoMapTest, Properties) {
107 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 107 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
108 108
109 scoped_refptr<Extension> extension1(CreateExtension("extension1")); 109 scoped_refptr<Extension> extension1(CreateExtension("extension1"));
110 scoped_refptr<Extension> extension2(CreateExtension("extension2")); 110 scoped_refptr<Extension> extension2(CreateExtension("extension2"));
111 111
112 info_map->AddExtension(extension1); 112 info_map->AddExtension(extension1, base::Time(), false);
113 info_map->AddExtension(extension2); 113 info_map->AddExtension(extension2, base::Time(), false);
114 114
115 EXPECT_EQ(2u, info_map->extensions().size()); 115 EXPECT_EQ(2u, info_map->extensions().size());
116 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id())); 116 EXPECT_EQ(extension1.get(), info_map->extensions().GetByID(extension1->id()));
117 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id())); 117 EXPECT_EQ(extension2.get(), info_map->extensions().GetByID(extension2->id()));
118 } 118 }
119 119
120 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs. 120 // Tests CheckURLAccessToExtensionPermission given both extension and app URLs.
121 TEST_F(ExtensionInfoMapTest, CheckPermissions) { 121 TEST_F(ExtensionInfoMapTest, CheckPermissions) {
122 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap()); 122 scoped_refptr<ExtensionInfoMap> info_map(new ExtensionInfoMap());
123 123
124 scoped_refptr<Extension> app(LoadManifest("manifest_tests", 124 scoped_refptr<Extension> app(LoadManifest("manifest_tests",
125 "valid_app.json")); 125 "valid_app.json"));
126 scoped_refptr<Extension> extension(LoadManifest("manifest_tests", 126 scoped_refptr<Extension> extension(LoadManifest("manifest_tests",
127 "tabs_extension.json")); 127 "tabs_extension.json"));
128 128
129 GURL app_url("http://www.google.com/mail/foo.html"); 129 GURL app_url("http://www.google.com/mail/foo.html");
130 ASSERT_TRUE(app->is_app()); 130 ASSERT_TRUE(app->is_app());
131 ASSERT_TRUE(app->web_extent().MatchesURL(app_url)); 131 ASSERT_TRUE(app->web_extent().MatchesURL(app_url));
132 132
133 info_map->AddExtension(app); 133 info_map->AddExtension(app, base::Time(), false);
134 info_map->AddExtension(extension); 134 info_map->AddExtension(extension, base::Time(), false);
135 135
136 // The app should have the notifications permission, either from a 136 // The app should have the notifications permission, either from a
137 // chrome-extension URL or from its web extent. 137 // chrome-extension URL or from its web extent.
138 const Extension* match = info_map->extensions().GetByURL( 138 const Extension* match = info_map->extensions().GetByURL(
139 app->GetResourceURL("a.html")); 139 app->GetResourceURL("a.html"));
140 EXPECT_TRUE(match && 140 EXPECT_TRUE(match &&
141 match->HasApiPermission(Extension::kNotificationPermission)); 141 match->HasApiPermission(Extension::kNotificationPermission));
142 match = info_map->extensions().GetByURL(app_url); 142 match = info_map->extensions().GetByURL(app_url);
143 EXPECT_TRUE(match && 143 EXPECT_TRUE(match &&
144 match->HasApiPermission(Extension::kNotificationPermission)); 144 match->HasApiPermission(Extension::kNotificationPermission));
145 EXPECT_FALSE(match && 145 EXPECT_FALSE(match &&
146 match->HasApiPermission(Extension::kTabPermission)); 146 match->HasApiPermission(Extension::kTabPermission));
147 147
148 // The extension should have the tabs permission. 148 // The extension should have the tabs permission.
149 match = info_map->extensions().GetByURL(extension->GetResourceURL("a.html")); 149 match = info_map->extensions().GetByURL(extension->GetResourceURL("a.html"));
150 EXPECT_TRUE(match && 150 EXPECT_TRUE(match &&
151 match->HasApiPermission(Extension::kTabPermission)); 151 match->HasApiPermission(Extension::kTabPermission));
152 EXPECT_FALSE(match && 152 EXPECT_FALSE(match &&
153 match->HasApiPermission(Extension::kNotificationPermission)); 153 match->HasApiPermission(Extension::kNotificationPermission));
154 154
155 // Random URL should not have any permissions. 155 // Random URL should not have any permissions.
156 match = info_map->extensions().GetByURL(GURL("http://evil.com/a.html")); 156 match = info_map->extensions().GetByURL(GURL("http://evil.com/a.html"));
157 EXPECT_FALSE(match); 157 EXPECT_FALSE(match);
158 } 158 }
159 159
160 } // namespace 160 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/extensions/extension_info_map.cc ('k') | chrome/browser/extensions/extension_webrequest_api.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698