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

Side by Side Diff: third_party/WebKit/Source/core/frame/csp/CSPSourceTest.cpp

Issue 2585283002: Migrate WTF::Vector::append() to ::push_back() [part 6 of N] (Closed)
Patch Set: Created 3 years, 12 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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 "core/frame/csp/CSPSource.h" 5 #include "core/frame/csp/CSPSource.h"
6 6
7 #include "core/dom/Document.h" 7 #include "core/dom/Document.h"
8 #include "core/frame/csp/ContentSecurityPolicy.h" 8 #include "core/frame/csp/ContentSecurityPolicy.h"
9 #include "platform/network/ResourceRequest.h" 9 #include "platform/network/ResourceRequest.h"
10 #include "platform/weborigin/KURL.h" 10 #include "platform/weborigin/KURL.h"
(...skipping 525 matching lines...) Expand 10 before | Expand all | Expand 10 after
536 new CSPSource(csp.get(), "http", "", 0, "", CSPSource::NoWildcard, 536 new CSPSource(csp.get(), "http", "", 0, "", CSPSource::NoWildcard,
537 CSPSource::NoWildcard); 537 CSPSource::NoWildcard);
538 CSPSource* httpsOnly = 538 CSPSource* httpsOnly =
539 new CSPSource(csp.get(), "https", "", 0, "", CSPSource::NoWildcard, 539 new CSPSource(csp.get(), "https", "", 0, "", CSPSource::NoWildcard,
540 CSPSource::NoWildcard); 540 CSPSource::NoWildcard);
541 541
542 for (const auto& test : cases) { 542 for (const auto& test : cases) {
543 // Setup default vectors. 543 // Setup default vectors.
544 HeapVector<Member<CSPSource>> listA; 544 HeapVector<Member<CSPSource>> listA;
545 HeapVector<Member<CSPSource>> listB; 545 HeapVector<Member<CSPSource>> listB;
546 listB.append(noWildcards); 546 listB.push_back(noWildcards);
547 // Empty `listA` implies `none` is allowed. 547 // Empty `listA` implies `none` is allowed.
548 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB)); 548 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB));
549 549
550 listA.append(noWildcards); 550 listA.push_back(noWildcards);
551 // Add CSPSources based on the current test. 551 // Add CSPSources based on the current test.
552 listB.append(new CSPSource(csp.get(), test.sourceB.scheme, 552 listB.push_back(new CSPSource(
553 test.sourceB.host, 0, test.sourceB.path, 553 csp.get(), test.sourceB.scheme, test.sourceB.host, 0, test.sourceB.path,
554 CSPSource::NoWildcard, CSPSource::NoWildcard)); 554 CSPSource::NoWildcard, CSPSource::NoWildcard));
555 listA.append(new CSPSource(csp.get(), test.schemeA, "second-example.com", 0, 555 listA.push_back(new CSPSource(csp.get(), test.schemeA, "second-example.com",
556 "/", CSPSource::NoWildcard, 556 0, "/", CSPSource::NoWildcard,
557 CSPSource::NoWildcard)); 557 CSPSource::NoWildcard));
558 // listB contains: ["http://example.com/", test.listB] 558 // listB contains: ["http://example.com/", test.listB]
559 // listA contains: ["http://example.com/", 559 // listA contains: ["http://example.com/",
560 // test.schemeA + "://second-example.com/"] 560 // test.schemeA + "://second-example.com/"]
561 EXPECT_EQ(test.expected, CSPSource::firstSubsumesSecond(listA, listB)); 561 EXPECT_EQ(test.expected, CSPSource::firstSubsumesSecond(listA, listB));
562 562
563 // If we add another source to `listB` with a host wildcard, 563 // If we add another source to `listB` with a host wildcard,
564 // then the result should definitely be false. 564 // then the result should definitely be false.
565 listB.append(hostWildcard); 565 listB.push_back(hostWildcard);
566 566
567 // If we add another source to `listA` with a port wildcard, 567 // If we add another source to `listA` with a port wildcard,
568 // it does not make `listB` to be subsumed under `listA`. 568 // it does not make `listB` to be subsumed under `listA`.
569 listB.append(portWildcard); 569 listB.push_back(portWildcard);
570 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB)); 570 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB));
571 571
572 // If however we add another source to `listA` with both wildcards, 572 // If however we add another source to `listA` with both wildcards,
573 // that CSPSource is subsumed, so the answer should be as expected 573 // that CSPSource is subsumed, so the answer should be as expected
574 // before. 574 // before.
575 listA.append(bothWildcards); 575 listA.push_back(bothWildcards);
576 EXPECT_EQ(test.expected, CSPSource::firstSubsumesSecond(listA, listB)); 576 EXPECT_EQ(test.expected, CSPSource::firstSubsumesSecond(listA, listB));
577 577
578 // If we add a scheme-source expression of 'https' to `listB`, then it 578 // If we add a scheme-source expression of 'https' to `listB`, then it
579 // should not be subsumed. 579 // should not be subsumed.
580 listB.append(httpsOnly); 580 listB.push_back(httpsOnly);
581 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB)); 581 EXPECT_FALSE(CSPSource::firstSubsumesSecond(listA, listB));
582 582
583 // If we add a scheme-source expression of 'http' to `listA`, then it should 583 // If we add a scheme-source expression of 'http' to `listA`, then it should
584 // subsume all current epxression in `listB`. 584 // subsume all current epxression in `listB`.
585 listA.append(httpOnly); 585 listA.push_back(httpOnly);
586 EXPECT_TRUE(CSPSource::firstSubsumesSecond(listA, listB)); 586 EXPECT_TRUE(CSPSource::firstSubsumesSecond(listA, listB));
587 } 587 }
588 } 588 }
589 589
590 TEST_F(CSPSourceTest, Intersect) { 590 TEST_F(CSPSourceTest, Intersect) {
591 struct TestCase { 591 struct TestCase {
592 const Source a; 592 const Source a;
593 const Source b; 593 const Source b;
594 const Source normalized; 594 const Source normalized;
595 } cases[] = { 595 } cases[] = {
(...skipping 184 matching lines...) Expand 10 before | Expand all | Expand 10 after
780 normalized = B->intersect(A); 780 normalized = B->intersect(A);
781 Source intersectBA = { 781 Source intersectBA = {
782 normalized->m_scheme, normalized->m_host, 782 normalized->m_scheme, normalized->m_host,
783 normalized->m_path, normalized->m_port, 783 normalized->m_path, normalized->m_port,
784 normalized->m_hostWildcard, normalized->m_portWildcard}; 784 normalized->m_hostWildcard, normalized->m_portWildcard};
785 EXPECT_TRUE(equalSources(intersectBA, test.normalized)); 785 EXPECT_TRUE(equalSources(intersectBA, test.normalized));
786 } 786 }
787 } 787 }
788 788
789 } // namespace blink 789 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698