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

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

Issue 2332263002: Updated suborigin serialization to latest spec proposal (Closed)
Patch Set: Fix unit tests Created 4 years, 3 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 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 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 16 matching lines...) Expand all
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
29 */ 29 */
30 30
31 // Basic tests that verify our KURL's interface behaves the same as the 31 // Basic tests that verify our KURL's interface behaves the same as the
32 // original KURL's. 32 // original KURL's.
33 33
34 #include "platform/weborigin/KURL.h" 34 #include "platform/weborigin/KURL.h"
35 35
36 #include "testing/gtest/include/gtest/gtest.h" 36 #include "testing/gtest/include/gtest/gtest.h"
37 #include "url/url_util.h"
37 #include "wtf/StdLibExtras.h" 38 #include "wtf/StdLibExtras.h"
38 #include "wtf/text/CString.h" 39 #include "wtf/text/CString.h"
39 #include "wtf/text/WTFString.h" 40 #include "wtf/text/WTFString.h"
40 41
41 namespace blink { 42 namespace blink {
42 43
43 struct ComponentCase { 44 struct ComponentCase {
44 const char* url; 45 const char* url;
45 const char* protocol; 46 const char* protocol;
46 const char* host; 47 const char* host;
(...skipping 369 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 EXPECT_STREQ("http://www.google.com:8000/favicon.ico", kurl.getString().utf8 ().data()); 417 EXPECT_STREQ("http://www.google.com:8000/favicon.ico", kurl.getString().utf8 ().data());
417 418
418 // Now let's test that giving an invalid replacement fails. Invalid 419 // Now let's test that giving an invalid replacement fails. Invalid
419 // protocols fail without modifying the URL, which should remain valid. 420 // protocols fail without modifying the URL, which should remain valid.
420 EXPECT_FALSE(kurl.setProtocol("f/sj#@")); 421 EXPECT_FALSE(kurl.setProtocol("f/sj#@"));
421 EXPECT_TRUE(kurl.isValid()); 422 EXPECT_TRUE(kurl.isValid());
422 } 423 }
423 424
424 TEST(KURLTest, Valid_HTTP_FTP_URLsHaveHosts) 425 TEST(KURLTest, Valid_HTTP_FTP_URLsHaveHosts)
425 { 426 {
427 // Since the suborigin schemes are added at the content layer, its
428 // necessary it explicitly add them as standard schemes for this test. If
429 // this is needed in the future across mulitple KURLTests, then KURLTest
430 // should probably be converted to a test fixture with a proper SetUp()
431 // method.
432 url::AddStandardScheme("http-so", url::SCHEME_WITH_PORT);
433 url::AddStandardScheme("https-so", url::SCHEME_WITH_PORT);
434
426 KURL kurl; 435 KURL kurl;
427 EXPECT_TRUE(kurl.setProtocol("http")); 436 EXPECT_TRUE(kurl.setProtocol("http"));
428 EXPECT_TRUE(kurl.protocolIs("http")); 437 EXPECT_TRUE(kurl.protocolIs("http"));
429 EXPECT_FALSE(kurl.isValid()); 438 EXPECT_FALSE(kurl.isValid());
430 439
440 EXPECT_TRUE(kurl.setProtocol("http-so"));
441 EXPECT_TRUE(kurl.protocolIs("http-so"));
442 EXPECT_FALSE(kurl.isValid());
443
431 EXPECT_TRUE(kurl.setProtocol("https")); 444 EXPECT_TRUE(kurl.setProtocol("https"));
432 EXPECT_TRUE(kurl.protocolIs("https")); 445 EXPECT_TRUE(kurl.protocolIs("https"));
433 EXPECT_FALSE(kurl.isValid()); 446 EXPECT_FALSE(kurl.isValid());
434 447
448 EXPECT_TRUE(kurl.setProtocol("https-so"));
449 EXPECT_TRUE(kurl.protocolIs("https-so"));
450 EXPECT_FALSE(kurl.isValid());
451
435 EXPECT_TRUE(kurl.setProtocol("ftp")); 452 EXPECT_TRUE(kurl.setProtocol("ftp"));
436 EXPECT_TRUE(kurl.protocolIs("ftp")); 453 EXPECT_TRUE(kurl.protocolIs("ftp"));
437 EXPECT_FALSE(kurl.isValid()); 454 EXPECT_FALSE(kurl.isValid());
438 455
439 kurl = KURL(KURL(), "http://"); 456 kurl = KURL(KURL(), "http://");
440 EXPECT_TRUE(kurl.protocolIs("http")); 457 EXPECT_TRUE(kurl.protocolIs("http"));
441 EXPECT_FALSE(kurl.isValid()); 458 EXPECT_FALSE(kurl.isValid());
442 459
460 kurl = KURL(KURL(), "http-so://");
461 EXPECT_TRUE(kurl.protocolIs("http-so"));
462 EXPECT_FALSE(kurl.isValid());
463
443 kurl = KURL(KURL(), "https://"); 464 kurl = KURL(KURL(), "https://");
444 EXPECT_TRUE(kurl.protocolIs("https")); 465 EXPECT_TRUE(kurl.protocolIs("https"));
445 EXPECT_FALSE(kurl.isValid()); 466 EXPECT_FALSE(kurl.isValid());
446 467
468 kurl = KURL(KURL(), "https-so://");
469 EXPECT_TRUE(kurl.protocolIs("https-so"));
470 EXPECT_FALSE(kurl.isValid());
471
447 kurl = KURL(KURL(), "ftp://"); 472 kurl = KURL(KURL(), "ftp://");
448 EXPECT_TRUE(kurl.protocolIs("ftp")); 473 EXPECT_TRUE(kurl.protocolIs("ftp"));
449 EXPECT_FALSE(kurl.isValid()); 474 EXPECT_FALSE(kurl.isValid());
450 475
451 kurl = KURL(KURL(), "http://host/"); 476 kurl = KURL(KURL(), "http://host/");
452 EXPECT_TRUE(kurl.isValid()); 477 EXPECT_TRUE(kurl.isValid());
453 kurl.setHost(""); 478 kurl.setHost("");
454 EXPECT_FALSE(kurl.isValid()); 479 EXPECT_FALSE(kurl.isValid());
455 480
481 kurl = KURL(KURL(), "http-so://host/");
482 EXPECT_TRUE(kurl.isValid());
483 kurl.setHost("");
484 EXPECT_FALSE(kurl.isValid());
485
456 kurl = KURL(KURL(), "https://host/"); 486 kurl = KURL(KURL(), "https://host/");
457 EXPECT_TRUE(kurl.isValid()); 487 EXPECT_TRUE(kurl.isValid());
458 kurl.setHost(""); 488 kurl.setHost("");
459 EXPECT_FALSE(kurl.isValid()); 489 EXPECT_FALSE(kurl.isValid());
460 490
491 kurl = KURL(KURL(), "https-so://host/");
492 EXPECT_TRUE(kurl.isValid());
493 kurl.setHost("");
494 EXPECT_FALSE(kurl.isValid());
495
461 kurl = KURL(KURL(), "ftp://host/"); 496 kurl = KURL(KURL(), "ftp://host/");
462 EXPECT_TRUE(kurl.isValid()); 497 EXPECT_TRUE(kurl.isValid());
463 kurl.setHost(""); 498 kurl.setHost("");
464 EXPECT_FALSE(kurl.isValid()); 499 EXPECT_FALSE(kurl.isValid());
465 500
466 kurl = KURL(KURL(), "http:///noodles/pho.php"); 501 kurl = KURL(KURL(), "http:///noodles/pho.php");
467 EXPECT_STREQ("http://noodles/pho.php", kurl.getString().utf8().data()); 502 EXPECT_STREQ("http://noodles/pho.php", kurl.getString().utf8().data());
468 EXPECT_STREQ("noodles", kurl.host().utf8().data()); 503 EXPECT_STREQ("noodles", kurl.host().utf8().data());
469 EXPECT_TRUE(kurl.isValid()); 504 EXPECT_TRUE(kurl.isValid());
470 505
(...skipping 291 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 }; 797 };
763 798
764 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrerCases); i++) { 799 for (size_t i = 0; i < WTF_ARRAY_LENGTH(referrerCases); i++) {
765 KURL kurl(ParsedURLString, referrerCases[i].input); 800 KURL kurl(ParsedURLString, referrerCases[i].input);
766 String referrer = kurl.strippedForUseAsReferrer(); 801 String referrer = kurl.strippedForUseAsReferrer();
767 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data()); 802 EXPECT_STREQ(referrerCases[i].output, referrer.utf8().data());
768 } 803 }
769 } 804 }
770 805
771 } // namespace blink 806 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698