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

Side by Side Diff: chrome/renderer/chrome_content_renderer_client_unittest.cc

Issue 15984016: Call scoped_refptr<T>::get() rather than relying on implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Rebased Created 7 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
« no previous file with comments | « chrome/nacl/nacl_listener.cc ('k') | chrome/service/cloud_print/cloud_print_auth.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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/renderer/chrome_content_renderer_client.h" 5 #include "chrome/renderer/chrome_content_renderer_client.h"
6 6
7 #include "base/strings/utf_string_conversions.h" 7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/common/extensions/extension.h" 8 #include "chrome/common/extensions/extension.h"
9 #include "chrome/common/extensions/extension_builder.h" 9 #include "chrome/common/extensions/extension_builder.h"
10 #include "chrome/common/extensions/extension_manifest_constants.h" 10 #include "chrome/common/extensions/extension_manifest_constants.h"
(...skipping 108 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 WebPluginInfo info; 119 WebPluginInfo info;
120 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com"); 120 AddContentTypeHandler(&info, "application/x-foo", "www.foo.com");
121 EXPECT_EQ(GURL("www.foo.com"), 121 EXPECT_EQ(GURL("www.foo.com"),
122 ChromeContentRendererClient::GetNaClContentHandlerURL( 122 ChromeContentRendererClient::GetNaClContentHandlerURL(
123 "application/x-foo", info)); 123 "application/x-foo", info));
124 } 124 }
125 // --enable-nacl allows all NaCl apps, with 'dev' interfaces. 125 // --enable-nacl allows all NaCl apps, with 'dev' interfaces.
126 { 126 {
127 WebPluginParams params; 127 WebPluginParams params;
128 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 128 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
129 GURL(), GURL(), kNaClUnrestricted, 129 GURL(),
130 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 130 GURL(),
131 kNaClUnrestricted,
132 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
131 &params)); 133 &params));
132 EXPECT_TRUE(AllowsDevInterfaces(params)); 134 EXPECT_TRUE(AllowsDevInterfaces(params));
133 } 135 }
134 // Unrestricted extensions are allowed without --enable-nacl, with 'dev' 136 // Unrestricted extensions are allowed without --enable-nacl, with 'dev'
135 // interfaces if called from an extension url. 137 // interfaces if called from an extension url.
136 { 138 {
137 WebPluginParams params; 139 WebPluginParams params;
138 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 140 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
139 GURL(), GURL(kExtensionUrl), kNaClRestricted, 141 GURL(),
140 CreateExtension(kExtensionUnrestricted, kExtensionNotFromWebStore), 142 GURL(kExtensionUrl),
143 kNaClRestricted,
144 CreateExtension(kExtensionUnrestricted, kExtensionNotFromWebStore)
145 .get(),
141 &params)); 146 &params));
142 EXPECT_TRUE(AllowsDevInterfaces(params)); 147 EXPECT_TRUE(AllowsDevInterfaces(params));
143 } 148 }
144 // CWS extensions are allowed without --enable-nacl, without 'dev' 149 // CWS extensions are allowed without --enable-nacl, without 'dev'
145 // interfaces if called from an extension url. 150 // interfaces if called from an extension url.
146 { 151 {
147 WebPluginParams params; 152 WebPluginParams params;
148 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 153 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
149 GURL(), GURL(kExtensionUrl), kNaClRestricted, 154 GURL(),
150 CreateExtension(kExtensionRestricted, kExtensionFromWebStore), 155 GURL(kExtensionUrl),
156 kNaClRestricted,
157 CreateExtension(kExtensionRestricted, kExtensionFromWebStore).get(),
151 &params)); 158 &params));
152 EXPECT_FALSE(AllowsDevInterfaces(params)); 159 EXPECT_FALSE(AllowsDevInterfaces(params));
153 } 160 }
154 // CWS extensions can't get 'dev' interfaces with --enable-nacl. 161 // CWS extensions can't get 'dev' interfaces with --enable-nacl.
155 { 162 {
156 WebPluginParams params; 163 WebPluginParams params;
157 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 164 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
158 GURL(), GURL(kExtensionUrl), kNaClUnrestricted, 165 GURL(),
159 CreateExtension(kExtensionRestricted, kExtensionFromWebStore), 166 GURL(kExtensionUrl),
167 kNaClUnrestricted,
168 CreateExtension(kExtensionRestricted, kExtensionFromWebStore).get(),
160 &params)); 169 &params));
161 EXPECT_FALSE(AllowsDevInterfaces(params)); 170 EXPECT_FALSE(AllowsDevInterfaces(params));
162 } 171 }
163 // CWS extensions can't get 'dev' interfaces by injecting a fake 172 // CWS extensions can't get 'dev' interfaces by injecting a fake
164 // '@dev' attribute. 173 // '@dev' attribute.
165 { 174 {
166 WebPluginParams params; 175 WebPluginParams params;
167 AddFakeDevAttribute(&params); 176 AddFakeDevAttribute(&params);
168 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 177 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
169 GURL(), GURL(kExtensionUrl), kNaClRestricted, 178 GURL(),
170 CreateExtension(kExtensionRestricted, kExtensionFromWebStore), 179 GURL(kExtensionUrl),
180 kNaClRestricted,
181 CreateExtension(kExtensionRestricted, kExtensionFromWebStore).get(),
171 &params)); 182 &params));
172 EXPECT_FALSE(AllowsDevInterfaces(params)); 183 EXPECT_FALSE(AllowsDevInterfaces(params));
173 } 184 }
174 // The NaCl PDF extension is allowed without --enable-nacl, with 'dev' 185 // The NaCl PDF extension is allowed without --enable-nacl, with 'dev'
175 // interfaces, from all URLs. 186 // interfaces, from all URLs.
176 { 187 {
177 WebPluginParams params; 188 WebPluginParams params;
178 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 189 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
179 GURL("chrome-extension://acadkphlmlegjaadjagenfimbpphcgnh"), 190 GURL("chrome-extension://acadkphlmlegjaadjagenfimbpphcgnh"),
180 GURL(), kNaClRestricted, 191 GURL(),
181 CreateExtension(kExtensionRestricted, kExtensionFromWebStore), 192 kNaClRestricted,
193 CreateExtension(kExtensionRestricted, kExtensionFromWebStore).get(),
182 &params)); 194 &params));
183 EXPECT_TRUE(AllowsDevInterfaces(params)); 195 EXPECT_TRUE(AllowsDevInterfaces(params));
184 } 196 }
185 // Whitelisted URLs are allowed without --enable-nacl, without 'dev' 197 // Whitelisted URLs are allowed without --enable-nacl, without 'dev'
186 // interfaces. 198 // interfaces.
187 { 199 {
188 WebPluginParams params; 200 WebPluginParams params;
189 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 201 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
190 GURL(), GURL("http://plus.google.com/foo"), 202 GURL(),
203 GURL("http://plus.google.com/foo"),
191 kNaClRestricted, 204 kNaClRestricted,
192 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 205 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
193 &params)); 206 &params));
194 EXPECT_FALSE(AllowsDevInterfaces(params)); 207 EXPECT_FALSE(AllowsDevInterfaces(params));
195 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 208 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
196 GURL(), GURL("https://plus.google.com/foo"), 209 GURL(),
210 GURL("https://plus.google.com/foo"),
197 kNaClRestricted, 211 kNaClRestricted,
198 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 212 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
199 &params)); 213 &params));
200 EXPECT_FALSE(AllowsDevInterfaces(params)); 214 EXPECT_FALSE(AllowsDevInterfaces(params));
201 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 215 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
202 GURL(), GURL("https://plus.google.com/209089085730"), 216 GURL(),
217 GURL("https://plus.google.com/209089085730"),
203 kNaClRestricted, 218 kNaClRestricted,
204 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 219 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
205 &params)); 220 &params));
206 EXPECT_FALSE(AllowsDevInterfaces(params)); 221 EXPECT_FALSE(AllowsDevInterfaces(params));
207 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 222 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
208 GURL(), GURL("http://plus.sandbox.google.com/foo"), 223 GURL(),
224 GURL("http://plus.sandbox.google.com/foo"),
209 kNaClRestricted, 225 kNaClRestricted,
210 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 226 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
211 &params)); 227 &params));
212 EXPECT_FALSE(AllowsDevInterfaces(params)); 228 EXPECT_FALSE(AllowsDevInterfaces(params));
213 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 229 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
214 GURL(), GURL("https://plus.sandbox.google.com/foo"), 230 GURL(),
231 GURL("https://plus.sandbox.google.com/foo"),
215 kNaClRestricted, 232 kNaClRestricted,
216 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 233 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
217 &params)); 234 &params));
218 EXPECT_FALSE(AllowsDevInterfaces(params)); 235 EXPECT_FALSE(AllowsDevInterfaces(params));
219 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 236 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
220 GURL(), GURL("https://plus.google.com/209089085730"), 237 GURL(),
238 GURL("https://plus.google.com/209089085730"),
221 kNaClRestricted, 239 kNaClRestricted,
222 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 240 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
223 &params)); 241 &params));
224 EXPECT_FALSE(AllowsDevInterfaces(params)); 242 EXPECT_FALSE(AllowsDevInterfaces(params));
225 } 243 }
226 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl. 244 // Whitelisted URLs can't get 'dev' interfaces with --enable-nacl.
227 { 245 {
228 WebPluginParams params; 246 WebPluginParams params;
229 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 247 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
230 GURL(), GURL("https://plus.google.com/209089085730"), 248 GURL(),
249 GURL("https://plus.google.com/209089085730"),
231 kNaClUnrestricted, 250 kNaClUnrestricted,
232 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 251 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
233 &params)); 252 &params));
234 EXPECT_FALSE(AllowsDevInterfaces(params)); 253 EXPECT_FALSE(AllowsDevInterfaces(params));
235 } 254 }
236 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake 255 // Whitelisted URLs can't get 'dev' interfaces by injecting a fake
237 // '@dev' attribute. 256 // '@dev' attribute.
238 { 257 {
239 WebPluginParams params; 258 WebPluginParams params;
240 AddFakeDevAttribute(&params); 259 AddFakeDevAttribute(&params);
241 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 260 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
242 GURL(), GURL("https://plus.google.com/209089085730"), 261 GURL(),
262 GURL("https://plus.google.com/209089085730"),
243 kNaClRestricted, 263 kNaClRestricted,
244 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 264 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
245 &params)); 265 &params));
246 EXPECT_FALSE(AllowsDevInterfaces(params)); 266 EXPECT_FALSE(AllowsDevInterfaces(params));
247 } 267 }
248 // Non-whitelisted URLs are blocked without --enable-nacl. 268 // Non-whitelisted URLs are blocked without --enable-nacl.
249 { 269 {
250 WebPluginParams params; 270 WebPluginParams params;
251 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 271 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
252 GURL(), GURL("https://plus.google.com.evil.com/foo1"), 272 GURL(),
273 GURL("https://plus.google.com.evil.com/foo1"),
253 kNaClRestricted, 274 kNaClRestricted,
254 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore), 275 CreateExtension(kExtensionRestricted, kExtensionNotFromWebStore).get(),
255 &params)); 276 &params));
256 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 277 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
257 GURL(), GURL("https://plus.google.com.evil.com/foo2"), 278 GURL(),
279 GURL("https://plus.google.com.evil.com/foo2"),
258 kNaClRestricted, 280 kNaClRestricted,
259 CreateExtension(kExtensionRestricted, kExtensionFromWebStore), 281 CreateExtension(kExtensionRestricted, kExtensionFromWebStore).get(),
260 &params)); 282 &params));
261 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 283 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
262 GURL(), GURL("https://plus.google.com.evil.com/foo3"), 284 GURL(),
285 GURL("https://plus.google.com.evil.com/foo3"),
263 kNaClRestricted, 286 kNaClRestricted,
264 CreateExtension(kExtensionUnrestricted, kExtensionNotFromWebStore), 287 CreateExtension(kExtensionUnrestricted, kExtensionNotFromWebStore)
288 .get(),
265 &params)); 289 &params));
266 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 290 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
267 GURL(), GURL("https://plus.google.com.evil.com/foo4"), 291 GURL(),
292 GURL("https://plus.google.com.evil.com/foo4"),
268 kNaClRestricted, 293 kNaClRestricted,
269 CreateExtension(kExtensionUnrestricted, kExtensionFromWebStore), 294 CreateExtension(kExtensionUnrestricted, kExtensionFromWebStore).get(),
270 &params)); 295 &params));
271 } 296 }
272 // Non chrome-extension:// URLs belonging to hosted apps are allowed. 297 // Non chrome-extension:// URLs belonging to hosted apps are allowed.
273 { 298 {
274 WebPluginParams params; 299 WebPluginParams params;
275 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed( 300 EXPECT_TRUE(ChromeContentRendererClient::IsNaClAllowed(
276 GURL(), GURL("http://example.com/test.html"), 301 GURL(),
302 GURL("http://example.com/test.html"),
277 kNaClRestricted, 303 kNaClRestricted,
278 CreateHostedApp(kExtensionRestricted, kExtensionNotFromWebStore, 304 CreateHostedApp(kExtensionRestricted,
279 "http://example.com/"), 305 kExtensionNotFromWebStore,
306 "http://example.com/").get(),
280 &params)); 307 &params));
281 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed( 308 EXPECT_FALSE(ChromeContentRendererClient::IsNaClAllowed(
282 GURL(), GURL("http://example.evil.com/test.html"), 309 GURL(),
310 GURL("http://example.evil.com/test.html"),
283 kNaClRestricted, 311 kNaClRestricted,
284 CreateHostedApp(kExtensionRestricted, kExtensionNotFromWebStore, 312 CreateHostedApp(kExtensionRestricted,
285 "http://example.com/"), 313 kExtensionNotFromWebStore,
314 "http://example.com/").get(),
286 &params)); 315 &params));
287 } 316 }
288 } 317 }
289 318
290 } // namespace chrome 319 } // namespace chrome
OLDNEW
« no previous file with comments | « chrome/nacl/nacl_listener.cc ('k') | chrome/service/cloud_print/cloud_print_auth.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698