OLD | NEW |
(Empty) | |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "content/browser/media/capture/capture_resolution_chooser.h" |
| 6 |
| 7 #include "base/location.h" |
| 8 #include "testing/gtest/include/gtest/gtest.h" |
| 9 |
| 10 using tracked_objects::Location; |
| 11 |
| 12 namespace content { |
| 13 |
| 14 namespace { |
| 15 |
| 16 // 16:9 maximum and minimum frame sizes. |
| 17 const int kMaxFrameWidth = 3840; |
| 18 const int kMaxFrameHeight = 2160; |
| 19 const int kMinFrameWidth = 320; |
| 20 const int kMinFrameHeight = 180; |
| 21 |
| 22 // Checks whether |size| is strictly between (inclusive) |min_size| and |
| 23 // |max_size| and has the same aspect ratio as |max_size|. |
| 24 void ExpectIsWithinBoundsAndSameAspectRatio(const Location& location, |
| 25 const gfx::Size& min_size, |
| 26 const gfx::Size& max_size, |
| 27 const gfx::Size& size) { |
| 28 SCOPED_TRACE(::testing::Message() << "From here: " << location.ToString()); |
| 29 EXPECT_LE(min_size.width(), size.width()); |
| 30 EXPECT_LE(min_size.height(), size.height()); |
| 31 EXPECT_GE(max_size.width(), size.width()); |
| 32 EXPECT_GE(max_size.height(), size.height()); |
| 33 EXPECT_NEAR(static_cast<double>(max_size.width()) / max_size.height(), |
| 34 static_cast<double>(size.width()) / size.height(), |
| 35 0.01); |
| 36 } |
| 37 |
| 38 } // namespace |
| 39 |
| 40 TEST(CaptureResolutionChooserTest, |
| 41 FixedResolutionPolicy_CaptureSizeAlwaysFixed) { |
| 42 const gfx::Size the_one_frame_size(kMaxFrameWidth, kMaxFrameHeight); |
| 43 CaptureResolutionChooser chooser(the_one_frame_size, |
| 44 media::RESOLUTION_POLICY_FIXED_RESOLUTION); |
| 45 EXPECT_EQ(the_one_frame_size, chooser.capture_size()); |
| 46 |
| 47 chooser.SetSourceSize(the_one_frame_size); |
| 48 EXPECT_EQ(the_one_frame_size, chooser.capture_size()); |
| 49 |
| 50 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth + 424, kMaxFrameHeight - 101)); |
| 51 EXPECT_EQ(the_one_frame_size, chooser.capture_size()); |
| 52 |
| 53 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth - 202, kMaxFrameHeight + 56)); |
| 54 EXPECT_EQ(the_one_frame_size, chooser.capture_size()); |
| 55 |
| 56 chooser.SetSourceSize(gfx::Size(kMinFrameWidth, kMinFrameHeight)); |
| 57 EXPECT_EQ(the_one_frame_size, chooser.capture_size()); |
| 58 } |
| 59 |
| 60 TEST(CaptureResolutionChooserTest, |
| 61 FixedAspectRatioPolicy_CaptureSizeHasSameAspectRatio) { |
| 62 CaptureResolutionChooser chooser( |
| 63 gfx::Size(kMaxFrameWidth, kMaxFrameHeight), |
| 64 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO); |
| 65 |
| 66 // Starting condition. |
| 67 const gfx::Size min_size(kMinFrameWidth, kMinFrameHeight); |
| 68 const gfx::Size max_size(kMaxFrameWidth, kMaxFrameHeight); |
| 69 ExpectIsWithinBoundsAndSameAspectRatio( |
| 70 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 71 |
| 72 // Max size in --> max size out. |
| 73 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth, kMaxFrameHeight)); |
| 74 ExpectIsWithinBoundsAndSameAspectRatio( |
| 75 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 76 |
| 77 // Various source sizes within bounds. |
| 78 chooser.SetSourceSize(gfx::Size(640, 480)); |
| 79 ExpectIsWithinBoundsAndSameAspectRatio( |
| 80 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 81 |
| 82 chooser.SetSourceSize(gfx::Size(480, 640)); |
| 83 ExpectIsWithinBoundsAndSameAspectRatio( |
| 84 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 85 |
| 86 chooser.SetSourceSize(gfx::Size(640, 640)); |
| 87 ExpectIsWithinBoundsAndSameAspectRatio( |
| 88 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 89 |
| 90 // Bad source size results in no update. |
| 91 const gfx::Size unchanged_size = chooser.capture_size(); |
| 92 chooser.SetSourceSize(gfx::Size(0, 0)); |
| 93 EXPECT_EQ(unchanged_size, chooser.capture_size()); |
| 94 |
| 95 // Downscaling size (preserving aspect ratio) when source size exceeds the |
| 96 // upper bounds. |
| 97 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2)); |
| 98 ExpectIsWithinBoundsAndSameAspectRatio( |
| 99 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 100 |
| 101 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight)); |
| 102 ExpectIsWithinBoundsAndSameAspectRatio( |
| 103 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 104 |
| 105 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2)); |
| 106 ExpectIsWithinBoundsAndSameAspectRatio( |
| 107 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 108 |
| 109 // Upscaling size (preserving aspect ratio) when source size is under the |
| 110 // lower bounds. |
| 111 chooser.SetSourceSize(gfx::Size(kMinFrameWidth / 2, kMinFrameHeight / 2)); |
| 112 ExpectIsWithinBoundsAndSameAspectRatio( |
| 113 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 114 |
| 115 chooser.SetSourceSize(gfx::Size(kMinFrameWidth / 2, kMaxFrameHeight)); |
| 116 ExpectIsWithinBoundsAndSameAspectRatio( |
| 117 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 118 |
| 119 chooser.SetSourceSize(gfx::Size(kMinFrameWidth, kMinFrameHeight / 2)); |
| 120 ExpectIsWithinBoundsAndSameAspectRatio( |
| 121 FROM_HERE, min_size, max_size, chooser.capture_size()); |
| 122 } |
| 123 |
| 124 TEST(CaptureResolutionChooserTest, |
| 125 AnyWithinLimitPolicy_CaptureSizeIsAnythingWithinLimits) { |
| 126 const gfx::Size max_size(kMaxFrameWidth, kMaxFrameHeight); |
| 127 CaptureResolutionChooser chooser( |
| 128 max_size, media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT); |
| 129 |
| 130 // Starting condition. |
| 131 EXPECT_EQ(max_size, chooser.capture_size()); |
| 132 |
| 133 // Max size in --> max size out. |
| 134 chooser.SetSourceSize(max_size); |
| 135 EXPECT_EQ(max_size, chooser.capture_size()); |
| 136 |
| 137 // Various source sizes within bounds. |
| 138 chooser.SetSourceSize(gfx::Size(640, 480)); |
| 139 EXPECT_EQ(gfx::Size(640, 480), chooser.capture_size()); |
| 140 |
| 141 chooser.SetSourceSize(gfx::Size(480, 640)); |
| 142 EXPECT_EQ(gfx::Size(480, 640), chooser.capture_size()); |
| 143 |
| 144 chooser.SetSourceSize(gfx::Size(640, 640)); |
| 145 EXPECT_EQ(gfx::Size(640, 640), chooser.capture_size()); |
| 146 |
| 147 chooser.SetSourceSize(gfx::Size(2, 2)); |
| 148 EXPECT_EQ(gfx::Size(2, 2), chooser.capture_size()); |
| 149 |
| 150 // Bad source size results in no update. |
| 151 const gfx::Size unchanged_size = chooser.capture_size(); |
| 152 chooser.SetSourceSize(gfx::Size(0, 0)); |
| 153 EXPECT_EQ(unchanged_size, chooser.capture_size()); |
| 154 |
| 155 // Downscaling size (preserving aspect ratio) when source size exceeds the |
| 156 // upper bounds. |
| 157 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2)); |
| 158 EXPECT_EQ(max_size, chooser.capture_size()); |
| 159 |
| 160 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight)); |
| 161 EXPECT_EQ(gfx::Size(kMaxFrameWidth, kMaxFrameHeight / 2), |
| 162 chooser.capture_size()); |
| 163 |
| 164 chooser.SetSourceSize(gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2)); |
| 165 EXPECT_EQ(gfx::Size(kMaxFrameWidth / 2, kMaxFrameHeight), |
| 166 chooser.capture_size()); |
| 167 } |
| 168 |
| 169 } // namespace content |
OLD | NEW |