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

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
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 30 matching lines...) Expand all
41 #include "third_party/WebKit/public/web/WebAXObject.h" 41 #include "third_party/WebKit/public/web/WebAXObject.h"
42 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" 42 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
43 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 43 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
44 #include "third_party/WebKit/public/web/WebDataSource.h" 44 #include "third_party/WebKit/public/web/WebDataSource.h"
45 #include "third_party/WebKit/public/web/WebDocument.h" 45 #include "third_party/WebKit/public/web/WebDocument.h"
46 #include "third_party/WebKit/public/web/WebElement.h" 46 #include "third_party/WebKit/public/web/WebElement.h"
47 #include "third_party/WebKit/public/web/WebHistoryItem.h" 47 #include "third_party/WebKit/public/web/WebHistoryItem.h"
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" 48 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebMIDIClientMock.h" 49 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
50 #include "third_party/WebKit/public/web/WebNode.h" 50 #include "third_party/WebKit/public/web/WebNode.h"
51 #include "third_party/WebKit/public/web/WebPagePopup.h"
51 #include "third_party/WebKit/public/web/WebPluginParams.h" 52 #include "third_party/WebKit/public/web/WebPluginParams.h"
52 #include "third_party/WebKit/public/web/WebPrintParams.h" 53 #include "third_party/WebKit/public/web/WebPrintParams.h"
53 #include "third_party/WebKit/public/web/WebRange.h" 54 #include "third_party/WebKit/public/web/WebRange.h"
54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 55 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
55 #include "third_party/WebKit/public/web/WebView.h" 56 #include "third_party/WebKit/public/web/WebView.h"
57 #include "third_party/WebKit/public/web/WebWidgetClient.h"
56 58
57 namespace content { 59 namespace content {
58 60
59 namespace { 61 namespace {
60 62
63 class CaptureCallback : public blink::WebCompositeAndReadbackAsyncCallback {
64 public:
65 CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback);
66 virtual ~CaptureCallback();
67
68 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; }
69 void set_popup_position(const gfx::Point& position) {
70 popup_position_ = position;
71 }
72
73 // WebCompositeAndReadbackAsyncCallback implementation.
74 virtual void didCompositeAndReadback(const SkBitmap& bitmap);
75
76 private:
77 base::Callback<void(const SkBitmap&)> callback_;
78 SkBitmap main_bitmap_;
79 bool wait_for_popup_;
80 gfx::Point popup_position_;
81 };
82
61 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { 83 class HostMethodTask : public WebMethodTask<WebTestProxyBase> {
62 public: 84 public:
63 typedef void (WebTestProxyBase::*CallbackMethodType)(); 85 typedef void (WebTestProxyBase::*CallbackMethodType)();
64 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) 86 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback)
65 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} 87 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {}
66 88
67 virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); } 89 virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); }
68 90
69 private: 91 private:
70 CallbackMethodType callback_; 92 CallbackMethodType callback_;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 chooser_count_(0) { 346 chooser_count_(0) {
325 // TODO(enne): using the scheduler introduces additional composite steps 347 // TODO(enne): using the scheduler introduces additional composite steps
326 // that create flakiness. This should go away eventually. 348 // that create flakiness. This should go away eventually.
327 base::CommandLine::ForCurrentProcess()->AppendSwitch( 349 base::CommandLine::ForCurrentProcess()->AppendSwitch(
328 switches::kDisableSingleThreadProxyScheduler); 350 switches::kDisableSingleThreadProxyScheduler);
329 Reset(); 351 Reset();
330 } 352 }
331 353
332 WebTestProxyBase::~WebTestProxyBase() { 354 WebTestProxyBase::~WebTestProxyBase() {
333 test_interfaces_->WindowClosed(this); 355 test_interfaces_->WindowClosed(this);
334 // Tests must wait for readback requests to finish before notifying that
335 // they are done.
336 CHECK_EQ(0u, composite_and_readback_callbacks_.size());
337 } 356 }
338 357
339 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { 358 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) {
340 test_interfaces_ = interfaces->testInterfaces(); 359 test_interfaces_ = interfaces->testInterfaces();
341 test_interfaces_->WindowOpened(this); 360 test_interfaces_->WindowOpened(this);
342 } 361 }
343 362
344 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { 363 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) {
345 delegate_ = delegate; 364 delegate_ = delegate;
346 spellcheck_->SetDelegate(delegate); 365 spellcheck_->SetDelegate(delegate);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 SkPaint paint; 470 SkPaint paint;
452 paint.setColor(0xFFFF0000); // Fully opaque red 471 paint.setColor(0xFFFF0000); // Fully opaque red
453 paint.setStyle(SkPaint::kStroke_Style); 472 paint.setStyle(SkPaint::kStroke_Style);
454 paint.setFlags(SkPaint::kAntiAlias_Flag); 473 paint.setFlags(SkPaint::kAntiAlias_Flag);
455 paint.setStrokeWidth(1.0f); 474 paint.setStrokeWidth(1.0f);
456 SkIRect rect; // Bounding rect 475 SkIRect rect; // Bounding rect
457 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);
458 canvas->drawIRect(rect, paint); 477 canvas->drawIRect(rect, paint);
459 } 478 }
460 479
461 void WebTestProxyBase::didCompositeAndReadback(const SkBitmap& bitmap) {
462 TRACE_EVENT2("shell",
463 "WebTestProxyBase::didCompositeAndReadback",
464 "x",
465 bitmap.info().fWidth,
466 "y",
467 bitmap.info().fHeight);
468 SkCanvas canvas(bitmap);
469 DrawSelectionRect(&canvas);
470 DCHECK(!composite_and_readback_callbacks_.empty());
471 composite_and_readback_callbacks_.front().Run(bitmap);
472 composite_and_readback_callbacks_.pop_front();
473 }
474
475 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) { 480 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
476 bool notify = accept_languages_ != accept_languages; 481 bool notify = accept_languages_ != accept_languages;
477 accept_languages_ = accept_languages; 482 accept_languages_ = accept_languages;
478 483
479 if (notify) 484 if (notify)
480 GetWebView()->acceptLanguagesChanged(); 485 GetWebView()->acceptLanguagesChanged();
481 } 486 }
482 487
483 void WebTestProxyBase::CopyImageAtAndCapturePixels( 488 void WebTestProxyBase::CopyImageAtAndCapturePixels(
484 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
521 } 526 }
522 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); 527 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels);
523 web_frame->printEnd(); 528 web_frame->printEnd();
524 529
525 DrawSelectionRect(canvas.get()); 530 DrawSelectionRect(canvas.get());
526 SkBaseDevice* device = skia::GetTopDevice(*canvas); 531 SkBaseDevice* device = skia::GetTopDevice(*canvas);
527 const SkBitmap& bitmap = device->accessBitmap(false); 532 const SkBitmap& bitmap = device->accessBitmap(false);
528 callback.Run(bitmap); 533 callback.Run(bitmap);
529 } 534 }
530 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 TRACE_EVENT2("shell",
546 "CaptureCallback::didCompositeAndReadback",
547 "x",
548 bitmap.info().fWidth,
549 "y",
550 bitmap.info().fHeight);
551 if (!wait_for_popup_) {
552 callback_.Run(bitmap);
553 delete this;
554 return;
555 }
556 if (main_bitmap_.isNull()) {
557 bitmap.deepCopyTo(&main_bitmap_);
558 return;
559 }
560 SkCanvas canvas(main_bitmap_);
561 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
562 callback_.Run(main_bitmap_);
563 delete this;
564 }
565
531 void WebTestProxyBase::CapturePixelsAsync( 566 void WebTestProxyBase::CapturePixelsAsync(
532 const base::Callback<void(const SkBitmap&)>& callback) { 567 const base::Callback<void(const SkBitmap&)>& callback) {
533 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); 568 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
534 569
535 DCHECK(web_widget_->isAcceleratedCompositingActive()); 570 DCHECK(web_widget_->isAcceleratedCompositingActive());
536 DCHECK(!callback.is_null()); 571 DCHECK(!callback.is_null());
537 572
538 if (test_interfaces_->GetTestRunner()->isPrinting()) { 573 if (test_interfaces_->GetTestRunner()->isPrinting()) {
539 base::MessageLoopProxy::current()->PostTask( 574 base::MessageLoopProxy::current()->PostTask(
540 FROM_HERE, 575 FROM_HERE,
541 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, 576 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting,
542 base::Unretained(this), 577 base::Unretained(this),
543 callback)); 578 callback));
544 return; 579 return;
545 } 580 }
546 581
547 composite_and_readback_callbacks_.push_back(callback); 582 CaptureCallback* capture_callback = new CaptureCallback(callback);
548 web_widget_->compositeAndReadbackAsync(this); 583 web_widget_->compositeAndReadbackAsync(capture_callback);
584 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) {
585 capture_callback->set_wait_for_popup(true);
586 capture_callback->set_popup_position(
587 popup->positionRelativeToOwner());
588 popup->compositeAndReadbackAsync(capture_callback);
589 }
549 } 590 }
550 591
551 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { 592 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {
552 log_console_output_ = enabled; 593 log_console_output_ = enabled;
553 } 594 }
554 595
555 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, 596 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback,
556 const SkBitmap& bitmap) { 597 const SkBitmap& bitmap) {
557 // Verify we actually composited. 598 // Verify we actually composited.
558 CHECK_NE(0, bitmap.info().fWidth); 599 CHECK_NE(0, bitmap.info().fWidth);
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 if (!push_client_.get()) 1329 if (!push_client_.get())
1289 push_client_.reset(new MockWebPushClient); 1330 push_client_.reset(new MockWebPushClient);
1290 return push_client_.get(); 1331 return push_client_.get();
1291 } 1332 }
1292 1333
1293 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { 1334 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() {
1294 return GetPushClientMock(); 1335 return GetPushClientMock();
1295 } 1336 }
1296 1337
1297 } // namespace content 1338 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698