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

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

Issue 1256183003: Fullscreen tab capture: Prefer standard resolutions (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Only applies to variable-resolution use cases, and add unit tests. Created 5 years, 5 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
« no previous file with comments | « content/browser/media/capture/web_contents_video_capture_device.cc ('k') | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: content/browser/media/capture/web_contents_video_capture_device_unittest.cc
diff --git a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
index 417d98c669048723139feedfe47de791ffc1cf14..80a95f929b63ff4fac8a68e66af09dd5fef29add 100644
--- a/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
+++ b/content/browser/media/capture/web_contents_video_capture_device_unittest.cc
@@ -37,6 +37,7 @@
#include "ui/base/layout.h"
#include "ui/gfx/display.h"
#include "ui/gfx/geometry/dip_util.h"
+#include "ui/gfx/geometry/size_conversions.h"
#include "ui/gfx/screen.h"
#include "ui/gfx/test/test_screen.h"
@@ -1026,5 +1027,100 @@ TEST_F(WebContentsVideoCaptureDeviceTest, VariableResolution_AnyWithinLimits) {
device()->StopAndDeAllocate();
}
+TEST_F(WebContentsVideoCaptureDeviceTest,
+ ComputesStandardResolutionsForPreferredSize) {
+ // Helper function to run the same testing procedure for multiple combinations
+ // of |policy|, |standard_size| and |oddball_size|.
+ const auto RunTestForPreferredSize =
+ [=](media::ResolutionChangePolicy policy,
+ const gfx::Size& oddball_size,
+ const gfx::Size& standard_size) {
+ SCOPED_TRACE(::testing::Message()
+ << "policy=" << policy
+ << ", oddball_size=" << oddball_size.ToString()
+ << ", standard_size=" << standard_size.ToString());
+
+ // Compute the expected preferred size. For the fixed-resolution use case,
+ // the |oddball_size| is always the expected size; whereas for the
+ // variable-resolution cases, the |standard_size| is the expected size.
+ // Also, adjust to account for the device scale factor.
+ gfx::Size capture_preferred_size = gfx::ToFlooredSize(gfx::ScaleSize(
+ policy == media::RESOLUTION_POLICY_FIXED_RESOLUTION ?
+ oddball_size : standard_size,
+ 1.0f / GetDeviceScaleFactor()));
+ ASSERT_NE(capture_preferred_size, web_contents()->GetPreferredSize());
+
+ // Start the WebContentsVideoCaptureDevice.
+ media::VideoCaptureParams capture_params;
+ capture_params.requested_format.frame_size = oddball_size;
+ capture_params.requested_format.frame_rate = kTestFramesPerSecond;
+ capture_params.requested_format.pixel_format =
+ media::VIDEO_CAPTURE_PIXEL_FORMAT_I420;
+ capture_params.resolution_change_policy = policy;
+ StubClientObserver unused_observer;
+ device()->AllocateAndStart(capture_params, unused_observer.PassClient());
+ base::RunLoop().RunUntilIdle();
+
+ // Check that the preferred size of the WebContents matches the one provided
+ // by WebContentsVideoCaptureDevice.
+ EXPECT_EQ(capture_preferred_size, web_contents()->GetPreferredSize());
+
+ // Stop the WebContentsVideoCaptureDevice.
+ device()->StopAndDeAllocate();
+ base::RunLoop().RunUntilIdle();
+ };
+
+ const media::ResolutionChangePolicy policies[3] = {
+ media::RESOLUTION_POLICY_FIXED_RESOLUTION,
+ media::RESOLUTION_POLICY_FIXED_ASPECT_RATIO,
+ media::RESOLUTION_POLICY_ANY_WITHIN_LIMIT,
+ };
+
+ for (size_t i = 0; i < arraysize(policies); ++i) {
+ // A 16:9 standard resolution should be set as the preferred size when the
+ // source size is almost or exactly 16:9.
+ for (int delta_w = 0; delta_w <= +5; ++delta_w) {
+ for (int delta_h = 0; delta_h <= +5; ++delta_h) {
+ RunTestForPreferredSize(policies[i],
+ gfx::Size(1280 + delta_w, 720 + delta_h),
+ gfx::Size(1280, 720));
+ }
+ }
+ for (int delta_w = -5; delta_w <= +5; ++delta_w) {
+ for (int delta_h = -5; delta_h <= +5; ++delta_h) {
+ RunTestForPreferredSize(policies[i],
+ gfx::Size(1365 + delta_w, 768 + delta_h),
+ gfx::Size(1280, 720));
+ }
+ }
+
+ // A 4:3 standard resolution should be set as the preferred size when the
+ // source size is almost or exactly 4:3.
+ for (int delta_w = 0; delta_w <= +5; ++delta_w) {
+ for (int delta_h = 0; delta_h <= +5; ++delta_h) {
+ RunTestForPreferredSize(policies[i],
+ gfx::Size(640 + delta_w, 480 + delta_h),
+ gfx::Size(640, 480));
+ }
+ }
+ for (int delta_w = -5; delta_w <= +5; ++delta_w) {
+ for (int delta_h = -5; delta_h <= +5; ++delta_h) {
+ RunTestForPreferredSize(policies[i],
+ gfx::Size(800 + delta_w, 600 + delta_h),
+ gfx::Size(768, 576));
+ }
+ }
+
+ // When the source size is not a common video aspect ratio, there is no
+ // adjustment made.
+ RunTestForPreferredSize(
+ policies[i], gfx::Size(1000, 1000), gfx::Size(1000, 1000));
+ RunTestForPreferredSize(
+ policies[i], gfx::Size(1600, 1000), gfx::Size(1600, 1000));
+ RunTestForPreferredSize(
+ policies[i], gfx::Size(837, 999), gfx::Size(837, 999));
+ }
+}
+
} // namespace
} // namespace content
« no previous file with comments | « content/browser/media/capture/web_contents_video_capture_device.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698