| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "public/platform/WebDocumentSubresourceFilter.h" | 5 #include "public/platform/WebDocumentSubresourceFilter.h" |
| 6 | 6 |
| 7 #include "core/dom/Element.h" | 7 #include "core/dom/Element.h" |
| 8 #include "core/html/HTMLImageElement.h" | 8 #include "core/html/HTMLImageElement.h" |
| 9 #include "platform/testing/URLTestHelpers.h" | 9 #include "platform/testing/URLTestHelpers.h" |
| 10 #include "platform/testing/UnitTestHelpers.h" | 10 #include "platform/testing/UnitTestHelpers.h" |
| 11 #include "public/platform/Platform.h" | 11 #include "public/platform/Platform.h" |
| 12 #include "public/platform/WebCache.h" | 12 #include "public/platform/WebCache.h" |
| 13 #include "public/platform/WebDocumentSubresourceFilterLoadPolicy.h" |
| 13 #include "public/platform/WebURLLoaderMockFactory.h" | 14 #include "public/platform/WebURLLoaderMockFactory.h" |
| 14 #include "public/web/WebDocument.h" | 15 #include "public/web/WebDocument.h" |
| 15 #include "public/web/WebElement.h" | 16 #include "public/web/WebElement.h" |
| 16 #include "public/web/WebLocalFrame.h" | 17 #include "public/web/WebLocalFrame.h" |
| 17 #include "testing/gmock/include/gmock/gmock.h" | 18 #include "testing/gmock/include/gmock/gmock.h" |
| 18 #include "testing/gtest/include/gtest/gtest.h" | 19 #include "testing/gtest/include/gtest/gtest.h" |
| 19 #include "web/tests/FrameTestHelpers.h" | 20 #include "web/tests/FrameTestHelpers.h" |
| 20 | 21 |
| 21 namespace blink { | 22 namespace blink { |
| 22 | 23 |
| 23 namespace { | 24 namespace { |
| 24 | 25 |
| 25 class TestDocumentSubresourceFilter : public WebDocumentSubresourceFilter { | 26 class TestDocumentSubresourceFilter : public WebDocumentSubresourceFilter { |
| 26 public: | 27 public: |
| 27 explicit TestDocumentSubresourceFilter(bool allowLoads) | 28 explicit TestDocumentSubresourceFilter(bool allowLoads) |
| 28 : m_allowLoads(allowLoads) {} | 29 : m_allowLoads(allowLoads) {} |
| 29 | 30 |
| 30 LoadPolicy getLoadPolicy(const WebURL& resourceUrl, | 31 WebDocumentSubresourceFilterLoadPolicy getLoadPolicy( |
| 31 WebURLRequest::RequestContext) override { | 32 const WebURL& resourceUrl, |
| 33 WebURLRequest::RequestContext) override { |
| 32 std::string resourcePath = WebString(KURL(resourceUrl).path()).utf8(); | 34 std::string resourcePath = WebString(KURL(resourceUrl).path()).utf8(); |
| 33 if (std::find(m_queriedSubresourcePaths.begin(), | 35 if (std::find(m_queriedSubresourcePaths.begin(), |
| 34 m_queriedSubresourcePaths.end(), | 36 m_queriedSubresourcePaths.end(), |
| 35 resourcePath) == m_queriedSubresourcePaths.end()) | 37 resourcePath) == m_queriedSubresourcePaths.end()) |
| 36 m_queriedSubresourcePaths.push_back(resourcePath); | 38 m_queriedSubresourcePaths.push_back(resourcePath); |
| 37 return m_allowLoads ? Allow : Disallow; | 39 return m_allowLoads ? WebDocumentSubresourceFilterLoadPolicy::Allow |
| 40 : WebDocumentSubresourceFilterLoadPolicy::Disallow; |
| 38 } | 41 } |
| 39 | 42 |
| 40 void reportDisallowedLoad() override {} | 43 void reportDisallowedLoad() override {} |
| 41 | 44 |
| 42 const std::vector<std::string>& queriedSubresourcePaths() const { | 45 const std::vector<std::string>& queriedSubresourcePaths() const { |
| 43 return m_queriedSubresourcePaths; | 46 return m_queriedSubresourcePaths; |
| 44 } | 47 } |
| 45 | 48 |
| 46 private: | 49 private: |
| 47 std::vector<std::string> m_queriedSubresourcePaths; | 50 std::vector<std::string> m_queriedSubresourcePaths; |
| (...skipping 96 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 loadDocument(!allowSubresources); | 147 loadDocument(!allowSubresources); |
| 145 expectSubresourceWasLoaded(!allowSubresources); | 148 expectSubresourceWasLoaded(!allowSubresources); |
| 146 EXPECT_THAT(queriedSubresourcePaths(), | 149 EXPECT_THAT(queriedSubresourcePaths(), |
| 147 ::testing::ElementsAre("/white-1x1.png")); | 150 ::testing::ElementsAre("/white-1x1.png")); |
| 148 | 151 |
| 149 WebCache::clear(); | 152 WebCache::clear(); |
| 150 } | 153 } |
| 151 } | 154 } |
| 152 | 155 |
| 153 } // namespace blink | 156 } // namespace blink |
| OLD | NEW |