| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "remoting/host/chromeos/aura_desktop_capturer.h" | 5 #include "remoting/host/chromeos/aura_desktop_capturer.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #include <stdint.h> | 8 #include <stdint.h> |
| 9 | 9 |
| 10 #include <utility> | 10 #include <utility> |
| 11 | 11 |
| 12 #include "cc/output/copy_output_result.h" | 12 #include "cc/output/copy_output_result.h" |
| 13 #include "testing/gmock/include/gmock/gmock.h" | 13 #include "testing/gmock/include/gmock/gmock.h" |
| 14 #include "testing/gtest/include/gtest/gtest.h" | 14 #include "testing/gtest/include/gtest/gtest.h" |
| 15 #include "third_party/skia/include/core/SkBitmap.h" | 15 #include "third_party/skia/include/core/SkBitmap.h" |
| 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" | 16 #include "third_party/webrtc/modules/desktop_capture/desktop_frame.h" |
| 17 | 17 |
| 18 using testing::_; | 18 using testing::_; |
| 19 using testing::SaveArg; | |
| 20 | 19 |
| 21 namespace remoting { | 20 namespace remoting { |
| 22 | 21 |
| 23 namespace { | 22 namespace { |
| 24 | 23 |
| 25 // Test frame data. | 24 // Test frame data. |
| 26 const unsigned char frame_data[] = { | 25 const unsigned char frame_data[] = { |
| 27 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, | 26 0x00, 0x00, 0x00, 0x9a, 0x65, 0x1e, 0x00, 0x00, 0x00, 0x01, 0x00, 0x00, |
| 28 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, | 27 0x00, 0x90, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x20, 0x60, 0x90, |
| 29 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, | 28 0x24, 0x71, 0xf8, 0xf2, 0xe5, 0xdf, 0x7f, 0x81, 0xc7, 0x49, 0xc4, 0xa3, |
| 30 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, | 29 0x58, 0x5c, 0xf6, 0xcc, 0x40, 0x14, 0x28, 0x0c, 0xa0, 0xfa, 0x03, 0x18, |
| 31 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, | 30 0x38, 0xd8, 0x7d, 0x77, 0x2b, 0x3a, 0x00, 0x00, 0x00, 0x20, 0x64, 0x46, |
| 32 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, | 31 0x47, 0x2f, 0xdf, 0x6e, 0xed, 0x7b, 0xf3, 0xc3, 0x37, 0x20, 0xf2, 0x36, |
| 33 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, | 32 0x67, 0x6c, 0x36, 0xe1, 0xb4, 0x5e, 0xbe, 0x04, 0x85, 0xdb, 0x89, 0xa3, |
| 34 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, | 33 0xcd, 0xfd, 0xd2, 0x4b, 0xd6, 0x9f, 0x00, 0x00, 0x00, 0x40, 0x38, 0x35, |
| 35 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, | 34 0x05, 0x75, 0x1d, 0x13, 0x6e, 0xb3, 0x6b, 0x1d, 0x29, 0xae, 0xd3, 0x43, |
| 36 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, | 35 0xe6, 0x84, 0x8f, 0xa3, 0x9d, 0x65, 0x4e, 0x2f, 0x57, 0xe3, 0xf6, 0xe6, |
| 37 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, | 36 0x20, 0x3c, 0x00, 0xc6, 0xe1, 0x73, 0x34, 0xe2, 0x23, 0x99, 0xc4, 0xfa, |
| 38 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7 | 37 0x91, 0xc2, 0xd5, 0x97, 0xc1, 0x8b, 0xd0, 0x3c, 0x13, 0xba, 0xf0, 0xd7 |
| 39 }; | 38 }; |
| 39 |
| 40 ACTION_P(SaveUniquePtrArg, dest) { |
| 41 *dest = std::move(*arg1); |
| 42 } |
| 43 |
| 40 } // namespace | 44 } // namespace |
| 41 | 45 |
| 42 class AuraDesktopCapturerTest : public testing::Test, | 46 class AuraDesktopCapturerTest : public testing::Test, |
| 43 public webrtc::DesktopCapturer::Callback { | 47 public webrtc::DesktopCapturer::Callback { |
| 44 public: | 48 public: |
| 45 AuraDesktopCapturerTest() {} | 49 AuraDesktopCapturerTest() {} |
| 46 | 50 |
| 47 void SetUp() override; | 51 void SetUp() override; |
| 48 | 52 |
| 49 MOCK_METHOD1(OnCaptureCompleted, void(webrtc::DesktopFrame* frame)); | 53 MOCK_METHOD2(OnCaptureResultPtr, |
| 54 void(webrtc::DesktopCapturer::Result result, |
| 55 std::unique_ptr<webrtc::DesktopFrame>* frame)); |
| 56 void OnCaptureResult(webrtc::DesktopCapturer::Result result, |
| 57 std::unique_ptr<webrtc::DesktopFrame> frame) override { |
| 58 OnCaptureResultPtr(result, &frame); |
| 59 } |
| 50 | 60 |
| 51 protected: | 61 protected: |
| 52 void SimulateFrameCapture() { | 62 void SimulateFrameCapture() { |
| 53 std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); | 63 std::unique_ptr<SkBitmap> bitmap(new SkBitmap()); |
| 54 const SkImageInfo& info = | 64 const SkImageInfo& info = |
| 55 SkImageInfo::Make(3, 4, kBGRA_8888_SkColorType, kPremul_SkAlphaType); | 65 SkImageInfo::Make(3, 4, kBGRA_8888_SkColorType, kPremul_SkAlphaType); |
| 56 bitmap->installPixels(info, const_cast<unsigned char*>(frame_data), 12); | 66 bitmap->installPixels(info, const_cast<unsigned char*>(frame_data), 12); |
| 57 | 67 |
| 58 capturer_->OnFrameCaptured( | 68 capturer_->OnFrameCaptured( |
| 59 cc::CopyOutputResult::CreateBitmapResult(std::move(bitmap))); | 69 cc::CopyOutputResult::CreateBitmapResult(std::move(bitmap))); |
| 60 } | 70 } |
| 61 | 71 |
| 62 std::unique_ptr<AuraDesktopCapturer> capturer_; | 72 std::unique_ptr<AuraDesktopCapturer> capturer_; |
| 63 }; | 73 }; |
| 64 | 74 |
| 65 void AuraDesktopCapturerTest::SetUp() { | 75 void AuraDesktopCapturerTest::SetUp() { |
| 66 capturer_.reset(new AuraDesktopCapturer()); | 76 capturer_.reset(new AuraDesktopCapturer()); |
| 67 } | 77 } |
| 68 | 78 |
| 69 TEST_F(AuraDesktopCapturerTest, ConvertSkBitmapToDesktopFrame) { | 79 TEST_F(AuraDesktopCapturerTest, ConvertSkBitmapToDesktopFrame) { |
| 70 webrtc::DesktopFrame* captured_frame = nullptr; | 80 std::unique_ptr<webrtc::DesktopFrame> captured_frame; |
| 71 | 81 |
| 72 EXPECT_CALL(*this, OnCaptureCompleted(_)).Times(1).WillOnce( | 82 EXPECT_CALL(*this, OnCaptureResultPtr(DesktopCatpurer::Result::SUCCESS, _)) |
| 73 SaveArg<0>(&captured_frame)); | 83 .Times(1) |
| 84 .WillOnce(SaveUniquePtrArg(&captured_frame)); |
| 74 capturer_->Start(this); | 85 capturer_->Start(this); |
| 75 | 86 |
| 76 SimulateFrameCapture(); | 87 SimulateFrameCapture(); |
| 77 | 88 |
| 78 ASSERT_TRUE(captured_frame != nullptr); | 89 ASSERT_TRUE(captured_frame); |
| 79 uint8_t* captured_data = captured_frame->data(); | 90 EXPECT_EQ(0, memcmp(frame_data, captured_frame->data(), sizeof(frame_data))); |
| 80 EXPECT_EQ( | |
| 81 0, | |
| 82 memcmp( | |
| 83 frame_data, captured_data, sizeof(frame_data))); | |
| 84 | |
| 85 delete captured_frame; | |
| 86 } | 91 } |
| 87 | 92 |
| 88 } // namespace remoting | 93 } // namespace remoting |
| OLD | NEW |