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/text_detection_impl_mac.h" | 5 #include "services/shape_detection/text_detection_impl_mac.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/mac/mac_util.h" | 8 #include "base/mac/mac_util.h" |
9 #include "base/mac/scoped_cftyperef.h" | 9 #include "base/mac/scoped_cftyperef.h" |
10 #include "base/mac/scoped_nsobject.h" | 10 #include "base/mac/scoped_nsobject.h" |
11 #include "base/mac/sdk_forward_declarations.h" | 11 #include "base/mac/sdk_forward_declarations.h" |
12 #include "base/run_loop.h" | 12 #include "base/run_loop.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/utils/mac/SkCGUtils.h" | |
16 #include "ui/gl/gl_switches.h" | 15 #include "ui/gl/gl_switches.h" |
17 | 16 |
18 namespace shape_detection { | 17 namespace shape_detection { |
19 | 18 |
20 ACTION_P(RunClosure, closure) { | 19 ACTION_P(RunClosure, closure) { |
21 closure.Run(); | 20 closure.Run(); |
22 } | 21 } |
23 | 22 |
24 class TextDetectionImplMacTest : public ::testing::Test { | 23 class TextDetectionImplMacTest : public ::testing::Test { |
25 public: | 24 public: |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
75 | 74 |
76 CGContextSetTextPosition(context, 10.0, height / 2.0); | 75 CGContextSetTextPosition(context, 10.0, height / 2.0); |
77 CTLineDraw(line, context); | 76 CTLineDraw(line, context); |
78 | 77 |
79 // Extract a CGImage and its raw pixels from |context|. | 78 // Extract a CGImage and its raw pixels from |context|. |
80 base::ScopedCFTypeRef<CGImageRef> cg_image( | 79 base::ScopedCFTypeRef<CGImageRef> cg_image( |
81 CGBitmapContextCreateImage(context)); | 80 CGBitmapContextCreateImage(context)); |
82 EXPECT_EQ(static_cast<size_t>(width), CGImageGetWidth(cg_image)); | 81 EXPECT_EQ(static_cast<size_t>(width), CGImageGetWidth(cg_image)); |
83 EXPECT_EQ(static_cast<size_t>(height), CGImageGetHeight(cg_image)); | 82 EXPECT_EQ(static_cast<size_t>(height), CGImageGetHeight(cg_image)); |
84 | 83 |
85 SkBitmap bitmap; | 84 base::ScopedCFTypeRef<CFDataRef> raw_cg_image_data( |
86 ASSERT_TRUE(SkCreateBitmapFromCGImage(&bitmap, cg_image)); | 85 CGDataProviderCopyData(CGImageGetDataProvider(cg_image))); |
| 86 EXPECT_TRUE(CFDataGetBytePtr(raw_cg_image_data)); |
| 87 const int num_bytes = width * height * 4; |
| 88 EXPECT_EQ(num_bytes, CFDataGetLength(raw_cg_image_data)); |
| 89 |
| 90 // Generate a new ScopedSharedBufferHandle of the aproppriate size, map it and |
| 91 // copy the generated text image pixels into it. |
| 92 auto handle = mojo::SharedBufferHandle::Create(num_bytes); |
| 93 ASSERT_TRUE(handle->is_valid()); |
| 94 |
| 95 mojo::ScopedSharedBufferMapping mapping = handle->Map(num_bytes); |
| 96 ASSERT_TRUE(mapping); |
| 97 |
| 98 memcpy(mapping.get(), CFDataGetBytePtr(raw_cg_image_data), num_bytes); |
87 | 99 |
88 base::RunLoop run_loop; | 100 base::RunLoop run_loop; |
89 base::Closure quit_closure = run_loop.QuitClosure(); | 101 base::Closure quit_closure = run_loop.QuitClosure(); |
90 // Send the image to Detect() and expect the response in callback. | 102 // Send the image to Detect() and expect the response in callback. |
91 EXPECT_CALL(*this, Detection(1)).WillOnce(RunClosure(quit_closure)); | 103 EXPECT_CALL(*this, Detection(1)).WillOnce(RunClosure(quit_closure)); |
92 impl_.Detect(bitmap, base::Bind(&TextDetectionImplMacTest::DetectCallback, | 104 impl_.Detect(std::move(handle), width, height, |
93 base::Unretained(this))); | 105 base::Bind(&TextDetectionImplMacTest::DetectCallback, |
| 106 base::Unretained(this))); |
94 | 107 |
95 run_loop.Run(); | 108 run_loop.Run(); |
96 } | 109 } |
97 | 110 |
98 } // shape_detection namespace | 111 } // shape_detection namespace |
OLD | NEW |