Index: third_party/WebKit/Source/web/WebPageProblemDetectorTest.cpp |
diff --git a/third_party/WebKit/Source/web/WebPageProblemDetectorTest.cpp b/third_party/WebKit/Source/web/WebPageProblemDetectorTest.cpp |
new file mode 100644 |
index 0000000000000000000000000000000000000000..8039be82ed79ec4c934a0efb996e5e2b93ce4efc |
--- /dev/null |
+++ b/third_party/WebKit/Source/web/WebPageProblemDetectorTest.cpp |
@@ -0,0 +1,109 @@ |
+/* |
+ * Copyright (C) 2017 Google Inc. All rights reserved. |
+ * |
+ * Redistribution and use in source and binary forms, with or without |
+ * modification, are permitted provided that the following conditions are |
+ * met: |
+ * |
+ * * Redistributions of source code must retain the above copyright |
+ * notice, this list of conditions and the following disclaimer. |
+ * * Redistributions in binary form must reproduce the above |
+ * copyright notice, this list of conditions and the following disclaimer |
+ * in the documentation and/or other materials provided with the |
+ * distribution. |
+ * * Neither the name of Google Inc. nor the names of its |
+ * contributors may be used to endorse or promote products derived from |
+ * this software without specific prior written permission. |
+ * |
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
+ * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
+ * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
+ * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
+ * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
+ * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
+ * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
+ * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
+ */ |
+ |
+#include "web/WebPageProblemDetector.h" |
+ |
+#include <utiliy> |
+#include <vector> |
+ |
+#include "core/dom/Node.h" |
+#include "testing/gtest/include/gtest/gtest.h" |
+ |
+namespace blink { |
+ |
+class TestWebPageProblemDetector : public WebPageProblemDetector { |
+ public: |
+ TestWebPageProblemDetector() |
+ : visit_node_called_(false), |
+ visiting_done_called_(false), |
+ last_visited_node_(nullptr) {} |
+ |
+ void VisitNode(const Node* node) { |
+ visit_node_called_ = true; |
+ last_visited_node_ = node; |
+ } |
+ |
+ void VisitingDone() { visiting_done_called_ = true; } |
+ |
+ bool IsVisitNodeCalled() { return visit_node_called_; } |
+ bool IsVisitingDoneCalled() { return visiting_done_called_; } |
+ Node* LastVisitedNode() { return last_visited_node_; } |
+ |
+ private: |
+ bool visit_node_called_; |
+ bool visiting_done_called_; |
+ Node* last_visited_node_; |
+} |
+ |
+TEST_F(WebPageProblemDetectorTest, VisitNode) { |
+ WebPageProblemDetectorCollection detectors; |
+ std::unique_ptr<TestWebPageProblemDetector> detector_used( |
+ new TestWebPageProblemDetector()); |
+ std::unique_ptr<TestWebPageProblemDetector> detector_unused( |
+ new TestWebPageProblemDetector()); |
+ detectors_.AddDetector(std::move(detector_used)); |
+ |
+ Node test_node; |
+ detectors.VisitNode(&test_node); |
+ |
+ EXPECT_TRUE(detector_used->IsVisitNodeCalled()); |
+ EXPECT_FALSE(detector_used->IsVisitingDoneCalled()); |
+ EXPECT_EQ(test_node, *detector_used->LastVisitedNode()); |
+ |
+ EXPECT_FALSE(detector_unused->IsVisitNodeCalled()); |
+ EXPECT_FALSE(detector_unused->IsVisitingDoneCalled()); |
+ EXPECT_EQ(nullptr, *detector_unused->LastVisitedNode()); |
+} |
+ |
+TEST_F(WebPageProblemDetectorTest, VisitingDone) { |
+ WebPageProblemDetectorCollection detectors; |
+ std::unique_ptr<TestWebPageProblemDetector> detector_used( |
+ new TestWebPageProblemDetector()); |
+ std::unique_ptr<TestWebPageProblemDetector> detector_unused( |
+ new TestWebPageProblemDetector()); |
+ detectors_.AddDetector(std::move(detector_used)); |
+ |
+ Node test_node; |
+ detectors.VisitNode(&test_node); |
+ |
+ EXPECT_TRUE(detector_used->IsVisitNodeCalled()); |
+ EXPECT_FALSE(detector_used->IsVisitingDoneCalled()); |
+ EXPECT_EQ(test_node, *detector_used->LastVisitedNode()); |
+ |
+ EXPECT_FALSE(detector_unused->IsVisitNodeCalled()); |
+ EXPECT_FALSE(detector_unused->IsVisitingDoneCalled()); |
+ EXPECT_EQ(nullptr, *detector_unused->LastVisitedNode()); |
+ |
+ detectors.VisitingDone(); |
+ EXPECT_TRUE(detector_used->IsVisitingDoneCalled()); |
+ EXPECT_FALSE(detector_unused->IsVisitingDoneCalled()); |
+} |
+ |
+} // namespace blink |