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

Side by Side Diff: services/shape_detection/android/junit/src/org/chromium/shape_detection/BitmapUtilsTest.java

Issue 2875243002: RELAND: ShapeDetection: use mojom::Bitmap for mojo interface. (Closed)
Patch Set: RELAND2: ShapeDetection: use mojom::Bitmap for mojo interface. Created 3 years, 6 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
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 package org.chromium.shape_detection; 5 package org.chromium.shape_detection;
6 6
7 import static org.junit.Assert.assertNull; 7 import static org.junit.Assert.assertNull;
8 8
9 import org.junit.Before; 9 import org.junit.Before;
10 import org.junit.Test; 10 import org.junit.Test;
11 import org.junit.runner.RunWith; 11 import org.junit.runner.RunWith;
12 import org.mockito.Mockito;
13 import org.mockito.MockitoAnnotations; 12 import org.mockito.MockitoAnnotations;
14 import org.robolectric.annotation.Config; 13 import org.robolectric.annotation.Config;
15 import org.robolectric.shadows.ShadowLog; 14 import org.robolectric.shadows.ShadowLog;
16 15
17 import org.chromium.base.test.util.Feature; 16 import org.chromium.base.test.util.Feature;
18 import org.chromium.mojo.system.SharedBufferHandle; 17 import org.chromium.skia.mojom.Bitmap;
19 import org.chromium.mojo.system.SharedBufferHandle.MapFlags; 18 import org.chromium.skia.mojom.ColorType;
20 import org.chromium.testing.local.LocalRobolectricTestRunner; 19 import org.chromium.testing.local.LocalRobolectricTestRunner;
21 20
22 import java.nio.ByteBuffer;
23
24 /** 21 /**
25 * Test suite for conversion-to-Frame utils. 22 * Test suite for conversion-to-Frame utils.
26 */ 23 */
27 @RunWith(LocalRobolectricTestRunner.class) 24 @RunWith(LocalRobolectricTestRunner.class)
28 @Config(manifest = Config.NONE) 25 @Config(manifest = Config.NONE)
29 public class SharedBufferUtilsTest { 26 public class BitmapUtilsTest {
30 private static final int VALID_WIDTH = 1; 27 private static final int VALID_WIDTH = 1;
31 private static final int VALID_HEIGHT = 1; 28 private static final int VALID_HEIGHT = 1;
32 private static final int INVALID_WIDTH = 0; 29 private static final int INVALID_WIDTH = 0;
33 private static final long NUM_BYTES = VALID_WIDTH * VALID_HEIGHT * 4; 30 private static final long NUM_BYTES = VALID_WIDTH * VALID_HEIGHT * 4;
31 private static final byte[] EMPTY_DATA = new byte[0];
34 32
35 public SharedBufferUtilsTest() {} 33 public BitmapUtilsTest() {}
36 34
37 @Before 35 @Before
38 public void setUp() { 36 public void setUp() {
39 ShadowLog.stream = System.out; 37 ShadowLog.stream = System.out;
40 MockitoAnnotations.initMocks(this); 38 MockitoAnnotations.initMocks(this);
41 } 39 }
42 40
43 /** 41 /**
44 * Verify conversion fails if the SharedBufferHandle is invalid. 42 * Verify conversion fails if the Bitmap is invalid.
45 */ 43 */
46 @Test 44 @Test
47 @Feature({"ShapeDetection"}) 45 @Feature({"ShapeDetection"})
48 public void testConversionFailsWithInvalidHandle() { 46 public void testConversionFailsWithInvalidBitmap() {
49 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); 47 Bitmap bitmap = new Bitmap();
50 Mockito.when(handle.isValid()).thenReturn(false); 48 bitmap.pixelData = null;
51 49
52 assertNull(SharedBufferUtils.convertToFrame(handle, VALID_WIDTH, VALID_H EIGHT)); 50 assertNull(BitmapUtils.convertToFrame(bitmap));
53 } 51 }
54 52
55 /** 53 /**
56 * Verify conversion fails if the sent dimensions are ugly. 54 * Verify conversion fails if the sent dimensions are ugly.
57 */ 55 */
58 @Test 56 @Test
59 @Feature({"ShapeDetection"}) 57 @Feature({"ShapeDetection"})
60 public void testConversionFailsWithInvalidDimensions() { 58 public void testConversionFailsWithInvalidDimensions() {
61 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); 59 Bitmap bitmap = new Bitmap();
62 Mockito.when(handle.isValid()).thenReturn(true); 60 bitmap.pixelData = EMPTY_DATA;
61 bitmap.width = INVALID_WIDTH;
62 bitmap.height = VALID_HEIGHT;
63 63
64 assertNull(SharedBufferUtils.convertToFrame(handle, INVALID_WIDTH, VALID _HEIGHT)); 64 assertNull(BitmapUtils.convertToFrame(bitmap));
65 } 65 }
66 66
67 /** 67 /**
68 * Verify conversion fails if SharedBufferHandle fails to map(). 68 * Verify conversion fails if Bitmap fails to wrap().
69 */ 69 */
70 @Test 70 @Test
71 @Feature({"ShapeDetection"}) 71 @Feature({"ShapeDetection"})
72 public void testConversionFailsWithWronglyMappedBuffer() { 72 public void testConversionFailsWithWronglyWrappedData() {
73 SharedBufferHandle handle = Mockito.mock(SharedBufferHandle.class); 73 Bitmap bitmap = new Bitmap();
74 Mockito.when(handle.isValid()).thenReturn(true); 74 bitmap.pixelData = EMPTY_DATA;
75 Mockito.when(handle.map(Mockito.eq(0L), Mockito.eq(NUM_BYTES), Mockito.a ny(MapFlags.class))) 75 bitmap.width = VALID_WIDTH;
76 .thenReturn(ByteBuffer.allocate(0)); 76 bitmap.height = VALID_HEIGHT;
77 bitmap.colorType = ColorType.RGBA_8888;
77 78
78 assertNull(SharedBufferUtils.convertToFrame(handle, VALID_WIDTH, VALID_H EIGHT)); 79 assertNull(BitmapUtils.convertToFrame(bitmap));
79 } 80 }
80 } 81 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698