Chromium Code Reviews| 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_evaluator.h" | |
| 6 | |
| 7 #include "testing/gtest/include/gtest/gtest.h" | |
| 8 | |
| 9 namespace content { | |
| 10 | |
| 11 namespace { | |
| 12 | |
|
Wez
2015/05/13 19:05:09
nit: Don't think you need an empty namespace since
miu
2015/05/14 01:21:32
I don't want to export these symbols. I could rem
Wez
2015/05/15 00:55:42
My point is that you neither need the namespace no
miu
2015/05/15 21:14:00
They are static, but the symbol is public in the c
Wez
2015/05/15 23:31:31
Yes, I understand that - if they were _global_ con
| |
| 13 // 16:9 maximum and minimum frame sizes. | |
| 14 const int kMaxFrameWidth = 3840; | |
| 15 const int kMaxFrameHeight = 2160; | |
| 16 const int kMinFrameWidth = 320; | |
| 17 const int kMinFrameHeight = 180; | |
| 18 | |
| 19 } // namespace | |
| 20 | |
| 21 TEST(CaptureResolutionEvaluatorTest, | |
| 22 FixedResolutionPolicy_CaptureSizeAlwaysFixed) { | |
|
Wez
2015/05/13 19:05:09
nit: Suggest putting a blank line between each cal
miu
2015/05/14 01:21:32
Done.
| |
| 23 const gfx::Size the_one_frame_size(kMaxFrameWidth, kMaxFrameHeight); | |
| 24 CaptureResolutionEvaluator evaluator( | |
| 25 the_one_frame_size, | |
| 26 media::RESOLUTION_POLICY_FIXED_RESOLUTION); | |
| 27 EXPECT_EQ(the_one_frame_size, evaluator.capture_size()); | |
| 28 evaluator.UpdateForNewSourceSize(the_one_frame_size); | |
| 29 EXPECT_EQ(the_one_frame_size, evaluator.capture_size()); | |
| 30 evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth + 424, | |
| 31 kMaxFrameHeight - 101)); | |
| 32 EXPECT_EQ(the_one_frame_size, evaluator.capture_size()); | |
| 33 evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth - 202, | |
| 34 kMaxFrameHeight + 56)); | |
| 35 EXPECT_EQ(the_one_frame_size, evaluator.capture_size()); | |
| 36 evaluator.UpdateForNewSourceSize(gfx::Size(kMinFrameWidth, kMinFrameHeight)); | |
| 37 EXPECT_EQ(the_one_frame_size, evaluator.capture_size()); | |
| 38 } | |
| 39 | |
| 40 TEST(CaptureResolutionEvaluatorTest, | |
| 41 FixedAspectRatioPolicy_CaptureSizeHasSameAspectRatio) { | |
| 42 CaptureResolutionEvaluator evaluator( | |
| 43 gfx::Size(kMaxFrameWidth, kMaxFrameHeight), | |
| 44 media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO); | |
| 45 | |
| 46 #define EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO() \ | |
|
Wez
2015/05/13 19:05:09
Might be cleaner to take the hit of parameterizing
miu
2015/05/14 01:21:32
Done.
| |
| 47 ASSERT_LE(kMinFrameWidth, evaluator.capture_size().width()); \ | |
| 48 ASSERT_LE(kMinFrameHeight, evaluator.capture_size().height()); \ | |
| 49 EXPECT_GE(kMaxFrameWidth, evaluator.capture_size().width()); \ | |
| 50 EXPECT_GE(kMaxFrameHeight, evaluator.capture_size().height()); \ | |
| 51 EXPECT_NEAR(static_cast<double>(kMaxFrameWidth) / kMaxFrameHeight, \ | |
| 52 static_cast<double>(evaluator.capture_size().width()) / \ | |
| 53 evaluator.capture_size().height(), \ | |
| 54 0.01) | |
| 55 | |
| 56 // Starting condition. | |
| 57 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 58 | |
| 59 // Max size in --> max size out. | |
| 60 evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth, kMaxFrameHeight)); | |
| 61 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 62 | |
| 63 // Various source sizes within bounds. | |
| 64 evaluator.UpdateForNewSourceSize(gfx::Size(640, 480)); | |
| 65 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 66 evaluator.UpdateForNewSourceSize(gfx::Size(480, 640)); | |
| 67 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 68 evaluator.UpdateForNewSourceSize(gfx::Size(640, 640)); | |
| 69 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 70 const gfx::Size unchanged_size = evaluator.capture_size(); | |
|
Wez
2015/05/13 19:05:09
Looks like this belongs in the next block?
miu
2015/05/14 01:21:33
Done.
| |
| 71 | |
| 72 // Bad source size results in no update. | |
| 73 evaluator.UpdateForNewSourceSize(gfx::Size(0, 0)); | |
| 74 EXPECT_EQ(unchanged_size, evaluator.capture_size()); | |
| 75 | |
| 76 // Downscaling size (preserving aspect ratio) when source size exceeds the | |
| 77 // upper bounds. | |
| 78 evaluator.UpdateForNewSourceSize( | |
| 79 gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2)); | |
| 80 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 81 evaluator.UpdateForNewSourceSize( | |
| 82 gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight)); | |
| 83 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 84 evaluator.UpdateForNewSourceSize( | |
| 85 gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2)); | |
| 86 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 87 | |
| 88 // Upscaling size (preserving aspect ratio) when source size is under the | |
| 89 // lower bounds. | |
| 90 evaluator.UpdateForNewSourceSize( | |
| 91 gfx::Size(kMinFrameWidth / 2, kMinFrameHeight / 2)); | |
| 92 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 93 evaluator.UpdateForNewSourceSize( | |
| 94 gfx::Size(kMinFrameWidth / 2, kMaxFrameHeight)); | |
| 95 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 96 evaluator.UpdateForNewSourceSize( | |
| 97 gfx::Size(kMinFrameWidth, kMinFrameHeight / 2)); | |
| 98 EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO(); | |
| 99 | |
| 100 #undef EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO | |
| 101 } | |
| 102 | |
| 103 TEST(CaptureResolutionEvaluatorTest, | |
| 104 AnyWithinLimitPolicy_CaptureSizeIsAnythingWithinLimits) { | |
| 105 const gfx::Size max_size(kMaxFrameWidth, kMaxFrameHeight); | |
| 106 CaptureResolutionEvaluator evaluator( | |
| 107 max_size, media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT); | |
| 108 | |
| 109 // Starting condition. | |
| 110 EXPECT_EQ(max_size, evaluator.capture_size()); | |
| 111 | |
| 112 // Max size in --> max size out. | |
| 113 evaluator.UpdateForNewSourceSize(max_size); | |
| 114 EXPECT_EQ(max_size, evaluator.capture_size()); | |
| 115 | |
| 116 // Various source sizes within bounds. | |
| 117 evaluator.UpdateForNewSourceSize(gfx::Size(640, 480)); | |
| 118 EXPECT_EQ(gfx::Size(640, 480), evaluator.capture_size()); | |
| 119 evaluator.UpdateForNewSourceSize(gfx::Size(480, 640)); | |
| 120 EXPECT_EQ(gfx::Size(480, 640), evaluator.capture_size()); | |
| 121 evaluator.UpdateForNewSourceSize(gfx::Size(640, 640)); | |
| 122 EXPECT_EQ(gfx::Size(640, 640), evaluator.capture_size()); | |
| 123 evaluator.UpdateForNewSourceSize(gfx::Size(2, 2)); | |
| 124 EXPECT_EQ(gfx::Size(2, 2), evaluator.capture_size()); | |
| 125 const gfx::Size unchanged_size = evaluator.capture_size(); | |
|
Wez
2015/05/13 19:05:09
As above
miu
2015/05/14 01:21:33
Done.
| |
| 126 | |
| 127 // Bad source size results in no update. | |
| 128 evaluator.UpdateForNewSourceSize(gfx::Size(0, 0)); | |
| 129 EXPECT_EQ(unchanged_size, evaluator.capture_size()); | |
| 130 | |
| 131 // Downscaling size (preserving aspect ratio) when source size exceeds the | |
| 132 // upper bounds. | |
| 133 evaluator.UpdateForNewSourceSize( | |
| 134 gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2)); | |
| 135 EXPECT_EQ(max_size, evaluator.capture_size()); | |
| 136 evaluator.UpdateForNewSourceSize( | |
| 137 gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight)); | |
| 138 EXPECT_EQ(gfx::Size(kMaxFrameWidth, kMaxFrameHeight / 2), | |
| 139 evaluator.capture_size()); | |
| 140 evaluator.UpdateForNewSourceSize( | |
| 141 gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2)); | |
| 142 EXPECT_EQ(gfx::Size(kMaxFrameWidth / 2, kMaxFrameHeight), | |
| 143 evaluator.capture_size()); | |
| 144 } | |
| 145 | |
| 146 } // namespace content | |
| OLD | NEW |