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

Side by Side Diff: third_party/WebKit/Source/platform/weborigin/SecurityOriginTest.cpp

Issue 1495013002: Check for equality of the URL's origin in replaceState/pushState (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Allow --disable-web-security again, add more tests Created 5 years 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 /* 1 /*
2 * Copyright (C) 2013 Google Inc. All rights reserved. 2 * Copyright (C) 2013 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 323 matching lines...) Expand 10 before | Expand all | Expand 10 after
334 }; 334 };
335 335
336 for (size_t i = 0; i < arraysize(tests); ++i) { 336 for (size_t i = 0; i < arraysize(tests); ++i) {
337 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(tests[i ].origin); 337 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(tests[i ].origin);
338 blink::KURL url(blink::ParsedURLString, tests[i].url); 338 blink::KURL url(blink::ParsedURLString, tests[i].url);
339 EXPECT_EQ(tests[i].canRequest, origin->canRequest(url)); 339 EXPECT_EQ(tests[i].canRequest, origin->canRequest(url));
340 EXPECT_EQ(tests[i].canRequestNoSuborigin, origin->canRequestNoSuborigin( url)); 340 EXPECT_EQ(tests[i].canRequestNoSuborigin, origin->canRequestNoSuborigin( url));
341 } 341 }
342 } 342 }
343 343
344 TEST_F(SecurityOriginTest, AreSamePageUrls)
345 {
346 struct TestCase {
347 bool areSamePageUrls;
348 const char* origin;
349 const char* url1;
350 const char* url2;
351 };
352
353 TestCase tests[] = {
354 { true, "http://a.com", "http://a.com", "http://a.com" },
355 { true, "http://a.com", "http://a.com", "http://a.com/" },
356 { true, "http://a.com", "http://a.com", "http://a.com/foo" },
357 { true, "http://a.com", "http://a.com", "http://a.com?foo=bar" },
358 { true, "http://a.com", "http://a.com", "http://a.com#foo=bar" },
359 { true, "http://a.com", "http://a.com/path/to/something", "http://a.com" },
360 { true, "http://a.com", "http://a.com/path/to/something", "http://a.com/ " },
361 { true, "http://a.com", "http://a.com/path/to/something", "http://a.com/ foo" },
362 { true, "http://a.com", "http://a.com/path/to/something", "http://a.com? foo=bar" },
363 { true, "http://a.com", "http://a.com/path/to/something", "http://a.com# foo=bar" },
364 { true, "http://a.com:1337", "http://a.com:1337", "http://a.com:1337" },
365
366 { false, "http://a.com:1337", "http://a.com:1337", "http://a.com:1338" } ,
367 { false, "http://a.com", "http://a.com", "https://a.com" },
368 { false, "http://a.com", "http://a.com", "blob:http://a.com/id" },
369 { false, "http://a.com", "http://a.com", "filesystem:http://a.com/path" },
370 { false, "http://a.com", "http://a.com", "blob:http://b.com/id" },
371 { false, "http://a.com", "http://a.com", "filesystem:http://b.com/path" },
372 { false, "http://a.com", "http://a.com", "about:blank" },
373 { false, "http://a.com", "http://a.com", "about:srcdoc" },
374 { false, "http://a.com", "about:blank", "about:blank" },
375 { false, "http://a.com", "about:srcdoc", "about:srcdoc" },
376 { false, "http://a.com", "data:,", "data:," },
377 { true, "http://a.com", "blob:http://a.com/id", "blob:http://a.com/id" } ,
378 { true, "http://a.com", "filesystem:http://a.com/path", "filesystem:http ://a.com/path" },
379 { false, "http://a.com", "http://a.com", "" },
380 { false, "http://a.com", "", "" },
381
382 { true, "blob:http://a.com/id", "blob:http://a.com/id", "blob:http://a.c om/id" },
383 { false, "blob:http://a.com/id", "blob:http://a.com/id", "http://a.com/i d" },
384 { false, "data:,", "data:,", "http://a.com" },
385 { false, "data:,", "data:,", "data:," },
386
387 { true, "file:///path", "file:///path", "file:///path" },
388 { true, "file:///path", "file:///path", "file:///path2" },
389 { false, "file:///path", "file://domain/path", "file://domain/path" },
390 { true, "file://domain/path", "file://domain/path", "file://domain/path" },
391 { false, "file://domain/path", "file://domain/path", "file:///path" },
392 };
393
394 for (size_t i = 0; i < arraysize(tests); ++i) {
395 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(tests[i ].origin);
396 blink::KURL url1(blink::ParsedURLString, tests[i].url1);
397 blink::KURL url2(blink::ParsedURLString, tests[i].url2);
398 EXPECT_EQ(tests[i].areSamePageUrls, origin->areSamePageUrls(url1, url2)) ;
399 EXPECT_EQ(tests[i].areSamePageUrls, origin->areSamePageUrls(url2, url1)) ;
400 }
401 }
402
344 TEST_F(SecurityOriginTest, EffectivePort) 403 TEST_F(SecurityOriginTest, EffectivePort)
345 { 404 {
346 struct TestCase { 405 struct TestCase {
347 unsigned short port; 406 unsigned short port;
348 unsigned short effectivePort; 407 unsigned short effectivePort;
349 const char* origin; 408 const char* origin;
350 } cases[] = { 409 } cases[] = {
351 {0, 80, "http://example.com"}, 410 {0, 80, "http://example.com"},
352 {0, 80, "http://example.com:80"}, 411 {0, 80, "http://example.com:80"},
353 {81, 81, "http://example.com:81"}, 412 {81, 81, "http://example.com:81"},
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after
412 471
413 KURL blobUrl = BlobURL::createPublicURL(origin.get()); 472 KURL blobUrl = BlobURL::createPublicURL(origin.get());
414 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl); 473 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl);
415 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique()); 474 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique());
416 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString()); 475 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString());
417 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString()); 476 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString());
418 } 477 }
419 } 478 }
420 479
421 } // namespace blink 480 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698