| OLD | NEW |
| (Empty) | |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 /* |
| 6 * Copyright (C) 2012 Google Inc. All rights reserved. |
| 7 * |
| 8 * Redistribution and use in source and binary forms, with or without |
| 9 * modification, are permitted provided that the following conditions are |
| 10 * met: |
| 11 * |
| 12 * * Redistributions of source code must retain the above copyright |
| 13 * notice, this list of conditions and the following disclaimer. |
| 14 * * Redistributions in binary form must reproduce the above |
| 15 * copyright notice, this list of conditions and the following disclaimer |
| 16 * in the documentation and/or other materials provided with the |
| 17 * distribution. |
| 18 * * Neither the name of Google Inc. nor the names of its |
| 19 * contributors may be used to endorse or promote products derived from |
| 20 * this software without specific prior written permission. |
| 21 * |
| 22 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS |
| 23 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT |
| 24 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR |
| 25 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT |
| 26 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, |
| 27 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT |
| 28 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, |
| 29 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY |
| 30 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
| 31 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE |
| 32 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
| 33 */ |
| 34 |
| 35 #include "content/public/test/layout_tests/WebTestProxy.h" |
| 36 |
| 37 #include <cctype> |
| 38 |
| 39 #include "content/public/test/layout_tests/WebTestDelegate.h" |
| 40 #include "content/public/test/layout_tests/WebTestInterfaces.h" |
| 41 #include "content/public/test/layout_tests/WebTestRunner.h" |
| 42 #include "content/test/layout_tests/runner/AccessibilityController.h" |
| 43 #include "content/test/layout_tests/runner/EventSender.h" |
| 44 #include "content/test/layout_tests/runner/MockColorChooser.h" |
| 45 #include "content/test/layout_tests/runner/MockWebSpeechInputController.h" |
| 46 #include "content/test/layout_tests/runner/MockWebSpeechRecognizer.h" |
| 47 #include "content/test/layout_tests/runner/SpellCheckClient.h" |
| 48 #include "content/test/layout_tests/runner/TestCommon.h" |
| 49 #include "content/test/layout_tests/runner/TestInterfaces.h" |
| 50 #include "content/test/layout_tests/runner/TestPlugin.h" |
| 51 #include "content/test/layout_tests/runner/TestRunner.h" |
| 52 #include "content/test/layout_tests/runner/WebUserMediaClientMock.h" |
| 53 // FIXME: Including platform_canvas.h here is a layering violation. |
| 54 #include "skia/ext/platform_canvas.h" |
| 55 #include "third_party/WebKit/public/platform/WebCString.h" |
| 56 #include "third_party/WebKit/public/platform/WebURLError.h" |
| 57 #include "third_party/WebKit/public/platform/WebURLRequest.h" |
| 58 #include "third_party/WebKit/public/platform/WebURLResponse.h" |
| 59 #include "third_party/WebKit/public/web/WebAXEnums.h" |
| 60 #include "third_party/WebKit/public/web/WebAXObject.h" |
| 61 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" |
| 62 #include "third_party/WebKit/public/web/WebConsoleMessage.h" |
| 63 #include "third_party/WebKit/public/web/WebDataSource.h" |
| 64 #include "third_party/WebKit/public/web/WebDocument.h" |
| 65 #include "third_party/WebKit/public/web/WebElement.h" |
| 66 #include "third_party/WebKit/public/web/WebFrame.h" |
| 67 #include "third_party/WebKit/public/web/WebGeolocationClientMock.h" |
| 68 #include "third_party/WebKit/public/web/WebHistoryItem.h" |
| 69 #include "third_party/WebKit/public/web/WebMIDIClientMock.h" |
| 70 #include "third_party/WebKit/public/web/WebNode.h" |
| 71 #include "third_party/WebKit/public/web/WebPluginParams.h" |
| 72 #include "third_party/WebKit/public/web/WebPrintParams.h" |
| 73 #include "third_party/WebKit/public/web/WebRange.h" |
| 74 #include "third_party/WebKit/public/web/WebScriptController.h" |
| 75 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" |
| 76 #include "third_party/WebKit/public/web/WebView.h" |
| 77 |
| 78 using namespace blink; |
| 79 using namespace std; |
| 80 |
| 81 namespace WebTestRunner { |
| 82 |
| 83 namespace { |
| 84 |
| 85 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { |
| 86 public: |
| 87 typedef void (WebTestProxyBase::*CallbackMethodType)(); |
| 88 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) |
| 89 : WebMethodTask<WebTestProxyBase>(object) |
| 90 , m_callback(callback) |
| 91 { } |
| 92 |
| 93 virtual void runIfValid() { (m_object->*m_callback)(); } |
| 94 |
| 95 private: |
| 96 CallbackMethodType m_callback; |
| 97 }; |
| 98 |
| 99 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) |
| 100 { |
| 101 string name8 = frame->uniqueName().utf8(); |
| 102 if (frame == frame->view()->mainFrame()) { |
| 103 if (!name8.length()) { |
| 104 delegate->printMessage("main frame"); |
| 105 return; |
| 106 } |
| 107 delegate->printMessage(string("main frame \"") + name8 + "\""); |
| 108 return; |
| 109 } |
| 110 if (!name8.length()) { |
| 111 delegate->printMessage("frame (anonymous)"); |
| 112 return; |
| 113 } |
| 114 delegate->printMessage(string("frame \"") + name8 + "\""); |
| 115 } |
| 116 |
| 117 void printFrameUserGestureStatus(WebTestDelegate* delegate, WebFrame* frame, con
st char* msg) |
| 118 { |
| 119 bool isUserGesture = WebUserGestureIndicator::isProcessingUserGesture(); |
| 120 delegate->printMessage(string("Frame with user gesture \"") + (isUserGesture
? "true" : "false") + "\"" + msg); |
| 121 } |
| 122 |
| 123 // Used to write a platform neutral file:/// URL by taking the |
| 124 // filename and its directory. (e.g., converts |
| 125 // "file:///tmp/foo/bar.txt" to just "bar.txt"). |
| 126 string descriptionSuitableForTestResult(const string& url) |
| 127 { |
| 128 if (url.empty() || string::npos == url.find("file://")) |
| 129 return url; |
| 130 |
| 131 size_t pos = url.rfind('/'); |
| 132 if (pos == string::npos || !pos) |
| 133 return "ERROR:" + url; |
| 134 pos = url.rfind('/', pos - 1); |
| 135 if (pos == string::npos) |
| 136 return "ERROR:" + url; |
| 137 |
| 138 return url.substr(pos + 1); |
| 139 } |
| 140 |
| 141 void printResponseDescription(WebTestDelegate* delegate, const WebURLResponse& r
esponse) |
| 142 { |
| 143 if (response.isNull()) { |
| 144 delegate->printMessage("(null)"); |
| 145 return; |
| 146 } |
| 147 string url = response.url().spec(); |
| 148 char data[100]; |
| 149 snprintf(data, sizeof(data), "%d", response. httpStatusCode()); |
| 150 delegate->printMessage(string("<NSURLResponse ") + descriptionSuitableForTes
tResult(url) + ", http status code " + data + ">"); |
| 151 } |
| 152 |
| 153 string URLDescription(const GURL& url) |
| 154 { |
| 155 if (url.SchemeIs("file")) |
| 156 return url.ExtractFileName(); |
| 157 return url.possibly_invalid_spec(); |
| 158 } |
| 159 |
| 160 string PriorityDescription(const WebURLRequest::Priority& priority) |
| 161 { |
| 162 switch (priority) { |
| 163 case WebURLRequest::PriorityVeryLow: |
| 164 return "VeryLow"; |
| 165 case WebURLRequest::PriorityLow: |
| 166 return "Low"; |
| 167 case WebURLRequest::PriorityMedium: |
| 168 return "Medium"; |
| 169 case WebURLRequest::PriorityHigh: |
| 170 return "High"; |
| 171 case WebURLRequest::PriorityVeryHigh: |
| 172 return "VeryHigh"; |
| 173 case WebURLRequest::PriorityUnresolved: |
| 174 default: |
| 175 return "Unresolved"; |
| 176 } |
| 177 } |
| 178 |
| 179 void blockRequest(WebURLRequest& request) |
| 180 { |
| 181 request.setURL(GURL("255.255.255.255")); |
| 182 } |
| 183 |
| 184 bool isLocalhost(const string& host) |
| 185 { |
| 186 return host == "127.0.0.1" || host == "localhost"; |
| 187 } |
| 188 |
| 189 bool hostIsUsedBySomeTestsToGenerateError(const string& host) |
| 190 { |
| 191 return host == "255.255.255.255"; |
| 192 } |
| 193 |
| 194 // Used to write a platform neutral file:/// URL by only taking the filename |
| 195 // (e.g., converts "file:///tmp/foo.txt" to just "foo.txt"). |
| 196 string urlSuitableForTestResult(const string& url) |
| 197 { |
| 198 if (url.empty() || string::npos == url.find("file://")) |
| 199 return url; |
| 200 |
| 201 size_t pos = url.rfind('/'); |
| 202 if (pos == string::npos) { |
| 203 #ifdef WIN32 |
| 204 pos = url.rfind('\\'); |
| 205 if (pos == string::npos) |
| 206 pos = 0; |
| 207 #else |
| 208 pos = 0; |
| 209 #endif |
| 210 } |
| 211 string filename = url.substr(pos + 1); |
| 212 if (filename.empty()) |
| 213 return "file:"; // A WebKit test has this in its expected output. |
| 214 return filename; |
| 215 } |
| 216 |
| 217 // WebNavigationType debugging strings taken from PolicyDelegate.mm. |
| 218 const char* linkClickedString = "link clicked"; |
| 219 const char* formSubmittedString = "form submitted"; |
| 220 const char* backForwardString = "back/forward"; |
| 221 const char* reloadString = "reload"; |
| 222 const char* formResubmittedString = "form resubmitted"; |
| 223 const char* otherString = "other"; |
| 224 const char* illegalString = "illegal value"; |
| 225 |
| 226 // Get a debugging string from a WebNavigationType. |
| 227 const char* webNavigationTypeToString(WebNavigationType type) |
| 228 { |
| 229 switch (type) { |
| 230 case blink::WebNavigationTypeLinkClicked: |
| 231 return linkClickedString; |
| 232 case blink::WebNavigationTypeFormSubmitted: |
| 233 return formSubmittedString; |
| 234 case blink::WebNavigationTypeBackForward: |
| 235 return backForwardString; |
| 236 case blink::WebNavigationTypeReload: |
| 237 return reloadString; |
| 238 case blink::WebNavigationTypeFormResubmitted: |
| 239 return formResubmittedString; |
| 240 case blink::WebNavigationTypeOther: |
| 241 return otherString; |
| 242 } |
| 243 return illegalString; |
| 244 } |
| 245 |
| 246 string dumpDocumentText(WebFrame* frame) |
| 247 { |
| 248 // We use the document element's text instead of the body text here because |
| 249 // not all documents have a body, such as XML documents. |
| 250 WebElement documentElement = frame->document().documentElement(); |
| 251 if (documentElement.isNull()) |
| 252 return string(); |
| 253 return documentElement.innerText().utf8(); |
| 254 } |
| 255 |
| 256 string dumpFramesAsText(WebFrame* frame, bool recursive) |
| 257 { |
| 258 string result; |
| 259 |
| 260 // Add header for all but the main frame. Skip empty frames. |
| 261 if (frame->parent() && !frame->document().documentElement().isNull()) { |
| 262 result.append("\n--------\nFrame: '"); |
| 263 result.append(frame->uniqueName().utf8().data()); |
| 264 result.append("'\n--------\n"); |
| 265 } |
| 266 |
| 267 result.append(dumpDocumentText(frame)); |
| 268 result.append("\n"); |
| 269 |
| 270 if (recursive) { |
| 271 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) |
| 272 result.append(dumpFramesAsText(child, recursive)); |
| 273 } |
| 274 |
| 275 return result; |
| 276 } |
| 277 |
| 278 string dumpFramesAsPrintedText(WebFrame* frame, bool recursive) |
| 279 { |
| 280 string result; |
| 281 |
| 282 // Cannot do printed format for anything other than HTML |
| 283 if (!frame->document().isHTMLDocument()) |
| 284 return string(); |
| 285 |
| 286 // Add header for all but the main frame. Skip empty frames. |
| 287 if (frame->parent() && !frame->document().documentElement().isNull()) { |
| 288 result.append("\n--------\nFrame: '"); |
| 289 result.append(frame->uniqueName().utf8().data()); |
| 290 result.append("'\n--------\n"); |
| 291 } |
| 292 |
| 293 result.append(frame->renderTreeAsText(WebFrame::RenderAsTextPrinting).utf8()
); |
| 294 result.append("\n"); |
| 295 |
| 296 if (recursive) { |
| 297 for (WebFrame* child = frame->firstChild(); child; child = child->nextSi
bling()) |
| 298 result.append(dumpFramesAsPrintedText(child, recursive)); |
| 299 } |
| 300 |
| 301 return result; |
| 302 } |
| 303 |
| 304 string dumpFrameScrollPosition(WebFrame* frame, bool recursive) |
| 305 { |
| 306 string result; |
| 307 WebSize offset = frame->scrollOffset(); |
| 308 if (offset.width > 0 || offset.height > 0) { |
| 309 if (frame->parent()) |
| 310 result = string("frame '") + frame->uniqueName().utf8().data() + "'
"; |
| 311 char data[100]; |
| 312 snprintf(data, sizeof(data), "scrolled to %d,%d\n", offset.width, offset
.height); |
| 313 result += data; |
| 314 } |
| 315 |
| 316 if (!recursive) |
| 317 return result; |
| 318 for (WebFrame* child = frame->firstChild(); child; child = child->nextSiblin
g()) |
| 319 result += dumpFrameScrollPosition(child, recursive); |
| 320 return result; |
| 321 } |
| 322 |
| 323 struct ToLower { |
| 324 char16 operator()(char16 c) { return tolower(c); } |
| 325 }; |
| 326 |
| 327 // Returns True if item1 < item2. |
| 328 bool HistoryItemCompareLess(const WebHistoryItem& item1, const WebHistoryItem& i
tem2) |
| 329 { |
| 330 string16 target1 = item1.target(); |
| 331 string16 target2 = item2.target(); |
| 332 std::transform(target1.begin(), target1.end(), target1.begin(), ToLower()); |
| 333 std::transform(target2.begin(), target2.end(), target2.begin(), ToLower()); |
| 334 return target1 < target2; |
| 335 } |
| 336 |
| 337 string dumpHistoryItem(const WebHistoryItem& item, int indent, bool isCurrent) |
| 338 { |
| 339 string result; |
| 340 |
| 341 if (isCurrent) { |
| 342 result.append("curr->"); |
| 343 result.append(indent - 6, ' '); // 6 == "curr->".length() |
| 344 } else |
| 345 result.append(indent, ' '); |
| 346 |
| 347 string url = normalizeLayoutTestURL(item.urlString().utf8()); |
| 348 result.append(url); |
| 349 if (!item.target().isEmpty()) { |
| 350 result.append(" (in frame \""); |
| 351 result.append(item.target().utf8()); |
| 352 result.append("\")"); |
| 353 } |
| 354 result.append("\n"); |
| 355 |
| 356 const WebVector<WebHistoryItem>& children = item.children(); |
| 357 if (!children.isEmpty()) { |
| 358 // Must sort to eliminate arbitrary result ordering which defeats |
| 359 // reproducible testing. |
| 360 // FIXME: WebVector should probably just be a std::vector!! |
| 361 std::vector<WebHistoryItem> sortedChildren; |
| 362 for (size_t i = 0; i < children.size(); ++i) |
| 363 sortedChildren.push_back(children[i]); |
| 364 std::sort(sortedChildren.begin(), sortedChildren.end(), HistoryItemCompa
reLess); |
| 365 for (size_t i = 0; i < sortedChildren.size(); ++i) |
| 366 result += dumpHistoryItem(sortedChildren[i], indent + 4, false); |
| 367 } |
| 368 |
| 369 return result; |
| 370 } |
| 371 |
| 372 void dumpBackForwardList(const WebVector<WebHistoryItem>& history, size_t curren
tEntryIndex, string& result) |
| 373 { |
| 374 result.append("\n============== Back Forward List ==============\n"); |
| 375 for (size_t index = 0; index < history.size(); ++index) |
| 376 result.append(dumpHistoryItem(history[index], 8, index == currentEntryIn
dex)); |
| 377 result.append("===============================================\n"); |
| 378 } |
| 379 |
| 380 string dumpAllBackForwardLists(TestInterfaces* interfaces, WebTestDelegate* dele
gate) |
| 381 { |
| 382 string result; |
| 383 const vector<WebTestProxyBase*>& windowList = interfaces->windowList(); |
| 384 for (unsigned i = 0; i < windowList.size(); ++i) { |
| 385 size_t currentEntryIndex = 0; |
| 386 WebVector<WebHistoryItem> history; |
| 387 delegate->captureHistoryForWindow(windowList.at(i), &history, ¤tEn
tryIndex); |
| 388 dumpBackForwardList(history, currentEntryIndex, result); |
| 389 } |
| 390 return result; |
| 391 } |
| 392 |
| 393 } |
| 394 |
| 395 WebTestProxyBase::WebTestProxyBase() |
| 396 : m_testInterfaces(0) |
| 397 , m_delegate(0) |
| 398 , m_webWidget(0) |
| 399 , m_spellcheck(new SpellCheckClient(this)) |
| 400 , m_chooserCount(0) |
| 401 { |
| 402 reset(); |
| 403 } |
| 404 |
| 405 WebTestProxyBase::~WebTestProxyBase() |
| 406 { |
| 407 m_testInterfaces->windowClosed(this); |
| 408 } |
| 409 |
| 410 void WebTestProxyBase::setInterfaces(WebTestInterfaces* interfaces) |
| 411 { |
| 412 m_testInterfaces = interfaces->testInterfaces(); |
| 413 m_testInterfaces->windowOpened(this); |
| 414 } |
| 415 |
| 416 void WebTestProxyBase::setDelegate(WebTestDelegate* delegate) |
| 417 { |
| 418 m_delegate = delegate; |
| 419 m_spellcheck->setDelegate(delegate); |
| 420 #if ENABLE_INPUT_SPEECH |
| 421 if (m_speechInputController.get()) |
| 422 m_speechInputController->setDelegate(delegate); |
| 423 #endif |
| 424 if (m_speechRecognizer.get()) |
| 425 m_speechRecognizer->setDelegate(delegate); |
| 426 } |
| 427 |
| 428 void WebTestProxyBase::setWidget(WebWidget* widget) |
| 429 { |
| 430 m_webWidget = widget; |
| 431 } |
| 432 |
| 433 WebWidget* WebTestProxyBase::webWidget() |
| 434 { |
| 435 return m_webWidget; |
| 436 } |
| 437 |
| 438 WebView* WebTestProxyBase::webView() |
| 439 { |
| 440 BLINK_ASSERT(m_webWidget); |
| 441 // TestRunner does not support popup widgets. So m_webWidget is always a Web
View. |
| 442 return static_cast<WebView*>(m_webWidget); |
| 443 } |
| 444 |
| 445 void WebTestProxyBase::didForceResize() |
| 446 { |
| 447 invalidateAll(); |
| 448 discardBackingStore(); |
| 449 } |
| 450 |
| 451 void WebTestProxyBase::reset() |
| 452 { |
| 453 m_paintRect = WebRect(); |
| 454 m_canvas.reset(); |
| 455 m_isPainting = false; |
| 456 m_animateScheduled = false; |
| 457 m_resourceIdentifierMap.clear(); |
| 458 m_logConsoleOutput = true; |
| 459 if (m_geolocationClient.get()) |
| 460 m_geolocationClient->resetMock(); |
| 461 if (m_midiClient.get()) |
| 462 m_midiClient->resetMock(); |
| 463 #if ENABLE_INPUT_SPEECH |
| 464 if (m_speechInputController.get()) |
| 465 m_speechInputController->clearResults(); |
| 466 #endif |
| 467 } |
| 468 |
| 469 WebSpellCheckClient* WebTestProxyBase::spellCheckClient() const |
| 470 { |
| 471 return m_spellcheck.get(); |
| 472 } |
| 473 |
| 474 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli
ent, const blink::WebColor& color) |
| 475 { |
| 476 // This instance is deleted by WebCore::ColorInputType |
| 477 return new MockColorChooser(client, m_delegate, this); |
| 478 } |
| 479 |
| 480 WebColorChooser* WebTestProxyBase::createColorChooser(WebColorChooserClient* cli
ent, const blink::WebColor& color, const blink::WebVector<blink::WebColorSuggest
ion>& suggestions) |
| 481 { |
| 482 // This instance is deleted by WebCore::ColorInputType |
| 483 return new MockColorChooser(client, m_delegate, this); |
| 484 } |
| 485 |
| 486 bool WebTestProxyBase::runFileChooser(const blink::WebFileChooserParams&, blink:
:WebFileChooserCompletion*) |
| 487 { |
| 488 m_delegate->printMessage("Mock: Opening a file chooser.\n"); |
| 489 // FIXME: Add ability to set file names to a file upload control. |
| 490 return false; |
| 491 } |
| 492 |
| 493 void WebTestProxyBase::showValidationMessage(const WebRect&, const WebString& me
ssage, const WebString& subMessage, WebTextDirection) |
| 494 { |
| 495 m_delegate->printMessage(std::string("ValidationMessageClient: main-message=
") + std::string(message.utf8()) + " sub-message=" + std::string(subMessage.utf8
()) + "\n"); |
| 496 } |
| 497 |
| 498 void WebTestProxyBase::hideValidationMessage() |
| 499 { |
| 500 } |
| 501 |
| 502 void WebTestProxyBase::moveValidationMessage(const WebRect&) |
| 503 { |
| 504 } |
| 505 |
| 506 string WebTestProxyBase::captureTree(bool debugRenderTree) |
| 507 { |
| 508 WebScriptController::flushConsoleMessages(); |
| 509 |
| 510 bool shouldDumpAsText = m_testInterfaces->testRunner()->shouldDumpAsText(); |
| 511 bool shouldDumpAsMarkup = m_testInterfaces->testRunner()->shouldDumpAsMarkup
(); |
| 512 bool shouldDumpAsPrinted = m_testInterfaces->testRunner()->isPrinting(); |
| 513 WebFrame* frame = webView()->mainFrame(); |
| 514 string dataUtf8; |
| 515 if (shouldDumpAsText) { |
| 516 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFramesAs
Text(); |
| 517 dataUtf8 = shouldDumpAsPrinted ? dumpFramesAsPrintedText(frame, recursiv
e) : dumpFramesAsText(frame, recursive); |
| 518 } else if (shouldDumpAsMarkup) { |
| 519 // Append a newline for the test driver. |
| 520 dataUtf8 = frame->contentAsMarkup().utf8() + "\n"; |
| 521 } else { |
| 522 bool recursive = m_testInterfaces->testRunner()->shouldDumpChildFrameScr
ollPositions(); |
| 523 WebFrame::RenderAsTextControls renderTextBehavior = WebFrame::RenderAsTe
xtNormal; |
| 524 if (shouldDumpAsPrinted) |
| 525 renderTextBehavior |= WebFrame::RenderAsTextPrinting; |
| 526 if (debugRenderTree) |
| 527 renderTextBehavior |= WebFrame::RenderAsTextDebug; |
| 528 dataUtf8 = frame->renderTreeAsText(renderTextBehavior).utf8(); |
| 529 dataUtf8 += dumpFrameScrollPosition(frame, recursive); |
| 530 } |
| 531 |
| 532 if (m_testInterfaces->testRunner()->shouldDumpBackForwardList()) |
| 533 dataUtf8 += dumpAllBackForwardLists(m_testInterfaces, m_delegate); |
| 534 |
| 535 return dataUtf8; |
| 536 } |
| 537 |
| 538 SkCanvas* WebTestProxyBase::capturePixels() |
| 539 { |
| 540 webWidget()->layout(); |
| 541 if (m_testInterfaces->testRunner()->testRepaint()) { |
| 542 WebSize viewSize = webWidget()->size(); |
| 543 int width = viewSize.width; |
| 544 int height = viewSize.height; |
| 545 if (m_testInterfaces->testRunner()->sweepHorizontally()) { |
| 546 for (WebRect column(0, 0, 1, height); column.x < width; column.x++) |
| 547 paintRect(column); |
| 548 } else { |
| 549 for (WebRect line(0, 0, width, 1); line.y < height; line.y++) |
| 550 paintRect(line); |
| 551 } |
| 552 } else if (m_testInterfaces->testRunner()->isPrinting()) |
| 553 paintPagesWithBoundaries(); |
| 554 else |
| 555 paintInvalidatedRegion(); |
| 556 |
| 557 // See if we need to draw the selection bounds rect. Selection bounds |
| 558 // rect is the rect enclosing the (possibly transformed) selection. |
| 559 // The rect should be drawn after everything is laid out and painted. |
| 560 if (m_testInterfaces->testRunner()->shouldDumpSelectionRect()) { |
| 561 // If there is a selection rect - draw a red 1px border enclosing rect |
| 562 WebRect wr = webView()->mainFrame()->selectionBoundsRect(); |
| 563 if (!wr.isEmpty()) { |
| 564 // Render a red rectangle bounding selection rect |
| 565 SkPaint paint; |
| 566 paint.setColor(0xFFFF0000); // Fully opaque red |
| 567 paint.setStyle(SkPaint::kStroke_Style); |
| 568 paint.setFlags(SkPaint::kAntiAlias_Flag); |
| 569 paint.setStrokeWidth(1.0f); |
| 570 SkIRect rect; // Bounding rect |
| 571 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); |
| 572 canvas()->drawIRect(rect, paint); |
| 573 } |
| 574 } |
| 575 |
| 576 return canvas(); |
| 577 } |
| 578 |
| 579 void WebTestProxyBase::setLogConsoleOutput(bool enabled) |
| 580 { |
| 581 m_logConsoleOutput = enabled; |
| 582 } |
| 583 |
| 584 void WebTestProxyBase::paintRect(const WebRect& rect) |
| 585 { |
| 586 BLINK_ASSERT(!m_isPainting); |
| 587 BLINK_ASSERT(canvas()); |
| 588 m_isPainting = true; |
| 589 float deviceScaleFactor = webView()->deviceScaleFactor(); |
| 590 int scaledX = static_cast<int>(static_cast<float>(rect.x) * deviceScaleFacto
r); |
| 591 int scaledY = static_cast<int>(static_cast<float>(rect.y) * deviceScaleFacto
r); |
| 592 int scaledWidth = static_cast<int>(ceil(static_cast<float>(rect.width) * dev
iceScaleFactor)); |
| 593 int scaledHeight = static_cast<int>(ceil(static_cast<float>(rect.height) * d
eviceScaleFactor)); |
| 594 WebRect deviceRect(scaledX, scaledY, scaledWidth, scaledHeight); |
| 595 webWidget()->paint(canvas(), deviceRect); |
| 596 m_isPainting = false; |
| 597 } |
| 598 |
| 599 void WebTestProxyBase::paintInvalidatedRegion() |
| 600 { |
| 601 webWidget()->animate(0.0); |
| 602 webWidget()->layout(); |
| 603 WebSize widgetSize = webWidget()->size(); |
| 604 WebRect clientRect(0, 0, widgetSize.width, widgetSize.height); |
| 605 |
| 606 // Paint the canvas if necessary. Allow painting to generate extra rects |
| 607 // for the first two calls. This is necessary because some WebCore rendering |
| 608 // objects update their layout only when painted. |
| 609 // Store the total area painted in total_paint. Then tell the gdk window |
| 610 // to update that area after we're done painting it. |
| 611 for (int i = 0; i < 3; ++i) { |
| 612 // rect = intersect(m_paintRect , clientRect) |
| 613 WebRect damageRect = m_paintRect; |
| 614 int left = max(damageRect.x, clientRect.x); |
| 615 int top = max(damageRect.y, clientRect.y); |
| 616 int right = min(damageRect.x + damageRect.width, clientRect.x + clientRe
ct.width); |
| 617 int bottom = min(damageRect.y + damageRect.height, clientRect.y + client
Rect.height); |
| 618 WebRect rect; |
| 619 if (left < right && top < bottom) |
| 620 rect = WebRect(left, top, right - left, bottom - top); |
| 621 |
| 622 m_paintRect = WebRect(); |
| 623 if (rect.isEmpty()) |
| 624 continue; |
| 625 paintRect(rect); |
| 626 } |
| 627 BLINK_ASSERT(m_paintRect.isEmpty()); |
| 628 } |
| 629 |
| 630 void WebTestProxyBase::paintPagesWithBoundaries() |
| 631 { |
| 632 BLINK_ASSERT(!m_isPainting); |
| 633 BLINK_ASSERT(canvas()); |
| 634 m_isPainting = true; |
| 635 |
| 636 WebSize pageSizeInPixels = webWidget()->size(); |
| 637 WebFrame* webFrame = webView()->mainFrame(); |
| 638 |
| 639 int pageCount = webFrame->printBegin(pageSizeInPixels); |
| 640 int totalHeight = pageCount * (pageSizeInPixels.height + 1) - 1; |
| 641 |
| 642 SkCanvas* testCanvas = skia::TryCreateBitmapCanvas(pageSizeInPixels.width, t
otalHeight, true); |
| 643 if (testCanvas) { |
| 644 discardBackingStore(); |
| 645 m_canvas.reset(testCanvas); |
| 646 } else { |
| 647 webFrame->printEnd(); |
| 648 return; |
| 649 } |
| 650 |
| 651 webFrame->printPagesWithBoundaries(canvas(), pageSizeInPixels); |
| 652 webFrame->printEnd(); |
| 653 |
| 654 m_isPainting = false; |
| 655 } |
| 656 |
| 657 SkCanvas* WebTestProxyBase::canvas() |
| 658 { |
| 659 if (m_canvas.get()) |
| 660 return m_canvas.get(); |
| 661 WebSize widgetSize = webWidget()->size(); |
| 662 float deviceScaleFactor = webView()->deviceScaleFactor(); |
| 663 int scaledWidth = static_cast<int>(ceil(static_cast<float>(widgetSize.width)
* deviceScaleFactor)); |
| 664 int scaledHeight = static_cast<int>(ceil(static_cast<float>(widgetSize.heigh
t) * deviceScaleFactor)); |
| 665 m_canvas.reset(skia::CreateBitmapCanvas(scaledWidth, scaledHeight, true)); |
| 666 return m_canvas.get(); |
| 667 } |
| 668 |
| 669 // Paints the entire canvas a semi-transparent black (grayish). This is used |
| 670 // by the layout tests in fast/repaint. The alpha value matches upstream. |
| 671 void WebTestProxyBase::displayRepaintMask() |
| 672 { |
| 673 canvas()->drawARGB(167, 0, 0, 0); |
| 674 } |
| 675 |
| 676 void WebTestProxyBase::display() |
| 677 { |
| 678 const blink::WebSize& size = webWidget()->size(); |
| 679 WebRect rect(0, 0, size.width, size.height); |
| 680 m_paintRect = rect; |
| 681 paintInvalidatedRegion(); |
| 682 displayRepaintMask(); |
| 683 } |
| 684 |
| 685 void WebTestProxyBase::displayInvalidatedRegion() |
| 686 { |
| 687 paintInvalidatedRegion(); |
| 688 displayRepaintMask(); |
| 689 } |
| 690 |
| 691 void WebTestProxyBase::discardBackingStore() |
| 692 { |
| 693 m_canvas.reset(); |
| 694 } |
| 695 |
| 696 WebGeolocationClientMock* WebTestProxyBase::geolocationClientMock() |
| 697 { |
| 698 if (!m_geolocationClient.get()) |
| 699 m_geolocationClient.reset(WebGeolocationClientMock::create()); |
| 700 return m_geolocationClient.get(); |
| 701 } |
| 702 |
| 703 WebMIDIClientMock* WebTestProxyBase::midiClientMock() |
| 704 { |
| 705 if (!m_midiClient.get()) |
| 706 m_midiClient.reset(new WebMIDIClientMock); |
| 707 return m_midiClient.get(); |
| 708 } |
| 709 |
| 710 #if ENABLE_INPUT_SPEECH |
| 711 MockWebSpeechInputController* WebTestProxyBase::speechInputControllerMock() |
| 712 { |
| 713 BLINK_ASSERT(m_speechInputController.get()); |
| 714 return m_speechInputController.get(); |
| 715 } |
| 716 #endif |
| 717 |
| 718 MockWebSpeechRecognizer* WebTestProxyBase::speechRecognizerMock() |
| 719 { |
| 720 if (!m_speechRecognizer.get()) { |
| 721 m_speechRecognizer.reset(new MockWebSpeechRecognizer()); |
| 722 m_speechRecognizer->setDelegate(m_delegate); |
| 723 } |
| 724 return m_speechRecognizer.get(); |
| 725 } |
| 726 |
| 727 void WebTestProxyBase::didInvalidateRect(const WebRect& rect) |
| 728 { |
| 729 // m_paintRect = m_paintRect U rect |
| 730 if (rect.isEmpty()) |
| 731 return; |
| 732 if (m_paintRect.isEmpty()) { |
| 733 m_paintRect = rect; |
| 734 return; |
| 735 } |
| 736 int left = min(m_paintRect.x, rect.x); |
| 737 int top = min(m_paintRect.y, rect.y); |
| 738 int right = max(m_paintRect.x + m_paintRect.width, rect.x + rect.width); |
| 739 int bottom = max(m_paintRect.y + m_paintRect.height, rect.y + rect.height); |
| 740 m_paintRect = WebRect(left, top, right - left, bottom - top); |
| 741 } |
| 742 |
| 743 void WebTestProxyBase::didScrollRect(int, int, const WebRect& clipRect) |
| 744 { |
| 745 didInvalidateRect(clipRect); |
| 746 } |
| 747 |
| 748 void WebTestProxyBase::invalidateAll() |
| 749 { |
| 750 m_paintRect = WebRect(0, 0, INT_MAX, INT_MAX); |
| 751 } |
| 752 |
| 753 void WebTestProxyBase::scheduleComposite() |
| 754 { |
| 755 invalidateAll(); |
| 756 } |
| 757 |
| 758 void WebTestProxyBase::scheduleAnimation() |
| 759 { |
| 760 if (!m_testInterfaces->testRunner()->testIsRunning()) |
| 761 return; |
| 762 |
| 763 if (!m_animateScheduled) { |
| 764 m_animateScheduled = true; |
| 765 m_delegate->postDelayedTask(new HostMethodTask(this, &WebTestProxyBase::
animateNow), 1); |
| 766 } |
| 767 } |
| 768 |
| 769 void WebTestProxyBase::animateNow() |
| 770 { |
| 771 if (m_animateScheduled) { |
| 772 m_animateScheduled = false; |
| 773 webWidget()->animate(0.0); |
| 774 } |
| 775 } |
| 776 |
| 777 void WebTestProxyBase::show(WebNavigationPolicy) |
| 778 { |
| 779 invalidateAll(); |
| 780 } |
| 781 |
| 782 void WebTestProxyBase::setWindowRect(const WebRect& rect) |
| 783 { |
| 784 invalidateAll(); |
| 785 discardBackingStore(); |
| 786 } |
| 787 |
| 788 void WebTestProxyBase::didAutoResize(const WebSize&) |
| 789 { |
| 790 invalidateAll(); |
| 791 } |
| 792 |
| 793 void WebTestProxyBase::postAccessibilityEvent(const blink::WebAXObject& obj, bli
nk::WebAXEvent event) |
| 794 { |
| 795 if (event == blink::WebAXEventFocus) |
| 796 m_testInterfaces->accessibilityController()->setFocusedElement(obj); |
| 797 |
| 798 const char* eventName = 0; |
| 799 switch (event) { |
| 800 case blink::WebAXEventActiveDescendantChanged: |
| 801 eventName = "ActiveDescendantChanged"; |
| 802 break; |
| 803 case blink::WebAXEventAlert: |
| 804 eventName = "Alert"; |
| 805 break; |
| 806 case blink::WebAXEventAriaAttributeChanged: |
| 807 eventName = "AriaAttributeChanged"; |
| 808 break; |
| 809 case blink::WebAXEventAutocorrectionOccured: |
| 810 eventName = "AutocorrectionOccured"; |
| 811 break; |
| 812 case blink::WebAXEventBlur: |
| 813 eventName = "Blur"; |
| 814 break; |
| 815 case blink::WebAXEventCheckedStateChanged: |
| 816 eventName = "CheckedStateChanged"; |
| 817 break; |
| 818 case blink::WebAXEventChildrenChanged: |
| 819 eventName = "ChildrenChanged"; |
| 820 break; |
| 821 case blink::WebAXEventFocus: |
| 822 eventName = "Focus"; |
| 823 break; |
| 824 case blink::WebAXEventHide: |
| 825 eventName = "Hide"; |
| 826 break; |
| 827 case blink::WebAXEventInvalidStatusChanged: |
| 828 eventName = "InvalidStatusChanged"; |
| 829 break; |
| 830 case blink::WebAXEventLayoutComplete: |
| 831 eventName = "LayoutComplete"; |
| 832 break; |
| 833 case blink::WebAXEventLiveRegionChanged: |
| 834 eventName = "LiveRegionChanged"; |
| 835 break; |
| 836 case blink::WebAXEventLoadComplete: |
| 837 eventName = "LoadComplete"; |
| 838 break; |
| 839 case blink::WebAXEventLocationChanged: |
| 840 eventName = "LocationChanged"; |
| 841 break; |
| 842 case blink::WebAXEventMenuListItemSelected: |
| 843 eventName = "MenuListItemSelected"; |
| 844 break; |
| 845 case blink::WebAXEventMenuListValueChanged: |
| 846 eventName = "MenuListValueChanged"; |
| 847 break; |
| 848 case blink::WebAXEventRowCollapsed: |
| 849 eventName = "RowCollapsed"; |
| 850 break; |
| 851 case blink::WebAXEventRowCountChanged: |
| 852 eventName = "RowCountChanged"; |
| 853 break; |
| 854 case blink::WebAXEventRowExpanded: |
| 855 eventName = "RowExpanded"; |
| 856 break; |
| 857 case blink::WebAXEventScrolledToAnchor: |
| 858 eventName = "ScrolledToAnchor"; |
| 859 break; |
| 860 case blink::WebAXEventSelectedChildrenChanged: |
| 861 eventName = "SelectedChildrenChanged"; |
| 862 break; |
| 863 case blink::WebAXEventSelectedTextChanged: |
| 864 eventName = "SelectedTextChanged"; |
| 865 break; |
| 866 case blink::WebAXEventShow: |
| 867 eventName = "Show"; |
| 868 break; |
| 869 case blink::WebAXEventTextChanged: |
| 870 eventName = "TextChanged"; |
| 871 break; |
| 872 case blink::WebAXEventTextInserted: |
| 873 eventName = "TextInserted"; |
| 874 break; |
| 875 case blink::WebAXEventTextRemoved: |
| 876 eventName = "TextRemoved"; |
| 877 break; |
| 878 case blink::WebAXEventValueChanged: |
| 879 eventName = "ValueChanged"; |
| 880 break; |
| 881 } |
| 882 |
| 883 m_testInterfaces->accessibilityController()->notificationReceived(obj, event
Name); |
| 884 |
| 885 if (m_testInterfaces->accessibilityController()->shouldLogAccessibilityEvent
s()) { |
| 886 string message("AccessibilityNotification - "); |
| 887 message += eventName; |
| 888 |
| 889 blink::WebNode node = obj.node(); |
| 890 if (!node.isNull() && node.isElementNode()) { |
| 891 blink::WebElement element = node.to<blink::WebElement>(); |
| 892 if (element.hasAttribute("id")) { |
| 893 message += " - id:"; |
| 894 message += element.getAttribute("id").utf8().data(); |
| 895 } |
| 896 } |
| 897 |
| 898 m_delegate->printMessage(message + "\n"); |
| 899 } |
| 900 } |
| 901 |
| 902 void WebTestProxyBase::startDragging(WebFrame*, const WebDragData& data, WebDrag
OperationsMask mask, const WebImage&, const WebPoint&) |
| 903 { |
| 904 // When running a test, we need to fake a drag drop operation otherwise |
| 905 // Windows waits for real mouse events to know when the drag is over. |
| 906 m_testInterfaces->eventSender()->doDragDrop(data, mask); |
| 907 } |
| 908 |
| 909 // The output from these methods in layout test mode should match that |
| 910 // expected by the layout tests. See EditingDelegate.m in DumpRenderTree. |
| 911 |
| 912 void WebTestProxyBase::didChangeSelection(bool isEmptySelection) |
| 913 { |
| 914 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) |
| 915 m_delegate->printMessage("EDITING DELEGATE: webViewDidChangeSelection:We
bViewDidChangeSelectionNotification\n"); |
| 916 } |
| 917 |
| 918 void WebTestProxyBase::didChangeContents() |
| 919 { |
| 920 if (m_testInterfaces->testRunner()->shouldDumpEditingCallbacks()) |
| 921 m_delegate->printMessage("EDITING DELEGATE: webViewDidChange:WebViewDidC
hangeNotification\n"); |
| 922 } |
| 923 |
| 924 bool WebTestProxyBase::createView(WebFrame*, const WebURLRequest& request, const
WebWindowFeatures&, const WebString&, WebNavigationPolicy, bool) |
| 925 { |
| 926 if (!m_testInterfaces->testRunner()->canOpenWindows()) |
| 927 return false; |
| 928 if (m_testInterfaces->testRunner()->shouldDumpCreateView()) |
| 929 m_delegate->printMessage(string("createView(") + URLDescription(request.
url()) + ")\n"); |
| 930 return true; |
| 931 } |
| 932 |
| 933 WebPlugin* WebTestProxyBase::createPlugin(WebFrame* frame, const WebPluginParams
& params) |
| 934 { |
| 935 if (params.mimeType == TestPlugin::mimeType()) |
| 936 return TestPlugin::create(frame, params, m_delegate); |
| 937 return 0; |
| 938 } |
| 939 |
| 940 void WebTestProxyBase::setStatusText(const WebString& text) |
| 941 { |
| 942 if (!m_testInterfaces->testRunner()->shouldDumpStatusCallbacks()) |
| 943 return; |
| 944 m_delegate->printMessage(string("UI DELEGATE STATUS CALLBACK: setStatusText:
") + text.utf8().data() + "\n"); |
| 945 } |
| 946 |
| 947 void WebTestProxyBase::didStopLoading() |
| 948 { |
| 949 if (m_testInterfaces->testRunner()->shouldDumpProgressFinishedCallback()) |
| 950 m_delegate->printMessage("postProgressFinishedNotification\n"); |
| 951 } |
| 952 |
| 953 void WebTestProxyBase::showContextMenu(WebFrame*, const WebContextMenuData& cont
extMenuData) |
| 954 { |
| 955 m_testInterfaces->eventSender()->setContextMenuData(contextMenuData); |
| 956 } |
| 957 |
| 958 WebUserMediaClient* WebTestProxyBase::userMediaClient() |
| 959 { |
| 960 if (!m_userMediaClient.get()) |
| 961 m_userMediaClient.reset(new WebUserMediaClientMock(m_delegate)); |
| 962 return m_userMediaClient.get(); |
| 963 } |
| 964 |
| 965 // Simulate a print by going into print mode and then exit straight away. |
| 966 void WebTestProxyBase::printPage(WebFrame* frame) |
| 967 { |
| 968 WebSize pageSizeInPixels = webWidget()->size(); |
| 969 if (pageSizeInPixels.isEmpty()) |
| 970 return; |
| 971 WebPrintParams printParams(pageSizeInPixels); |
| 972 frame->printBegin(printParams); |
| 973 frame->printEnd(); |
| 974 } |
| 975 |
| 976 WebNotificationPresenter* WebTestProxyBase::notificationPresenter() |
| 977 { |
| 978 return m_testInterfaces->testRunner()->notificationPresenter(); |
| 979 } |
| 980 |
| 981 WebGeolocationClient* WebTestProxyBase::geolocationClient() |
| 982 { |
| 983 return geolocationClientMock(); |
| 984 } |
| 985 |
| 986 WebMIDIClient* WebTestProxyBase::webMIDIClient() |
| 987 { |
| 988 return midiClientMock(); |
| 989 } |
| 990 |
| 991 WebSpeechInputController* WebTestProxyBase::speechInputController(WebSpeechInput
Listener* listener) |
| 992 { |
| 993 #if ENABLE_INPUT_SPEECH |
| 994 if (!m_speechInputController.get()) { |
| 995 m_speechInputController.reset(new MockWebSpeechInputController(listener)
); |
| 996 m_speechInputController->setDelegate(m_delegate); |
| 997 } |
| 998 return m_speechInputController.get(); |
| 999 #else |
| 1000 BLINK_ASSERT(listener); |
| 1001 return 0; |
| 1002 #endif |
| 1003 } |
| 1004 |
| 1005 WebSpeechRecognizer* WebTestProxyBase::speechRecognizer() |
| 1006 { |
| 1007 return speechRecognizerMock(); |
| 1008 } |
| 1009 |
| 1010 bool WebTestProxyBase::requestPointerLock() |
| 1011 { |
| 1012 return m_testInterfaces->testRunner()->requestPointerLock(); |
| 1013 } |
| 1014 |
| 1015 void WebTestProxyBase::requestPointerUnlock() |
| 1016 { |
| 1017 m_testInterfaces->testRunner()->requestPointerUnlock(); |
| 1018 } |
| 1019 |
| 1020 bool WebTestProxyBase::isPointerLocked() |
| 1021 { |
| 1022 return m_testInterfaces->testRunner()->isPointerLocked(); |
| 1023 } |
| 1024 |
| 1025 void WebTestProxyBase::didFocus() |
| 1026 { |
| 1027 m_delegate->setFocus(this, true); |
| 1028 } |
| 1029 |
| 1030 void WebTestProxyBase::didBlur() |
| 1031 { |
| 1032 m_delegate->setFocus(this, false); |
| 1033 } |
| 1034 |
| 1035 void WebTestProxyBase::setToolTipText(const WebString& text, WebTextDirection) |
| 1036 { |
| 1037 m_testInterfaces->testRunner()->setToolTipText(text); |
| 1038 } |
| 1039 |
| 1040 void WebTestProxyBase::didOpenChooser() |
| 1041 { |
| 1042 m_chooserCount++; |
| 1043 } |
| 1044 |
| 1045 void WebTestProxyBase::didCloseChooser() |
| 1046 { |
| 1047 m_chooserCount--; |
| 1048 } |
| 1049 |
| 1050 bool WebTestProxyBase::isChooserShown() |
| 1051 { |
| 1052 return 0 < m_chooserCount; |
| 1053 } |
| 1054 |
| 1055 void WebTestProxyBase::didStartProvisionalLoad(WebFrame* frame) |
| 1056 { |
| 1057 if (!m_testInterfaces->testRunner()->topLoadingFrame()) |
| 1058 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, false); |
| 1059 |
| 1060 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1061 printFrameDescription(m_delegate, frame); |
| 1062 m_delegate->printMessage(" - didStartProvisionalLoadForFrame\n"); |
| 1063 } |
| 1064 |
| 1065 if (m_testInterfaces->testRunner()->shouldDumpUserGestureInFrameLoadCallback
s()) |
| 1066 printFrameUserGestureStatus(m_delegate, frame, " - in didStartProvisiona
lLoadForFrame\n"); |
| 1067 } |
| 1068 |
| 1069 void WebTestProxyBase::didReceiveServerRedirectForProvisionalLoad(WebFrame* fram
e) |
| 1070 { |
| 1071 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1072 printFrameDescription(m_delegate, frame); |
| 1073 m_delegate->printMessage(" - didReceiveServerRedirectForProvisionalLoadF
orFrame\n"); |
| 1074 } |
| 1075 } |
| 1076 |
| 1077 bool WebTestProxyBase::didFailProvisionalLoad(WebFrame* frame, const WebURLError
&) |
| 1078 { |
| 1079 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1080 printFrameDescription(m_delegate, frame); |
| 1081 m_delegate->printMessage(" - didFailProvisionalLoadWithError\n"); |
| 1082 } |
| 1083 locationChangeDone(frame); |
| 1084 return !frame->provisionalDataSource(); |
| 1085 } |
| 1086 |
| 1087 void WebTestProxyBase::didCommitProvisionalLoad(WebFrame* frame, bool) |
| 1088 { |
| 1089 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1090 printFrameDescription(m_delegate, frame); |
| 1091 m_delegate->printMessage(" - didCommitLoadForFrame\n"); |
| 1092 } |
| 1093 } |
| 1094 |
| 1095 void WebTestProxyBase::didReceiveTitle(WebFrame* frame, const WebString& title,
WebTextDirection direction) |
| 1096 { |
| 1097 WebCString title8 = title.utf8(); |
| 1098 |
| 1099 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1100 printFrameDescription(m_delegate, frame); |
| 1101 m_delegate->printMessage(string(" - didReceiveTitle: ") + title8.data()
+ "\n"); |
| 1102 } |
| 1103 |
| 1104 if (m_testInterfaces->testRunner()->shouldDumpTitleChanges()) |
| 1105 m_delegate->printMessage(string("TITLE CHANGED: '") + title8.data() + "'
\n"); |
| 1106 } |
| 1107 |
| 1108 void WebTestProxyBase::didChangeIcon(WebFrame* frame, WebIconURL::Type) |
| 1109 { |
| 1110 if (m_testInterfaces->testRunner()->shouldDumpIconChanges()) { |
| 1111 printFrameDescription(m_delegate, frame); |
| 1112 m_delegate->printMessage(string(" - didChangeIcons\n")); |
| 1113 } |
| 1114 } |
| 1115 |
| 1116 void WebTestProxyBase::didFinishDocumentLoad(WebFrame* frame) |
| 1117 { |
| 1118 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1119 printFrameDescription(m_delegate, frame); |
| 1120 m_delegate->printMessage(" - didFinishDocumentLoadForFrame\n"); |
| 1121 } else { |
| 1122 unsigned pendingUnloadEvents = frame->unloadListenerCount(); |
| 1123 if (pendingUnloadEvents) { |
| 1124 printFrameDescription(m_delegate, frame); |
| 1125 char buffer[100]; |
| 1126 snprintf(buffer, sizeof(buffer), " - has %u onunload handler(s)\n",
pendingUnloadEvents); |
| 1127 m_delegate->printMessage(buffer); |
| 1128 } |
| 1129 } |
| 1130 } |
| 1131 |
| 1132 void WebTestProxyBase::didHandleOnloadEvents(WebFrame* frame) |
| 1133 { |
| 1134 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1135 printFrameDescription(m_delegate, frame); |
| 1136 m_delegate->printMessage(" - didHandleOnloadEventsForFrame\n"); |
| 1137 } |
| 1138 } |
| 1139 |
| 1140 void WebTestProxyBase::didFailLoad(WebFrame* frame, const WebURLError&) |
| 1141 { |
| 1142 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1143 printFrameDescription(m_delegate, frame); |
| 1144 m_delegate->printMessage(" - didFailLoadWithError\n"); |
| 1145 } |
| 1146 locationChangeDone(frame); |
| 1147 } |
| 1148 |
| 1149 void WebTestProxyBase::didFinishLoad(WebFrame* frame) |
| 1150 { |
| 1151 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) { |
| 1152 printFrameDescription(m_delegate, frame); |
| 1153 m_delegate->printMessage(" - didFinishLoadForFrame\n"); |
| 1154 } |
| 1155 locationChangeDone(frame); |
| 1156 } |
| 1157 |
| 1158 void WebTestProxyBase::didDetectXSS(WebFrame*, const WebURL&, bool) |
| 1159 { |
| 1160 if (m_testInterfaces->testRunner()->shouldDumpFrameLoadCallbacks()) |
| 1161 m_delegate->printMessage("didDetectXSS\n"); |
| 1162 } |
| 1163 |
| 1164 void WebTestProxyBase::didDispatchPingLoader(WebFrame*, const WebURL& url) |
| 1165 { |
| 1166 if (m_testInterfaces->testRunner()->shouldDumpPingLoaderCallbacks()) |
| 1167 m_delegate->printMessage(string("PingLoader dispatched to '") + URLDescr
iption(url).c_str() + "'.\n"); |
| 1168 } |
| 1169 |
| 1170 void WebTestProxyBase::willRequestResource(WebFrame* frame, const blink::WebCach
edURLRequest& request) |
| 1171 { |
| 1172 if (m_testInterfaces->testRunner()->shouldDumpResourceRequestCallbacks()) { |
| 1173 printFrameDescription(m_delegate, frame); |
| 1174 m_delegate->printMessage(string(" - ") + request.initiatorName().utf8().
data()); |
| 1175 m_delegate->printMessage(string(" requested '") + URLDescription(request
.urlRequest().url()).c_str() + "'\n"); |
| 1176 } |
| 1177 } |
| 1178 |
| 1179 void WebTestProxyBase::didCreateDataSource(WebFrame*, WebDataSource* ds) |
| 1180 { |
| 1181 if (!m_testInterfaces->testRunner()->deferMainResourceDataLoad()) |
| 1182 ds->setDeferMainResourceDataLoad(false); |
| 1183 } |
| 1184 |
| 1185 void WebTestProxyBase::willSendRequest(WebFrame*, unsigned identifier, blink::We
bURLRequest& request, const blink::WebURLResponse& redirectResponse) |
| 1186 { |
| 1187 // Need to use GURL for host() and SchemeIs() |
| 1188 GURL url = request.url(); |
| 1189 string requestURL = url.possibly_invalid_spec(); |
| 1190 |
| 1191 GURL mainDocumentURL = request.firstPartyForCookies(); |
| 1192 |
| 1193 if (redirectResponse.isNull() && (m_testInterfaces->testRunner()->shouldDump
ResourceLoadCallbacks() || m_testInterfaces->testRunner()->shouldDumpResourcePri
orities())) { |
| 1194 BLINK_ASSERT(m_resourceIdentifierMap.find(identifier) == m_resourceIdent
ifierMap.end()); |
| 1195 m_resourceIdentifierMap[identifier] = descriptionSuitableForTestResult(r
equestURL); |
| 1196 } |
| 1197 |
| 1198 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1199 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) |
| 1200 m_delegate->printMessage("<unknown>"); |
| 1201 else |
| 1202 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); |
| 1203 m_delegate->printMessage(" - willSendRequest <NSURLRequest URL "); |
| 1204 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_
str()); |
| 1205 m_delegate->printMessage(", main document URL "); |
| 1206 m_delegate->printMessage(URLDescription(mainDocumentURL).c_str()); |
| 1207 m_delegate->printMessage(", http method "); |
| 1208 m_delegate->printMessage(request.httpMethod().utf8().data()); |
| 1209 m_delegate->printMessage("> redirectResponse "); |
| 1210 printResponseDescription(m_delegate, redirectResponse); |
| 1211 m_delegate->printMessage("\n"); |
| 1212 } |
| 1213 |
| 1214 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) { |
| 1215 m_delegate->printMessage(descriptionSuitableForTestResult(requestURL).c_
str()); |
| 1216 m_delegate->printMessage(" has priority "); |
| 1217 m_delegate->printMessage(PriorityDescription(request.priority())); |
| 1218 m_delegate->printMessage("\n"); |
| 1219 } |
| 1220 |
| 1221 if (m_testInterfaces->testRunner()->httpHeadersToClear()) { |
| 1222 const set<string> *clearHeaders = m_testInterfaces->testRunner()->httpHe
adersToClear(); |
| 1223 for (set<string>::const_iterator header = clearHeaders->begin(); header
!= clearHeaders->end(); ++header) |
| 1224 request.clearHTTPHeaderField(WebString::fromUTF8(*header)); |
| 1225 } |
| 1226 |
| 1227 string host = url.host(); |
| 1228 if (!host.empty() && (url.SchemeIs("http") || url.SchemeIs("https"))) { |
| 1229 if (!isLocalhost(host) && !hostIsUsedBySomeTestsToGenerateError(host) |
| 1230 && ((!mainDocumentURL.SchemeIs("http") && !mainDocumentURL.SchemeIs(
"https")) || isLocalhost(mainDocumentURL.host())) |
| 1231 && !m_delegate->allowExternalPages()) { |
| 1232 m_delegate->printMessage(string("Blocked access to external URL ") +
requestURL + "\n"); |
| 1233 blockRequest(request); |
| 1234 return; |
| 1235 } |
| 1236 } |
| 1237 |
| 1238 // Set the new substituted URL. |
| 1239 request.setURL(m_delegate->rewriteLayoutTestsURL(request.url().spec())); |
| 1240 } |
| 1241 |
| 1242 void WebTestProxyBase::didReceiveResponse(WebFrame*, unsigned identifier, const
blink::WebURLResponse& response) |
| 1243 { |
| 1244 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1245 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) |
| 1246 m_delegate->printMessage("<unknown>"); |
| 1247 else |
| 1248 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); |
| 1249 m_delegate->printMessage(" - didReceiveResponse "); |
| 1250 printResponseDescription(m_delegate, response); |
| 1251 m_delegate->printMessage("\n"); |
| 1252 } |
| 1253 if (m_testInterfaces->testRunner()->shouldDumpResourceResponseMIMETypes()) { |
| 1254 GURL url = response.url(); |
| 1255 WebString mimeType = response.mimeType(); |
| 1256 m_delegate->printMessage(url.ExtractFileName()); |
| 1257 m_delegate->printMessage(" has MIME type "); |
| 1258 // Simulate NSURLResponse's mapping of empty/unknown MIME types to appli
cation/octet-stream |
| 1259 m_delegate->printMessage(mimeType.isEmpty() ? "application/octet-stream"
: mimeType.utf8().data()); |
| 1260 m_delegate->printMessage("\n"); |
| 1261 } |
| 1262 } |
| 1263 |
| 1264 void WebTestProxyBase::didChangeResourcePriority(WebFrame*, unsigned identifier,
const blink::WebURLRequest::Priority& priority) |
| 1265 { |
| 1266 if (m_testInterfaces->testRunner()->shouldDumpResourcePriorities()) { |
| 1267 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) |
| 1268 m_delegate->printMessage("<unknown>"); |
| 1269 else |
| 1270 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); |
| 1271 m_delegate->printMessage(" changed priority to "); |
| 1272 m_delegate->printMessage(PriorityDescription(priority)); |
| 1273 m_delegate->printMessage("\n"); |
| 1274 } |
| 1275 } |
| 1276 |
| 1277 void WebTestProxyBase::didFinishResourceLoad(WebFrame*, unsigned identifier) |
| 1278 { |
| 1279 if (m_testInterfaces->testRunner()->shouldDumpResourceLoadCallbacks()) { |
| 1280 if (m_resourceIdentifierMap.find(identifier) == m_resourceIdentifierMap.
end()) |
| 1281 m_delegate->printMessage("<unknown>"); |
| 1282 else |
| 1283 m_delegate->printMessage(m_resourceIdentifierMap[identifier]); |
| 1284 m_delegate->printMessage(" - didFinishLoading\n"); |
| 1285 } |
| 1286 m_resourceIdentifierMap.erase(identifier); |
| 1287 } |
| 1288 |
| 1289 void WebTestProxyBase::didAddMessageToConsole(const WebConsoleMessage& message,
const WebString& sourceName, unsigned sourceLine) |
| 1290 { |
| 1291 // This matches win DumpRenderTree's UIDelegate.cpp. |
| 1292 if (!m_logConsoleOutput) |
| 1293 return; |
| 1294 string level; |
| 1295 switch (message.level) { |
| 1296 case WebConsoleMessage::LevelDebug: |
| 1297 level = "DEBUG"; |
| 1298 break; |
| 1299 case WebConsoleMessage::LevelLog: |
| 1300 level = "MESSAGE"; |
| 1301 break; |
| 1302 case WebConsoleMessage::LevelInfo: |
| 1303 level = "INFO"; |
| 1304 break; |
| 1305 case WebConsoleMessage::LevelWarning: |
| 1306 level = "WARNING"; |
| 1307 break; |
| 1308 case WebConsoleMessage::LevelError: |
| 1309 level = "ERROR"; |
| 1310 break; |
| 1311 } |
| 1312 m_delegate->printMessage(string("CONSOLE ") + level + ": "); |
| 1313 if (sourceLine) { |
| 1314 char buffer[40]; |
| 1315 snprintf(buffer, sizeof(buffer), "line %d: ", sourceLine); |
| 1316 m_delegate->printMessage(buffer); |
| 1317 } |
| 1318 if (!message.text.isEmpty()) { |
| 1319 string newMessage; |
| 1320 newMessage = message.text.utf8(); |
| 1321 size_t fileProtocol = newMessage.find("file://"); |
| 1322 if (fileProtocol != string::npos) { |
| 1323 newMessage = newMessage.substr(0, fileProtocol) |
| 1324 + urlSuitableForTestResult(newMessage.substr(fileProtocol)); |
| 1325 } |
| 1326 m_delegate->printMessage(newMessage); |
| 1327 } |
| 1328 m_delegate->printMessage(string("\n")); |
| 1329 } |
| 1330 |
| 1331 void WebTestProxyBase::runModalAlertDialog(WebFrame*, const WebString& message) |
| 1332 { |
| 1333 m_delegate->printMessage(string("ALERT: ") + message.utf8().data() + "\n"); |
| 1334 } |
| 1335 |
| 1336 bool WebTestProxyBase::runModalConfirmDialog(WebFrame*, const WebString& message
) |
| 1337 { |
| 1338 m_delegate->printMessage(string("CONFIRM: ") + message.utf8().data() + "\n")
; |
| 1339 return true; |
| 1340 } |
| 1341 |
| 1342 bool WebTestProxyBase::runModalPromptDialog(WebFrame* frame, const WebString& me
ssage, const WebString& defaultValue, WebString*) |
| 1343 { |
| 1344 m_delegate->printMessage(string("PROMPT: ") + message.utf8().data() + ", def
ault text: " + defaultValue.utf8().data() + "\n"); |
| 1345 return true; |
| 1346 } |
| 1347 |
| 1348 bool WebTestProxyBase::runModalBeforeUnloadDialog(WebFrame*, const WebString& me
ssage) |
| 1349 { |
| 1350 m_delegate->printMessage(string("CONFIRM NAVIGATION: ") + message.utf8().dat
a() + "\n"); |
| 1351 return !m_testInterfaces->testRunner()->shouldStayOnPageAfterHandlingBeforeU
nload(); |
| 1352 } |
| 1353 |
| 1354 void WebTestProxyBase::locationChangeDone(WebFrame* frame) |
| 1355 { |
| 1356 if (frame != m_testInterfaces->testRunner()->topLoadingFrame()) |
| 1357 return; |
| 1358 m_testInterfaces->testRunner()->setTopLoadingFrame(frame, true); |
| 1359 } |
| 1360 |
| 1361 WebNavigationPolicy WebTestProxyBase::decidePolicyForNavigation(WebFrame*, WebDa
taSource::ExtraData*, const WebURLRequest& request, WebNavigationType type, WebN
avigationPolicy defaultPolicy, bool isRedirect) |
| 1362 { |
| 1363 WebNavigationPolicy result; |
| 1364 if (!m_testInterfaces->testRunner()->policyDelegateEnabled()) |
| 1365 return defaultPolicy; |
| 1366 |
| 1367 m_delegate->printMessage(string("Policy delegate: attempt to load ") + URLDe
scription(request.url()) + " with navigation type '" + webNavigationTypeToString
(type) + "'\n"); |
| 1368 if (m_testInterfaces->testRunner()->policyDelegateIsPermissive()) |
| 1369 result = blink::WebNavigationPolicyCurrentTab; |
| 1370 else |
| 1371 result = blink::WebNavigationPolicyIgnore; |
| 1372 |
| 1373 if (m_testInterfaces->testRunner()->policyDelegateShouldNotifyDone()) |
| 1374 m_testInterfaces->testRunner()->policyDelegateDone(); |
| 1375 return result; |
| 1376 } |
| 1377 |
| 1378 bool WebTestProxyBase::willCheckAndDispatchMessageEvent(WebFrame*, WebFrame*, We
bSecurityOrigin, WebDOMMessageEvent) |
| 1379 { |
| 1380 if (m_testInterfaces->testRunner()->shouldInterceptPostMessage()) { |
| 1381 m_delegate->printMessage("intercepted postMessage\n"); |
| 1382 return true; |
| 1383 } |
| 1384 |
| 1385 return false; |
| 1386 } |
| 1387 |
| 1388 void WebTestProxyBase::postSpellCheckEvent(const WebString& eventName) |
| 1389 { |
| 1390 if (m_testInterfaces->testRunner()->shouldDumpSpellCheckCallbacks()) { |
| 1391 m_delegate->printMessage(string("SpellCheckEvent: ") + eventName.utf8().
data() + "\n"); |
| 1392 } |
| 1393 } |
| 1394 |
| 1395 void WebTestProxyBase::resetInputMethod() |
| 1396 { |
| 1397 // If a composition text exists, then we need to let the browser process |
| 1398 // to cancel the input method's ongoing composition session. |
| 1399 if (m_webWidget) |
| 1400 m_webWidget->confirmComposition(); |
| 1401 } |
| 1402 |
| 1403 } |
| OLD | NEW |