Chromium Code Reviews| Index: third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp |
| diff --git a/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp b/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp |
| index c9f16700d83011311de3b31c057881a96761cb0b..c587a8bca0810a8bd7b03d7f5a9e1d064b9561bb 100644 |
| --- a/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp |
| +++ b/third_party/WebKit/Source/core/frame/csp/SourceListDirectiveTest.cpp |
| @@ -253,8 +253,8 @@ TEST_F(SourceListDirectiveTest, GetIntersectCSPSources) { |
| {"http://*.example1.com/foo/ http://foo.example2.com/bar/", |
| "http://example1.com/foo/ http://foo.example2.com/bar/"}, |
| // Normalizing ports. |
| - {"http://example1.com:80/foo/ http://example2.com/bar/", |
| - "http://example1.com:80/foo/ http://example2.com/bar/"}, |
| + {"http://example1.com/foo/ http://example2.com/bar/", |
| + "http://example1.com/foo/ http://example2.com/bar/"}, |
| {"http://example1.com/foo/ http://example2.com:90/bar/", |
| "http://example1.com/foo/"}, |
| {"http://example1.com:*/foo/ http://example2.com/bar/", |
| @@ -293,4 +293,57 @@ TEST_F(SourceListDirectiveTest, GetIntersectCSPSources) { |
| } |
| } |
| +TEST_F(SourceListDirectiveTest, GetIntersectCSPSourcesSchemes) { |
| + KURL base; |
| + String sources = |
| + "http: http://example1.com/foo/ https://example1.com/foo/ " |
| + "http://example1.com/bar/page.html"; |
| + SourceListDirective sourceList("script-src", sources, csp.get()); |
|
Mike West
2016/11/17 10:58:31
Might as well just inline the source string here.
|
| + struct TestCase { |
| + String sources; |
| + String expected; |
| + } cases[] = { |
| + {"http:", |
| + "http: http://example1.com/foo/ https://example1.com/foo/ " |
| + "http://example1.com/bar/page.html"}, |
| + {"https:", |
| + "https: https://example1.com/foo/ https://example1.com/foo/ " |
| + "https://example1.com/bar/page.html"}, |
| + {"https: http://example1.com/foo/", |
| + "https: http://example1.com/foo/ https://example1.com/foo/ " |
| + "https://example1.com/bar/page.html"}, |
| + {"http://*.example1.com/", |
| + "http://*.example1.com/ http://example1.com/foo/ " |
| + "https://example1.com/foo/ http://example1.com/bar/page.html"}, |
| + {"http://example1.com/foo/ https://example1.com/foo/", |
| + "https://example1.com/foo/ http://example1.com/foo/ " |
| + "https://example1.com/foo/"}, |
| + {"https://example1.com/foo/ https://example1.com/foo/", |
| + "https://example1.com/foo/ https://example1.com/foo/ " |
| + "https://example1.com/foo/"}, |
| + {"https://example1.com/foo/ http://example1.com/foo/", |
| + "http://example1.com/foo/ http://example1.com/foo/ " |
| + "https://example1.com/foo/"}, |
| + }; |
| + |
| + for (const auto& test : cases) { |
| + SourceListDirective secondList("script-src", test.sources, csp.get()); |
| + HeapVector<Member<CSPSource>> normalized = |
| + sourceList.getIntersectCSPSources(secondList.m_list); |
|
Mike West
2016/11/17 10:58:31
This should be symmetric right? Could you add chec
|
| + SourceListDirective helperSourceList("script-src", test.expected, |
| + csp.get()); |
| + HeapVector<Member<CSPSource>> expected = helperSourceList.m_list; |
| + EXPECT_EQ(normalized.size(), expected.size()); |
| + for (size_t i = 0; i < normalized.size(); i++) { |
| + Source a = {normalized[i]->m_scheme, normalized[i]->m_host, |
| + normalized[i]->m_port, normalized[i]->m_path, |
| + normalized[i]->m_hostWildcard, normalized[i]->m_portWildcard}; |
| + Source b = {expected[i]->m_scheme, expected[i]->m_host, |
| + expected[i]->m_port, expected[i]->m_path, |
| + expected[i]->m_hostWildcard, expected[i]->m_portWildcard}; |
| + EXPECT_TRUE(equalSources(a, b)); |
| + } |
| + } |
| +} |
| + |
| } // namespace blink |