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

Side by Side Diff: Source/web/tests/AssociatedURLLoaderTest.cpp

Issue 398673003: Rename WebCore namespace to blink in bindings and web (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 6 years, 5 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 | « Source/web/tests/ActivityLoggerTest.cpp ('k') | Source/web/tests/ChromeClientImplTest.cpp » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2011 Google Inc. All rights reserved. 2 * Copyright (C) 2011 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are 5 * modification, are permitted provided that the following conditions are
6 * met: 6 * met:
7 * 7 *
8 * * Redistributions of source code must retain the above copyright 8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above 10 * * Redistributions in binary form must reproduce the above
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after
67 , m_didFail(false) 67 , m_didFail(false)
68 , m_runningMessageLoop(false) 68 , m_runningMessageLoop(false)
69 { 69 {
70 // Reuse one of the test files from WebFrameTest. 70 // Reuse one of the test files from WebFrameTest.
71 m_baseFilePath = Platform::current()->unitTestSupport()->webKitRootDir() ; 71 m_baseFilePath = Platform::current()->unitTestSupport()->webKitRootDir() ;
72 m_baseFilePath.append("/Source/web/tests/data/"); 72 m_baseFilePath.append("/Source/web/tests/data/");
73 m_frameFilePath = m_baseFilePath; 73 m_frameFilePath = m_baseFilePath;
74 m_frameFilePath.append("iframes_test.html"); 74 m_frameFilePath.append("iframes_test.html");
75 } 75 }
76 76
77 WebCore::KURL RegisterMockedUrl(const std::string& urlRoot, const WTF::Strin g& filename) 77 blink::KURL RegisterMockedUrl(const std::string& urlRoot, const WTF::String& filename)
78 { 78 {
79 WebURLResponse response; 79 WebURLResponse response;
80 response.initialize(); 80 response.initialize();
81 response.setMIMEType("text/html"); 81 response.setMIMEType("text/html");
82 WTF::String localPath = m_baseFilePath; 82 WTF::String localPath = m_baseFilePath;
83 localPath.append(filename); 83 localPath.append(filename);
84 WebCore::KURL url = toKURL(urlRoot + filename.utf8().data()); 84 blink::KURL url = toKURL(urlRoot + filename.utf8().data());
85 Platform::current()->unitTestSupport()->registerMockedURL(url, response, localPath); 85 Platform::current()->unitTestSupport()->registerMockedURL(url, response, localPath);
86 return url; 86 return url;
87 } 87 }
88 88
89 void SetUp() 89 void SetUp()
90 { 90 {
91 m_helper.initialize(); 91 m_helper.initialize();
92 92
93 std::string urlRoot = "http://www.test.com/"; 93 std::string urlRoot = "http://www.test.com/";
94 WebCore::KURL url = RegisterMockedUrl(urlRoot, "iframes_test.html"); 94 blink::KURL url = RegisterMockedUrl(urlRoot, "iframes_test.html");
95 const char* iframeSupportFiles[] = { 95 const char* iframeSupportFiles[] = {
96 "invisible_iframe.html", 96 "invisible_iframe.html",
97 "visible_iframe.html", 97 "visible_iframe.html",
98 "zero_sized_iframe.html", 98 "zero_sized_iframe.html",
99 }; 99 };
100 for (size_t i = 0; i < arraysize(iframeSupportFiles); ++i) { 100 for (size_t i = 0; i < arraysize(iframeSupportFiles); ++i) {
101 RegisterMockedUrl(urlRoot, iframeSupportFiles[i]); 101 RegisterMockedUrl(urlRoot, iframeSupportFiles[i]);
102 } 102 }
103 103
104 FrameTestHelpers::loadFrame(mainFrame(), url.string().utf8().data()); 104 FrameTestHelpers::loadFrame(mainFrame(), url.string().utf8().data());
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
231 } 231 }
232 232
233 bool CheckAccessControlHeaders(const char* headerName, bool exposed) 233 bool CheckAccessControlHeaders(const char* headerName, bool exposed)
234 { 234 {
235 std::string id("http://www.other.com/CheckAccessControlExposeHeaders_"); 235 std::string id("http://www.other.com/CheckAccessControlExposeHeaders_");
236 id.append(headerName); 236 id.append(headerName);
237 if (exposed) 237 if (exposed)
238 id.append("-Exposed"); 238 id.append("-Exposed");
239 id.append(".html"); 239 id.append(".html");
240 240
241 WebCore::KURL url = toKURL(id); 241 blink::KURL url = toKURL(id);
242 WebURLRequest request; 242 WebURLRequest request;
243 request.initialize(); 243 request.initialize();
244 request.setURL(url); 244 request.setURL(url);
245 245
246 WebString headerNameString(WebString::fromUTF8(headerName)); 246 WebString headerNameString(WebString::fromUTF8(headerName));
247 m_expectedResponse = WebURLResponse(); 247 m_expectedResponse = WebURLResponse();
248 m_expectedResponse.initialize(); 248 m_expectedResponse.initialize();
249 m_expectedResponse.setMIMEType("text/html"); 249 m_expectedResponse.setMIMEType("text/html");
250 m_expectedResponse.setHTTPStatusCode(200); 250 m_expectedResponse.setHTTPStatusCode(200);
251 m_expectedResponse.addHTTPHeaderField("Access-Control-Allow-Origin", "*" ); 251 m_expectedResponse.addHTTPHeaderField("Access-Control-Allow-Origin", "*" );
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 bool m_didReceiveData; 286 bool m_didReceiveData;
287 bool m_didReceiveCachedMetadata; 287 bool m_didReceiveCachedMetadata;
288 bool m_didFinishLoading; 288 bool m_didFinishLoading;
289 bool m_didFail; 289 bool m_didFail;
290 bool m_runningMessageLoop; 290 bool m_runningMessageLoop;
291 }; 291 };
292 292
293 // Test a successful same-origin URL load. 293 // Test a successful same-origin URL load.
294 TEST_F(AssociatedURLLoaderTest, SameOriginSuccess) 294 TEST_F(AssociatedURLLoaderTest, SameOriginSuccess)
295 { 295 {
296 WebCore::KURL url = toKURL("http://www.test.com/SameOriginSuccess.html"); 296 blink::KURL url = toKURL("http://www.test.com/SameOriginSuccess.html");
297 WebURLRequest request; 297 WebURLRequest request;
298 request.initialize(); 298 request.initialize();
299 request.setURL(url); 299 request.setURL(url);
300 300
301 m_expectedResponse = WebURLResponse(); 301 m_expectedResponse = WebURLResponse();
302 m_expectedResponse.initialize(); 302 m_expectedResponse.initialize();
303 m_expectedResponse.setMIMEType("text/html"); 303 m_expectedResponse.setMIMEType("text/html");
304 m_expectedResponse.setHTTPStatusCode(200); 304 m_expectedResponse.setHTTPStatusCode(200);
305 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 305 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
306 306
307 m_expectedLoader = createAssociatedURLLoader(); 307 m_expectedLoader = createAssociatedURLLoader();
308 EXPECT_TRUE(m_expectedLoader); 308 EXPECT_TRUE(m_expectedLoader);
309 m_expectedLoader->loadAsynchronously(request, this); 309 m_expectedLoader->loadAsynchronously(request, this);
310 serveRequests(); 310 serveRequests();
311 EXPECT_TRUE(m_didReceiveResponse); 311 EXPECT_TRUE(m_didReceiveResponse);
312 EXPECT_TRUE(m_didReceiveData); 312 EXPECT_TRUE(m_didReceiveData);
313 EXPECT_TRUE(m_didFinishLoading); 313 EXPECT_TRUE(m_didFinishLoading);
314 } 314 }
315 315
316 // Test that the same-origin restriction is the default. 316 // Test that the same-origin restriction is the default.
317 TEST_F(AssociatedURLLoaderTest, SameOriginRestriction) 317 TEST_F(AssociatedURLLoaderTest, SameOriginRestriction)
318 { 318 {
319 // This is cross-origin since the frame was loaded from www.test.com. 319 // This is cross-origin since the frame was loaded from www.test.com.
320 WebCore::KURL url = toKURL("http://www.other.com/SameOriginRestriction.html" ); 320 blink::KURL url = toKURL("http://www.other.com/SameOriginRestriction.html");
321 WebURLRequest request; 321 WebURLRequest request;
322 request.initialize(); 322 request.initialize();
323 request.setURL(url); 323 request.setURL(url);
324 CheckFails(request); 324 CheckFails(request);
325 } 325 }
326 326
327 // Test a successful cross-origin load. 327 // Test a successful cross-origin load.
328 TEST_F(AssociatedURLLoaderTest, CrossOriginSuccess) 328 TEST_F(AssociatedURLLoaderTest, CrossOriginSuccess)
329 { 329 {
330 // This is cross-origin since the frame was loaded from www.test.com. 330 // This is cross-origin since the frame was loaded from www.test.com.
331 WebCore::KURL url = toKURL("http://www.other.com/CrossOriginSuccess.html"); 331 blink::KURL url = toKURL("http://www.other.com/CrossOriginSuccess.html");
332 WebURLRequest request; 332 WebURLRequest request;
333 request.initialize(); 333 request.initialize();
334 request.setURL(url); 334 request.setURL(url);
335 335
336 m_expectedResponse = WebURLResponse(); 336 m_expectedResponse = WebURLResponse();
337 m_expectedResponse.initialize(); 337 m_expectedResponse.initialize();
338 m_expectedResponse.setMIMEType("text/html"); 338 m_expectedResponse.setMIMEType("text/html");
339 m_expectedResponse.setHTTPStatusCode(200); 339 m_expectedResponse.setHTTPStatusCode(200);
340 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 340 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
341 341
342 WebURLLoaderOptions options; 342 WebURLLoaderOptions options;
343 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyAllow; 343 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyAllow;
344 m_expectedLoader = createAssociatedURLLoader(options); 344 m_expectedLoader = createAssociatedURLLoader(options);
345 EXPECT_TRUE(m_expectedLoader); 345 EXPECT_TRUE(m_expectedLoader);
346 m_expectedLoader->loadAsynchronously(request, this); 346 m_expectedLoader->loadAsynchronously(request, this);
347 serveRequests(); 347 serveRequests();
348 EXPECT_TRUE(m_didReceiveResponse); 348 EXPECT_TRUE(m_didReceiveResponse);
349 EXPECT_TRUE(m_didReceiveData); 349 EXPECT_TRUE(m_didReceiveData);
350 EXPECT_TRUE(m_didFinishLoading); 350 EXPECT_TRUE(m_didFinishLoading);
351 } 351 }
352 352
353 // Test a successful cross-origin load using CORS. 353 // Test a successful cross-origin load using CORS.
354 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlSuccess) 354 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlSuccess)
355 { 355 {
356 // This is cross-origin since the frame was loaded from www.test.com. 356 // This is cross-origin since the frame was loaded from www.test.com.
357 WebCore::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessContro lSuccess.html"); 357 blink::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessControlS uccess.html");
358 WebURLRequest request; 358 WebURLRequest request;
359 request.initialize(); 359 request.initialize();
360 request.setURL(url); 360 request.setURL(url);
361 361
362 m_expectedResponse = WebURLResponse(); 362 m_expectedResponse = WebURLResponse();
363 m_expectedResponse.initialize(); 363 m_expectedResponse.initialize();
364 m_expectedResponse.setMIMEType("text/html"); 364 m_expectedResponse.setMIMEType("text/html");
365 m_expectedResponse.setHTTPStatusCode(200); 365 m_expectedResponse.setHTTPStatusCode(200);
366 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*"); 366 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
367 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 367 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
368 368
369 WebURLLoaderOptions options; 369 WebURLLoaderOptions options;
370 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl; 370 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl;
371 m_expectedLoader = createAssociatedURLLoader(options); 371 m_expectedLoader = createAssociatedURLLoader(options);
372 EXPECT_TRUE(m_expectedLoader); 372 EXPECT_TRUE(m_expectedLoader);
373 m_expectedLoader->loadAsynchronously(request, this); 373 m_expectedLoader->loadAsynchronously(request, this);
374 serveRequests(); 374 serveRequests();
375 EXPECT_TRUE(m_didReceiveResponse); 375 EXPECT_TRUE(m_didReceiveResponse);
376 EXPECT_TRUE(m_didReceiveData); 376 EXPECT_TRUE(m_didReceiveData);
377 EXPECT_TRUE(m_didFinishLoading); 377 EXPECT_TRUE(m_didFinishLoading);
378 } 378 }
379 379
380 // Test an unsuccessful cross-origin load using CORS. 380 // Test an unsuccessful cross-origin load using CORS.
381 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlFailure) 381 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlFailure)
382 { 382 {
383 // This is cross-origin since the frame was loaded from www.test.com. 383 // This is cross-origin since the frame was loaded from www.test.com.
384 WebCore::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessContro lFailure.html"); 384 blink::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessControlF ailure.html");
385 WebURLRequest request; 385 WebURLRequest request;
386 request.initialize(); 386 request.initialize();
387 request.setURL(url); 387 request.setURL(url);
388 388
389 m_expectedResponse = WebURLResponse(); 389 m_expectedResponse = WebURLResponse();
390 m_expectedResponse.initialize(); 390 m_expectedResponse.initialize();
391 m_expectedResponse.setMIMEType("text/html"); 391 m_expectedResponse.setMIMEType("text/html");
392 m_expectedResponse.setHTTPStatusCode(200); 392 m_expectedResponse.setHTTPStatusCode(200);
393 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*"); 393 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
394 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 394 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
(...skipping 12 matching lines...) Expand all
407 // The loader needs to receive the response, before doing the CORS check. 407 // The loader needs to receive the response, before doing the CORS check.
408 serveRequests(); 408 serveRequests();
409 EXPECT_TRUE(m_didFail); 409 EXPECT_TRUE(m_didFail);
410 EXPECT_FALSE(m_didReceiveResponse); 410 EXPECT_FALSE(m_didReceiveResponse);
411 } 411 }
412 412
413 // Test an unsuccessful cross-origin load using CORS. 413 // Test an unsuccessful cross-origin load using CORS.
414 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlFailureBadStatusCode ) 414 TEST_F(AssociatedURLLoaderTest, CrossOriginWithAccessControlFailureBadStatusCode )
415 { 415 {
416 // This is cross-origin since the frame was loaded from www.test.com. 416 // This is cross-origin since the frame was loaded from www.test.com.
417 WebCore::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessContro lFailure.html"); 417 blink::KURL url = toKURL("http://www.other.com/CrossOriginWithAccessControlF ailure.html");
418 WebURLRequest request; 418 WebURLRequest request;
419 request.initialize(); 419 request.initialize();
420 request.setURL(url); 420 request.setURL(url);
421 421
422 m_expectedResponse = WebURLResponse(); 422 m_expectedResponse = WebURLResponse();
423 m_expectedResponse.initialize(); 423 m_expectedResponse.initialize();
424 m_expectedResponse.setMIMEType("text/html"); 424 m_expectedResponse.setMIMEType("text/html");
425 m_expectedResponse.setHTTPStatusCode(0); 425 m_expectedResponse.setHTTPStatusCode(0);
426 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*"); 426 m_expectedResponse.addHTTPHeaderField("access-control-allow-origin", "*");
427 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 427 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
428 428
429 WebURLLoaderOptions options; 429 WebURLLoaderOptions options;
430 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl; 430 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl;
431 m_expectedLoader = createAssociatedURLLoader(options); 431 m_expectedLoader = createAssociatedURLLoader(options);
432 EXPECT_TRUE(m_expectedLoader); 432 EXPECT_TRUE(m_expectedLoader);
433 m_expectedLoader->loadAsynchronously(request, this); 433 m_expectedLoader->loadAsynchronously(request, this);
434 434
435 // Failure should not be reported synchronously. 435 // Failure should not be reported synchronously.
436 EXPECT_FALSE(m_didFail); 436 EXPECT_FALSE(m_didFail);
437 // The loader needs to receive the response, before doing the CORS check. 437 // The loader needs to receive the response, before doing the CORS check.
438 serveRequests(); 438 serveRequests();
439 EXPECT_TRUE(m_didFail); 439 EXPECT_TRUE(m_didFail);
440 EXPECT_FALSE(m_didReceiveResponse); 440 EXPECT_FALSE(m_didReceiveResponse);
441 } 441 }
442 442
443 // Test a same-origin URL redirect and load. 443 // Test a same-origin URL redirect and load.
444 TEST_F(AssociatedURLLoaderTest, RedirectSuccess) 444 TEST_F(AssociatedURLLoaderTest, RedirectSuccess)
445 { 445 {
446 WebCore::KURL url = toKURL("http://www.test.com/RedirectSuccess.html"); 446 blink::KURL url = toKURL("http://www.test.com/RedirectSuccess.html");
447 char redirect[] = "http://www.test.com/RedirectSuccess2.html"; // Same-orig in 447 char redirect[] = "http://www.test.com/RedirectSuccess2.html"; // Same-orig in
448 WebCore::KURL redirectURL = toKURL(redirect); 448 blink::KURL redirectURL = toKURL(redirect);
449 449
450 WebURLRequest request; 450 WebURLRequest request;
451 request.initialize(); 451 request.initialize();
452 request.setURL(url); 452 request.setURL(url);
453 453
454 m_expectedRedirectResponse = WebURLResponse(); 454 m_expectedRedirectResponse = WebURLResponse();
455 m_expectedRedirectResponse.initialize(); 455 m_expectedRedirectResponse.initialize();
456 m_expectedRedirectResponse.setMIMEType("text/html"); 456 m_expectedRedirectResponse.setMIMEType("text/html");
457 m_expectedRedirectResponse.setHTTPStatusCode(301); 457 m_expectedRedirectResponse.setHTTPStatusCode(301);
458 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect); 458 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
(...skipping 16 matching lines...) Expand all
475 EXPECT_TRUE(m_willSendRequest); 475 EXPECT_TRUE(m_willSendRequest);
476 EXPECT_TRUE(m_didReceiveResponse); 476 EXPECT_TRUE(m_didReceiveResponse);
477 EXPECT_TRUE(m_didReceiveData); 477 EXPECT_TRUE(m_didReceiveData);
478 EXPECT_TRUE(m_didFinishLoading); 478 EXPECT_TRUE(m_didFinishLoading);
479 } 479 }
480 480
481 // Test that a cross origin redirect response without CORS headers fails. 481 // Test that a cross origin redirect response without CORS headers fails.
482 // Disabled, http://crbug.com/240912 . 482 // Disabled, http://crbug.com/240912 .
483 TEST_F(AssociatedURLLoaderTest, DISABLED_RedirectCrossOriginWithAccessControlFai lure) 483 TEST_F(AssociatedURLLoaderTest, DISABLED_RedirectCrossOriginWithAccessControlFai lure)
484 { 484 {
485 WebCore::KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAcces sControlFailure.html"); 485 blink::KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessC ontrolFailure.html");
486 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Failure.html"; // Cross-origin 486 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Failure.html"; // Cross-origin
487 WebCore::KURL redirectURL = toKURL(redirect); 487 blink::KURL redirectURL = toKURL(redirect);
488 488
489 WebURLRequest request; 489 WebURLRequest request;
490 request.initialize(); 490 request.initialize();
491 request.setURL(url); 491 request.setURL(url);
492 492
493 // Create a redirect response without CORS headers. 493 // Create a redirect response without CORS headers.
494 m_expectedRedirectResponse = WebURLResponse(); 494 m_expectedRedirectResponse = WebURLResponse();
495 m_expectedRedirectResponse.initialize(); 495 m_expectedRedirectResponse.initialize();
496 m_expectedRedirectResponse.setMIMEType("text/html"); 496 m_expectedRedirectResponse.setMIMEType("text/html");
497 m_expectedRedirectResponse.setHTTPStatusCode(301); 497 m_expectedRedirectResponse.setHTTPStatusCode(301);
498 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect); 498 m_expectedRedirectResponse.setHTTPHeaderField("Location", redirect);
499 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRed irectResponse, m_frameFilePath); 499 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRed irectResponse, m_frameFilePath);
500 500
501 WebURLLoaderOptions options; 501 WebURLLoaderOptions options;
502 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl; 502 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl;
503 m_expectedLoader = createAssociatedURLLoader(options); 503 m_expectedLoader = createAssociatedURLLoader(options);
504 EXPECT_TRUE(m_expectedLoader); 504 EXPECT_TRUE(m_expectedLoader);
505 m_expectedLoader->loadAsynchronously(request, this); 505 m_expectedLoader->loadAsynchronously(request, this);
506 serveRequests(); 506 serveRequests();
507 // We should not receive a notification for the redirect or any response. 507 // We should not receive a notification for the redirect or any response.
508 EXPECT_FALSE(m_willSendRequest); 508 EXPECT_FALSE(m_willSendRequest);
509 EXPECT_FALSE(m_didReceiveResponse); 509 EXPECT_FALSE(m_didReceiveResponse);
510 EXPECT_FALSE(m_didReceiveData); 510 EXPECT_FALSE(m_didReceiveData);
511 EXPECT_FALSE(m_didFail); 511 EXPECT_FALSE(m_didFail);
512 } 512 }
513 513
514 // Test that a cross origin redirect response with CORS headers that allow the r equesting origin succeeds. 514 // Test that a cross origin redirect response with CORS headers that allow the r equesting origin succeeds.
515 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginWithAccessControlSuccess) 515 TEST_F(AssociatedURLLoaderTest, RedirectCrossOriginWithAccessControlSuccess)
516 { 516 {
517 WebCore::KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAcces sControlSuccess.html"); 517 blink::KURL url = toKURL("http://www.test.com/RedirectCrossOriginWithAccessC ontrolSuccess.html");
518 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Success.html"; // Cross-origin 518 char redirect[] = "http://www.other.com/RedirectCrossOriginWithAccessControl Success.html"; // Cross-origin
519 WebCore::KURL redirectURL = toKURL(redirect); 519 blink::KURL redirectURL = toKURL(redirect);
520 520
521 WebURLRequest request; 521 WebURLRequest request;
522 request.initialize(); 522 request.initialize();
523 request.setURL(url); 523 request.setURL(url);
524 // Add a CORS simple header. 524 // Add a CORS simple header.
525 request.setHTTPHeaderField("accept", "application/json"); 525 request.setHTTPHeaderField("accept", "application/json");
526 526
527 // Create a redirect response that allows the redirect to pass the access co ntrol checks. 527 // Create a redirect response that allows the redirect to pass the access co ntrol checks.
528 m_expectedRedirectResponse = WebURLResponse(); 528 m_expectedRedirectResponse = WebURLResponse();
529 m_expectedRedirectResponse.initialize(); 529 m_expectedRedirectResponse.initialize();
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
634 634
635 // Test that Set-Cookie headers aren't returned, even if exposed. 635 // Test that Set-Cookie headers aren't returned, even if exposed.
636 EXPECT_FALSE(CheckAccessControlHeaders("Set-Cookie", true)); 636 EXPECT_FALSE(CheckAccessControlHeaders("Set-Cookie", true));
637 } 637 }
638 638
639 // Test that the loader can allow non-whitelisted response headers for trusted C ORS loads. 639 // Test that the loader can allow non-whitelisted response headers for trusted C ORS loads.
640 TEST_F(AssociatedURLLoaderTest, CrossOriginHeaderAllowResponseHeaders) 640 TEST_F(AssociatedURLLoaderTest, CrossOriginHeaderAllowResponseHeaders)
641 { 641 {
642 WebURLRequest request; 642 WebURLRequest request;
643 request.initialize(); 643 request.initialize();
644 WebCore::KURL url = toKURL("http://www.other.com/CrossOriginHeaderAllowRespo nseHeaders.html"); 644 blink::KURL url = toKURL("http://www.other.com/CrossOriginHeaderAllowRespons eHeaders.html");
645 request.setURL(url); 645 request.setURL(url);
646 646
647 WebString headerNameString(WebString::fromUTF8("non-whitelisted")); 647 WebString headerNameString(WebString::fromUTF8("non-whitelisted"));
648 m_expectedResponse = WebURLResponse(); 648 m_expectedResponse = WebURLResponse();
649 m_expectedResponse.initialize(); 649 m_expectedResponse.initialize();
650 m_expectedResponse.setMIMEType("text/html"); 650 m_expectedResponse.setMIMEType("text/html");
651 m_expectedResponse.setHTTPStatusCode(200); 651 m_expectedResponse.setHTTPStatusCode(200);
652 m_expectedResponse.addHTTPHeaderField("Access-Control-Allow-Origin", "*"); 652 m_expectedResponse.addHTTPHeaderField("Access-Control-Allow-Origin", "*");
653 m_expectedResponse.addHTTPHeaderField(headerNameString, "foo"); 653 m_expectedResponse.addHTTPHeaderField(headerNameString, "foo");
654 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath); 654 Platform::current()->unitTestSupport()->registerMockedURL(url, m_expectedRes ponse, m_frameFilePath);
655 655
656 WebURLLoaderOptions options; 656 WebURLLoaderOptions options;
657 options.exposeAllResponseHeaders = true; // This turns off response whitelis ting. 657 options.exposeAllResponseHeaders = true; // This turns off response whitelis ting.
658 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl; 658 options.crossOriginRequestPolicy = WebURLLoaderOptions::CrossOriginRequestPo licyUseAccessControl;
659 m_expectedLoader = createAssociatedURLLoader(options); 659 m_expectedLoader = createAssociatedURLLoader(options);
660 EXPECT_TRUE(m_expectedLoader); 660 EXPECT_TRUE(m_expectedLoader);
661 m_expectedLoader->loadAsynchronously(request, this); 661 m_expectedLoader->loadAsynchronously(request, this);
662 serveRequests(); 662 serveRequests();
663 EXPECT_TRUE(m_didReceiveResponse); 663 EXPECT_TRUE(m_didReceiveResponse);
664 EXPECT_TRUE(m_didReceiveData); 664 EXPECT_TRUE(m_didReceiveData);
665 EXPECT_TRUE(m_didFinishLoading); 665 EXPECT_TRUE(m_didFinishLoading);
666 666
667 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty()); 667 EXPECT_FALSE(m_actualResponse.httpHeaderField(headerNameString).isEmpty());
668 } 668 }
669 669
670 } 670 }
OLDNEW
« no previous file with comments | « Source/web/tests/ActivityLoggerTest.cpp ('k') | Source/web/tests/ChromeClientImplTest.cpp » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698