| OLD | NEW |
| 1 // Copyright 2017 The Chromium Authors. All rights reserved. | 1 // Copyright 2017 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 "services/shape_detection/face_detection_impl_mac.h" | 5 #include "services/shape_detection/face_detection_impl_mac.h" |
| 6 | 6 |
| 7 #include "base/base64.h" | 7 #include "base/base64.h" |
| 8 #include "base/command_line.h" | 8 #include "base/command_line.h" |
| 9 #include "base/mac/scoped_nsobject.h" | 9 #include "base/mac/scoped_nsobject.h" |
| 10 #include "base/run_loop.h" | 10 #include "base/run_loop.h" |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 74 reinterpret_cast<const uint8_t*>(image_as_jpeg.data()), | 74 reinterpret_cast<const uint8_t*>(image_as_jpeg.data()), |
| 75 image_as_jpeg.size()); | 75 image_as_jpeg.size()); |
| 76 ASSERT_TRUE(image); | 76 ASSERT_TRUE(image); |
| 77 ASSERT_EQ(kJpegImageWidth, image->width()); | 77 ASSERT_EQ(kJpegImageWidth, image->width()); |
| 78 ASSERT_EQ(kJpegImageHeight, image->height()); | 78 ASSERT_EQ(kJpegImageHeight, image->height()); |
| 79 | 79 |
| 80 const gfx::Size size(image->width(), image->height()); | 80 const gfx::Size size(image->width(), image->height()); |
| 81 const int num_bytes = size.GetArea() * 4 /* bytes per pixel */; | 81 const int num_bytes = size.GetArea() * 4 /* bytes per pixel */; |
| 82 ASSERT_EQ(num_bytes, image->computeSize64()); | 82 ASSERT_EQ(num_bytes, image->computeSize64()); |
| 83 | 83 |
| 84 // Generate a new ScopedSharedBufferHandle of the aproppriate size, map it and | |
| 85 // copy the image pixels into it. | |
| 86 mojo::ScopedSharedBufferHandle handle = | |
| 87 mojo::SharedBufferHandle::Create(num_bytes); | |
| 88 ASSERT_TRUE(handle->is_valid()); | |
| 89 | |
| 90 mojo::ScopedSharedBufferMapping mapping = handle->Map(num_bytes); | |
| 91 ASSERT_TRUE(mapping); | |
| 92 | |
| 93 memcpy(mapping.get(), image->getPixels(), num_bytes); | |
| 94 | |
| 95 base::RunLoop run_loop; | 84 base::RunLoop run_loop; |
| 96 base::Closure quit_closure = run_loop.QuitClosure(); | 85 base::Closure quit_closure = run_loop.QuitClosure(); |
| 97 // Send the image to Detect() and expect the response in callback. | 86 // Send the image to Detect() and expect the response in callback. |
| 98 EXPECT_CALL(*this, Detection()).WillOnce(RunClosure(quit_closure)); | 87 EXPECT_CALL(*this, Detection()).WillOnce(RunClosure(quit_closure)); |
| 99 impl_->Detect(std::move(handle), size.width(), size.height(), | 88 impl_->Detect(*image, base::Bind(&FaceDetectionImplMacTest::DetectCallback, |
| 100 base::Bind(&FaceDetectionImplMacTest::DetectCallback, | 89 base::Unretained(this))); |
| 101 base::Unretained(this))); | |
| 102 | 90 |
| 103 run_loop.Run(); | 91 run_loop.Run(); |
| 104 } | 92 } |
| 105 | 93 |
| 106 INSTANTIATE_TEST_CASE_P(, FaceDetectionImplMacTest, ValuesIn({true, false})); | 94 INSTANTIATE_TEST_CASE_P(, FaceDetectionImplMacTest, ValuesIn({true, false})); |
| 107 | 95 |
| 108 } // shape_detection namespace | 96 } // shape_detection namespace |
| OLD | NEW |