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

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 16 matching lines...) Expand all
27 #include "content/shell/renderer/test_runner/spell_check_client.h" 27 #include "content/shell/renderer/test_runner/spell_check_client.h"
28 #include "content/shell/renderer/test_runner/test_interfaces.h" 28 #include "content/shell/renderer/test_runner/test_interfaces.h"
29 #include "content/shell/renderer/test_runner/test_plugin.h" 29 #include "content/shell/renderer/test_runner/test_plugin.h"
30 #include "content/shell/renderer/test_runner/test_runner.h" 30 #include "content/shell/renderer/test_runner/test_runner.h"
31 #include "content/shell/renderer/test_runner/web_test_runner.h" 31 #include "content/shell/renderer/test_runner/web_test_runner.h"
32 // FIXME: Including platform_canvas.h here is a layering violation. 32 // FIXME: Including platform_canvas.h here is a layering violation.
33 #include "skia/ext/platform_canvas.h" 33 #include "skia/ext/platform_canvas.h"
34 #include "third_party/WebKit/public/platform/Platform.h" 34 #include "third_party/WebKit/public/platform/Platform.h"
35 #include "third_party/WebKit/public/platform/WebCString.h" 35 #include "third_party/WebKit/public/platform/WebCString.h"
36 #include "third_party/WebKit/public/platform/WebClipboard.h" 36 #include "third_party/WebKit/public/platform/WebClipboard.h"
37 #include "third_party/WebKit/public/platform/WebCompositeAndReadbackAsyncCallbac k.h"
37 #include "third_party/WebKit/public/platform/WebURLError.h" 38 #include "third_party/WebKit/public/platform/WebURLError.h"
38 #include "third_party/WebKit/public/platform/WebURLRequest.h" 39 #include "third_party/WebKit/public/platform/WebURLRequest.h"
39 #include "third_party/WebKit/public/platform/WebURLResponse.h" 40 #include "third_party/WebKit/public/platform/WebURLResponse.h"
40 #include "third_party/WebKit/public/web/WebAXEnums.h" 41 #include "third_party/WebKit/public/web/WebAXEnums.h"
41 #include "third_party/WebKit/public/web/WebAXObject.h" 42 #include "third_party/WebKit/public/web/WebAXObject.h"
42 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" 43 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
43 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 44 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
44 #include "third_party/WebKit/public/web/WebDataSource.h" 45 #include "third_party/WebKit/public/web/WebDataSource.h"
45 #include "third_party/WebKit/public/web/WebDocument.h" 46 #include "third_party/WebKit/public/web/WebDocument.h"
46 #include "third_party/WebKit/public/web/WebElement.h" 47 #include "third_party/WebKit/public/web/WebElement.h"
47 #include "third_party/WebKit/public/web/WebHistoryItem.h" 48 #include "third_party/WebKit/public/web/WebHistoryItem.h"
48 #include "third_party/WebKit/public/web/WebLocalFrame.h" 49 #include "third_party/WebKit/public/web/WebLocalFrame.h"
49 #include "third_party/WebKit/public/web/WebMIDIClientMock.h" 50 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
50 #include "third_party/WebKit/public/web/WebNode.h" 51 #include "third_party/WebKit/public/web/WebNode.h"
52 #include "third_party/WebKit/public/web/WebPagePopup.h"
51 #include "third_party/WebKit/public/web/WebPluginParams.h" 53 #include "third_party/WebKit/public/web/WebPluginParams.h"
52 #include "third_party/WebKit/public/web/WebPrintParams.h" 54 #include "third_party/WebKit/public/web/WebPrintParams.h"
53 #include "third_party/WebKit/public/web/WebRange.h" 55 #include "third_party/WebKit/public/web/WebRange.h"
54 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h" 56 #include "third_party/WebKit/public/web/WebUserGestureIndicator.h"
55 #include "third_party/WebKit/public/web/WebView.h" 57 #include "third_party/WebKit/public/web/WebView.h"
58 #include "third_party/WebKit/public/web/WebWidgetClient.h"
56 59
57 namespace content { 60 namespace content {
58 61
59 namespace { 62 namespace {
60 63
64 class CaptureCallback : public blink::WebCompositeAndReadbackAsyncCallback {
65 public:
66 CaptureCallback(const base::Callback<void(const SkBitmap&)>& callback);
67 virtual ~CaptureCallback();
68
69 void set_wait_for_popup(bool wait) { wait_for_popup_ = wait; }
70 void set_popup_position(const gfx::Point& position) {
71 popup_position_ = position;
72 }
73
74 // WebCompositeAndReadbackAsyncCallback implementation.
75 virtual void didCompositeAndReadback(const SkBitmap& bitmap);
76
77 private:
78 base::Callback<void(const SkBitmap&)> callback_;
79 SkBitmap main_bitmap_;
80 bool wait_for_popup_;
81 gfx::Point popup_position_;
82 };
83
61 class HostMethodTask : public WebMethodTask<WebTestProxyBase> { 84 class HostMethodTask : public WebMethodTask<WebTestProxyBase> {
62 public: 85 public:
63 typedef void (WebTestProxyBase::*CallbackMethodType)(); 86 typedef void (WebTestProxyBase::*CallbackMethodType)();
64 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback) 87 HostMethodTask(WebTestProxyBase* object, CallbackMethodType callback)
65 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {} 88 : WebMethodTask<WebTestProxyBase>(object), callback_(callback) {}
66 89
67 virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); } 90 virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); }
68 91
69 private: 92 private:
70 CallbackMethodType callback_; 93 CallbackMethodType callback_;
(...skipping 253 matching lines...) Expand 10 before | Expand all | Expand 10 after
324 chooser_count_(0) { 347 chooser_count_(0) {
325 // TODO(enne): using the scheduler introduces additional composite steps 348 // TODO(enne): using the scheduler introduces additional composite steps
326 // that create flakiness. This should go away eventually. 349 // that create flakiness. This should go away eventually.
327 base::CommandLine::ForCurrentProcess()->AppendSwitch( 350 base::CommandLine::ForCurrentProcess()->AppendSwitch(
328 switches::kDisableSingleThreadProxyScheduler); 351 switches::kDisableSingleThreadProxyScheduler);
329 Reset(); 352 Reset();
330 } 353 }
331 354
332 WebTestProxyBase::~WebTestProxyBase() { 355 WebTestProxyBase::~WebTestProxyBase() {
333 test_interfaces_->WindowClosed(this); 356 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 } 357 }
338 358
339 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) { 359 void WebTestProxyBase::SetInterfaces(WebTestInterfaces* interfaces) {
340 test_interfaces_ = interfaces->testInterfaces(); 360 test_interfaces_ = interfaces->testInterfaces();
341 test_interfaces_->WindowOpened(this); 361 test_interfaces_->WindowOpened(this);
342 } 362 }
343 363
344 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) { 364 void WebTestProxyBase::SetDelegate(WebTestDelegate* delegate) {
345 delegate_ = delegate; 365 delegate_ = delegate;
346 spellcheck_->SetDelegate(delegate); 366 spellcheck_->SetDelegate(delegate);
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after
451 SkPaint paint; 471 SkPaint paint;
452 paint.setColor(0xFFFF0000); // Fully opaque red 472 paint.setColor(0xFFFF0000); // Fully opaque red
453 paint.setStyle(SkPaint::kStroke_Style); 473 paint.setStyle(SkPaint::kStroke_Style);
454 paint.setFlags(SkPaint::kAntiAlias_Flag); 474 paint.setFlags(SkPaint::kAntiAlias_Flag);
455 paint.setStrokeWidth(1.0f); 475 paint.setStrokeWidth(1.0f);
456 SkIRect rect; // Bounding rect 476 SkIRect rect; // Bounding rect
457 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height); 477 rect.set(wr.x, wr.y, wr.x + wr.width, wr.y + wr.height);
458 canvas->drawIRect(rect, paint); 478 canvas->drawIRect(rect, paint);
459 } 479 }
460 480
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) { 481 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
476 bool notify = accept_languages_ != accept_languages; 482 bool notify = accept_languages_ != accept_languages;
477 accept_languages_ = accept_languages; 483 accept_languages_ = accept_languages;
478 484
479 if (notify) 485 if (notify)
480 GetWebView()->acceptLanguagesChanged(); 486 GetWebView()->acceptLanguagesChanged();
481 } 487 }
482 488
483 void WebTestProxyBase::CopyImageAtAndCapturePixels( 489 void WebTestProxyBase::CopyImageAtAndCapturePixels(
484 int x, int y, const base::Callback<void(const SkBitmap&)>& callback) { 490 int x, int y, const base::Callback<void(const SkBitmap&)>& callback) {
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 } 527 }
522 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels); 528 web_frame->printPagesWithBoundaries(canvas.get(), page_size_in_pixels);
523 web_frame->printEnd(); 529 web_frame->printEnd();
524 530
525 DrawSelectionRect(canvas.get()); 531 DrawSelectionRect(canvas.get());
526 SkBaseDevice* device = skia::GetTopDevice(*canvas); 532 SkBaseDevice* device = skia::GetTopDevice(*canvas);
527 const SkBitmap& bitmap = device->accessBitmap(false); 533 const SkBitmap& bitmap = device->accessBitmap(false);
528 callback.Run(bitmap); 534 callback.Run(bitmap);
529 } 535 }
530 536
537 CaptureCallback::CaptureCallback(
538 const base::Callback<void(const SkBitmap&)>& callback)
539 : callback_(callback), wait_for_popup_(false) {
540 }
541
542 CaptureCallback::~CaptureCallback() {
543 }
544
545 void CaptureCallback::didCompositeAndReadback(const SkBitmap& bitmap) {
546 TRACE_EVENT2("shell",
547 "CaptureCallback::didCompositeAndReadback",
548 "x",
549 bitmap.info().fWidth,
550 "y",
551 bitmap.info().fHeight);
552 if (!wait_for_popup_) {
553 callback_.Run(bitmap);
554 delete this;
555 return;
556 }
557 if (main_bitmap_.isNull()) {
558 bitmap.deepCopyTo(&main_bitmap_);
559 return;
560 }
561 SkCanvas canvas(main_bitmap_);
562 canvas.drawBitmap(bitmap, popup_position_.x(), popup_position_.y());
563 callback_.Run(main_bitmap_);
564 delete this;
565 }
566
531 void WebTestProxyBase::CapturePixelsAsync( 567 void WebTestProxyBase::CapturePixelsAsync(
532 const base::Callback<void(const SkBitmap&)>& callback) { 568 const base::Callback<void(const SkBitmap&)>& callback) {
533 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync"); 569 TRACE_EVENT0("shell", "WebTestProxyBase::CapturePixelsAsync");
534 570
535 DCHECK(web_widget_->isAcceleratedCompositingActive()); 571 DCHECK(web_widget_->isAcceleratedCompositingActive());
536 DCHECK(!callback.is_null()); 572 DCHECK(!callback.is_null());
537 573
538 if (test_interfaces_->GetTestRunner()->isPrinting()) { 574 if (test_interfaces_->GetTestRunner()->isPrinting()) {
539 base::MessageLoopProxy::current()->PostTask( 575 base::MessageLoopProxy::current()->PostTask(
540 FROM_HERE, 576 FROM_HERE,
541 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting, 577 base::Bind(&WebTestProxyBase::CapturePixelsForPrinting,
542 base::Unretained(this), 578 base::Unretained(this),
543 callback)); 579 callback));
544 return; 580 return;
545 } 581 }
546 582
547 composite_and_readback_callbacks_.push_back(callback); 583 CaptureCallback* capture_callback = new CaptureCallback(base::Bind(
548 web_widget_->compositeAndReadbackAsync(this); 584 &WebTestProxyBase::DidCapturePixelsAsync, base::Unretained(this),
585 callback));
586 web_widget_->compositeAndReadbackAsync(capture_callback);
587 if (blink::WebPagePopup* popup = web_widget_->pagePopup()) {
588 capture_callback->set_wait_for_popup(true);
589 capture_callback->set_popup_position(popup->positionRelativeToOwner());
590 popup->compositeAndReadbackAsync(capture_callback);
591 }
592 }
593
594 void WebTestProxyBase::DidCapturePixelsAsync(const base::Callback<void(const SkB itmap&)>& callback,
595 const SkBitmap& bitmap) {
596 SkCanvas canvas(bitmap);
597 DrawSelectionRect(&canvas);
keishi 2014/09/18 09:14:17 I forgot to call DrawSelectionRect in my previous
598 if (!callback.is_null())
599 callback.Run(bitmap);
549 } 600 }
550 601
551 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) { 602 void WebTestProxyBase::SetLogConsoleOutput(bool enabled) {
552 log_console_output_ = enabled; 603 log_console_output_ = enabled;
553 } 604 }
554 605
555 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback, 606 void WebTestProxyBase::DidDisplayAsync(const base::Closure& callback,
556 const SkBitmap& bitmap) { 607 const SkBitmap& bitmap) {
557 // Verify we actually composited. 608 // Verify we actually composited.
558 CHECK_NE(0, bitmap.info().fWidth); 609 CHECK_NE(0, bitmap.info().fWidth);
(...skipping 729 matching lines...) Expand 10 before | Expand all | Expand 10 after
1288 if (!push_client_.get()) 1339 if (!push_client_.get())
1289 push_client_.reset(new MockWebPushClient); 1340 push_client_.reset(new MockWebPushClient);
1290 return push_client_.get(); 1341 return push_client_.get();
1291 } 1342 }
1292 1343
1293 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { 1344 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() {
1294 return GetPushClientMock(); 1345 return GetPushClientMock();
1295 } 1346 }
1296 1347
1297 } // namespace content 1348 } // 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