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

Side by Side Diff: services/shape_detection/barcode_detection_impl_mac_unittest.mm

Issue 2677553003: Shape detection unittests mac (QR and Face) in GPU bots (Closed)
Patch Set: Using GPU bots, removed software rendering parts Created 3 years, 10 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 unified diff | Download patch
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "services/shape_detection/barcode_detection_impl_mac.h"
6
7 #include "base/mac/mac_util.h"
8 #include "base/mac/scoped_nsobject.h"
9 #include "base/mac/sdk_forward_declarations.h"
10 #include "base/run_loop.h"
11 #include "testing/gmock/include/gmock/gmock.h"
12 #include "testing/gtest/include/gtest/gtest.h"
13
14 namespace shape_detection {
15
16 class BarcodeDetectionImplMacTest : public ::testing::Test {
17 public:
18 BarcodeDetectionImplMacTest() = default;
Robert Sesek 2017/02/10 20:24:37 Do you need to provide a ctor and dtor here?
mcasas 2017/02/10 21:05:06 Ah yeah (and also in the face detection unittest).
19 ~BarcodeDetectionImplMacTest() override = default;
20
21 void DetectCallback(std::vector<mojom::BarcodeDetectionResultPtr> results) {
22 Detection(results.size(), results.empty() ? "" : results[0]->raw_value);
23 }
24 MOCK_METHOD2(Detection, void(size_t, const std::string&));
25
26 BarcodeDetectionImplMac impl_;
27 const base::MessageLoop message_loop_;
28
29 private:
30 DISALLOW_COPY_AND_ASSIGN(BarcodeDetectionImplMacTest);
31 };
32
33 TEST_F(BarcodeDetectionImplMacTest, CreateAndDestroy) {}
34
35 // This test generates a single QR code and scans it back.
36 TEST_F(BarcodeDetectionImplMacTest, ScanOneBarcode) {
37 const std::string kInfoString = "https://www.chromium.org";
38 // Generate a QR code image as a CIImage by using |qr_code_generator|.
39 NSData* const qr_code_data =
40 [[NSString stringWithUTF8String:kInfoString.c_str()]
41 dataUsingEncoding:NSISOLatin1StringEncoding];
42 // TODO(mcasas): Consider using other generator types (e.g.
43 // CI{AztecCode,Code128Barcode,PDF417Barcode}Generator) when the minimal OS X
44 // is upgraded to 10.10 (https://crbug.com/624049).
45 CIFilter* qr_code_generator =
46 [CIFilter filterWithName:@"CIQRCodeGenerator"];
47 [qr_code_generator setValue:qr_code_data forKey:@"inputMessage"];
48
49 // [CIImage outputImage] is available in macOS 10.10+. Could be added to
50 // sdk_forward_declarations.h but seems hardly worth it.
51 EXPECT_TRUE([qr_code_generator respondsToSelector:@selector(outputImage)]);
Robert Sesek 2017/02/10 20:24:37 Won't this test then fail on 10.9?
mcasas 2017/02/10 21:05:06 Yes although the bots are 10.11.4 and there's code
52 CIImage* qr_code_image =
53 [qr_code_generator performSelector:@selector(outputImage)];
54
55 const gfx::Size size([qr_code_image extent].size.width,
56 [qr_code_image extent].size.height);
57 const int num_bytes = size.GetArea() * 4 /* bytes per pixel */;
58
59 base::scoped_nsobject<CIContext> context([[CIContext alloc] init]);
60
61 CGImageRef cg_image =
62 [context createCGImage:qr_code_image fromRect:[qr_code_image extent]];
Robert Sesek 2017/02/10 20:24:37 This API follows the "create" rule for memory mana
mcasas 2017/02/10 21:05:06 Done.
63 EXPECT_EQ(static_cast<size_t>(size.width()), CGImageGetWidth(cg_image));
64 EXPECT_EQ(static_cast<size_t>(size.height()), CGImageGetHeight(cg_image));
65
66 CFDataRef raw_cg_image_data =
67 CGDataProviderCopyData(CGImageGetDataProvider(cg_image));
Robert Sesek 2017/02/10 20:24:37 Same; the "copy" rule indicates a strong reference
mcasas 2017/02/10 21:05:06 Done.
68 EXPECT_TRUE(CFDataGetBytePtr(raw_cg_image_data));
69 EXPECT_EQ(num_bytes, CFDataGetLength(raw_cg_image_data));
70
71 // Generate a new ScopedSharedBufferHandle of the aproppriate size, map it and
72 // copy the generated qr code image pixels into it.
73 mojo::ScopedSharedBufferHandle handle =
74 mojo::SharedBufferHandle::Create(num_bytes);
75 ASSERT_TRUE(handle->is_valid());
76
77 mojo::ScopedSharedBufferMapping mapping = handle->Map(num_bytes);
78 ASSERT_TRUE(mapping);
79
80 memcpy(mapping.get(), CFDataGetBytePtr(raw_cg_image_data), num_bytes);
81
82 // Send the image Detect() and expect the response in callback.
83 EXPECT_CALL(*this, Detection(1, kInfoString));
84 impl_.Detect(std::move(handle), size.width(), size.height(),
85 base::Bind(&BarcodeDetectionImplMacTest::DetectCallback,
86 base::Unretained(this)));
87
88 base::RunLoop().RunUntilIdle();
89 }
90
91 } // shape_detection namespace
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698