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

Side by Side Diff: third_party/WebKit/Source/web/WebPageProblemDetectorTest.cpp

Issue 2886943003: [Offline Pages] Adding missing image/CSS detection in FrameSerializer. (Closed)
Patch Set: comments from dcheng@. Created 3 years, 6 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
(Empty)
1 /*
2 * Copyright (C) 2017 Google Inc. All rights reserved.
3 *
4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions are
6 * met:
7 *
8 * * Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer.
10 * * Redistributions in binary form must reproduce the above
11 * copyright notice, this list of conditions and the following disclaimer
12 * in the documentation and/or other materials provided with the
13 * distribution.
14 * * Neither the name of Google Inc. nor the names of its
15 * contributors may be used to endorse or promote products derived from
16 * this software without specific prior written permission.
17 *
18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
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.
29 */
30
31 #include "web/WebPageProblemDetector.h"
32
33 #include <utiliy>
34 #include <vector>
35
36 #include "core/dom/Node.h"
37 #include "testing/gtest/include/gtest/gtest.h"
38
39 namespace blink {
40
41 class TestWebPageProblemDetector : public WebPageProblemDetector {
42 public:
43 TestWebPageProblemDetector()
44 : visit_node_called_(false),
45 visiting_done_called_(false),
46 last_visited_node_(nullptr) {}
47
48 void VisitNode(const Node* node) {
49 visit_node_called_ = true;
50 last_visited_node_ = node;
51 }
52
53 void VisitingDone() { visiting_done_called_ = true; }
54
55 bool IsVisitNodeCalled() { return visit_node_called_; }
56 bool IsVisitingDoneCalled() { return visiting_done_called_; }
57 Node* LastVisitedNode() { return last_visited_node_; }
58
59 private:
60 bool visit_node_called_;
61 bool visiting_done_called_;
62 Node* last_visited_node_;
63 }
64
65 TEST_F(WebPageProblemDetectorTest, VisitNode) {
66 WebPageProblemDetectorCollection detectors;
67 std::unique_ptr<TestWebPageProblemDetector> detector_used(
68 new TestWebPageProblemDetector());
69 std::unique_ptr<TestWebPageProblemDetector> detector_unused(
70 new TestWebPageProblemDetector());
71 detectors_.AddDetector(std::move(detector_used));
72
73 Node test_node;
74 detectors.VisitNode(&test_node);
75
76 EXPECT_TRUE(detector_used->IsVisitNodeCalled());
77 EXPECT_FALSE(detector_used->IsVisitingDoneCalled());
78 EXPECT_EQ(test_node, *detector_used->LastVisitedNode());
79
80 EXPECT_FALSE(detector_unused->IsVisitNodeCalled());
81 EXPECT_FALSE(detector_unused->IsVisitingDoneCalled());
82 EXPECT_EQ(nullptr, *detector_unused->LastVisitedNode());
83 }
84
85 TEST_F(WebPageProblemDetectorTest, VisitingDone) {
86 WebPageProblemDetectorCollection detectors;
87 std::unique_ptr<TestWebPageProblemDetector> detector_used(
88 new TestWebPageProblemDetector());
89 std::unique_ptr<TestWebPageProblemDetector> detector_unused(
90 new TestWebPageProblemDetector());
91 detectors_.AddDetector(std::move(detector_used));
92
93 Node test_node;
94 detectors.VisitNode(&test_node);
95
96 EXPECT_TRUE(detector_used->IsVisitNodeCalled());
97 EXPECT_FALSE(detector_used->IsVisitingDoneCalled());
98 EXPECT_EQ(test_node, *detector_used->LastVisitedNode());
99
100 EXPECT_FALSE(detector_unused->IsVisitNodeCalled());
101 EXPECT_FALSE(detector_unused->IsVisitingDoneCalled());
102 EXPECT_EQ(nullptr, *detector_unused->LastVisitedNode());
103
104 detectors.VisitingDone();
105 EXPECT_TRUE(detector_used->IsVisitingDoneCalled());
106 EXPECT_FALSE(detector_unused->IsVisitingDoneCalled());
107 }
108
109 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698