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