OLD | NEW |
1 /* | 1 /* |
2 * Copyright (c) 2013, Opera Software ASA. All rights reserved. | 2 * Copyright (c) 2013, Opera Software ASA. 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 | 5 * modification, are permitted provided that the following conditions |
6 * are met: | 6 * are met: |
7 * | 7 * |
8 * 1. Redistributions of source code must retain the above copyright | 8 * 1. 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 * 2. Redistributions in binary form must reproduce the above copyright | 10 * 2. Redistributions in binary form must reproduce the above copyright |
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
100 | 100 |
101 WebURLResponse response; | 101 WebURLResponse response; |
102 response.SetMIMEType("text/html"); | 102 response.SetMIMEType("text/html"); |
103 response.SetHTTPStatusCode(status_code); | 103 response.SetHTTPStatusCode(status_code); |
104 | 104 |
105 Platform::Current()->GetURLLoaderMockFactory()->RegisterErrorURL( | 105 Platform::Current()->GetURLLoaderMockFactory()->RegisterErrorURL( |
106 KURL(base_url_, file), response, error); | 106 KURL(base_url_, file), response, error); |
107 } | 107 } |
108 | 108 |
109 void RegisterRewriteURL(const char* from_url, const char* to_url) { | 109 void RegisterRewriteURL(const char* from_url, const char* to_url) { |
110 rewrite_ur_ls_.insert(from_url, to_url); | 110 rewrite_urls_.insert(from_url, to_url); |
111 } | 111 } |
112 | 112 |
113 void RegisterSkipURL(const char* url) { | 113 void RegisterSkipURL(const char* url) { |
114 skip_ur_ls_.push_back(KURL(base_url_, url)); | 114 skip_urls_.push_back(KURL(base_url_, url)); |
115 } | 115 } |
116 | 116 |
117 void Serialize(const char* url) { | 117 void Serialize(const char* url) { |
118 FrameTestHelpers::LoadFrame(helper_.WebView()->MainFrame(), | 118 FrameTestHelpers::LoadFrame(helper_.WebView()->MainFrame(), |
119 KURL(base_url_, url).GetString().Utf8().Data()); | 119 KURL(base_url_, url).GetString().Utf8().Data()); |
120 FrameSerializer serializer(resources_, *this); | 120 FrameSerializer serializer(resources_, *this); |
121 Frame* frame = helper_.WebView()->MainFrameImpl()->GetFrame(); | 121 Frame* frame = helper_.WebView()->MainFrameImpl()->GetFrame(); |
122 for (; frame; frame = frame->Tree().TraverseNext()) { | 122 for (; frame; frame = frame->Tree().TraverseNext()) { |
123 // This is safe, because tests do not do cross-site navigation | 123 // This is safe, because tests do not do cross-site navigation |
124 // (and therefore don't have remote frames). | 124 // (and therefore don't have remote frames). |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 // FrameSerializer::Delegate implementation. | 166 // FrameSerializer::Delegate implementation. |
167 bool RewriteLink(const Element& element, String& rewritten_link) { | 167 bool RewriteLink(const Element& element, String& rewritten_link) { |
168 String complete_url; | 168 String complete_url; |
169 for (const auto& attribute : element.Attributes()) { | 169 for (const auto& attribute : element.Attributes()) { |
170 if (element.HasLegalLinkAttribute(attribute.GetName())) { | 170 if (element.HasLegalLinkAttribute(attribute.GetName())) { |
171 complete_url = element.GetDocument().CompleteURL(attribute.Value()); | 171 complete_url = element.GetDocument().CompleteURL(attribute.Value()); |
172 break; | 172 break; |
173 } | 173 } |
174 } | 174 } |
175 | 175 |
176 if (complete_url.IsNull() || !rewrite_ur_ls_.Contains(complete_url)) | 176 if (complete_url.IsNull() || !rewrite_urls_.Contains(complete_url)) |
177 return false; | 177 return false; |
178 | 178 |
179 StringBuilder uri_builder; | 179 StringBuilder uri_builder; |
180 uri_builder.Append(rewrite_folder_); | 180 uri_builder.Append(rewrite_folder_); |
181 uri_builder.Append('/'); | 181 uri_builder.Append('/'); |
182 uri_builder.Append(rewrite_ur_ls_.at(complete_url)); | 182 uri_builder.Append(rewrite_urls_.at(complete_url)); |
183 rewritten_link = uri_builder.ToString(); | 183 rewritten_link = uri_builder.ToString(); |
184 return true; | 184 return true; |
185 } | 185 } |
186 | 186 |
187 bool ShouldSkipResourceWithURL(const KURL& url) { | 187 bool ShouldSkipResourceWithURL(const KURL& url) { |
188 return skip_ur_ls_.Contains(url); | 188 return skip_urls_.Contains(url); |
189 } | 189 } |
190 | 190 |
191 FrameTestHelpers::WebViewHelper helper_; | 191 FrameTestHelpers::WebViewHelper helper_; |
192 std::string folder_; | 192 std::string folder_; |
193 KURL base_url_; | 193 KURL base_url_; |
194 Deque<SerializedResource> resources_; | 194 Deque<SerializedResource> resources_; |
195 HashMap<String, String> rewrite_ur_ls_; | 195 HashMap<String, String> rewrite_urls_; |
196 Vector<String> skip_ur_ls_; | 196 Vector<String> skip_urls_; |
197 String rewrite_folder_; | 197 String rewrite_folder_; |
198 }; | 198 }; |
199 | 199 |
200 TEST_F(FrameSerializerTest, HTMLElements) { | 200 TEST_F(FrameSerializerTest, HTMLElements) { |
201 SetBaseFolder("frameserializer/elements/"); | 201 SetBaseFolder("frameserializer/elements/"); |
202 | 202 |
203 RegisterURL("elements.html", "text/html"); | 203 RegisterURL("elements.html", "text/html"); |
204 RegisterURL("style.css", "style.css", "text/css"); | 204 RegisterURL("style.css", "style.css", "text/css"); |
205 RegisterURL("copyright.html", "empty.txt", "text/html"); | 205 RegisterURL("copyright.html", "empty.txt", "text/html"); |
206 RegisterURL("script.js", "empty.txt", "text/javascript"); | 206 RegisterURL("script.js", "empty.txt", "text/javascript"); |
(...skipping 347 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
554 KURL(kParsedURLString, "http://foo.com?--"))); | 554 KURL(kParsedURLString, "http://foo.com?--"))); |
555 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", | 555 EXPECT_EQ("saved from url=(0020)http://foo.com/#-%2D", |
556 FrameSerializer::MarkOfTheWebDeclaration( | 556 FrameSerializer::MarkOfTheWebDeclaration( |
557 KURL(kParsedURLString, "http://foo.com#--"))); | 557 KURL(kParsedURLString, "http://foo.com#--"))); |
558 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", | 558 EXPECT_EQ("saved from url=(0026)http://foo.com/#bar-%2Dbaz", |
559 FrameSerializer::MarkOfTheWebDeclaration( | 559 FrameSerializer::MarkOfTheWebDeclaration( |
560 KURL(kParsedURLString, "http://foo.com#bar--baz"))); | 560 KURL(kParsedURLString, "http://foo.com#bar--baz"))); |
561 } | 561 } |
562 | 562 |
563 } // namespace blink | 563 } // namespace blink |
OLD | NEW |