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

Side by Side Diff: net/proxy/proxy_resolver_v8_unittest.cc

Issue 950433002: Fix a crash when processing an invalid PAC script. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Address feedback from mmenke Created 5 years, 10 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 "base/compiler_specific.h" 5 #include "base/compiler_specific.h"
6 #include "base/files/file_util.h" 6 #include "base/files/file_util.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/string_util.h" 8 #include "base/strings/string_util.h"
9 #include "base/strings/stringprintf.h" 9 #include "base/strings/stringprintf.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 235 matching lines...) Expand 10 before | Expand all | Expand 10 after
246 TEST(ProxyResolverV8Test, NoEntryPoint) { 246 TEST(ProxyResolverV8Test, NoEntryPoint) {
247 ProxyResolverV8WithMockBindings resolver; 247 ProxyResolverV8WithMockBindings resolver;
248 int result = resolver.SetPacScriptFromDisk("no_entrypoint.js"); 248 int result = resolver.SetPacScriptFromDisk("no_entrypoint.js");
249 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); 249 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result);
250 250
251 ProxyInfo proxy_info; 251 ProxyInfo proxy_info;
252 result = resolver.GetProxyForURL( 252 result = resolver.GetProxyForURL(
253 kQueryUrl, &proxy_info, CompletionCallback(), NULL, BoundNetLog()); 253 kQueryUrl, &proxy_info, CompletionCallback(), NULL, BoundNetLog());
254 254
255 EXPECT_EQ(ERR_FAILED, result); 255 EXPECT_EQ(ERR_FAILED, result);
256
257 MockJSBindings* bindings = resolver.mock_js_bindings();
258 ASSERT_EQ(1U, bindings->errors.size());
259 EXPECT_EQ("FindProxyForURL is undefined or not a function.",
260 bindings->errors[0]);
261 EXPECT_EQ(-1, bindings->errors_line_number[0]);
256 } 262 }
257 263
258 // Try loading a malformed PAC script. 264 // Try loading a malformed PAC script.
259 TEST(ProxyResolverV8Test, ParseError) { 265 TEST(ProxyResolverV8Test, ParseError) {
260 ProxyResolverV8WithMockBindings resolver; 266 ProxyResolverV8WithMockBindings resolver;
261 int result = resolver.SetPacScriptFromDisk("missing_close_brace.js"); 267 int result = resolver.SetPacScriptFromDisk("missing_close_brace.js");
262 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); 268 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result);
263 269
264 ProxyInfo proxy_info; 270 ProxyInfo proxy_info;
265 result = resolver.GetProxyForURL( 271 result = resolver.GetProxyForURL(
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
321 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result); 327 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result);
322 328
323 MockJSBindings* bindings = resolver.mock_js_bindings(); 329 MockJSBindings* bindings = resolver.mock_js_bindings();
324 EXPECT_EQ(0U, bindings->alerts.size()); 330 EXPECT_EQ(0U, bindings->alerts.size());
325 ASSERT_EQ(1U, bindings->errors.size()); 331 ASSERT_EQ(1U, bindings->errors.size());
326 EXPECT_EQ("Uncaught ReferenceError: undefined_variable is not defined", 332 EXPECT_EQ("Uncaught ReferenceError: undefined_variable is not defined",
327 bindings->errors[0]); 333 bindings->errors[0]);
328 EXPECT_EQ(3, bindings->errors_line_number[0]); 334 EXPECT_EQ(3, bindings->errors_line_number[0]);
329 } 335 }
330 336
337 // Execute a PAC script which throws an exception when first accessing
338 // FindProxyForURL
339 TEST(ProxyResolverV8Test, ExceptionAccessingFindProxyForURLDuringInit) {
340 ProxyResolverV8WithMockBindings resolver;
341 int result =
342 resolver.SetPacScriptFromDisk("exception_findproxyforurl_during_init.js");
343 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result);
344
345 MockJSBindings* bindings = resolver.mock_js_bindings();
346 ASSERT_EQ(2U, bindings->errors.size());
347 EXPECT_EQ("Uncaught crash!", bindings->errors[0]);
348 EXPECT_EQ("Accessing FindProxyForURL threw an exception.",
349 bindings->errors[1]);
350 }
351
352 // Execute a PAC script which throws an exception during the second access to
353 // FindProxyForURL
354 TEST(ProxyResolverV8Test, ExceptionAccessingFindProxyForURLDuringResolve) {
355 ProxyResolverV8WithMockBindings resolver;
356 int result = resolver.SetPacScriptFromDisk(
357 "exception_findproxyforurl_during_resolve.js");
358 EXPECT_EQ(OK, result);
359
360 ProxyInfo proxy_info;
361 result = resolver.GetProxyForURL(kQueryUrl, &proxy_info, CompletionCallback(),
362 NULL, BoundNetLog());
363
364 EXPECT_EQ(ERR_PAC_SCRIPT_FAILED, result);
365
366 MockJSBindings* bindings = resolver.mock_js_bindings();
367 ASSERT_EQ(2U, bindings->errors.size());
368 EXPECT_EQ("Uncaught crash!", bindings->errors[0]);
369 EXPECT_EQ("Accessing FindProxyForURL threw an exception.",
370 bindings->errors[1]);
371 }
372
331 TEST(ProxyResolverV8Test, ReturnUnicode) { 373 TEST(ProxyResolverV8Test, ReturnUnicode) {
332 ProxyResolverV8WithMockBindings resolver; 374 ProxyResolverV8WithMockBindings resolver;
333 int result = resolver.SetPacScriptFromDisk("return_unicode.js"); 375 int result = resolver.SetPacScriptFromDisk("return_unicode.js");
334 EXPECT_EQ(OK, result); 376 EXPECT_EQ(OK, result);
335 377
336 ProxyInfo proxy_info; 378 ProxyInfo proxy_info;
337 result = resolver.GetProxyForURL( 379 result = resolver.GetProxyForURL(
338 kQueryUrl, &proxy_info, CompletionCallback(), NULL, BoundNetLog()); 380 kQueryUrl, &proxy_info, CompletionCallback(), NULL, BoundNetLog());
339 381
340 // The result from this resolve was unparseable, because it 382 // The result from this resolve was unparseable, because it
(...skipping 275 matching lines...) Expand 10 before | Expand all | Expand 10 after
616 GURL("http://kittens/"), &proxy_info, 658 GURL("http://kittens/"), &proxy_info,
617 CompletionCallback(), NULL, BoundNetLog()); 659 CompletionCallback(), NULL, BoundNetLog());
618 660
619 EXPECT_EQ(OK, result); 661 EXPECT_EQ(OK, result);
620 EXPECT_EQ(0u, bindings->errors.size()); 662 EXPECT_EQ(0u, bindings->errors.size());
621 EXPECT_EQ("kittens:88", proxy_info.proxy_server().ToURI()); 663 EXPECT_EQ("kittens:88", proxy_info.proxy_server().ToURI());
622 } 664 }
623 665
624 } // namespace 666 } // namespace
625 } // namespace net 667 } // namespace net
OLDNEW
« net/proxy/proxy_resolver_v8.cc ('K') | « net/proxy/proxy_resolver_v8.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698