1 /* 2 * Copyright (C) 2022 The Android Open Source Project 3 * 4 * Licensed under the Apache License, Version 2.0 (the "License"); 5 * you may not use this file except in compliance with the License. 6 * You may obtain a copy of the License at 7 * 8 * http://www.apache.org/licenses/LICENSE-2.0 9 * 10 * Unless required by applicable law or agreed to in writing, software 11 * distributed under the License is distributed on an "AS IS" BASIS, 12 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 13 * See the License for the specific language governing permissions and 14 * limitations under the License. 15 */ 16 17 package platform.test.screenshot 18 19 import android.os.Build 20 import platform.test.screenshot.matchers.MSSIMMatcher 21 import platform.test.screenshot.matchers.PixelPerfectMatcher 22 23 /** 24 * The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for 25 * screenshot *unit* tests. 26 */ 27 val UnitTestBitmapMatcher = 28 if (Build.CPU_ABI == "x86_64" || Build.FINGERPRINT.contains("robolectric")) { 29 // Different CPU architectures can sometimes end up rendering differently, so we can't do 30 // pixel-perfect matching on different architectures using the same golden. Given that our 31 // presubmits are run on cf_x86_64_phone, our goldens should be perfectly matched on the 32 // x86_64 architecture and use the Structural Similarity Index on others. 33 // TODO(b/237511747): Run our screenshot presubmit tests on arm64 instead so that we can 34 // do pixel perfect matching both at presubmit time and at development time with actual 35 // devices. 36 PixelPerfectMatcher() 37 } else { 38 MSSIMMatcher() 39 } 40 41 /** 42 * The [BitmapMatcher][platform.test.screenshot.matchers.BitmapMatcher] that should be used for 43 * screenshot *unit* tests. 44 * 45 * We use the Structural Similarity Index for integration tests because they usually contain 46 * additional information and noise that shouldn't break the test. 47 */ 48 val IntegrationTestBitmapMatcher = MSSIMMatcher() 49