OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 Google Inc. All rights reserved. |
3 * | 3 * |
4 * Redistribution and use in source and binary forms, with or without | 4 * Redistribution and use in source and binary forms, with or without |
5 * modification, are permitted provided that the following conditions are | 5 * modification, are permitted provided that the following conditions are |
6 * met: | 6 * met: |
7 * | 7 * |
8 * * Redistributions of source code must retain the above copyright | 8 * * Redistributions of source code must retain the above copyright |
9 * notice, this list of conditions and the following disclaimer. | 9 * notice, this list of conditions and the following disclaimer. |
10 * * Redistributions in binary form must reproduce the above | 10 * * Redistributions in binary form must reproduce the above |
(...skipping 2853 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
2864 } | 2864 } |
2865 | 2865 |
2866 TEST_F(WebFrameTest, DivScrollIntoEditableTest) | 2866 TEST_F(WebFrameTest, DivScrollIntoEditableTest) |
2867 { | 2867 { |
2868 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); | 2868 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); |
2869 | 2869 |
2870 int viewportWidth = 450; | 2870 int viewportWidth = 450; |
2871 int viewportHeight = 300; | 2871 int viewportHeight = 300; |
2872 float leftBoxRatio = 0.3f; | 2872 float leftBoxRatio = 0.3f; |
2873 int caretPadding = 10; | 2873 int caretPadding = 10; |
2874 float minReadableCaretHeight = 18.0f; | 2874 float minReadableCaretHeight = 16.0f; |
2875 FrameTestHelpers::WebViewHelper webViewHelper; | 2875 FrameTestHelpers::WebViewHelper webViewHelper; |
2876 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl
e_test.html"); | 2876 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl
e_test.html"); |
| 2877 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(fal
se); |
2877 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); | 2878 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
2878 webViewHelper.webView()->setPageScaleFactorLimits(1, 4); | 2879 webViewHelper.webView()->setPageScaleFactorLimits(0.25f, 4); |
| 2880 webViewHelper.webView()->setDeviceScaleFactor(1.5f); |
2879 webViewHelper.webView()->layout(); | 2881 webViewHelper.webView()->layout(); |
2880 webViewHelper.webView()->setDeviceScaleFactor(1.5f); | |
2881 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr
ue); | 2882 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr
ue); |
2882 | 2883 |
2883 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 2884 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
2884 | 2885 |
2885 WebRect editBoxWithText(200, 200, 250, 20); | 2886 WebRect editBoxWithText(200, 200, 250, 20); |
2886 WebRect editBoxWithNoText(200, 250, 250, 20); | 2887 WebRect editBoxWithNoText(200, 250, 250, 20); |
2887 | 2888 |
2888 // Test scrolling the focused node | 2889 // Test scrolling the focused node |
2889 // The edit box is shorter and narrower than the viewport when legible. | 2890 // The edit box is shorter and narrower than the viewport when legible. |
2890 webViewHelper.webView()->advanceFocus(false); | 2891 webViewHelper.webView()->advanceFocus(false); |
2891 // Set the caret to the end of the input box. | 2892 // Set the caret to the end of the input box. |
2892 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith
Text").to<WebInputElement>().setSelectionRange(1000, 1000); | 2893 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith
Text").to<WebInputElement>().setSelectionRange(1000, 1000); |
2893 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); | 2894 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); |
2894 WebRect rect, caret; | 2895 WebRect rect, caret; |
2895 webViewHelper.webViewImpl()->selectionBounds(caret, rect); | 2896 webViewHelper.webViewImpl()->selectionBounds(caret, rect); |
2896 | 2897 |
| 2898 // Set the page scale to be smaller than the minimal readable scale. |
| 2899 float initialScale = minReadableCaretHeight / caret.height * 0.5f; |
| 2900 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialS
cale); |
| 2901 |
2897 float scale; | 2902 float scale; |
2898 IntPoint scroll; | 2903 IntPoint scroll; |
2899 bool needAnimation; | 2904 bool needAnimation; |
2900 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); | 2905 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
2901 EXPECT_TRUE(needAnimation); | 2906 EXPECT_TRUE(needAnimation); |
2902 // The edit box should be left aligned with a margin for possible label. | 2907 // The edit box should be left aligned with a margin for possible label. |
2903 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale; | 2908 int hScroll = editBoxWithText.x - leftBoxRatio * viewportWidth / scale; |
2904 EXPECT_NEAR(hScroll, scroll.x(), 5); | 2909 EXPECT_NEAR(hScroll, scroll.x(), 2); |
2905 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText.
height) / 2; | 2910 int vScroll = editBoxWithText.y - (viewportHeight / scale - editBoxWithText.
height) / 2; |
2906 EXPECT_NEAR(vScroll, scroll.y(), 1); | 2911 EXPECT_NEAR(vScroll, scroll.y(), 2); |
2907 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 2912 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
2908 | 2913 |
2909 // The edit box is wider than the viewport when legible. | 2914 // The edit box is wider than the viewport when legible. |
2910 viewportWidth = 200; | 2915 viewportWidth = 200; |
2911 viewportHeight = 150; | 2916 viewportHeight = 150; |
2912 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); | 2917 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
2913 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); | 2918 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialS
cale); |
2914 webViewHelper.webViewImpl()->selectionBounds(caret, rect); | |
2915 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); | 2919 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
2916 EXPECT_TRUE(needAnimation); | 2920 EXPECT_TRUE(needAnimation); |
2917 // The caret should be right aligned since the caret would be offscreen when
the edit box is left aligned. | 2921 // The caret should be right aligned since the caret would be offscreen when
the edit box is left aligned. |
2918 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale; | 2922 hScroll = caret.x + caret.width + caretPadding - viewportWidth / scale; |
2919 EXPECT_NEAR(hScroll, scroll.x(), 1); | 2923 EXPECT_NEAR(hScroll, scroll.x(), 2); |
2920 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 2924 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
2921 | 2925 |
2922 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); | 2926 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), initialS
cale); |
2923 // Move focus to edit box with text. | 2927 // Move focus to edit box with text. |
2924 webViewHelper.webView()->advanceFocus(false); | 2928 webViewHelper.webView()->advanceFocus(false); |
2925 webViewHelper.webViewImpl()->selectionBounds(caret, rect); | |
2926 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); | 2929 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
2927 EXPECT_TRUE(needAnimation); | 2930 EXPECT_TRUE(needAnimation); |
2928 // The edit box should be left aligned. | 2931 // The edit box should be left aligned. |
2929 hScroll = editBoxWithNoText.x; | 2932 hScroll = editBoxWithNoText.x; |
2930 EXPECT_NEAR(hScroll, scroll.x(), 1); | 2933 EXPECT_NEAR(hScroll, scroll.x(), 2); |
2931 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText.
height) / 2; | 2934 vScroll = editBoxWithNoText.y - (viewportHeight / scale - editBoxWithNoText.
height) / 2; |
2932 EXPECT_NEAR(vScroll, scroll.y(), 1); | 2935 EXPECT_NEAR(vScroll, scroll.y(), 2); |
2933 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); | 2936 EXPECT_NEAR(minReadableCaretHeight / caret.height, scale, 0.1); |
2934 | 2937 |
2935 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, scale); | |
2936 | |
2937 // Move focus back to the first edit box. | 2938 // Move focus back to the first edit box. |
2938 webViewHelper.webView()->advanceFocus(true); | 2939 webViewHelper.webView()->advanceFocus(true); |
| 2940 // Zoom out slightly. |
| 2941 const float withinToleranceScale = scale * 0.9f; |
| 2942 setScaleAndScrollAndLayout(webViewHelper.webViewImpl(), scroll, withinTolera
nceScale); |
| 2943 // Move focus back to the second edit box. |
| 2944 webViewHelper.webView()->advanceFocus(false); |
2939 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); | 2945 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
2940 // The position should have stayed the same since this box was already on sc
reen with the right scale. | 2946 // The scale should not be adjusted as the zoomed out scale was sufficiently
close to the previously focused scale. |
2941 EXPECT_FALSE(needAnimation); | 2947 EXPECT_FALSE(needAnimation); |
2942 } | 2948 } |
2943 | 2949 |
2944 TEST_F(WebFrameTest, DivScrollIntoEditablePreservePageScaleTest) | 2950 TEST_F(WebFrameTest, DivScrollIntoEditablePreservePageScaleTest) |
2945 { | 2951 { |
2946 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); | 2952 registerMockedHttpURLLoad("get_scale_for_zoom_into_editable_test.html"); |
2947 | 2953 |
2948 const int viewportWidth = 450; | 2954 const int viewportWidth = 450; |
2949 const int viewportHeight = 300; | 2955 const int viewportHeight = 300; |
2950 const float minReadableCaretHeight = 18.0f; | 2956 const float minReadableCaretHeight = 16.0f; |
2951 FrameTestHelpers::WebViewHelper webViewHelper; | 2957 FrameTestHelpers::WebViewHelper webViewHelper; |
2952 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl
e_test.html"); | 2958 webViewHelper.initializeAndLoad(m_baseURL + "get_scale_for_zoom_into_editabl
e_test.html"); |
| 2959 webViewHelper.webViewImpl()->page()->settings().setTextAutosizingEnabled(fal
se); |
2953 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); | 2960 webViewHelper.webView()->resize(WebSize(viewportWidth, viewportHeight)); |
2954 webViewHelper.webView()->setPageScaleFactorLimits(1, 4); | 2961 webViewHelper.webView()->setPageScaleFactorLimits(1.f, 4); |
| 2962 webViewHelper.webView()->setDeviceScaleFactor(1.5f); |
2955 webViewHelper.webView()->layout(); | 2963 webViewHelper.webView()->layout(); |
2956 webViewHelper.webView()->setDeviceScaleFactor(1.5f); | |
2957 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr
ue); | 2964 webViewHelper.webView()->settings()->setAutoZoomFocusedNodeToLegibleScale(tr
ue); |
2958 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); | 2965 webViewHelper.webViewImpl()->enableFakePageScaleAnimationForTesting(true); |
2959 | 2966 |
2960 const WebRect editBoxWithText(200, 200, 250, 20); | 2967 const WebRect editBoxWithText(200, 200, 250, 20); |
2961 | 2968 |
2962 webViewHelper.webView()->advanceFocus(false); | 2969 webViewHelper.webView()->advanceFocus(false); |
2963 // Set the caret to the begining of the input box. | 2970 // Set the caret to the begining of the input box. |
2964 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith
Text").to<WebInputElement>().setSelectionRange(0, 0); | 2971 webViewHelper.webView()->mainFrame()->document().getElementById("EditBoxWith
Text").to<WebInputElement>().setSelectionRange(0, 0); |
2965 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); | 2972 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), 1); |
2966 WebRect rect, caret; | 2973 WebRect rect, caret; |
2967 webViewHelper.webViewImpl()->selectionBounds(caret, rect); | 2974 webViewHelper.webViewImpl()->selectionBounds(caret, rect); |
2968 | 2975 |
2969 // Set page scale twice larger then minimal readable scale | 2976 // Set the page scale to be twice as large as the minimal readable scale. |
2970 float newScale = minReadableCaretHeight / caret.height * 2.0; | 2977 float newScale = minReadableCaretHeight / caret.height * 2.0; |
2971 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), newScale
); | 2978 setScaleAndScrollAndLayout(webViewHelper.webView(), WebPoint(0, 0), newScale
); |
2972 | 2979 |
2973 float scale; | 2980 float scale; |
2974 IntPoint scroll; | 2981 IntPoint scroll; |
2975 bool needAnimation; | 2982 bool needAnimation; |
2976 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); | 2983 webViewHelper.webViewImpl()->computeScaleAndScrollForFocusedNode(webViewHelp
er.webViewImpl()->focusedElement(), scale, scroll, needAnimation); |
2977 EXPECT_TRUE(needAnimation); | 2984 EXPECT_TRUE(needAnimation); |
2978 // Edit box and caret should be left alinged | 2985 // Edit box and caret should be left alinged |
2979 int hScroll = editBoxWithText.x; | 2986 int hScroll = editBoxWithText.x; |
(...skipping 3936 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
6916 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); | 6923 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); |
6917 | 6924 |
6918 // Neither should a page reload. | 6925 // Neither should a page reload. |
6919 localFrame->reload(); | 6926 localFrame->reload(); |
6920 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); | 6927 EXPECT_EQ(4u, frameClient.provisionalLoadCount()); |
6921 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); | 6928 EXPECT_FALSE(frameClient.wasLastProvisionalLoadATransition()); |
6922 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); | 6929 EXPECT_EQ(1u, frameClient.navigationalDataReceivedCount()); |
6923 } | 6930 } |
6924 | 6931 |
6925 } // namespace | 6932 } // namespace |
OLD | NEW |