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/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 Loading... | |
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 #if CGFLOAT_IS_DOUBLE | |
920 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.
| |
921 #else | |
922 return std::fabsf(val1 - val2) < FLT_EPSILON; | |
923 #endif // CGFLOAT_IS_DOUBLE | |
924 } | |
925 | |
917 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, | 926 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, |
918 CRWWKWebControllerPageScrollStateTest, | 927 CRWWKWebControllerPageScrollStateTest, |
919 SetPageStateWithUserScalableDisabled) { | 928 SetPageStateWithUserScalableDisabled) { |
920 #if !TARGET_IPHONE_SIMULATOR | 929 #if !TARGET_IPHONE_SIMULATOR |
921 // This test fails flakily on device with WKWebView, so skip it there. | 930 // This test fails flakily on device with WKWebView, so skip it there. |
922 // crbug.com/453530 | 931 // crbug.com/453530 |
923 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE) | 932 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE) |
924 return; | 933 return; |
925 #endif | 934 #endif |
926 this->LoadHtml(@"<html><head>" | 935 this->LoadHtml(@"<html><head>" |
(...skipping 11 matching lines...) Expand all Loading... | |
938 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset | 947 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset |
939 3.0, // relative zoom scale | 948 3.0, // relative zoom scale |
940 1.0, // original minimum zoom scale | 949 1.0, // original minimum zoom scale |
941 5.0, // original maximum zoom scale | 950 5.0, // original maximum zoom scale |
942 1.0); // original zoom scale | 951 1.0); // original zoom scale |
943 [this->webController_ setPageScrollState:scrollState]; | 952 [this->webController_ setPageScrollState:scrollState]; |
944 | 953 |
945 // setPageState: is async; wait for its completion. | 954 // setPageState: is async; wait for its completion. |
946 scrollView = [[[this->webController_ view] subviews][0] scrollView]; | 955 scrollView = [[[this->webController_ view] subviews][0] scrollView]; |
947 base::test::ios::WaitUntilCondition(^bool() { | 956 base::test::ios::WaitUntilCondition(^bool() { |
948 return [scrollView contentOffset].x == 1.0f; | 957 return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f); |
949 }); | 958 }); |
950 | 959 |
951 ASSERT_EQ(originZoomScale, scrollView.zoomScale); | 960 ASSERT_CGFLOAT_EQ(originZoomScale, scrollView.zoomScale); |
952 ASSERT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale); | 961 ASSERT_CGFLOAT_EQ(originMinimumZoomScale, scrollView.minimumZoomScale); |
953 ASSERT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale); | 962 ASSERT_CGFLOAT_EQ(originMaximumZoomScale, scrollView.maximumZoomScale); |
954 }; | 963 }; |
955 | 964 |
956 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, | 965 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, |
957 CRWWKWebControllerPageScrollStateTest, | 966 CRWWKWebControllerPageScrollStateTest, |
958 SetPageStateWithUserScalableEnabled) { | 967 SetPageStateWithUserScalableEnabled) { |
959 this->LoadHtml(@"<html><head>" | 968 this->LoadHtml(@"<html><head>" |
960 "<meta name='viewport' content=" | 969 "<meta name='viewport' content=" |
961 "'width=device-width,maximum-scale=10,initial-scale=1.0'" | 970 "'width=device-width,maximum-scale=10,initial-scale=1.0'" |
962 " /></head><body>Test</body></html>"); | 971 " /></head><body>Test</body></html>"); |
963 | 972 |
964 ui::test::uiview_utils::ForceViewRendering([this->webController_ view]); | 973 ui::test::uiview_utils::ForceViewRendering([this->webController_ view]); |
965 web::PageScrollState scrollState = | 974 web::PageScrollState scrollState = |
966 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset | 975 this->CreateTestScrollState(CGPointMake(1.0, 1.0), // scroll offset |
967 3.0, // relative zoom scale | 976 3.0, // relative zoom scale |
968 1.0, // original minimum zoom scale | 977 1.0, // original minimum zoom scale |
969 10.0, // original maximum zoom scale | 978 10.0, // original maximum zoom scale |
970 1.0); // original zoom scale | 979 1.0); // original zoom scale |
971 [this->webController_ setPageScrollState:scrollState]; | 980 [this->webController_ setPageScrollState:scrollState]; |
972 | 981 |
973 // setPageState: is async; wait for its completion. | 982 // setPageState: is async; wait for its completion. |
974 id webView = [[this->webController_ view] subviews][0]; | 983 id webView = [[this->webController_ view] subviews][0]; |
975 UIScrollView* scrollView = [webView scrollView]; | 984 UIScrollView* scrollView = [webView scrollView]; |
976 base::test::ios::WaitUntilCondition(^bool() { | 985 base::test::ios::WaitUntilCondition(^bool() { |
977 return [scrollView contentOffset].x == 1.0f; | 986 return CGFloatsAreEqual(scrollView.contentOffset.x, 1.0f); |
978 }); | 987 }); |
979 | 988 |
980 EXPECT_FLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale); | 989 ASSERT_CGFLOAT_EQ(3, scrollView.zoomScale / scrollView.minimumZoomScale); |
981 }; | 990 }; |
982 | 991 |
983 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, | 992 WEB_TEST_F(CRWUIWebControllerPageScrollStateTest, |
984 CRWWKWebControllerPageScrollStateTest, | 993 CRWWKWebControllerPageScrollStateTest, |
985 AtTop) { | 994 AtTop) { |
986 // This test fails on iPhone 6/6+ with WKWebView; skip until it's fixed. | 995 // This test fails on iPhone 6/6+ with WKWebView; skip until it's fixed. |
987 // crbug.com/453105 | 996 // crbug.com/453105 |
988 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE && | 997 if ([this->webController_ webViewType] == web::WK_WEB_VIEW_TYPE && |
989 IsIPhone6Or6Plus()) | 998 IsIPhone6Or6Plus()) |
990 return; | 999 return; |
991 | 1000 |
992 this->LoadHtml(@"<html><head>" | 1001 this->LoadHtml(@"<html><head>" |
993 "<meta name='viewport' content=" | 1002 "<meta name='viewport' content=" |
994 "'width=device-width,maximum-scale=5.0,initial-scale=1.0'" | 1003 "'width=device-width,maximum-scale=5.0,initial-scale=1.0'" |
995 " /></head><body>Test</body></html>"); | 1004 " /></head><body>Test</body></html>"); |
996 ASSERT_TRUE(this->webController_.get().atTop); | 1005 ASSERT_TRUE(this->webController_.get().atTop); |
997 | 1006 |
998 web::PageScrollState scrollState = | 1007 web::PageScrollState scrollState = |
999 this->CreateTestScrollState(CGPointMake(0.0, 30.0), // scroll offset | 1008 this->CreateTestScrollState(CGPointMake(0.0, 30.0), // scroll offset |
1000 5.0, // relative zoom scale | 1009 5.0, // relative zoom scale |
1001 1.0, // original minimum zoom scale | 1010 1.0, // original minimum zoom scale |
1002 5.0, // original maximum zoom scale | 1011 5.0, // original maximum zoom scale |
1003 1.0); // original zoom scale | 1012 1.0); // original zoom scale |
1004 [this->webController_ setPageScrollState:scrollState]; | 1013 [this->webController_ setPageScrollState:scrollState]; |
1005 | 1014 |
1006 // setPageState: is async; wait for its completion. | 1015 // setPageState: is async; wait for its completion. |
1007 id webView = [[this->webController_ view] subviews][0]; | 1016 id webView = [[this->webController_ view] subviews][0]; |
1008 base::test::ios::WaitUntilCondition(^bool() { | 1017 base::test::ios::WaitUntilCondition(^bool() { |
1009 return [[webView scrollView] contentOffset].y == 30.0f; | 1018 return CGFloatsAreEqual([webView scrollView].contentOffset.y, 30.0f); |
1010 }); | 1019 }); |
1011 | 1020 |
1012 ASSERT_FALSE([this->webController_ atTop]); | 1021 ASSERT_FALSE([this->webController_ atTop]); |
1013 }; | 1022 }; |
1014 | 1023 |
1015 // Tests that evaluateJavaScript:completionHandler: properly forwards the | 1024 // Tests that evaluateJavaScript:completionHandler: properly forwards the |
1016 // call to UIWebView. | 1025 // call to UIWebView. |
1017 TEST_F(CRWUIWebViewWebControllerTest, JavaScriptEvaluation) { | 1026 TEST_F(CRWUIWebViewWebControllerTest, JavaScriptEvaluation) { |
1018 NSString* kTestScript = @"script"; | 1027 NSString* kTestScript = @"script"; |
1019 NSString* kTestResult = @"result"; | 1028 NSString* kTestResult = @"result"; |
(...skipping 452 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1472 // https://bugs.webkit.org/show_bug.cgi?id=140203 | 1481 // https://bugs.webkit.org/show_bug.cgi?id=140203 |
1473 VLOG(1) << "Script has been flushed."; | 1482 VLOG(1) << "Script has been flushed."; |
1474 }]; | 1483 }]; |
1475 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript | 1484 // -evaluateJavaScript:stringResultHandler: is asynchronous so JavaScript |
1476 // evaluation will not happen until TearDown, which deallocates | 1485 // evaluation will not happen until TearDown, which deallocates |
1477 // CRWWebController, which in its turn will deallocate WKWebView to create a | 1486 // CRWWebController, which in its turn will deallocate WKWebView to create a |
1478 // crashy condition. | 1487 // crashy condition. |
1479 }; | 1488 }; |
1480 | 1489 |
1481 } // namespace | 1490 } // namespace |
OLD | NEW |