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

Side by Side Diff: Source/web/tests/WebPageSerializerTest.cpp

Issue 1295063002: Revert "Remove old serializer" It caused a regression, crbug.com/510422 (Closed) Base URL: svn://svn.chromium.org/blink/trunk
Patch Set: Created 5 years, 4 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 | Annotate | Revision Log
OLDNEW
(Empty)
1 /*
2 * Copyright (C) 2011 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 "config.h"
32 #include "public/web/WebPageSerializer.h"
33
34 #include "platform/testing/URLTestHelpers.h"
35 #include "public/platform/Platform.h"
36 #include "public/platform/WebString.h"
37 #include "public/platform/WebURL.h"
38 #include "public/platform/WebURLRequest.h"
39 #include "public/platform/WebURLResponse.h"
40 #include "public/platform/WebUnitTestSupport.h"
41 #include "public/web/WebDocument.h"
42 #include "public/web/WebFrame.h"
43 #include "public/web/WebView.h"
44 #include "web/tests/FrameTestHelpers.h"
45 #include <gtest/gtest.h>
46
47 using blink::Document;
48 using blink::URLTestHelpers::toKURL;
49
50 namespace blink {
51
52 class WebPageSerializerTest : public testing::Test {
53 public:
54 WebPageSerializerTest() : m_supportedSchemes(static_cast<size_t>(3))
55 {
56 m_supportedSchemes[0] = "http";
57 m_supportedSchemes[1] = "https";
58 m_supportedSchemes[2] = "file";
59 }
60
61 protected:
62 void SetUp() override
63 {
64 m_helper.initialize();
65 }
66
67 void TearDown() override
68 {
69 Platform::current()->unitTestSupport()->unregisterAllMockedURLs();
70 }
71
72 void registerMockedURLLoad(const std::string& url, const WebString& fileName )
73 {
74 URLTestHelpers::registerMockedURLLoad(toKURL(url), fileName, WebString:: fromUTF8("pageserialization/"), WebString::fromUTF8("text/html"));
75 }
76
77 void loadURLInTopFrame(const WebURL& url)
78 {
79 FrameTestHelpers::loadFrame(m_helper.webView()->mainFrame(), url.string( ).utf8());
80 }
81
82 static bool webVectorContains(const WebVector<WebURL>& vector, const char* u rl)
83 {
84 return vector.contains(WebURL(toKURL(std::string(url))));
85 }
86
87 // Useful for debugging.
88 static void printWebURLs(const WebVector<WebURL>& urls)
89 {
90 for (size_t i = 0; i < urls.size(); i++)
91 printf("%s\n", urls[i].spec().data());
92 }
93
94 WebView* webView() const { return m_helper.webView(); }
95
96 WebVector<WebCString> m_supportedSchemes;
97
98 private:
99 FrameTestHelpers::WebViewHelper m_helper;
100 };
101
102 TEST_F(WebPageSerializerTest, HTMLNodes)
103 {
104 // Register the mocked frame and load it.
105 WebURL topFrameURL = toKURL("http://www.test.com");
106 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("simple_pag e.html"));
107 registerMockedURLLoad("http://www.example.com/beautifull.css", WebString::fr omUTF8("beautifull.css"));
108 loadURLInTopFrame(topFrameURL);
109
110 // Retrieve all resources.
111 WebVector<WebURL> frames;
112 WebVector<WebURL> resources;
113 ASSERT_TRUE(WebPageSerializer::retrieveAllResources(
114 webView(), m_supportedSchemes, &resources, &frames));
115
116 // Tests that all resources from the frame have been retrieved.
117 EXPECT_EQ(1U, frames.size()); // There should be no duplicates.
118 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com"));
119
120 EXPECT_EQ(14U, resources.size()); // There should be no duplicates.
121 EXPECT_TRUE(webVectorContains(resources, "http://www.example.com/beautifull. css"));
122 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/awesome.js"));
123 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/bodyBackground .jpg"));
124 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/awesome.png")) ;
125 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/imageButton.pn g"));
126 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/tableBackgroun d.png"));
127 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/trBackground.p ng"));
128 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/tdBackground.p ng"));
129 EXPECT_TRUE(webVectorContains(resources, "http://www.evene.fr/citations/aute ur.php?ida=46"));
130 EXPECT_TRUE(webVectorContains(resources, "http://www.brainyquote.com/quotes/ authors/c/charles_darwin.html"));
131 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_deleted.ht ml"));
132 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_inserted.h tml"));
133 EXPECT_TRUE(webVectorContains(resources, "https://www.secure.com/https.gif") );
134 EXPECT_TRUE(webVectorContains(resources, "file://c/my_folder/file.gif"));
135 }
136
137 TEST_F(WebPageSerializerTest, MultipleFrames)
138 {
139 // Register the mocked frames.
140 WebURL topFrameURL = toKURL("http://www.test.com");
141 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("top_frame. html"));
142 registerMockedURLLoad("http://www.test.com/simple_iframe.html",
143 WebString::fromUTF8("simple_iframe.html"));
144 registerMockedURLLoad("http://www.test.com/object_iframe.html",
145 WebString::fromUTF8("object_iframe.html"));
146 registerMockedURLLoad("http://www.test.com/embed_iframe.html",
147 WebString::fromUTF8("embed_iframe.html"));
148 // If we don't register a mocked resource for awesome.png, it causes the
149 // document loader of the iframe that has it as its src to assert on close,
150 // not sure why.
151 registerMockedURLLoad("http://www.test.com/awesome.png",
152 WebString::fromUTF8("awesome.png"));
153
154 loadURLInTopFrame(topFrameURL);
155
156 // Retrieve all resources.
157 WebVector<WebURL> frames;
158 WebVector<WebURL> resources;
159 ASSERT_TRUE(WebPageSerializer::retrieveAllResources(
160 webView(), m_supportedSchemes, &resources, &frames));
161
162 // Tests that all resources from the frame have been retrieved.
163 EXPECT_EQ(4U, frames.size()); // There should be no duplicates.
164 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com"));
165 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/simple_iframe.htm l"));
166 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/object_iframe.htm l"));
167 EXPECT_TRUE(webVectorContains(frames, "http://www.test.com/embed_iframe.html "));
168
169 EXPECT_EQ(5U, resources.size()); // There should be no duplicates.
170 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/awesome.png")) ;
171 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/innerFrame.png "));
172 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/flash.swf"));
173 // FIXME: for some reason the following resources is missing on one of the b ot
174 // causing the test to fail. Probably a plugin issue.
175 // EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/music.mid") );
176 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/object.png"));
177 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/embed.png"));
178 }
179
180 } // namespace blink
OLDNEW
« no previous file with comments | « Source/web/WebPageSerializerImpl.cpp ('k') | Source/web/tests/data/pageserialization/awesome.png » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698