Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011, 2012 Google Inc. All rights reserved. | 2 * Copyright (C) 2011, 2012 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 3011 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 3022 ASSERT_EQ(4ul, renders.size()); | 3022 ASSERT_EQ(4ul, renders.size()); |
| 3023 for (size_t i = 0; i < renders.size(); ++i) { | 3023 for (size_t i = 0; i < renders.size(); ++i) { |
| 3024 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; | 3024 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; |
| 3025 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); | 3025 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); |
| 3026 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; | 3026 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; |
| 3027 double docDuration = docFinishTime - docStartTime; | 3027 double docDuration = docFinishTime - docStartTime; |
| 3028 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); | 3028 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); |
| 3029 } | 3029 } |
| 3030 } | 3030 } |
| 3031 | 3031 |
| 3032 TEST_F(WebViewTest, MoveFocusToNextFocusableElementInForm) | |
| 3033 { | |
|
kochi
2015/08/05 10:15:13
This test has become very long...
Could you consid
AKV
2015/08/05 13:42:50
Done.
| |
| 3034 const std::string testFile = "advance_focus_in_form.html"; | |
| 3035 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8(testFile.c_str())); | |
| 3036 WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFil e, true, 0); | |
| 3037 webViewImpl->setInitialFocus(false); | |
| 3038 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame()); | |
| 3039 HTMLDocument* document = toHTMLDocument(frame->frame()->document()); | |
| 3040 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences; | |
| 3041 | |
| 3042 // Forward Navigation in form1 with NEXT | |
| 3043 Element* input1 = document->getElementById("input1"); | |
| 3044 input1->focus(); | |
| 3045 WebTextInputInfo textInputInfo = webViewImpl->textInputInfo(); | |
| 3046 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags); | |
| 3047 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3048 | |
| 3049 Element* button1 = document->getElementById("button1"); | |
| 3050 EXPECT_NE(button1, document->focusedElement()); | |
| 3051 | |
| 3052 Element* contenteditable1 = document->getElementById("contenteditable1"); | |
| 3053 EXPECT_EQ(contenteditable1, document->focusedElement()); | |
| 3054 textInputInfo = webViewImpl->textInputInfo(); | |
| 3055 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags); | |
| 3056 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3057 | |
| 3058 Element* input2 = document->getElementById("input2"); | |
| 3059 EXPECT_EQ(input2, document->focusedElement()); | |
| 3060 textInputInfo = webViewImpl->textInputInfo(); | |
| 3061 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement | WebTextInputFlagListeningToKeybo ardEvents, textInputInfo.flags); | |
| 3062 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3063 | |
| 3064 Element* anchor1 = document->getElementById("anchor1"); | |
| 3065 EXPECT_NE(anchor1, document->focusedElement()); | |
| 3066 | |
| 3067 Element* textarea1 = document->getElementById("textarea1"); | |
| 3068 EXPECT_EQ(textarea1, document->focusedElement()); | |
| 3069 textInputInfo = webViewImpl->textInputInfo(); | |
| 3070 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3071 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3072 | |
| 3073 Element* input3 = document->getElementById("input3"); | |
| 3074 EXPECT_EQ(input3, document->focusedElement()); | |
| 3075 textInputInfo = webViewImpl->textInputInfo(); | |
| 3076 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3077 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3078 | |
| 3079 Element* textarea2 = document->getElementById("textarea2"); | |
| 3080 EXPECT_EQ(textarea2, document->focusedElement()); | |
| 3081 textInputInfo = webViewImpl->textInputInfo(); | |
| 3082 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableEleme nt, textInputInfo.flags); | |
| 3083 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3084 // No next element, hence focus will stay on same element. | |
| 3085 EXPECT_EQ(textarea2, document->focusedElement()); | |
| 3086 | |
| 3087 // Backward Navigation in form1 with PREVIOUS | |
| 3088 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3089 EXPECT_EQ(input3, document->focusedElement()); | |
| 3090 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3091 EXPECT_EQ(textarea1, document->focusedElement()); | |
| 3092 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3093 EXPECT_EQ(input2, document->focusedElement()); | |
| 3094 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3095 EXPECT_EQ(contenteditable1, document->focusedElement()); | |
| 3096 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3097 EXPECT_EQ(input1, document->focusedElement()); | |
| 3098 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3099 // No previous element, hence focus will stay on same element. | |
| 3100 EXPECT_EQ(input1, document->focusedElement()); | |
| 3101 | |
| 3102 // Setting a non editable element as focus in form1, and ensuring editable n avigation is fine in forward and backward. | |
| 3103 button1->focus(); | |
| 3104 textInputInfo = webViewImpl->textInputInfo(); | |
| 3105 // No Next/Previous element for elements outside form. | |
| 3106 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3107 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3108 EXPECT_EQ(contenteditable1, document->focusedElement()); | |
| 3109 button1->focus(); | |
| 3110 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3111 EXPECT_EQ(input1, document->focusedElement()); | |
| 3112 | |
| 3113 anchor1->focus(); | |
| 3114 textInputInfo = webViewImpl->textInputInfo(); | |
| 3115 // No Next/Previous element for elements outside form. | |
| 3116 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3117 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3118 // Since anchor is not a form control element, next/previous element will be null, hence focus will stay same as it is. | |
| 3119 EXPECT_EQ(anchor1, document->focusedElement()); | |
| 3120 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3121 EXPECT_EQ(anchor1, document->focusedElement()); | |
| 3122 | |
| 3123 // Navigation of elements which is not part of any forms. | |
| 3124 Element* textarea3 = document->getElementById("textarea3"); | |
| 3125 textarea3->focus(); | |
| 3126 textInputInfo = webViewImpl->textInputInfo(); | |
| 3127 // No Next/Previous element for elements outside form. | |
| 3128 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3129 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3130 // No Next/Previous element to this element because it's not part of any for m. Hence focus won't change wrt NEXT/PREVIOUS. | |
| 3131 EXPECT_EQ(textarea3, document->focusedElement()); | |
| 3132 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3133 EXPECT_EQ(textarea3, document->focusedElement()); | |
| 3134 | |
| 3135 // Navigation from an element which is part of a form but not an editable el ement. | |
| 3136 Element* button2 = document->getElementById("button2"); | |
| 3137 button2->focus(); | |
| 3138 textInputInfo = webViewImpl->textInputInfo(); | |
| 3139 // No Next element for this element, due to last element outside the form. | |
| 3140 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3141 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3142 // No Next element to this element because it's not part of any form. Hence focus won't change wrt NEXT. | |
| 3143 EXPECT_EQ(button2, document->focusedElement()); | |
| 3144 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3145 // Since button is a form control element from form1, ensuring focus is set at correct position. | |
| 3146 EXPECT_EQ(textarea2, document->focusedElement()); | |
| 3147 | |
| 3148 Element* contenteditable2 = document->getElementById("contenteditable2"); | |
| 3149 document->setFocusedElement(contenteditable2); | |
| 3150 textInputInfo = webViewImpl->textInputInfo(); | |
| 3151 // No Next/Previous element for elements outside form. | |
| 3152 EXPECT_NE(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags); | |
| 3153 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3154 // No Next/Previous element to this element because it's not part of any for m. Hence focus won't change wrt NEXT/PREVIOUS. | |
| 3155 EXPECT_EQ(contenteditable2, document->focusedElement()); | |
| 3156 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3157 EXPECT_EQ(contenteditable2, document->focusedElement()); | |
| 3158 | |
| 3159 // Navigation of elements which is having invalid form attribute and hence n ot part of any forms. | |
| 3160 Element* textarea4 = document->getElementById("textarea4"); | |
| 3161 textarea4->focus(); | |
| 3162 textInputInfo = webViewImpl->textInputInfo(); | |
| 3163 // No Next/Previous element for elements which is having invalid form attrib ute. | |
| 3164 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3165 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3166 // No Next/Previous element to this element because it's not part of any for m. Hence focus won't change wrt NEXT/PREVIOUS. | |
| 3167 EXPECT_EQ(textarea4, document->focusedElement()); | |
| 3168 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3169 EXPECT_EQ(textarea4, document->focusedElement()); | |
| 3170 | |
| 3171 // Forward Navigation in form2 with NEXT | |
| 3172 Element* textarea5 = document->getElementById("textarea5"); | |
| 3173 textarea5->focus(); | |
| 3174 textInputInfo = webViewImpl->textInputInfo(); | |
| 3175 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags); | |
| 3176 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3177 | |
| 3178 Element* input4 = document->getElementById("input4"); | |
| 3179 EXPECT_EQ(input4, document->focusedElement()); | |
| 3180 textInputInfo = webViewImpl->textInputInfo(); | |
| 3181 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusab leElement, textInputInfo.flags); | |
| 3182 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3183 | |
| 3184 Element* contenteditable3 = document->getElementById("contenteditable3"); | |
| 3185 EXPECT_EQ(contenteditable3, document->focusedElement()); | |
| 3186 textInputInfo = webViewImpl->textInputInfo(); | |
| 3187 EXPECT_EQ(WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHavePr eviousFocusableElement, textInputInfo.flags); | |
| 3188 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3189 | |
| 3190 // Anchor is not an editable navigation element, hence skipping in traversal . | |
| 3191 Element* anchor2 = document->getElementById("anchor2"); | |
| 3192 EXPECT_NE(anchor2, document->focusedElement()); | |
| 3193 // No next element, hence focus will stay on same element. | |
| 3194 EXPECT_EQ(contenteditable3, document->focusedElement()); | |
| 3195 | |
| 3196 // Backward Navigation in form2 with PREVIOUS | |
| 3197 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3198 EXPECT_EQ(input4, document->focusedElement()); | |
| 3199 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3200 EXPECT_EQ(textarea5, document->focusedElement()); | |
| 3201 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3202 // No previous element, hence focus will stay on same element. | |
| 3203 EXPECT_EQ(textarea5, document->focusedElement()); | |
| 3204 | |
| 3205 // Setting a non editable element as focus in form1, and ensuring editable n avigation is fine in forward and backward. | |
| 3206 anchor2->focus(); | |
| 3207 textInputInfo = webViewImpl->textInputInfo(); | |
| 3208 // No Next/Previous element for elements outside form. | |
| 3209 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3210 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3211 // No editable element after this inside the form, hence focus won't change. | |
| 3212 EXPECT_EQ(anchor2, document->focusedElement()); | |
| 3213 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3214 // Since anchor is not a form control element, next/previous element will be null, hence focus will stay same as it is. | |
| 3215 EXPECT_EQ(anchor2, document->focusedElement()); | |
| 3216 | |
| 3217 // Forward Navigation in form3 with NEXT which has tabindex attribute which differs visual order. | |
| 3218 Element* textarea6 = document->getElementById("textarea6"); | |
| 3219 textarea6->focus(); | |
| 3220 textInputInfo = webViewImpl->textInputInfo(); | |
| 3221 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags); | |
| 3222 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3223 | |
| 3224 Element* input5 = document->getElementById("input5"); | |
| 3225 EXPECT_EQ(input5, document->focusedElement()); | |
| 3226 textInputInfo = webViewImpl->textInputInfo(); | |
| 3227 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags); | |
| 3228 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3229 | |
| 3230 Element* contenteditable4 = document->getElementById("contenteditable4"); | |
| 3231 EXPECT_EQ(contenteditable4, document->focusedElement()); | |
| 3232 textInputInfo = webViewImpl->textInputInfo(); | |
| 3233 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags); | |
| 3234 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3235 | |
| 3236 Element* input6 = document->getElementById("input6"); | |
| 3237 EXPECT_EQ(input6, document->focusedElement()); | |
| 3238 textInputInfo = webViewImpl->textInputInfo(); | |
| 3239 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableEleme nt, textInputInfo.flags); | |
| 3240 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3241 | |
| 3242 Element* contenteditable5 = document->getElementById("contenteditable5"); | |
| 3243 EXPECT_NE(contenteditable5, document->focusedElement()); | |
| 3244 // No next editable element which is focusable with proper tab index, hence staying on previous focus. | |
| 3245 EXPECT_EQ(input6, document->focusedElement()); | |
| 3246 | |
| 3247 // Backward Navigation in form3 with PREVIOUS which has tabindex attribute w hich differs visual order. | |
| 3248 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3249 EXPECT_EQ(contenteditable4, document->focusedElement()); | |
| 3250 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3251 EXPECT_EQ(input5, document->focusedElement()); | |
| 3252 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3253 EXPECT_EQ(textarea6, document->focusedElement()); | |
| 3254 | |
| 3255 // Setting an element which has invalid tabindex and ensuring it is not modi fying further navigation. | |
| 3256 contenteditable5->focus(); | |
| 3257 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3258 EXPECT_EQ(input6, document->focusedElement()); | |
| 3259 contenteditable5->focus(); | |
| 3260 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3261 EXPECT_EQ(textarea6, document->focusedElement()); | |
| 3262 | |
| 3263 // Forward Navigation in form4 with NEXT which has has disabled/enabled elem ents which will gets skipped during navigation. | |
| 3264 Element* contenteditable6 = document->getElementById("contenteditable6"); | |
| 3265 contenteditable6->focus(); | |
| 3266 textInputInfo = webViewImpl->textInputInfo(); | |
| 3267 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags); | |
| 3268 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3269 | |
| 3270 Element* input7 = document->getElementById("input7"); | |
| 3271 EXPECT_NE(input7, document->focusedElement()); | |
| 3272 Element* contenteditable7 = document->getElementById("contenteditable7"); | |
| 3273 EXPECT_EQ(contenteditable7, document->focusedElement()); | |
| 3274 textInputInfo = webViewImpl->textInputInfo(); | |
| 3275 EXPECT_EQ(WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags) ; | |
| 3276 webViewImpl->advanceFocusInForm(WebFocusTypeForward); | |
| 3277 // No more elements present further in the form in forward direction, so foc us won't change. | |
| 3278 EXPECT_EQ(contenteditable7, document->focusedElement()); | |
| 3279 | |
| 3280 // Backward Navigation in form4 with PREVIOUS which has has disabled/enabled elements which will gets skipped during navigation. | |
| 3281 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3282 Element* textarea7 = document->getElementById("textarea7"); | |
| 3283 EXPECT_NE(textarea7, document->focusedElement()); | |
| 3284 EXPECT_EQ(contenteditable6, document->focusedElement()); | |
| 3285 webViewImpl->advanceFocusInForm(WebFocusTypeBackward); | |
| 3286 // No more elements present further in the form in backward direction, so fo cus won't change. | |
| 3287 EXPECT_EQ(contenteditable6, document->focusedElement()); | |
| 3288 | |
| 3289 m_webViewHelper.reset(); | |
| 3290 } | |
| 3291 | |
| 3032 } // namespace blink | 3292 } // namespace blink |
| OLD | NEW |