| OLD | NEW |
| 1 // Copyright 2012 The Chromium Authors. All rights reserved. | 1 // Copyright 2012 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 #import "ios/chrome/browser/ui/ui_util.h" | 5 #import "ios/chrome/browser/ui/ui_util.h" |
| 6 | 6 |
| 7 #include <stddef.h> | 7 #include <stddef.h> |
| 8 #import <UIKit/UIKit.h> | 8 #import <UIKit/UIKit.h> |
| 9 | 9 |
| 10 #include "base/macros.h" | 10 #include "base/macros.h" |
| 11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
| 12 #include "testing/gtest_mac.h" | 12 #include "testing/gtest_mac.h" |
| 13 | 13 |
| 14 #if !defined(__has_feature) || !__has_feature(objc_arc) |
| 15 #error "This file requires ARC support." |
| 16 #endif |
| 17 |
| 14 TEST(UIUtilTest, AlignToPixel) { | 18 TEST(UIUtilTest, AlignToPixel) { |
| 15 CGFloat scale = [[UIScreen mainScreen] scale]; | 19 CGFloat scale = [[UIScreen mainScreen] scale]; |
| 16 // Pick a few interesting values: already aligned, aligned on retina, and | 20 // Pick a few interesting values: already aligned, aligned on retina, and |
| 17 // some unaligned values that would round differently. Ensure that all are | 21 // some unaligned values that would round differently. Ensure that all are |
| 18 // "integer" values within <1 of the original value in the scaled space. | 22 // "integer" values within <1 of the original value in the scaled space. |
| 19 CGFloat test_values[] = {10.0, 55.5, 3.14159, 2.71828}; | 23 CGFloat test_values[] = {10.0, 55.5, 3.14159, 2.71828}; |
| 20 const CGFloat kMaxAlignDelta = 0.9999; | 24 const CGFloat kMaxAlignDelta = 0.9999; |
| 21 size_t value_count = arraysize(test_values); | 25 size_t value_count = arraysize(test_values); |
| 22 for (unsigned int i = 0; i < value_count; ++i) { | 26 for (unsigned int i = 0; i < value_count; ++i) { |
| 23 CGFloat aligned = AlignValueToPixel(test_values[i]); | 27 CGFloat aligned = AlignValueToPixel(test_values[i]); |
| (...skipping 270 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 294 originalSize = CGSizeMake(50, 100); | 298 originalSize = CGSizeMake(50, 100); |
| 295 targetSize = CGSizeMake(40, 60); | 299 targetSize = CGSizeMake(40, 60); |
| 296 expectedProjection = CGRectMake(0, 0, 40, 80); | 300 expectedProjection = CGRectMake(0, 0, 40, 80); |
| 297 expectedRevisedSize = expectedProjection.size; | 301 expectedRevisedSize = expectedProjection.size; |
| 298 CalculateProjection(originalSize, targetSize, | 302 CalculateProjection(originalSize, targetSize, |
| 299 ProjectionMode::kAspectFillNoClipping, revisedSize, | 303 ProjectionMode::kAspectFillNoClipping, revisedSize, |
| 300 projection); | 304 projection); |
| 301 EXPECT_EQ_RECT(expectedProjection, projection); | 305 EXPECT_EQ_RECT(expectedProjection, projection); |
| 302 EXPECT_EQ_SIZE(expectedRevisedSize, revisedSize); | 306 EXPECT_EQ_SIZE(expectedRevisedSize, revisedSize); |
| 303 } | 307 } |
| OLD | NEW |