| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 Google Inc. All rights reserved. |
| 3 * | 3 * |
| 4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
| 5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
| 6 * met: | 6 * met: |
| 7 * | 7 * |
| 8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
| 9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
| 10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
| (...skipping 22 matching lines...) Expand all Loading... |
| 33 | 33 |
| 34 #include "platform/testing/URLTestHelpers.h" | 34 #include "platform/testing/URLTestHelpers.h" |
| 35 #include "public/platform/Platform.h" | 35 #include "public/platform/Platform.h" |
| 36 #include "public/platform/WebString.h" | 36 #include "public/platform/WebString.h" |
| 37 #include "public/platform/WebURL.h" | 37 #include "public/platform/WebURL.h" |
| 38 #include "public/platform/WebURLRequest.h" | 38 #include "public/platform/WebURLRequest.h" |
| 39 #include "public/platform/WebURLResponse.h" | 39 #include "public/platform/WebURLResponse.h" |
| 40 #include "public/platform/WebUnitTestSupport.h" | 40 #include "public/platform/WebUnitTestSupport.h" |
| 41 #include "public/web/WebDocument.h" | 41 #include "public/web/WebDocument.h" |
| 42 #include "public/web/WebFrame.h" | 42 #include "public/web/WebFrame.h" |
| 43 #include "public/web/WebPageSerializerClient.h" |
| 43 #include "public/web/WebView.h" | 44 #include "public/web/WebView.h" |
| 44 #include "web/tests/FrameTestHelpers.h" | 45 #include "web/tests/FrameTestHelpers.h" |
| 45 #include <gtest/gtest.h> | 46 #include <gtest/gtest.h> |
| 46 | 47 |
| 47 using blink::Document; | 48 using blink::Document; |
| 48 using blink::URLTestHelpers::toKURL; | 49 using blink::URLTestHelpers::toKURL; |
| 49 | 50 |
| 50 namespace blink { | 51 namespace blink { |
| 51 | 52 |
| 53 namespace { |
| 54 class SimpleWebPageSerializerClient : public WebPageSerializerClient { |
| 55 public: |
| 56 std::string toString() const { return m_string; } |
| 57 |
| 58 private: |
| 59 void didSerializeDataForFrame(const WebURL&, const WebCString& data, PageSer
ializationStatus) final |
| 60 { |
| 61 m_string += data; |
| 62 } |
| 63 |
| 64 std::string m_string; |
| 65 }; |
| 66 |
| 67 } // namespace |
| 68 |
| 52 class WebPageSerializerTest : public testing::Test { | 69 class WebPageSerializerTest : public testing::Test { |
| 53 public: | 70 public: |
| 54 WebPageSerializerTest() : m_supportedSchemes(static_cast<size_t>(3)) | 71 WebPageSerializerTest() : m_supportedSchemes(static_cast<size_t>(3)) |
| 55 { | 72 { |
| 56 m_supportedSchemes[0] = "http"; | 73 m_supportedSchemes[0] = "http"; |
| 57 m_supportedSchemes[1] = "https"; | 74 m_supportedSchemes[1] = "https"; |
| 58 m_supportedSchemes[2] = "file"; | 75 m_supportedSchemes[2] = "file"; |
| 59 } | 76 } |
| 60 | 77 |
| 61 protected: | 78 protected: |
| (...skipping 65 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 127 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/trBackground.p
ng")); | 144 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/trBackground.p
ng")); |
| 128 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/tdBackground.p
ng")); | 145 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")); | 146 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")); | 147 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")); | 148 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")); | 149 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/why_inserted.h
tml")); |
| 133 EXPECT_TRUE(webVectorContains(resources, "https://www.secure.com/https.gif")
); | 150 EXPECT_TRUE(webVectorContains(resources, "https://www.secure.com/https.gif")
); |
| 134 EXPECT_TRUE(webVectorContains(resources, "file://c/my_folder/file.gif")); | 151 EXPECT_TRUE(webVectorContains(resources, "file://c/my_folder/file.gif")); |
| 135 } | 152 } |
| 136 | 153 |
| 154 TEST_F(WebPageSerializerTest, fromUrlWithMinusMinus) |
| 155 { |
| 156 WebURL topFrameURL = toKURL("http://www.test.com?--x--"); |
| 157 registerMockedURLLoad(topFrameURL.spec(), WebString::fromUTF8("text_only_pag
e.html")); |
| 158 loadURLInTopFrame(topFrameURL); |
| 159 |
| 160 SimpleWebPageSerializerClient serializerClient; |
| 161 WebVector<WebURL> links(&topFrameURL, 1); |
| 162 WebVector<WebString> localPaths(&"local", 1); |
| 163 WebPageSerializer::serialize(webView()->mainFrame()->toWebLocalFrame(), &ser
ializerClient, links, localPaths, ""); |
| 164 |
| 165 EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", se
rializerClient.toString().substr(1, 60)); |
| 166 } |
| 167 |
| 137 TEST_F(WebPageSerializerTest, MultipleFrames) | 168 TEST_F(WebPageSerializerTest, MultipleFrames) |
| 138 { | 169 { |
| 139 // Register the mocked frames. | 170 // Register the mocked frames. |
| 140 WebURL topFrameURL = toKURL("http://www.test.com"); | 171 WebURL topFrameURL = toKURL("http://www.test.com"); |
| 141 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("top_frame.
html")); | 172 registerMockedURLLoad("http://www.test.com", WebString::fromUTF8("top_frame.
html")); |
| 142 registerMockedURLLoad("http://www.test.com/simple_iframe.html", | 173 registerMockedURLLoad("http://www.test.com/simple_iframe.html", |
| 143 WebString::fromUTF8("simple_iframe.html")); | 174 WebString::fromUTF8("simple_iframe.html")); |
| 144 registerMockedURLLoad("http://www.test.com/object_iframe.html", | 175 registerMockedURLLoad("http://www.test.com/object_iframe.html", |
| 145 WebString::fromUTF8("object_iframe.html")); | 176 WebString::fromUTF8("object_iframe.html")); |
| 146 registerMockedURLLoad("http://www.test.com/embed_iframe.html", | 177 registerMockedURLLoad("http://www.test.com/embed_iframe.html", |
| (...skipping 24 matching lines...) Expand all Loading... |
| 171 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/innerFrame.png
")); | 202 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/innerFrame.png
")); |
| 172 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/flash.swf")); | 203 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 | 204 // 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. | 205 // causing the test to fail. Probably a plugin issue. |
| 175 // EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/music.mid")
); | 206 // EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/music.mid")
); |
| 176 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/object.png")); | 207 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/object.png")); |
| 177 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/embed.png")); | 208 EXPECT_TRUE(webVectorContains(resources, "http://www.test.com/embed.png")); |
| 178 } | 209 } |
| 179 | 210 |
| 180 } // namespace blink | 211 } // namespace blink |
| OLD | NEW |