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 61 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
72 { | 72 { |
73 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 73 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
74 } | 74 } |
75 | 75 |
76 void registerMockedImageURL(const String& url) | 76 void registerMockedImageURL(const String& url) |
77 { | 77 { |
78 // Image resources need to be mocked, but irrelevant here what image the
y map to. | 78 // Image resources need to be mocked, but irrelevant here what image the
y map to. |
79 URLTestHelpers::registerMockedURLLoad(KURL(ParsedURLString, url), "frame
serialization/awesome.png"); | 79 URLTestHelpers::registerMockedURLLoad(KURL(ParsedURLString, url), "frame
serialization/awesome.png"); |
80 } | 80 } |
81 | 81 |
| 82 class SingleLinkRewritingDelegate : public WebFrameSerializer::LinkRewriting
Delegate { |
| 83 public: |
| 84 SingleLinkRewritingDelegate(const WebURL& url, const WebString& localPat
h) |
| 85 : m_url(url) |
| 86 , m_localPath(localPath) |
| 87 { |
| 88 } |
| 89 |
| 90 bool rewriteFrameSource(WebFrame* frame, WebString* rewrittenLink) overr
ide |
| 91 { |
| 92 return false; |
| 93 } |
| 94 |
| 95 bool rewriteLink(const WebURL& url, WebString* rewrittenLink) override |
| 96 { |
| 97 if (url != m_url) |
| 98 return false; |
| 99 |
| 100 *rewrittenLink = m_localPath; |
| 101 return true; |
| 102 } |
| 103 |
| 104 private: |
| 105 const WebURL m_url; |
| 106 const WebString m_localPath; |
| 107 }; |
| 108 |
82 String serializeFile(const String& url, const String& fileName) | 109 String serializeFile(const String& url, const String& fileName) |
83 { | 110 { |
84 KURL parsedURL(ParsedURLString, url); | 111 KURL parsedURL(ParsedURLString, url); |
85 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, "frameseriali
zation/", "text/html"); | 112 URLTestHelpers::registerMockedURLLoad(parsedURL, fileName, "frameseriali
zation/", "text/html"); |
86 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); | 113 FrameTestHelpers::loadFrame(mainFrameImpl(), url.utf8().data()); |
87 std::vector<std::pair<WebURL, WebString>> urlsToLocalPaths; | 114 SingleLinkRewritingDelegate delegate(parsedURL, WebString("local")); |
88 urlsToLocalPaths.push_back(std::make_pair(parsedURL, WebString("local"))
); | |
89 SimpleWebFrameSerializerClient serializerClient; | 115 SimpleWebFrameSerializerClient serializerClient; |
90 WebFrameSerializer::serialize(mainFrameImpl(), &serializerClient, urlsTo
LocalPaths); | 116 WebFrameSerializer::serialize( |
| 117 mainFrameImpl(), &serializerClient, &delegate); |
91 return serializerClient.toString(); | 118 return serializerClient.toString(); |
92 } | 119 } |
93 | 120 |
94 WebLocalFrameImpl* mainFrameImpl() | 121 WebLocalFrameImpl* mainFrameImpl() |
95 { | 122 { |
96 return m_helper.webViewImpl()->mainFrameImpl(); | 123 return m_helper.webViewImpl()->mainFrameImpl(); |
97 } | 124 } |
98 | 125 |
99 private: | 126 private: |
100 FrameTestHelpers::WebViewHelper m_helper; | 127 FrameTestHelpers::WebViewHelper m_helper; |
(...skipping 28 matching lines...) Expand all Loading... |
129 EXPECT_EQ(expectedHTML, actualHTML); | 156 EXPECT_EQ(expectedHTML, actualHTML); |
130 } | 157 } |
131 | 158 |
132 TEST_F(WebFrameSerializerTest, FromUrlWithMinusMinus) | 159 TEST_F(WebFrameSerializerTest, FromUrlWithMinusMinus) |
133 { | 160 { |
134 String actualHTML = serializeFile("http://www.test.com?--x--", "text_only_pa
ge.html"); | 161 String actualHTML = serializeFile("http://www.test.com?--x--", "text_only_pa
ge.html"); |
135 EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", ac
tualHTML.substring(1, 60)); | 162 EXPECT_EQ("<!-- saved from url=(0030)http://www.test.com/?-%2Dx-%2D -->", ac
tualHTML.substring(1, 60)); |
136 } | 163 } |
137 | 164 |
138 } // namespace blink | 165 } // namespace blink |
OLD | NEW |