OLD | NEW |
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 400 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
411 struct TestCase { | 411 struct TestCase { |
412 const char* scheme; | 412 const char* scheme; |
413 const char* host; | 413 const char* host; |
414 unsigned short port; | 414 unsigned short port; |
415 const char* origin; | 415 const char* origin; |
416 } cases[] = { | 416 } cases[] = { |
417 {"http", "example.com", 80, "http://example.com"}, | 417 {"http", "example.com", 80, "http://example.com"}, |
418 {"http", "example.com", 81, "http://example.com:81"}, | 418 {"http", "example.com", 81, "http://example.com:81"}, |
419 {"https", "example.com", 443, "https://example.com"}, | 419 {"https", "example.com", 443, "https://example.com"}, |
420 {"https", "example.com", 444, "https://example.com:444"}, | 420 {"https", "example.com", 444, "https://example.com:444"}, |
421 {"file", "", 0, "file://"}, | 421 {"file", "", 0, "file:///"}, |
422 {"file", "example.com", 0, "file://"}, | 422 {"file", "example.com", 0, "file:///"}, |
423 }; | 423 }; |
424 | 424 |
425 for (const auto& test : cases) { | 425 for (const auto& test : cases) { |
426 RefPtr<SecurityOrigin> origin = | 426 RefPtr<SecurityOrigin> origin = |
427 SecurityOrigin::create(test.scheme, test.host, test.port); | 427 SecurityOrigin::create(test.scheme, test.host, test.port); |
428 EXPECT_EQ(test.origin, origin->toString()) << test.origin; | 428 EXPECT_EQ(test.origin, origin->toString()) << test.origin; |
429 } | 429 } |
430 } | 430 } |
431 | 431 |
432 TEST_F(SecurityOriginTest, UniquenessPropagatesToBlobUrls) { | 432 TEST_F(SecurityOriginTest, UniquenessPropagatesToBlobUrls) { |
433 struct TestCase { | 433 struct TestCase { |
434 const char* url; | 434 const char* url; |
435 bool expectedUniqueness; | 435 bool expectedUniqueness; |
436 const char* expectedOriginString; | 436 const char* expectedOriginString; |
437 } cases[]{ | 437 } cases[]{ |
438 {"", true, "null"}, | 438 {"", true, "null"}, |
439 {"null", true, "null"}, | 439 {"null", true, "null"}, |
440 {"data:text/plain,hello_world", true, "null"}, | 440 {"data:text/plain,hello_world", true, "null"}, |
441 {"file:///path", false, "file://"}, | 441 {"file:///path", false, "file:///"}, |
442 {"filesystem:http://host/filesystem-path", false, "http://host"}, | 442 {"filesystem:http://host/filesystem-path", false, "http://host"}, |
443 {"filesystem:file:///filesystem-path", false, "file://"}, | 443 {"filesystem:file:///filesystem-path", false, "file:///"}, |
444 {"filesystem:null/filesystem-path", true, "null"}, | 444 {"filesystem:null/filesystem-path", true, "null"}, |
445 {"blob:http://host/blob-id", false, "http://host"}, | 445 {"blob:http://host/blob-id", false, "http://host"}, |
446 {"blob:file:///blob-id", false, "file://"}, | 446 {"blob:file:///blob-id", false, "file:///"}, |
447 {"blob:null/blob-id", true, "null"}, | 447 {"blob:null/blob-id", true, "null"}, |
448 }; | 448 }; |
449 | 449 |
450 for (const TestCase& test : cases) { | 450 for (const TestCase& test : cases) { |
451 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(test.url); | 451 RefPtr<SecurityOrigin> origin = SecurityOrigin::createFromString(test.url); |
452 EXPECT_EQ(test.expectedUniqueness, origin->isUnique()); | 452 EXPECT_EQ(test.expectedUniqueness, origin->isUnique()); |
453 EXPECT_EQ(test.expectedOriginString, origin->toString()); | 453 EXPECT_EQ(test.expectedOriginString, origin->toString()); |
454 | 454 |
455 KURL blobUrl = BlobURL::createPublicURL(origin.get()); | 455 KURL blobUrl = BlobURL::createPublicURL(origin.get()); |
456 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl); | 456 RefPtr<SecurityOrigin> blobUrlOrigin = SecurityOrigin::create(blobUrl); |
457 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique()); | 457 EXPECT_EQ(blobUrlOrigin->isUnique(), origin->isUnique()); |
458 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString()); | 458 EXPECT_EQ(blobUrlOrigin->toString(), origin->toString()); |
459 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString()); | 459 EXPECT_EQ(blobUrlOrigin->toRawString(), origin->toRawString()); |
460 } | 460 } |
461 } | 461 } |
462 | 462 |
463 TEST_F(SecurityOriginTest, UniqueOriginIsSameSchemeHostPort) { | 463 TEST_F(SecurityOriginTest, UniqueOriginIsSameSchemeHostPort) { |
464 RefPtr<SecurityOrigin> uniqueOrigin = SecurityOrigin::createUnique(); | 464 RefPtr<SecurityOrigin> uniqueOrigin = SecurityOrigin::createUnique(); |
465 RefPtr<SecurityOrigin> tupleOrigin = | 465 RefPtr<SecurityOrigin> tupleOrigin = |
466 SecurityOrigin::createFromString("http://example.com"); | 466 SecurityOrigin::createFromString("http://example.com"); |
467 | 467 |
468 EXPECT_TRUE(uniqueOrigin->isSameSchemeHostPort(uniqueOrigin.get())); | 468 EXPECT_TRUE(uniqueOrigin->isSameSchemeHostPort(uniqueOrigin.get())); |
469 EXPECT_FALSE( | 469 EXPECT_FALSE( |
470 SecurityOrigin::createUnique()->isSameSchemeHostPort(uniqueOrigin.get())); | 470 SecurityOrigin::createUnique()->isSameSchemeHostPort(uniqueOrigin.get())); |
471 EXPECT_FALSE(tupleOrigin->isSameSchemeHostPort(uniqueOrigin.get())); | 471 EXPECT_FALSE(tupleOrigin->isSameSchemeHostPort(uniqueOrigin.get())); |
472 EXPECT_FALSE(uniqueOrigin->isSameSchemeHostPort(tupleOrigin.get())); | 472 EXPECT_FALSE(uniqueOrigin->isSameSchemeHostPort(tupleOrigin.get())); |
473 } | 473 } |
474 | 474 |
475 } // namespace blink | 475 } // namespace blink |
OLD | NEW |