OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "content/shell/renderer/test_runner/web_test_proxy.h" | 5 #include "content/shell/renderer/test_runner/web_test_proxy.h" |
6 | 6 |
7 #include <cctype> | 7 #include <cctype> |
8 | 8 |
9 #include "base/callback_helpers.h" | 9 #include "base/callback_helpers.h" |
10 #include "base/debug/trace_event.h" | 10 #include "base/debug/trace_event.h" |
(...skipping 187 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
198 case blink::WebNavigationTypeReload: | 198 case blink::WebNavigationTypeReload: |
199 return kReloadString; | 199 return kReloadString; |
200 case blink::WebNavigationTypeFormResubmitted: | 200 case blink::WebNavigationTypeFormResubmitted: |
201 return kFormResubmittedString; | 201 return kFormResubmittedString; |
202 case blink::WebNavigationTypeOther: | 202 case blink::WebNavigationTypeOther: |
203 return kOtherString; | 203 return kOtherString; |
204 } | 204 } |
205 return kIllegalString; | 205 return kIllegalString; |
206 } | 206 } |
207 | 207 |
| 208 std::string DumpFrameHeaderIfNeeded(blink::WebFrame* frame) { |
| 209 std::string result; |
| 210 |
| 211 // Add header for all but the main frame. Skip empty frames. |
| 212 if (frame->parent() && !frame->document().documentElement().isNull()) { |
| 213 result.append("\n--------\nFrame: '"); |
| 214 result.append(frame->uniqueName().utf8().data()); |
| 215 result.append("'\n--------\n"); |
| 216 } |
| 217 |
| 218 return result; |
| 219 } |
| 220 |
| 221 std::string DumpFramesAsMarkup(blink::WebFrame* frame, bool recursive) { |
| 222 std::string result = DumpFrameHeaderIfNeeded(frame); |
| 223 result.append(frame->contentAsMarkup().utf8()); |
| 224 result.append("\n"); |
| 225 |
| 226 if (recursive) { |
| 227 for (blink::WebFrame* child = frame->firstChild(); child; |
| 228 child = child->nextSibling()) |
| 229 result.append(DumpFramesAsMarkup(child, recursive)); |
| 230 } |
| 231 |
| 232 return result; |
| 233 } |
| 234 |
208 std::string DumpDocumentText(blink::WebFrame* frame) { | 235 std::string DumpDocumentText(blink::WebFrame* frame) { |
209 // We use the document element's text instead of the body text here because | 236 // We use the document element's text instead of the body text here because |
210 // not all documents have a body, such as XML documents. | 237 // not all documents have a body, such as XML documents. |
211 blink::WebElement document_element = frame->document().documentElement(); | 238 blink::WebElement document_element = frame->document().documentElement(); |
212 if (document_element.isNull()) | 239 if (document_element.isNull()) |
213 return std::string(); | 240 return std::string(); |
214 return document_element.innerText().utf8(); | 241 return document_element.innerText().utf8(); |
215 } | 242 } |
216 | 243 |
217 std::string DumpFramesAsText(blink::WebFrame* frame, bool recursive) { | 244 std::string DumpFramesAsText(blink::WebFrame* frame, bool recursive) { |
218 std::string result; | 245 std::string result = DumpFrameHeaderIfNeeded(frame); |
219 | |
220 // Add header for all but the main frame. Skip empty frames. | |
221 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
222 result.append("\n--------\nFrame: '"); | |
223 result.append(frame->uniqueName().utf8().data()); | |
224 result.append("'\n--------\n"); | |
225 } | |
226 | |
227 result.append(DumpDocumentText(frame)); | 246 result.append(DumpDocumentText(frame)); |
228 result.append("\n"); | 247 result.append("\n"); |
229 | 248 |
230 if (recursive) { | 249 if (recursive) { |
231 for (blink::WebFrame* child = frame->firstChild(); child; | 250 for (blink::WebFrame* child = frame->firstChild(); child; |
232 child = child->nextSibling()) | 251 child = child->nextSibling()) |
233 result.append(DumpFramesAsText(child, recursive)); | 252 result.append(DumpFramesAsText(child, recursive)); |
234 } | 253 } |
235 | 254 |
236 return result; | 255 return result; |
237 } | 256 } |
238 | 257 |
239 std::string DumpFramesAsPrintedText(blink::WebFrame* frame, bool recursive) { | 258 std::string DumpFramesAsPrintedText(blink::WebFrame* frame, bool recursive) { |
240 std::string result; | |
241 | |
242 // Cannot do printed format for anything other than HTML | 259 // Cannot do printed format for anything other than HTML |
243 if (!frame->document().isHTMLDocument()) | 260 if (!frame->document().isHTMLDocument()) |
244 return std::string(); | 261 return std::string(); |
245 | 262 |
246 // Add header for all but the main frame. Skip empty frames. | 263 std::string result = DumpFrameHeaderIfNeeded(frame); |
247 if (frame->parent() && !frame->document().documentElement().isNull()) { | |
248 result.append("\n--------\nFrame: '"); | |
249 result.append(frame->uniqueName().utf8().data()); | |
250 result.append("'\n--------\n"); | |
251 } | |
252 | |
253 result.append( | 264 result.append( |
254 frame->renderTreeAsText(blink::WebFrame::RenderAsTextPrinting).utf8()); | 265 frame->renderTreeAsText(blink::WebFrame::RenderAsTextPrinting).utf8()); |
255 result.append("\n"); | 266 result.append("\n"); |
256 | 267 |
257 if (recursive) { | 268 if (recursive) { |
258 for (blink::WebFrame* child = frame->firstChild(); child; | 269 for (blink::WebFrame* child = frame->firstChild(); child; |
259 child = child->nextSibling()) | 270 child = child->nextSibling()) |
260 result.append(DumpFramesAsPrintedText(child, recursive)); | 271 result.append(DumpFramesAsPrintedText(child, recursive)); |
261 } | 272 } |
262 | 273 |
(...skipping 112 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
375 test_interfaces_->testRunner()->shouldDumpAsMarkup(); | 386 test_interfaces_->testRunner()->shouldDumpAsMarkup(); |
376 bool should_dump_as_printed = test_interfaces_->testRunner()->isPrinting(); | 387 bool should_dump_as_printed = test_interfaces_->testRunner()->isPrinting(); |
377 blink::WebFrame* frame = GetWebView()->mainFrame(); | 388 blink::WebFrame* frame = GetWebView()->mainFrame(); |
378 std::string data_utf8; | 389 std::string data_utf8; |
379 if (should_dump_custom_text) { | 390 if (should_dump_custom_text) { |
380 // Append a newline for the test driver. | 391 // Append a newline for the test driver. |
381 data_utf8 = test_interfaces_->testRunner()->customDumpText() + "\n"; | 392 data_utf8 = test_interfaces_->testRunner()->customDumpText() + "\n"; |
382 } else if (should_dump_as_text) { | 393 } else if (should_dump_as_text) { |
383 bool recursive = | 394 bool recursive = |
384 test_interfaces_->testRunner()->shouldDumpChildFramesAsText(); | 395 test_interfaces_->testRunner()->shouldDumpChildFramesAsText(); |
385 data_utf8 = should_dump_as_printed | 396 data_utf8 = should_dump_as_printed ? |
386 ? DumpFramesAsPrintedText(frame, recursive) | 397 DumpFramesAsPrintedText(frame, recursive) : |
387 : DumpFramesAsText(frame, recursive); | 398 DumpFramesAsText(frame, recursive); |
388 } else if (should_dump_as_markup) { | 399 } else if (should_dump_as_markup) { |
| 400 bool recursive = |
| 401 test_interfaces_->testRunner()->shouldDumpChildFramesAsMarkup(); |
389 // Append a newline for the test driver. | 402 // Append a newline for the test driver. |
390 data_utf8 = frame->contentAsMarkup().utf8() + "\n"; | 403 data_utf8 = DumpFramesAsMarkup(frame, recursive); |
391 } else { | 404 } else { |
392 bool recursive = | 405 bool recursive = |
393 test_interfaces_->testRunner()->shouldDumpChildFrameScrollPositions(); | 406 test_interfaces_->testRunner()->shouldDumpChildFrameScrollPositions(); |
394 blink::WebFrame::RenderAsTextControls render_text_behavior = | 407 blink::WebFrame::RenderAsTextControls render_text_behavior = |
395 blink::WebFrame::RenderAsTextNormal; | 408 blink::WebFrame::RenderAsTextNormal; |
396 if (should_dump_as_printed) | 409 if (should_dump_as_printed) |
397 render_text_behavior |= blink::WebFrame::RenderAsTextPrinting; | 410 render_text_behavior |= blink::WebFrame::RenderAsTextPrinting; |
398 if (debug_render_tree) | 411 if (debug_render_tree) |
399 render_text_behavior |= blink::WebFrame::RenderAsTextDebug; | 412 render_text_behavior |= blink::WebFrame::RenderAsTextDebug; |
400 data_utf8 = frame->renderTreeAsText(render_text_behavior).utf8(); | 413 data_utf8 = frame->renderTreeAsText(render_text_behavior).utf8(); |
(...skipping 794 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1195 // to cancel the input method's ongoing composition session. | 1208 // to cancel the input method's ongoing composition session. |
1196 if (web_widget_) | 1209 if (web_widget_) |
1197 web_widget_->confirmComposition(); | 1210 web_widget_->confirmComposition(); |
1198 } | 1211 } |
1199 | 1212 |
1200 blink::WebString WebTestProxyBase::acceptLanguages() { | 1213 blink::WebString WebTestProxyBase::acceptLanguages() { |
1201 return blink::WebString::fromUTF8(accept_languages_); | 1214 return blink::WebString::fromUTF8(accept_languages_); |
1202 } | 1215 } |
1203 | 1216 |
1204 } // namespace content | 1217 } // namespace content |
OLD | NEW |