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

Unified Diff: content/browser/media/capture/capture_resolution_evaluator_unittest.cc

Issue 1135823004: Implement all resolution change policies for desktop and tab capture. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@resolution_change_policy_constraints_ITEM1_CR1
Patch Set: Addressed Dale's comments. Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
Index: content/browser/media/capture/capture_resolution_evaluator_unittest.cc
diff --git a/content/browser/media/capture/capture_resolution_evaluator_unittest.cc b/content/browser/media/capture/capture_resolution_evaluator_unittest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..e7f0beeb7018cb5a039c4abca642b8216f0164dc
--- /dev/null
+++ b/content/browser/media/capture/capture_resolution_evaluator_unittest.cc
@@ -0,0 +1,146 @@
+// Copyright 2015 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "content/browser/media/capture/capture_resolution_evaluator.h"
+
+#include "testing/gtest/include/gtest/gtest.h"
+
+namespace content {
+
+namespace {
+
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
+// 16:9 maximum and minimum frame sizes.
+const int kMaxFrameWidth = 3840;
+const int kMaxFrameHeight = 2160;
+const int kMinFrameWidth = 320;
+const int kMinFrameHeight = 180;
+
+} // namespace
+
+TEST(CaptureResolutionEvaluatorTest,
+ 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.
+ const gfx::Size the_one_frame_size(kMaxFrameWidth, kMaxFrameHeight);
+ CaptureResolutionEvaluator evaluator(
+ the_one_frame_size,
+ media::RESOLUTION_POLICY_FIXED_RESOLUTION);
+ EXPECT_EQ(the_one_frame_size, evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(the_one_frame_size);
+ EXPECT_EQ(the_one_frame_size, evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth + 424,
+ kMaxFrameHeight - 101));
+ EXPECT_EQ(the_one_frame_size, evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth - 202,
+ kMaxFrameHeight + 56));
+ EXPECT_EQ(the_one_frame_size, evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(kMinFrameWidth, kMinFrameHeight));
+ EXPECT_EQ(the_one_frame_size, evaluator.capture_size());
+}
+
+TEST(CaptureResolutionEvaluatorTest,
+ FixedAspectRatioPolicy_CaptureSizeHasSameAspectRatio) {
+ CaptureResolutionEvaluator evaluator(
+ gfx::Size(kMaxFrameWidth, kMaxFrameHeight),
+ media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO);
+
+#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.
+ ASSERT_LE(kMinFrameWidth, evaluator.capture_size().width()); \
+ ASSERT_LE(kMinFrameHeight, evaluator.capture_size().height()); \
+ EXPECT_GE(kMaxFrameWidth, evaluator.capture_size().width()); \
+ EXPECT_GE(kMaxFrameHeight, evaluator.capture_size().height()); \
+ EXPECT_NEAR(static_cast<double>(kMaxFrameWidth) / kMaxFrameHeight, \
+ static_cast<double>(evaluator.capture_size().width()) / \
+ evaluator.capture_size().height(), \
+ 0.01)
+
+ // Starting condition.
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+
+ // Max size in --> max size out.
+ evaluator.UpdateForNewSourceSize(gfx::Size(kMaxFrameWidth, kMaxFrameHeight));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+
+ // Various source sizes within bounds.
+ evaluator.UpdateForNewSourceSize(gfx::Size(640, 480));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(gfx::Size(480, 640));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(gfx::Size(640, 640));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ 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.
+
+ // Bad source size results in no update.
+ evaluator.UpdateForNewSourceSize(gfx::Size(0, 0));
+ EXPECT_EQ(unchanged_size, evaluator.capture_size());
+
+ // Downscaling size (preserving aspect ratio) when source size exceeds the
+ // upper bounds.
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+
+ // Upscaling size (preserving aspect ratio) when source size is under the
+ // lower bounds.
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMinFrameWidth / 2, kMinFrameHeight / 2));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMinFrameWidth / 2, kMaxFrameHeight));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMinFrameWidth, kMinFrameHeight / 2));
+ EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO();
+
+#undef EXPECT_IS_WITHIN_BOUNDS_AND_SAME_ASPECT_RATIO
+}
+
+TEST(CaptureResolutionEvaluatorTest,
+ AnyWithinLimitPolicy_CaptureSizeIsAnythingWithinLimits) {
+ const gfx::Size max_size(kMaxFrameWidth, kMaxFrameHeight);
+ CaptureResolutionEvaluator evaluator(
+ max_size, media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT);
+
+ // Starting condition.
+ EXPECT_EQ(max_size, evaluator.capture_size());
+
+ // Max size in --> max size out.
+ evaluator.UpdateForNewSourceSize(max_size);
+ EXPECT_EQ(max_size, evaluator.capture_size());
+
+ // Various source sizes within bounds.
+ evaluator.UpdateForNewSourceSize(gfx::Size(640, 480));
+ EXPECT_EQ(gfx::Size(640, 480), evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(480, 640));
+ EXPECT_EQ(gfx::Size(480, 640), evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(640, 640));
+ EXPECT_EQ(gfx::Size(640, 640), evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(gfx::Size(2, 2));
+ EXPECT_EQ(gfx::Size(2, 2), evaluator.capture_size());
+ 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.
+
+ // Bad source size results in no update.
+ evaluator.UpdateForNewSourceSize(gfx::Size(0, 0));
+ EXPECT_EQ(unchanged_size, evaluator.capture_size());
+
+ // Downscaling size (preserving aspect ratio) when source size exceeds the
+ // upper bounds.
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight * 2));
+ EXPECT_EQ(max_size, evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth * 2, kMaxFrameHeight));
+ EXPECT_EQ(gfx::Size(kMaxFrameWidth, kMaxFrameHeight / 2),
+ evaluator.capture_size());
+ evaluator.UpdateForNewSourceSize(
+ gfx::Size(kMaxFrameWidth, kMaxFrameHeight * 2));
+ EXPECT_EQ(gfx::Size(kMaxFrameWidth / 2, kMaxFrameHeight),
+ evaluator.capture_size());
+}
+
+} // namespace content

Powered by Google App Engine
This is Rietveld 408576698