| OLD | NEW |
| 1 // Copyright 2013 The Chromium Authors. All rights reserved. | 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 | 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/WebTestProxy.h" | 5 #include "content/shell/renderer/test_runner/WebTestProxy.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 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 59 : WebMethodTask<WebTestProxyBase>(object) | 59 : WebMethodTask<WebTestProxyBase>(object) |
| 60 , m_callback(callback) | 60 , m_callback(callback) |
| 61 { } | 61 { } |
| 62 | 62 |
| 63 virtual void runIfValid() OVERRIDE { (m_object->*m_callback)(); } | 63 virtual void runIfValid() OVERRIDE { (m_object->*m_callback)(); } |
| 64 | 64 |
| 65 private: | 65 private: |
| 66 CallbackMethodType m_callback; | 66 CallbackMethodType m_callback; |
| 67 }; | 67 }; |
| 68 | 68 |
| 69 class ClosureTask : public WebMethodTask<WebTestProxyBase> { | |
| 70 public: | |
| 71 ClosureTask(WebTestProxyBase* object, base::Closure callback) | |
| 72 : WebMethodTask<WebTestProxyBase>(object), m_callback(callback) {} | |
| 73 | |
| 74 virtual void runIfValid() OVERRIDE { | |
| 75 if (!m_callback.is_null()) | |
| 76 m_callback.Run(); | |
| 77 } | |
| 78 | |
| 79 private: | |
| 80 base::Closure m_callback; | |
| 81 }; | |
| 82 | |
| 83 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) | 69 void printFrameDescription(WebTestDelegate* delegate, WebFrame* frame) |
| 84 { | 70 { |
| 85 string name8 = frame->uniqueName().utf8(); | 71 string name8 = frame->uniqueName().utf8(); |
| 86 if (frame == frame->view()->mainFrame()) { | 72 if (frame == frame->view()->mainFrame()) { |
| 87 if (!name8.length()) { | 73 if (!name8.length()) { |
| 88 delegate->printMessage("main frame"); | 74 delegate->printMessage("main frame"); |
| 89 return; | 75 return; |
| 90 } | 76 } |
| 91 delegate->printMessage(string("main frame \"") + name8 + "\""); | 77 delegate->printMessage(string("main frame \"") + name8 + "\""); |
| 92 return; | 78 return; |
| (...skipping 393 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 486 bitmap.info().fWidth, | 472 bitmap.info().fWidth, |
| 487 "y", | 473 "y", |
| 488 bitmap.info().fHeight); | 474 bitmap.info().fHeight); |
| 489 SkCanvas canvas(bitmap); | 475 SkCanvas canvas(bitmap); |
| 490 DrawSelectionRect(&canvas); | 476 DrawSelectionRect(&canvas); |
| 491 DCHECK(!m_compositeAndReadbackCallbacks.empty()); | 477 DCHECK(!m_compositeAndReadbackCallbacks.empty()); |
| 492 m_compositeAndReadbackCallbacks.front().Run(bitmap); | 478 m_compositeAndReadbackCallbacks.front().Run(bitmap); |
| 493 m_compositeAndReadbackCallbacks.pop_front(); | 479 m_compositeAndReadbackCallbacks.pop_front(); |
| 494 } | 480 } |
| 495 | 481 |
| 482 void WebTestProxyBase::CapturePixelsForPrinting( |
| 483 base::Callback<void(const SkBitmap&)> callback) { |
| 484 // TODO(enne): get rid of stateful canvas(). |
| 485 webWidget()->layout(); |
| 486 paintPagesWithBoundaries(); |
| 487 DrawSelectionRect(canvas()); |
| 488 SkBaseDevice* device = skia::GetTopDevice(*canvas()); |
| 489 const SkBitmap& bitmap = device->accessBitmap(false); |
| 490 callback.Run(bitmap); |
| 491 } |
| 492 |
| 496 void WebTestProxyBase::CapturePixelsAsync( | 493 void WebTestProxyBase::CapturePixelsAsync( |
| 497 base::Callback<void(const SkBitmap&)> callback) { | 494 base::Callback<void(const SkBitmap&)> callback) { |
| 498 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); | 495 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); |
| 499 | 496 |
| 500 DCHECK(webWidget()->isAcceleratedCompositingActive()); | 497 DCHECK(webWidget()->isAcceleratedCompositingActive()); |
| 501 DCHECK(!callback.is_null()); | 498 DCHECK(!callback.is_null()); |
| 499 |
| 500 if (m_testInterfaces->testRunner()->isPrinting()) { |
| 501 base::MessageLoopProxy::current()->PostTask( |
| 502 FROM_HERE, |
| 503 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, |
| 504 base::Unretained(this), |
| 505 callback)); |
| 506 return; |
| 507 } |
| 508 |
| 502 m_compositeAndReadbackCallbacks.push_back(callback); | 509 m_compositeAndReadbackCallbacks.push_back(callback); |
| 503 webWidget()->compositeAndReadbackAsync(this); | 510 webWidget()->compositeAndReadbackAsync(this); |
| 504 } | 511 } |
| 505 | 512 |
| 506 void WebTestProxyBase::setLogConsoleOutput(bool enabled) | 513 void WebTestProxyBase::setLogConsoleOutput(bool enabled) |
| 507 { | 514 { |
| 508 m_logConsoleOutput = enabled; | 515 m_logConsoleOutput = enabled; |
| 509 } | 516 } |
| 510 | 517 |
| 511 void WebTestProxyBase::paintRect(const WebRect& rect) | 518 void WebTestProxyBase::paintRect(const WebRect& rect) |
| (...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 616 } | 623 } |
| 617 | 624 |
| 618 void WebTestProxyBase::displayAsyncThen(base::Closure callback) { | 625 void WebTestProxyBase::displayAsyncThen(base::Closure callback) { |
| 619 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); | 626 TRACE_EVENT0("shell", "WebTestProxyBase::displayAsyncThen"); |
| 620 | 627 |
| 621 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. | 628 // TODO(danakj): Remove when we have kForceCompositingMode everywhere. |
| 622 if (!webWidget()->isAcceleratedCompositingActive()) { | 629 if (!webWidget()->isAcceleratedCompositingActive()) { |
| 623 TRACE_EVENT0("shell", | 630 TRACE_EVENT0("shell", |
| 624 "WebTestProxyBase::displayAsyncThen " | 631 "WebTestProxyBase::displayAsyncThen " |
| 625 "isAcceleratedCompositingActive false"); | 632 "isAcceleratedCompositingActive false"); |
| 626 m_delegate->postTask( | 633 base::MessageLoopProxy::current()->PostTask( |
| 627 new ClosureTask(this, | 634 FROM_HERE, |
| 628 base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, | 635 base::Bind(&WebTestProxyBase::DisplayForSoftwareMode, |
| 629 base::Unretained(this), | 636 base::Unretained(this), |
| 630 callback))); | 637 callback)); |
| 631 return; | 638 return; |
| 632 } | 639 } |
| 633 | 640 |
| 634 CapturePixelsAsync(base::Bind( | 641 CapturePixelsAsync(base::Bind( |
| 635 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback)); | 642 &WebTestProxyBase::DidDisplayAsync, base::Unretained(this), callback)); |
| 636 } | 643 } |
| 637 | 644 |
| 638 void WebTestProxyBase::discardBackingStore() | 645 void WebTestProxyBase::discardBackingStore() |
| 639 { | 646 { |
| 640 m_canvas.reset(); | 647 m_canvas.reset(); |
| (...skipping 671 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1312 | 1319 |
| 1313 void WebTestProxyBase::resetInputMethod() | 1320 void WebTestProxyBase::resetInputMethod() |
| 1314 { | 1321 { |
| 1315 // If a composition text exists, then we need to let the browser process | 1322 // If a composition text exists, then we need to let the browser process |
| 1316 // to cancel the input method's ongoing composition session. | 1323 // to cancel the input method's ongoing composition session. |
| 1317 if (m_webWidget) | 1324 if (m_webWidget) |
| 1318 m_webWidget->confirmComposition(); | 1325 m_webWidget->confirmComposition(); |
| 1319 } | 1326 } |
| 1320 | 1327 |
| 1321 } // namespace content | 1328 } // namespace content |
| OLD | NEW |