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

Side by Side Diff: content/browser/renderer_host/render_widget_host_view_browsertest.cc

Issue 462173002: Fix set_area sizes for RequestCopyOfOutput, and related tests. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: RWHVBrowserTest changes, per danakj's comments. Disabled tests on Windows. Created 6 years, 4 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 | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 "base/command_line.h" 5 #include "base/command_line.h"
6 #include "base/message_loop/message_loop_proxy.h" 6 #include "base/message_loop/message_loop_proxy.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/run_loop.h" 8 #include "base/run_loop.h"
9 #include "content/browser/gpu/compositor_util.h" 9 #include "content/browser/gpu/compositor_util.h"
10 #include "content/browser/gpu/gpu_data_manager_impl.h" 10 #include "content/browser/gpu/gpu_data_manager_impl.h"
(...skipping 11 matching lines...) Expand all
22 #include "content/public/test/content_browser_test.h" 22 #include "content/public/test/content_browser_test.h"
23 #include "content/public/test/content_browser_test_utils.h" 23 #include "content/public/test/content_browser_test_utils.h"
24 #include "content/shell/browser/shell.h" 24 #include "content/shell/browser/shell.h"
25 #include "media/base/video_frame.h" 25 #include "media/base/video_frame.h"
26 #include "media/filters/skcanvas_video_renderer.h" 26 #include "media/filters/skcanvas_video_renderer.h"
27 #include "net/base/filename_util.h" 27 #include "net/base/filename_util.h"
28 #include "third_party/skia/include/core/SkBitmap.h" 28 #include "third_party/skia/include/core/SkBitmap.h"
29 #include "third_party/skia/include/core/SkCanvas.h" 29 #include "third_party/skia/include/core/SkCanvas.h"
30 #include "ui/base/layout.h" 30 #include "ui/base/layout.h"
31 #include "ui/base/ui_base_switches.h" 31 #include "ui/base/ui_base_switches.h"
32 #include "ui/gfx/size_conversions.h" 32 #include "ui/gfx/geometry/size_conversions.h"
33 #include "ui/gfx/switches.h" 33 #include "ui/gfx/switches.h"
34 #include "ui/gl/gl_switches.h" 34 #include "ui/gl/gl_switches.h"
35 35
36 #if defined(OS_WIN) 36 #if defined(OS_WIN)
37 #include "base/win/windows_version.h" 37 #include "base/win/windows_version.h"
38 #include "ui/gfx/win/dpi.h" 38 #include "ui/gfx/win/dpi.h"
39 #endif 39 #endif
40 40
41 namespace content { 41 namespace content {
42 namespace { 42 namespace {
(...skipping 385 matching lines...) Expand 10 before | Expand all | Expand 10 after
428 428
429 const SkBitmap& expected_bitmap = 429 const SkBitmap& expected_bitmap =
430 expected_copy_from_compositing_surface_bitmap_; 430 expected_copy_from_compositing_surface_bitmap_;
431 EXPECT_EQ(expected_bitmap.width(), bitmap.width()); 431 EXPECT_EQ(expected_bitmap.width(), bitmap.width());
432 EXPECT_EQ(expected_bitmap.height(), bitmap.height()); 432 EXPECT_EQ(expected_bitmap.height(), bitmap.height());
433 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType()); 433 EXPECT_EQ(expected_bitmap.colorType(), bitmap.colorType());
434 SkAutoLockPixels expected_bitmap_lock(expected_bitmap); 434 SkAutoLockPixels expected_bitmap_lock(expected_bitmap);
435 SkAutoLockPixels bitmap_lock(bitmap); 435 SkAutoLockPixels bitmap_lock(bitmap);
436 int fails = 0; 436 int fails = 0;
437 for (int i = 0; i < bitmap.width() && fails < 10; ++i) { 437 for (int i = 0; i < bitmap.width() && fails < 10; ++i) {
438 // Exclude the middle 3 columns of pixels from testing since scaling could
439 // cause these pixels to be a mix of the two colors.
440 if (i >= (bitmap.width() / 2 - 1) && i <= (bitmap.width() / 2 + 1))
441 continue;
442
438 for (int j = 0; j < bitmap.height() && fails < 10; ++j) { 443 for (int j = 0; j < bitmap.height() && fails < 10; ++j) {
439 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j)) 444 if (!exclude_rect_.IsEmpty() && exclude_rect_.Contains(i, j))
440 continue; 445 continue;
441 446
442 SkColor expected_color = expected_bitmap.getColor(i, j); 447 SkColor expected_color = expected_bitmap.getColor(i, j);
443 SkColor color = bitmap.getColor(i, j); 448 SkColor color = bitmap.getColor(i, j);
444 int expected_alpha = SkColorGetA(expected_color); 449 int expected_alpha = SkColorGetA(expected_color);
445 int alpha = SkColorGetA(color); 450 int alpha = SkColorGetA(color);
446 int expected_red = SkColorGetR(expected_color); 451 int expected_red = SkColorGetR(expected_color);
447 int red = SkColorGetR(color); 452 int red = SkColorGetR(color);
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
516 521
517 virtual GURL TestUrl() OVERRIDE { 522 virtual GURL TestUrl() OVERRIDE {
518 return GURL(test_url_); 523 return GURL(test_url_);
519 } 524 }
520 525
521 void SetTestUrl(std::string url) { test_url_ = url; } 526 void SetTestUrl(std::string url) { test_url_ = url; }
522 527
523 // Loads a page two boxes side-by-side, each half the width of 528 // Loads a page two boxes side-by-side, each half the width of
524 // |html_rect_size|, and with different background colors. The test then 529 // |html_rect_size|, and with different background colors. The test then
525 // copies from |copy_rect| region of the page into a bitmap of size 530 // copies from |copy_rect| region of the page into a bitmap of size
526 // |output_size|, and compares that with a bitmap of size 531 // |output_size|, and examines the resulting bitmap/VideoFrame.
527 // |expected_bitmap_size|.
528 // Note that |output_size| may not have the same size as |copy_rect| (e.g. 532 // Note that |output_size| may not have the same size as |copy_rect| (e.g.
529 // when the output is scaled). Also note that |expected_bitmap_size| may not 533 // when the output is scaled).
530 // be the same as |output_size| (e.g. when the device scale factor is not 1).
531 void PerformTestWithLeftRightRects(const gfx::Size& html_rect_size, 534 void PerformTestWithLeftRightRects(const gfx::Size& html_rect_size,
532 const gfx::Rect& copy_rect, 535 const gfx::Rect& copy_rect,
533 const gfx::Size& output_size, 536 const gfx::Size& output_size,
534 const gfx::Size& expected_bitmap_size,
535 bool video_frame) { 537 bool video_frame) {
536 const gfx::Size box_size(html_rect_size.width() / 2, 538 const gfx::Size box_size(html_rect_size.width() / 2,
537 html_rect_size.height()); 539 html_rect_size.height());
538 SetTestUrl(base::StringPrintf( 540 SetTestUrl(base::StringPrintf(
539 "data:text/html,<!doctype html>" 541 "data:text/html,<!doctype html>"
540 "<div class='left'>" 542 "<div class='left'>"
541 " <div class='right'></div>" 543 " <div class='right'></div>"
542 "</div>" 544 "</div>"
543 "<style>" 545 "<style>"
544 "body { padding: 0; margin: 0; }" 546 "body { padding: 0; margin: 0; }"
(...skipping 13 matching lines...) Expand all
558 " domAutomationController.setAutomationId(0);" 560 " domAutomationController.setAutomationId(0);"
559 " domAutomationController.send(\"DONE\");" 561 " domAutomationController.send(\"DONE\");"
560 "</script>", 562 "</script>",
561 box_size.width(), 563 box_size.width(),
562 box_size.height(), 564 box_size.height(),
563 box_size.width(), 565 box_size.width(),
564 box_size.width(), 566 box_size.width(),
565 box_size.height())); 567 box_size.height()));
566 568
567 SET_UP_SURFACE_OR_PASS_TEST("\"DONE\""); 569 SET_UP_SURFACE_OR_PASS_TEST("\"DONE\"");
568 if (!ShouldContinueAfterTestURLLoad())
569 return;
570 570
571 RenderWidgetHostViewBase* rwhvp = GetRenderWidgetHostView(); 571 RenderWidgetHostViewBase* rwhvp = GetRenderWidgetHostView();
572 if (video_frame && !rwhvp->CanCopyToVideoFrame()) { 572 if (video_frame && !rwhvp->CanCopyToVideoFrame()) {
573 // This should only happen on Mac when using the software compositor. 573 // This should only happen on Mac when using the software compositor.
574 // Otherwise, raise an error. This can be removed when Mac is moved to a 574 // Otherwise, raise an error. This can be removed when Mac is moved to a
575 // browser compositor. 575 // browser compositor.
576 // http://crbug.com/314190 576 // http://crbug.com/314190
577 #if defined(OS_MACOSX) 577 #if defined(OS_MACOSX)
578 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) { 578 if (!content::GpuDataManager::GetInstance()->GpuAccessAllowed(NULL)) {
579 LOG(WARNING) << ("Blindly passing this test because copying to " 579 LOG(WARNING) << ("Blindly passing this test because copying to "
580 "video frames is not supported on this platform."); 580 "video frames is not supported on this platform.");
581 return; 581 return;
582 } 582 }
583 #endif 583 #endif
584 NOTREACHED(); 584 NOTREACHED();
585 } 585 }
586 586
587 // The page is loaded in the renderer, wait for a new frame to arrive. 587 // The page is loaded in the renderer, wait for a new frame to arrive.
588 uint32 frame = rwhvp->RendererFrameNumber(); 588 uint32 frame = rwhvp->RendererFrameNumber();
589 while (!GetRenderWidgetHost()->ScheduleComposite()) 589 while (!GetRenderWidgetHost()->ScheduleComposite())
590 GiveItSomeTime(); 590 GiveItSomeTime();
591 while (rwhvp->RendererFrameNumber() == frame) 591 while (rwhvp->RendererFrameNumber() == frame)
592 GiveItSomeTime(); 592 GiveItSomeTime();
593 593
594 SkBitmap expected_bitmap; 594 SkBitmap expected_bitmap;
595 SetupLeftRightBitmap(expected_bitmap_size, &expected_bitmap); 595 SetupLeftRightBitmap(output_size, &expected_bitmap);
596 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap); 596 SetExpectedCopyFromCompositingSurfaceResult(true, expected_bitmap);
597 597
598 base::RunLoop run_loop; 598 base::RunLoop run_loop;
599 if (video_frame) { 599 if (video_frame) {
600 // Allow pixel differences as long as we have the right idea. 600 // Allow pixel differences as long as we have the right idea.
601 SetAllowableError(0x10); 601 SetAllowableError(0x10);
602 // Exclude the middle two columns which are blended between the two sides. 602 // Exclude the middle two columns which are blended between the two sides.
603 SetExcludeRect( 603 SetExcludeRect(
604 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height())); 604 gfx::Rect(output_size.width() / 2 - 1, 0, 2, output_size.height()));
605 605
606 scoped_refptr<media::VideoFrame> video_frame = 606 scoped_refptr<media::VideoFrame> video_frame =
607 media::VideoFrame::CreateFrame(media::VideoFrame::YV12, 607 media::VideoFrame::CreateFrame(media::VideoFrame::YV12,
608 expected_bitmap_size, 608 output_size,
609 gfx::Rect(expected_bitmap_size), 609 gfx::Rect(output_size),
610 expected_bitmap_size, 610 output_size,
611 base::TimeDelta()); 611 base::TimeDelta());
612 612
613 base::Callback<void(bool success)> callback = 613 base::Callback<void(bool success)> callback =
614 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture:: 614 base::Bind(&CompositingRenderWidgetHostViewBrowserTestTabCapture::
615 CopyFromCompositingSurfaceCallbackForVideo, 615 CopyFromCompositingSurfaceCallbackForVideo,
616 base::Unretained(this), 616 base::Unretained(this),
617 video_frame, 617 video_frame,
618 run_loop.QuitClosure()); 618 run_loop.QuitClosure());
619 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect, 619 rwhvp->CopyFromCompositingSurfaceToVideoFrame(copy_rect,
620 video_frame, 620 video_frame,
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
655 SkAutoLockPixels lock(*bitmap); 655 SkAutoLockPixels lock(*bitmap);
656 for (int i = 0; i < copy_size.width() / 2; ++i) { 656 for (int i = 0; i < copy_size.width() / 2; ++i) {
657 for (int j = 0; j < copy_size.height(); ++j) { 657 for (int j = 0; j < copy_size.height(); ++j) {
658 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) = 658 *(bitmap->getAddr32(copy_size.width() / 2 + i, j)) =
659 SkColorSetARGB(255, 255, 255, 0); 659 SkColorSetARGB(255, 255, 255, 0);
660 } 660 }
661 } 661 }
662 } 662 }
663 } 663 }
664 664
665 protected:
666 virtual bool ShouldContinueAfterTestURLLoad() {
667 return true;
668 }
669
670 private: 665 private:
671 bool expected_copy_from_compositing_surface_result_; 666 bool expected_copy_from_compositing_surface_result_;
672 SkBitmap expected_copy_from_compositing_surface_bitmap_; 667 SkBitmap expected_copy_from_compositing_surface_bitmap_;
673 int allowable_error_; 668 int allowable_error_;
674 gfx::Rect exclude_rect_; 669 gfx::Rect exclude_rect_;
675 std::string test_url_; 670 std::string test_url_;
676 }; 671 };
677 672
678 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 673 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
679 CopyFromCompositingSurface_Origin_Unscaled) { 674 CopyFromCompositingSurface_Origin_Unscaled) {
680 gfx::Rect copy_rect(400, 300); 675 gfx::Rect copy_rect(400, 300);
681 gfx::Size output_size = copy_rect.size(); 676 gfx::Size output_size = copy_rect.size();
682 gfx::Size expected_bitmap_size = output_size;
683 gfx::Size html_rect_size(400, 300); 677 gfx::Size html_rect_size(400, 300);
684 bool video_frame = false; 678 bool video_frame = false;
685 PerformTestWithLeftRightRects(html_rect_size, 679 PerformTestWithLeftRightRects(html_rect_size,
686 copy_rect, 680 copy_rect,
687 output_size, 681 output_size,
688 expected_bitmap_size,
689 video_frame); 682 video_frame);
690 } 683 }
691 684
692 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 685 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
693 CopyFromCompositingSurface_Origin_Scaled) { 686 CopyFromCompositingSurface_Origin_Scaled) {
694 gfx::Rect copy_rect(400, 300); 687 gfx::Rect copy_rect(400, 300);
695 gfx::Size output_size(200, 100); 688 gfx::Size output_size(200, 100);
696 gfx::Size expected_bitmap_size = output_size;
697 gfx::Size html_rect_size(400, 300); 689 gfx::Size html_rect_size(400, 300);
698 bool video_frame = false; 690 bool video_frame = false;
699 PerformTestWithLeftRightRects(html_rect_size, 691 PerformTestWithLeftRightRects(html_rect_size,
700 copy_rect, 692 copy_rect,
701 output_size, 693 output_size,
702 expected_bitmap_size,
703 video_frame); 694 video_frame);
704 } 695 }
705 696
706 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 697 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
707 CopyFromCompositingSurface_Cropped_Unscaled) { 698 CopyFromCompositingSurface_Cropped_Unscaled) {
708 // Grab 60x60 pixels from the center of the tab contents. 699 // Grab 60x60 pixels from the center of the tab contents.
709 gfx::Rect copy_rect(400, 300); 700 gfx::Rect copy_rect(400, 300);
710 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30), 701 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30),
711 gfx::Size(60, 60)); 702 gfx::Size(60, 60));
712 gfx::Size output_size = copy_rect.size(); 703 gfx::Size output_size = copy_rect.size();
713 gfx::Size expected_bitmap_size = output_size;
714 gfx::Size html_rect_size(400, 300); 704 gfx::Size html_rect_size(400, 300);
715 bool video_frame = false; 705 bool video_frame = false;
716 PerformTestWithLeftRightRects(html_rect_size, 706 PerformTestWithLeftRightRects(html_rect_size,
717 copy_rect, 707 copy_rect,
718 output_size, 708 output_size,
719 expected_bitmap_size,
720 video_frame); 709 video_frame);
721 } 710 }
722 711
723 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 712 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
724 CopyFromCompositingSurface_Cropped_Scaled) { 713 CopyFromCompositingSurface_Cropped_Scaled) {
725 // Grab 60x60 pixels from the center of the tab contents. 714 // Grab 60x60 pixels from the center of the tab contents.
726 gfx::Rect copy_rect(400, 300); 715 gfx::Rect copy_rect(400, 300);
727 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30), 716 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(30, 30),
728 gfx::Size(60, 60)); 717 gfx::Size(60, 60));
729 gfx::Size output_size(20, 10); 718 gfx::Size output_size(20, 10);
730 gfx::Size expected_bitmap_size = output_size;
731 gfx::Size html_rect_size(400, 300); 719 gfx::Size html_rect_size(400, 300);
732 bool video_frame = false; 720 bool video_frame = false;
733 PerformTestWithLeftRightRects(html_rect_size, 721 PerformTestWithLeftRightRects(html_rect_size,
734 copy_rect, 722 copy_rect,
735 output_size, 723 output_size,
736 expected_bitmap_size,
737 video_frame); 724 video_frame);
738 } 725 }
739 726
740 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 727 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
741 CopyFromCompositingSurface_ForVideoFrame) { 728 CopyFromCompositingSurface_ForVideoFrame) {
742 // Grab 90x60 pixels from the center of the tab contents. 729 // Grab 90x60 pixels from the center of the tab contents.
743 gfx::Rect copy_rect(400, 300); 730 gfx::Rect copy_rect(400, 300);
744 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(45, 30), 731 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(45, 30),
745 gfx::Size(90, 60)); 732 gfx::Size(90, 60));
746 gfx::Size output_size = copy_rect.size(); 733 gfx::Size output_size = copy_rect.size();
747 gfx::Size expected_bitmap_size = output_size;
748 gfx::Size html_rect_size(400, 300); 734 gfx::Size html_rect_size(400, 300);
749 bool video_frame = true; 735 bool video_frame = true;
750 PerformTestWithLeftRightRects(html_rect_size, 736 PerformTestWithLeftRightRects(html_rect_size,
751 copy_rect, 737 copy_rect,
752 output_size, 738 output_size,
753 expected_bitmap_size,
754 video_frame); 739 video_frame);
755 } 740 }
756 741
757 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture, 742 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewBrowserTestTabCapture,
758 CopyFromCompositingSurface_ForVideoFrame_Scaled) { 743 CopyFromCompositingSurface_ForVideoFrame_Scaled) {
759 // Grab 90x60 pixels from the center of the tab contents. 744 // Grab 90x60 pixels from the center of the tab contents.
760 gfx::Rect copy_rect(400, 300); 745 gfx::Rect copy_rect(400, 300);
761 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(45, 30), 746 copy_rect = gfx::Rect(copy_rect.CenterPoint() - gfx::Vector2d(45, 30),
762 gfx::Size(90, 60)); 747 gfx::Size(90, 60));
763 // Scale to 30 x 20 (preserve aspect ratio). 748 // Scale to 30 x 20 (preserve aspect ratio).
764 gfx::Size output_size(30, 20); 749 gfx::Size output_size(30, 20);
765 gfx::Size expected_bitmap_size = output_size;
766 gfx::Size html_rect_size(400, 300); 750 gfx::Size html_rect_size(400, 300);
767 bool video_frame = true; 751 bool video_frame = true;
768 PerformTestWithLeftRightRects(html_rect_size, 752 PerformTestWithLeftRightRects(html_rect_size,
769 copy_rect, 753 copy_rect,
770 output_size, 754 output_size,
771 expected_bitmap_size,
772 video_frame); 755 video_frame);
773 } 756 }
774 757
775 class CompositingRenderWidgetHostViewTabCaptureHighDPI 758 class CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI
776 : public CompositingRenderWidgetHostViewBrowserTestTabCapture { 759 : public CompositingRenderWidgetHostViewBrowserTestTabCapture {
777 public: 760 public:
778 CompositingRenderWidgetHostViewTabCaptureHighDPI() : kScale(2.f) {} 761 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI() {}
779 762
780 virtual void SetUpOnMainThread() OVERRIDE { 763 protected:
781 base::CommandLine* cmd = base::CommandLine::ForCurrentProcess(); 764 virtual void SetUpCommandLine(base::CommandLine* cmd) OVERRIDE {
765 CompositingRenderWidgetHostViewBrowserTestTabCapture::SetUpCommandLine(cmd);
782 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor, 766 cmd->AppendSwitchASCII(switches::kForceDeviceScaleFactor,
783 base::StringPrintf("%f", scale())); 767 base::StringPrintf("%f", scale()));
784 #if defined(OS_WIN)
785 gfx::ForceHighDPISupportForTesting(scale());
786 gfx::EnableHighDPISupport();
787 #endif
788 } 768 }
789 769
790 float scale() const { return kScale; } 770 static float scale() { return 2.0f; }
791 771
792 private: 772 private:
793 virtual bool ShouldContinueAfterTestURLLoad() OVERRIDE { 773 DISALLOW_COPY_AND_ASSIGN(
794 // Short-circuit a pass for platforms where setting up high-DPI fails. 774 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI);
795 if (ui::GetScaleForScaleFactor(ui::GetSupportedScaleFactor(
796 GetScaleFactorForView(GetRenderWidgetHostView()))) != scale()) {
797 LOG(WARNING) << "Blindly passing this test: failed to set up "
798 "scale factor: " << scale();
799 return false;
800 }
801 return true;
802 }
803
804 const float kScale;
805
806 DISALLOW_COPY_AND_ASSIGN(CompositingRenderWidgetHostViewTabCaptureHighDPI);
807 }; 775 };
808 776
809 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewTabCaptureHighDPI, 777 // ImageSkia (related to ResourceBundle) implementation crashes the process on
810 CopyFromCompositingSurface) { 778 // Windows when this content_browsertest forces a device scale factor.
779 // http://crbug.com/399349
780 #if defined(OS_WIN)
781 #define MAYBE_CopyToBitmap_EntireRegion DISABLED_CopyToBitmap_EntireRegion
782 #define MAYBE_CopyToBitmap_CenterRegion DISABLED_CopyToBitmap_CenterRegion
783 #define MAYBE_CopyToBitmap_ScaledResult DISABLED_CopyToBitmap_ScaledResult
784 #define MAYBE_CopyToVideoFr_EntireRegion DISABLED_CopyToVideoFr_EntireRegion
785 #define MAYBE_CopyToVideoFr_CenterRegion DISABLED_CopyToVideoFr_CenterRegion
786 #define MAYBE_CopyToVideoFr_ScaledResult DISABLED_CopyToVideoFr_ScaledResult
787 #else
788 #define MAYBE_CopyToBitmap_EntireRegion CopyToBitmap_EntireRegion
789 #define MAYBE_CopyToBitmap_CenterRegion CopyToBitmap_CenterRegion
790 #define MAYBE_CopyToBitmap_ScaledResult CopyToBitmap_ScaledResult
791 #define MAYBE_CopyToVideoFr_EntireRegion CopyToVideoFr_EntireRegion
792 #define MAYBE_CopyToVideoFr_CenterRegion CopyToVideoFr_CenterRegion
793 #define MAYBE_CopyToVideoFr_ScaledResult CopyToVideoFr_ScaledResult
794 #endif
795
796 IN_PROC_BROWSER_TEST_P(
797 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
798 MAYBE_CopyToBitmap_EntireRegion) {
799 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
800 gfx::Size html_rect_size(200, 150);
811 gfx::Rect copy_rect(200, 150); 801 gfx::Rect copy_rect(200, 150);
812 gfx::Size output_size = copy_rect.size(); 802 // Scale the output size so that, internally, scaling is not occurring.
813 gfx::Size expected_bitmap_size = 803 gfx::Size output_size =
814 gfx::ToFlooredSize(gfx::ScaleSize(output_size, scale(), scale())); 804 gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale()));
815 gfx::Size html_rect_size(200, 150);
816 bool video_frame = false; 805 bool video_frame = false;
817 PerformTestWithLeftRightRects(html_rect_size, 806 PerformTestWithLeftRightRects(html_rect_size,
818 copy_rect, 807 copy_rect,
819 output_size, 808 output_size,
820 expected_bitmap_size,
821 video_frame); 809 video_frame);
822 } 810 }
823 811
824 IN_PROC_BROWSER_TEST_P(CompositingRenderWidgetHostViewTabCaptureHighDPI, 812 IN_PROC_BROWSER_TEST_P(
825 CopyFromCompositingSurfaceVideoFrame) { 813 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
814 MAYBE_CopyToBitmap_CenterRegion) {
815 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
826 gfx::Size html_rect_size(200, 150); 816 gfx::Size html_rect_size(200, 150);
827 // Grab 90x60 pixels from the center of the tab contents. 817 // Grab 90x60 pixels from the center of the tab contents.
828 gfx::Rect copy_rect = 818 gfx::Rect copy_rect =
829 gfx::Rect(gfx::Rect(html_rect_size).CenterPoint() - gfx::Vector2d(45, 30), 819 gfx::Rect(gfx::Rect(html_rect_size).CenterPoint() - gfx::Vector2d(45, 30),
830 gfx::Size(90, 60)); 820 gfx::Size(90, 60));
831 gfx::Size output_size = copy_rect.size(); 821 // Scale the output size so that, internally, scaling is not occurring.
832 gfx::Size expected_bitmap_size = 822 gfx::Size output_size =
833 gfx::ToFlooredSize(gfx::ScaleSize(output_size, scale(), scale())); 823 gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale()));
824 bool video_frame = false;
825 PerformTestWithLeftRightRects(html_rect_size,
826 copy_rect,
827 output_size,
828 video_frame);
829 }
830
831 IN_PROC_BROWSER_TEST_P(
832 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
833 MAYBE_CopyToBitmap_ScaledResult) {
834 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
835 gfx::Size html_rect_size(200, 100);
836 gfx::Rect copy_rect(200, 100);
837 // Output is being down-scaled since output_size is in phyiscal pixels:
danakj 2014/08/13 18:39:31 nit: s/:/./
miu 2014/08/13 18:48:27 Done.
838 gfx::Size output_size(200, 100);
839 bool video_frame = false;
840 PerformTestWithLeftRightRects(html_rect_size,
841 copy_rect,
842 output_size,
843 video_frame);
844 }
845
846 IN_PROC_BROWSER_TEST_P(
847 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
848 MAYBE_CopyToVideoFr_EntireRegion) {
danakj 2014/08/13 18:39:31 CopyToVideoFrame please, don't drop half the word
miu 2014/08/13 18:48:27 Done. I had truncated it because of the 80 char l
849 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
850 gfx::Size html_rect_size(200, 150);
851 gfx::Rect copy_rect(200, 150);
852 // Scale the output size so that, internally, scaling is not occurring.
853 gfx::Size output_size =
854 gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale()));
834 bool video_frame = true; 855 bool video_frame = true;
835 PerformTestWithLeftRightRects(html_rect_size, 856 PerformTestWithLeftRightRects(html_rect_size,
836 copy_rect, 857 copy_rect,
837 output_size, 858 output_size,
838 expected_bitmap_size,
839 video_frame); 859 video_frame);
840 } 860 }
841 861
842 #if !defined(USE_AURA) && !defined(OS_MACOSX) 862 IN_PROC_BROWSER_TEST_P(
843 // TODO(danakj): Remove this case when GTK linux is no more and move the 863 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
844 // values inline to testing::Values() below. 864 MAYBE_CopyToVideoFr_CenterRegion) {
845 static const CompositingMode kAllCompositingModes[] = {GL_COMPOSITING}; 865 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
846 #else 866 gfx::Size html_rect_size(200, 150);
847 static const CompositingMode kAllCompositingModes[] = {GL_COMPOSITING, 867 // Grab 90x60 pixels from the center of the tab contents.
848 SOFTWARE_COMPOSITING}; 868 gfx::Rect copy_rect =
849 #endif 869 gfx::Rect(gfx::Rect(html_rect_size).CenterPoint() - gfx::Vector2d(45, 30),
870 gfx::Size(90, 60));
871 // Scale the output size so that, internally, scaling is not occurring.
872 gfx::Size output_size =
873 gfx::ToRoundedSize(gfx::ScaleSize(copy_rect.size(), scale()));
874 bool video_frame = true;
875 PerformTestWithLeftRightRects(html_rect_size,
876 copy_rect,
877 output_size,
878 video_frame);
879 }
880
881 IN_PROC_BROWSER_TEST_P(
882 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
883 MAYBE_CopyToVideoFr_ScaledResult) {
884 ASSERT_EQ(scale(), GetScaleFactorForView(GetRenderWidgetHostView()));
885 gfx::Size html_rect_size(200, 100);
886 gfx::Rect copy_rect(200, 100);
887 // Output is being down-scaled since output_size is in phyiscal pixels:
888 gfx::Size output_size(200, 100);
889 bool video_frame = true;
890 PerformTestWithLeftRightRects(html_rect_size,
891 copy_rect,
892 output_size,
893 video_frame);
894 }
850 895
851 INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, 896 INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing,
852 CompositingRenderWidgetHostViewBrowserTest, 897 CompositingRenderWidgetHostViewBrowserTest,
853 testing::ValuesIn(kAllCompositingModes)); 898 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING));
854 INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, 899 INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing,
855 CompositingRenderWidgetHostViewBrowserTestTabCapture, 900 CompositingRenderWidgetHostViewBrowserTestTabCapture,
856 testing::ValuesIn(kAllCompositingModes)); 901 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING));
857 INSTANTIATE_TEST_CASE_P(GLAndSoftwareCompositing, 902 INSTANTIATE_TEST_CASE_P(
858 CompositingRenderWidgetHostViewTabCaptureHighDPI, 903 GLAndSoftwareCompositing,
859 testing::ValuesIn(kAllCompositingModes)); 904 CompositingRenderWidgetHostViewBrowserTestTabCaptureHighDPI,
905 testing::Values(GL_COMPOSITING, SOFTWARE_COMPOSITING));
860 906
861 #endif // !defined(OS_ANDROID) && !defined(OS_IOS) 907 #endif // !defined(OS_ANDROID) && !defined(OS_IOS)
862 908
863 } // namespace 909 } // namespace
864 } // namespace content 910 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698