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

Side by Side 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: Include gtest_mac.h from callers instead of adding it to ui_cocoa_test_helper.h Created 5 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
« no previous file with comments | « no previous file | testing/gtest_mac.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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/web/web_state/ui/crw_web_controller.h" 5 #import "ios/web/web_state/ui/crw_web_controller.h"
6 6
7 #import <UIKit/UIKit.h> 7 #import <UIKit/UIKit.h>
8 #import <WebKit/WebKit.h> 8 #import <WebKit/WebKit.h>
9 9
10 #include "base/mac/scoped_nsobject.h" 10 #include "base/mac/scoped_nsobject.h"
(...skipping 896 matching lines...) Expand 10 before | Expand all | Expand 10 after
907 CGFloat original_minimum_zoom_scale, 907 CGFloat original_minimum_zoom_scale,
908 CGFloat original_maximum_zoom_scale, 908 CGFloat original_maximum_zoom_scale,
909 CGFloat original_zoom_scale) const { 909 CGFloat original_zoom_scale) const {
910 return web::PageScrollState( 910 return web::PageScrollState(
911 scroll_offset.x, scroll_offset.y, original_minimum_zoom_scale, 911 scroll_offset.x, scroll_offset.y, original_minimum_zoom_scale,
912 original_maximum_zoom_scale, 912 original_maximum_zoom_scale,
913 relative_zoom_scale * original_minimum_zoom_scale); 913 relative_zoom_scale * original_minimum_zoom_scale);
914 } 914 }
915 }; 915 };
916 916
917 // Helper function for comparing two CGFloats.
918 bool CGFloatsAreEqual(CGFloat val1, CGFloat val2) {
919 return std::fabs(val1 - val2) < std::numeric_limits<CGFloat>::epsilon();
920 }
921
917 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, 922 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
918 CRWWKWebControllerPageScrollStateTest, 923 CRWWKWebControllerPageScrollStateTest,
919 SetPageStateWithUserScalableDisabled) { 924 SetPageStateWithUserScalableDisabled) {
920 #if !TARGET_IPHONE_SIMULATOR 925 #if !TARGET_IPHONE_SIMULATOR
921 // This test fails flakily on device with WKWebView, so skip it there. 926 // This test fails flakily on device with WKWebView, so skip it there.
922 // crbug.com/453530 927 // crbug.com/453530
923 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE) 928 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE)
924 return; 929 return;
925 #endif 930 #endif
926 this->LoadHtml(@"<html><head>" 931 this->LoadHtml(@"<html><head>"
(...skipping 11 matching lines...) Expand all
938 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset 943 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset
939 3.0, // relative zoom scale 944 3.0, // relative zoom scale
940 1.0, // original minimum zoom scale 945 1.0, // original minimum zoom scale
941 5.0, // original maximum zoom scale 946 5.0, // original maximum zoom scale
942 1.0); // original zoom scale 947 1.0); // original zoom scale
943 [this->webController_ setPageScrollState:scrollState]; 948 [this->webController_ setPageScrollState:scrollState];
944 949
945 // setPageState: is async; wait for its completion. 950 // setPageState: is async; wait for its completion.
946 scrollView = [[[this->webController_ view] subviews][0] scrollView]; 951 scrollView = [[[this->webController_ view] subviews][0] scrollView];
947 base::test::ios::WaitUntilCondition(^bool() { 952 base::test::ios::WaitUntilCondition(^bool() {
948 return [scrollView contentOffset].x == 1.0f; 953 return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f);
949 }); 954 });
950 955
951 ASSERT_EQ(originZoomScale, scrollView.zoomScale); 956 ASSERT_CGFLOAT_EQ(originZoomScale, scrollView.zoomScale);
952 ASSERT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale); 957 ASSERT_CGFLOAT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale);
953 ASSERT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale); 958 ASSERT_CGFLOAT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale);
954 }; 959 };
955 960
956 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, 961 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
957 CRWWKWebControllerPageScrollStateTest, 962 CRWWKWebControllerPageScrollStateTest,
958 SetPageStateWithUserScalableEnabled) { 963 SetPageStateWithUserScalableEnabled) {
959 this->LoadHtml(@"<html><head>" 964 this->LoadHtml(@"<html><head>"
960 "<meta name='viewport' content=" 965 "<meta name='viewport' content="
961 "'width=device-width,maximum-scale=10,initial-scale=1.0'" 966 "'width=device-width,maximum-scale=10,initial-scale=1.0'"
962 " /></head><body>Test</body></html>"); 967 " /></head><body>Test</body></html>");
963 968
964 ui::test::uiview_utils::ForceViewRendering([this->webController_ view]); 969 ui::test::uiview_utils::ForceViewRendering([this->webController_ view]);
965 web::PageScrollState scrollState = 970 web::PageScrollState scrollState =
966 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset 971 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset
967 3.0, // relative zoom scale 972 3.0, // relative zoom scale
968 1.0, // original minimum zoom scale 973 1.0, // original minimum zoom scale
969 10.0, // original maximum zoom scale 974 10.0, // original maximum zoom scale
970 1.0); // original zoom scale 975 1.0); // original zoom scale
971 [this->webController_ setPageScrollState:scrollState]; 976 [this->webController_ setPageScrollState:scrollState];
972 977
973 // setPageState: is async; wait for its completion. 978 // setPageState: is async; wait for its completion.
974 id webView = [[this->webController_ view] subviews][0]; 979 id webView = [[this->webController_ view] subviews][0];
975 UIScrollView* scrollView = [webView scrollView]; 980 UIScrollView* scrollView = [webView scrollView];
976 base::test::ios::WaitUntilCondition(^bool() { 981 base::test::ios::WaitUntilCondition(^bool() {
977 return [scrollView contentOffset].x == 1.0f; 982 return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f);
978 }); 983 });
979 984
980 EXPECT_FLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale); 985 ASSERT_FLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale);
981 }; 986 };
982 987
983 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, 988 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest,
984 CRWWKWebControllerPageScrollStateTest, 989 CRWWKWebControllerPageScrollStateTest,
985 AtTop) { 990 AtTop) {
986 // This test fails on iPhone 6/6+ with WKWebView; skip until it's fixed. 991 // This test fails on iPhone 6/6+ with WKWebView; skip until it's fixed.
987 // crbug.com/453105 992 // crbug.com/453105
988 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE && 993 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE &&
989 IsIPhone6Or6Plus()) 994 IsIPhone6Or6Plus())
990 return; 995 return;
991 996
992 this->LoadHtml(@"<html><head>" 997 this->LoadHtml(@"<html><head>"
993 "<meta name='viewport' content=" 998 "<meta name='viewport' content="
994 "'width=device-width,maximum-scale=5.0,initial-scale=1.0'" 999 "'width=device-width,maximum-scale=5.0,initial-scale=1.0'"
995 " /></head><body>Test</body></html>"); 1000 " /></head><body>Test</body></html>");
996 ASSERT_TRUE(this->webController_.get().atTop); 1001 ASSERT_TRUE(this->webController_.get().atTop);
997 1002
998 web::PageScrollState scrollState = 1003 web::PageScrollState scrollState =
999 this->CreateTestScrollState(CGPointMake(0.0, 30.0), // scroll offset 1004 this->CreateTestScrollState(CGPointMake(0.0, 30.0), // scroll offset
1000 5.0, // relative zoom scale 1005 5.0, // relative zoom scale
1001 1.0, // original minimum zoom scale 1006 1.0, // original minimum zoom scale
1002 5.0, // original maximum zoom scale 1007 5.0, // original maximum zoom scale
1003 1.0); // original zoom scale 1008 1.0); // original zoom scale
1004 [this->webController_ setPageScrollState:scrollState]; 1009 [this->webController_ setPageScrollState:scrollState];
1005 1010
1006 // setPageState: is async; wait for its completion. 1011 // setPageState: is async; wait for its completion.
1007 id webView = [[this->webController_ view] subviews][0]; 1012 id webView = [[this->webController_ view] subviews][0];
1008 base::test::ios::WaitUntilCondition(^bool() { 1013 base::test::ios::WaitUntilCondition(^bool() {
1009 return [[webView scrollView] contentOffset].y == 30.0f; 1014 return CGFloatsAreEqual([webView scrollView].contentOffset.y, 30.0f);
1010 }); 1015 });
1011 1016
1012 ASSERT_FALSE([this->webController_ atTop]); 1017 ASSERT_FALSE([this->webController_ atTop]);
1013 }; 1018 };
1014 1019
1015 // Tests that evaluateJavaScript:completionHandler: properly forwards the 1020 // Tests that evaluateJavaScript:completionHandler: properly forwards the
1016 // call to UIWebView. 1021 // call to UIWebView.
1017 TEST_F(CRWUIWebViewWebControllerTest, JavaScriptEvaluation) { 1022 TEST_F(CRWUIWebViewWebControllerTest, JavaScriptEvaluation) {
1018 NSString* kTestScript = @"script"; 1023 NSString* kTestScript = @"script";
1019 NSString* kTestResult = @"result"; 1024 NSString* kTestResult = @"result";
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after
1472 // https://bugs.webkit.org/show_bug.cgi?id=140203 1477 // https://bugs.webkit.org/show_bug.cgi?id=140203
1473 VLOG(1) << "Script has been flushed."; 1478 VLOG(1) << "Script has been flushed.";
1474 }]; 1479 }];
1475 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript 1480 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript
1476 // evaluation will not happen until TearDown, which deallocates 1481 // evaluation will not happen until TearDown, which deallocates
1477 // CRWWebController, which in its turn will deallocate WKWebView to create a 1482 // CRWWebController, which in its turn will deallocate WKWebView to create a
1478 // crashy condition. 1483 // crashy condition.
1479 }; 1484 };
1480 1485
1481 } // namespace 1486 } // namespace
OLDNEW
« 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