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

Unified Diff: ios/web/web_state/ui/crw_web_controller_unittest.mm

Issue 1155623002: Added CGFloat comparison functions. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 years, 7 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « no previous file | testing/gtest_mac.h » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: ios/web/web_state/ui/crw_web_controller_unittest.mm
diff --git a/ios/web/web_state/ui/crw_web_controller_unittest.mm b/ios/web/web_state/ui/crw_web_controller_unittest.mm
index 56fd77a09054f38ab70470793c0ac3f0966d25e9..795e9fdbbf19c6cf8c5c83335f10d33fd0d27cf3 100644
--- a/ios/web/web_state/ui/crw_web_controller_unittest.mm
+++ b/ios/web/web_state/ui/crw_web_controller_unittest.mm
@@ -914,6 +914,15 @@ class CRWWKWebControllerPageScrollStateTest : public web::WKWebViewWebTest {
}
};
+// Helper function for comparing two CGFloats.
+bool CGFloatsAreEqual(CGFloat val1, CGFloat val2) {
+#if CGFLOAT_IS_DOUBLE
+ return std::fabs(val1 - val2) < DBL_EPSILON;
Eugene But (OOO till 7-30) 2015/05/21 21:13:11 Can you use "std::numeric_limits<CGFloat>::epsilon
kkhorimoto 2015/05/21 22:07:09 Done.
+#else
+ return std::fabsf(val1 - val2) < FLT_EPSILON;
+#endif // CGFLOAT_IS_DOUBLE
+}
+
WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
CRWWKWebControllerPageScrollStateTest,
SetPageStateWithUserScalableDisabled) {
@@ -945,12 +954,12 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
// setPageState: is async; wait for its completion.
scrollView = [[[this->webController_ view] subviews][0] scrollView];
base::test::ios::WaitUntilCondition(^bool() {
- return [scrollView contentOffset].x == 1.0f;
+ return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f);
});
- ASSERT_EQ(originZoomScale, scrollView.zoomScale);
- ASSERT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale);
- ASSERT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale);
+ ASSERT_CGFLOAT_EQ(originZoomScale, scrollView.zoomScale);
+ ASSERT_CGFLOAT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale);
+ ASSERT_CGFLOAT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale);
};
WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
@@ -974,10 +983,10 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
id webView = [[this->webController_ view] subviews][0];
UIScrollView* scrollView = [webView scrollView];
base::test::ios::WaitUntilCondition(^bool() {
- return [scrollView contentOffset].x == 1.0f;
+ return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f);
});
- EXPECT_FLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale);
+ ASSERT_CGFLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale);
};
WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
@@ -1006,7 +1015,7 @@ WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
// setPageState: is async; wait for its completion.
id webView = [[this->webController_ view] subviews][0];
base::test::ios::WaitUntilCondition(^bool() {
- return [[webView scrollView] contentOffset].y == 30.0f;
+ return CGFloatsAreEqual([webView scrollView].contentOffset.y, 30.0f);
});
ASSERT_FALSE([this->webController_ atTop]);
« no previous file with comments | « no previous file | testing/gtest_mac.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698