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

Unified Diff: content/renderer/media/canvas_capture_handler_unittest.cc

Issue 1918073003: Fix odd size and visible rect issues in CanvasCaptureHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 4 years, 8 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/renderer/media/canvas_capture_handler_unittest.cc
diff --git a/content/renderer/media/canvas_capture_handler_unittest.cc b/content/renderer/media/canvas_capture_handler_unittest.cc
index d5153123206d8149231cbfe4e3c79eb52be19295..3d5d87c28f7f9b0a0f276d6aa31d805442cbf7f3 100644
--- a/content/renderer/media/canvas_capture_handler_unittest.cc
+++ b/content/renderer/media/canvas_capture_handler_unittest.cc
@@ -33,7 +33,8 @@ static const double kTestCanvasCaptureFramesPerSecond = 55.5;
static const int kTestCanvasCaptureFrameWidth = 2;
static const int kTestCanvasCaptureFrameHeight = 2;
-static const int kTestCanvasCaptureFrameErrorTolerance = 2;
+static const int kTestCanvasOddSizeOffset = 1;
+static const int kTestCanvasCaptureFrameColorErrorTolerance = 2;
static const int kTestAlphaValue = 175;
ACTION_P(RunClosure, closure) {
@@ -42,7 +43,8 @@ ACTION_P(RunClosure, closure) {
} // namespace
-class CanvasCaptureHandlerTest : public TestWithParam<bool> {
+class CanvasCaptureHandlerTest
+ : public TestWithParam<testing::tuple<bool, bool>> {
public:
CanvasCaptureHandlerTest() {}
@@ -81,17 +83,18 @@ class CanvasCaptureHandlerTest : public TestWithParam<bool> {
void OnRunning(bool state) { DoOnRunning(state); }
// Verify returned frames.
- static sk_sp<SkImage> GenerateTestImage(bool opaque) {
-
+ static sk_sp<SkImage> GenerateTestImage(bool opaque, bool odd_size) {
SkBitmap testBitmap;
- testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth,
- kTestCanvasCaptureFrameHeight, opaque);
+ const int offset = odd_size ? kTestCanvasOddSizeOffset : 0;
mcasas 2016/04/26 00:07:14 I'd say: Just use an integer parameter for the tes
emircan 2016/04/26 19:47:07 Done.
+ testBitmap.allocN32Pixels(kTestCanvasCaptureFrameWidth + offset,
+ kTestCanvasCaptureFrameHeight + offset, opaque);
testBitmap.eraseARGB(kTestAlphaValue, 30, 60, 200);
return SkImage::MakeFromBitmap(testBitmap);
}
void OnVerifyDeliveredFrame(
bool opaque,
+ bool odd_size,
const scoped_refptr<media::VideoFrame>& video_frame,
base::TimeTicks estimated_capture_time) {
if (opaque)
@@ -101,17 +104,22 @@ class CanvasCaptureHandlerTest : public TestWithParam<bool> {
EXPECT_EQ(video_frame->timestamp().InMilliseconds(),
(estimated_capture_time - base::TimeTicks()).InMilliseconds());
- const gfx::Size& size = video_frame->coded_size();
- EXPECT_EQ(kTestCanvasCaptureFrameWidth, size.width());
- EXPECT_EQ(kTestCanvasCaptureFrameHeight, size.height());
- const uint8_t* y_plane = video_frame->data(media::VideoFrame::kYPlane);
- EXPECT_NEAR(74, y_plane[0], kTestCanvasCaptureFrameErrorTolerance);
- const uint8_t* u_plane = video_frame->data(media::VideoFrame::kUPlane);
- EXPECT_NEAR(193, u_plane[0], kTestCanvasCaptureFrameErrorTolerance);
- const uint8_t* v_plane = video_frame->data(media::VideoFrame::kVPlane);
- EXPECT_NEAR(105, v_plane[0], kTestCanvasCaptureFrameErrorTolerance);
+ const int offset = odd_size ? kTestCanvasOddSizeOffset : 0;
+ const gfx::Size& size = video_frame->visible_rect().size();
+ EXPECT_EQ(kTestCanvasCaptureFrameWidth + offset, size.width());
+ EXPECT_EQ(kTestCanvasCaptureFrameHeight + offset, size.height());
+ const uint8_t* y_plane =
+ video_frame->visible_data(media::VideoFrame::kYPlane);
+ EXPECT_NEAR(74, y_plane[0], kTestCanvasCaptureFrameColorErrorTolerance);
+ const uint8_t* u_plane =
+ video_frame->visible_data(media::VideoFrame::kUPlane);
+ EXPECT_NEAR(193, u_plane[0], kTestCanvasCaptureFrameColorErrorTolerance);
+ const uint8_t* v_plane =
+ video_frame->visible_data(media::VideoFrame::kVPlane);
+ EXPECT_NEAR(105, v_plane[0], kTestCanvasCaptureFrameColorErrorTolerance);
if (!opaque) {
- const uint8_t* a_plane = video_frame->data(media::VideoFrame::kAPlane);
+ const uint8_t* a_plane =
+ video_frame->visible_data(media::VideoFrame::kAPlane);
EXPECT_EQ(kTestAlphaValue, a_plane[0]);
}
}
@@ -193,15 +201,17 @@ TEST_P(CanvasCaptureHandlerTest, GetFormatsStartAndStop) {
params, base::Bind(&CanvasCaptureHandlerTest::OnDeliverFrame,
base::Unretained(this)),
base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this)));
- canvas_capture_handler_->sendNewFrame(GenerateTestImage(GetParam()).get());
+ canvas_capture_handler_->sendNewFrame(GenerateTestImage(
+ testing::get<0>(GetParam()), testing::get<1>(GetParam())).get());
run_loop.Run();
source->StopCapture();
}
// Verifies that SkImage is processed and produces VideoFrame as expected.
-TEST_P(CanvasCaptureHandlerTest, VerifyOpaqueFrame) {
- const bool isOpaque = GetParam();
+TEST_P(CanvasCaptureHandlerTest, VerifyFrame) {
+ const bool opaque_frame = testing::get<0>(GetParam());
+ const bool odd_size_frame = testing::get<1>(GetParam());
InSequence s;
media::VideoCapturerSource* const source =
GetVideoCapturerSource(static_cast<MediaStreamVideoCapturerSource*>(
@@ -213,9 +223,10 @@ TEST_P(CanvasCaptureHandlerTest, VerifyOpaqueFrame) {
media::VideoCaptureParams params;
source->StartCapture(
params, base::Bind(&CanvasCaptureHandlerTest::OnVerifyDeliveredFrame,
- base::Unretained(this), isOpaque),
+ base::Unretained(this), opaque_frame, odd_size_frame),
base::Bind(&CanvasCaptureHandlerTest::OnRunning, base::Unretained(this)));
- canvas_capture_handler_->sendNewFrame(GenerateTestImage(isOpaque).get());
+ canvas_capture_handler_->sendNewFrame(
+ GenerateTestImage(opaque_frame, odd_size_frame).get());
run_loop.RunUntilIdle();
}
@@ -231,6 +242,9 @@ TEST_F(CanvasCaptureHandlerTest, CheckNeedsNewFrame) {
EXPECT_FALSE(canvas_capture_handler_->needsNewFrame());
}
-INSTANTIATE_TEST_CASE_P(, CanvasCaptureHandlerTest, ::testing::Bool());
+INSTANTIATE_TEST_CASE_P(,
+ CanvasCaptureHandlerTest,
+ ::testing::Combine(::testing::Bool(),
+ ::testing::Bool()));
} // namespace content

Powered by Google App Engine
This is Rietveld 408576698