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