Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(246)

Side by Side Diff: content/shell/renderer/test_runner/web_test_proxy.cc

Issue 508063002: Draw page popups in layout tests (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/command_line.h" 10 #include "base/command_line.h"
(...skipping 29 matching lines...) Expand all
40 #include "third_party/WebKit/public/web/WebAXObject.h" 40 #include "third_party/WebKit/public/web/WebAXObject.h"
41 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" 41 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
42 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 42 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
43 #include "third_party/WebKit/public/web/WebDataSource.h" 43 #include "third_party/WebKit/public/web/WebDataSource.h"
44 #include "third_party/WebKit/public/web/WebDocument.h" 44 #include "third_party/WebKit/public/web/WebDocument.h"
45 #include "third_party/WebKit/public/web/WebElement.h" 45 #include "third_party/WebKit/public/web/WebElement.h"
46 #include "third_party/WebKit/public/web/WebHistoryItem.h" 46 #include "third_party/WebKit/public/web/WebHistoryItem.h"
47 #include "third_party/WebKit/public/web/WebLocalFrame.h" 47 #include "third_party/WebKit/public/web/WebLocalFrame.h"
48 #include "third_party/WebKit/public/web/WebMIDIClientMock.h" 48 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
49 #include "third_party/WebKit/public/web/WebNode.h" 49 #include "third_party/WebKit/public/web/WebNode.h"
50 #include "third_party/WebKit/public/web/WebPagePopup.h"
50 #include "third_party/WebKit/public/web/WebPluginParams.h" 51 #include "third_party/WebKit/public/web/WebPluginParams.h"
51 #include "third_party/WebKit/public/web/WebPrintParams.h" 52 #include "third_party/WebKit/public/web/WebPrintParams.h"
52 #include "third_party/WebKit/public/web/WebRange.h" 53 #include "third_party/WebKit/public/web/WebRange.h"
53 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
54 #include "third_party/WebKit/public/web/WebView.h" 55 #include "third_party/WebKit/public/web/WebView.h"
56 #include "third_party/WebKit/public/web/WebWidgetClient.h"
55 57
56 namespace content { 58 namespace content {
57 59
58 namespace { 60 namespace {
59 61
62 class CaptureCallback : public blink::WebCompositeAndReadbackAsyncCallback {
63 public:
64 CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback);
65 virtual ~CaptureCallback();
66
67 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; }
68 void set_popup_position(gfx::Point position) { popup_position_ = position; }
tkent 2014/09/18 05:30:40 gfx::Point -> const gfx::Point&
keishi 2014/09/18 05:54:20 Done.
69
70 // WebCompositeAndReadbackAsyncCallback implementation.
71 virtual void didCompositeAndReadback(const SkBitmap& bitmap);
72
73 private:
74 base::Callback<void(const SkBitmap&)> callback_;
75 SkBitmap main_bitmap_;
76 bool wait_for_popup_;
77 gfx::Point popup_position_;
78 };
79
60 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { 80 class HostMethodTask : public WebMethodTask<WebTestProxyBase> {
61 public: 81 public:
62 typedef void (WebTestProxyBase::*CallbackMethodType)(); 82 typedef void (WebTestProxyBase::*CallbackMethodType)();
63 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) 83 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback)
64 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} 84 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {}
65 85
66 virtual void runIfValid() OVERRIDE { (m_object->*callback_)(); } 86 virtual void runIfValid() OVERRIDE { (m_object->*callback_)(); }
67 87
68 private: 88 private:
69 CallbackMethodType callback_; 89 CallbackMethodType callback_;
(...skipping 255 matching lines...) Expand 10 before | Expand all | Expand 10 after
325 // that create flakiness. This should go away eventually. 345 // that create flakiness. This should go away eventually.
326 base::CommandLine::ForCurrentProcess()->AppendSwitch( 346 base::CommandLine::ForCurrentProcess()->AppendSwitch(
327 switches::kDisableSingleThreadProxyScheduler); 347 switches::kDisableSingleThreadProxyScheduler);
328 Reset(); 348 Reset();
329 } 349 }
330 350
331 WebTestProxyBase::~WebTestProxyBase() { 351 WebTestProxyBase::~WebTestProxyBase() {
332 test_interfaces_->WindowClosed(this); 352 test_interfaces_->WindowClosed(this);
333 // Tests must wait for readback requests to finish before notifying that 353 // Tests must wait for readback requests to finish before notifying that
334 // they are done. 354 // they are done.
335 CHECK_EQ(0u, composite_and_readback_callbacks_.size()); 355 //CHECK_EQ(0u, composite_and_readback_callbacks_.size());
tkent 2014/09/18 05:30:40 Remove this line and the above comment.
keishi 2014/09/18 05:54:20 Done.
336 } 356 }
337 357
338 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { 358 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) {
339 test_interfaces_ = interfaces->testInterfaces(); 359 test_interfaces_ = interfaces->testInterfaces();
340 test_interfaces_->WindowOpened(this); 360 test_interfaces_->WindowOpened(this);
341 } 361 }
342 362
343 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { 363 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) {
344 delegate_ = delegate; 364 delegate_ = delegate;
345 spellcheck_->SetDelegate(delegate); 365 spellcheck_->SetDelegate(delegate);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
450 SkPaint paint; 470 SkPaint paint;
451 paint.setColor(0xFFFF0000); // Fully opaque red 471 paint.setColor(0xFFFF0000); // Fully opaque red
452 paint.setStyle(SkPaint::kStroke_Style); 472 paint.setStyle(SkPaint::kStroke_Style);
453 paint.setFlags(SkPaint::kAntiAlias_Flag); 473 paint.setFlags(SkPaint::kAntiAlias_Flag);
454 paint.setStrokeWidth(1.0f); 474 paint.setStrokeWidth(1.0f);
455 SkIRect rect; // Bounding rect 475 SkIRect rect; // Bounding rect
456 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); 476 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
457 canvas->drawIRect(rect, paint); 477 canvas->drawIRect(rect, paint);
458 } 478 }
459 479
460 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) {
461 TRACE_EVENT2("shell",
tkent 2014/09/18 05:30:41 Can you move the TRACE_EVENT2 to CaptureCallback::
keishi 2014/09/18 05:54:20 Done.
462 "WebTestProxyBase::didCompositeAndReadback",
463 "x",
464 bitmap.info().fWidth,
465 "y",
466 bitmap.info().fHeight);
467 SkCanvas canvas(bitmap);
468 DrawSelectionRect(&canvas);
469 DCHECK(!composite_and_readback_callbacks_.empty());
470 composite_and_readback_callbacks_.front().Run(bitmap);
471 composite_and_readback_callbacks_.pop_front();
472 }
473
474 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) { 480 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
475 bool notify = accept_languages_ != accept_languages; 481 bool notify = accept_languages_ != accept_languages;
476 accept_languages_ = accept_languages; 482 accept_languages_ = accept_languages;
477 483
478 if (notify) 484 if (notify)
479 GetWebView()->acceptLanguagesChanged(); 485 GetWebView()->acceptLanguagesChanged();
480 } 486 }
481 487
482 void WebTestProxyBase::CopyImageAtAndCapturePixels( 488 void WebTestProxyBase::CopyImageAtAndCapturePixels(
483 int x, int y, const base::Callback<void(const SkBitmap&)>& callback) { 489 int x, int y, const base::Callback<void(const SkBitmap&)>& callback) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
520 } 526 }
521 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); 527 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels);
522 web_frame->printEnd(); 528 web_frame->printEnd();
523 529
524 DrawSelectionRect(canvas.get()); 530 DrawSelectionRect(canvas.get());
525 SkBaseDevice* device = skia::GetTopDevice(*canvas); 531 SkBaseDevice* device = skia::GetTopDevice(*canvas);
526 const SkBitmap& bitmap = device->accessBitmap(false); 532 const SkBitmap& bitmap = device->accessBitmap(false);
527 callback.Run(bitmap); 533 callback.Run(bitmap);
528 } 534 }
529 535
536 CaptureCallback::CaptureCallback(
537 const base::Callback<void(const SkBitmap&)>& callback)
538 : callback_(callback), wait_for_popup_(false) {
539 }
540
541 CaptureCallback::~CaptureCallback() {
542 }
543
544 void CaptureCallback::didCompositeAndReadback(const SkBitmap& bitmap) {
545 if (!wait_for_popup_) {
546 callback_.Run(bitmap);
547 delete this;
548 return;
549 }
550 if (main_bitmap_.isNull()) {
551 bitmap.deepCopyTo(&main_bitmap_);
552 return;
553 }
554 SkCanvas canvas(main_bitmap_);
555 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
556 callback_.Run(main_bitmap_);
557 delete this;
558 }
559
530 void WebTestProxyBase::CapturePixelsAsync( 560 void WebTestProxyBase::CapturePixelsAsync(
531 const base::Callback<void(const SkBitmap&)>& callback) { 561 const base::Callback<void(const SkBitmap&)>& callback) {
532 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); 562 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
533 563
534 DCHECK(web_widget_->isAcceleratedCompositingActive()); 564 DCHECK(web_widget_->isAcceleratedCompositingActive());
535 DCHECK(!callback.is_null()); 565 DCHECK(!callback.is_null());
536 566
537 if (test_interfaces_->GetTestRunner()->isPrinting()) { 567 if (test_interfaces_->GetTestRunner()->isPrinting()) {
538 base::MessageLoopProxy::current()->PostTask( 568 base::MessageLoopProxy::current()->PostTask(
539 FROM_HERE, 569 FROM_HERE,
540 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, 570 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting,
541 base::Unretained(this), 571 base::Unretained(this),
542 callback)); 572 callback));
543 return; 573 return;
544 } 574 }
545 575
546 composite_and_readback_callbacks_.push_back(callback); 576 CaptureCallback* capture_callback = new CaptureCallback(callback);
547 web_widget_->compositeAndReadbackAsync(this); 577 web_widget_->compositeAndReadbackAsync(capture_callback);
578 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) {
579 capture_callback->set_wait_for_popup(true);
580 blink::WebPoint popup_position = popup->positionRelativeToOwner();
581 capture_callback->set_popup_position(
tkent 2014/09/18 05:30:40 I think we can write this like: capture_callba
582 gfx::Point(popup_position.x, popup_position.y));
583 popup->compositeAndReadbackAsync(capture_callback);
584 }
548 } 585 }
549 586
550 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { 587 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {
551 log_console_output_ = enabled; 588 log_console_output_ = enabled;
552 } 589 }
553 590
554 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, 591 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback,
555 const SkBitmap& bitmap) { 592 const SkBitmap& bitmap) {
556 // Verify we actually composited. 593 // Verify we actually composited.
557 CHECK_NE(0, bitmap.info().fWidth); 594 CHECK_NE(0, bitmap.info().fWidth);
(...skipping 722 matching lines...) Expand 10 before | Expand all | Expand 10 after
1280 if (!push_client_.get()) 1317 if (!push_client_.get())
1281 push_client_.reset(new MockWebPushClient); 1318 push_client_.reset(new MockWebPushClient);
1282 return push_client_.get(); 1319 return push_client_.get();
1283 } 1320 }
1284 1321
1285 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { 1322 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() {
1286 return GetPushClientMock(); 1323 return GetPushClientMock();
1287 } 1324 }
1288 1325
1289 } // namespace content 1326 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698