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

Side by Side Diff: Source/web/tests/WebViewTest.cpp

Issue 939603002: Adding support for Smart GO NEXT feature in Android Chrome (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Fixed build breaks in disabled element form. Created 5 years, 4 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
OLDNEW
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
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, MoveFocusToNextFocusableElementInFormWithKeyEventListenersAn dNonEditableElements)
3033 {
3034 const std::string testFile = "advance_focus_in_form_with_key_event_listeners .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);
kochi 2015/08/06 02:21:00 Could you specify the exact expected result of |te
AKV 2015/08/06 08:39:33 Done.
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);
kochi 2015/08/06 02:20:59 Ditto.
AKV 2015/08/06 08:39:32 Done.
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);
kochi 2015/08/06 02:21:00 Ditto.
AKV 2015/08/06 08:39:33 Done.
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);
kochi 2015/08/06 02:21:00 Ditto.
AKV 2015/08/06 08:39:32 Done.
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);
kochi 2015/08/06 02:21:00 Ditto.
AKV 2015/08/06 08:39:32 Done.
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);
kochi 2015/08/06 02:21:00 Ditto.
AKV 2015/08/06 08:39:33 Done.
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 m_webViewHelper.reset();
3172 }
3173
3174 TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithNonEditableNonFormC ontrolElements)
3175 {
3176 const std::string testFile = "advance_focus_in_form_with_key_event_listeners .html";
3177 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8(testFile.c_str()));
3178 WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFil e, true, 0);
3179 webViewImpl->setInitialFocus(false);
3180 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
3181 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
3182 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
3183
3184 // Forward Navigation in form2 with NEXT
3185 Element* textarea5 = document->getElementById("textarea5");
3186 textarea5->focus();
3187 WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
3188 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
3189 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3190
3191 Element* input4 = document->getElementById("input4");
3192 EXPECT_EQ(input4, document->focusedElement());
3193 textInputInfo = webViewImpl->textInputInfo();
3194 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusab leElement, textInputInfo.flags);
3195 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3196
3197 Element* contenteditable3 = document->getElementById("contenteditable3");
3198 EXPECT_EQ(contenteditable3, document->focusedElement());
3199 textInputInfo = webViewImpl->textInputInfo();
3200 EXPECT_EQ(WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHavePr eviousFocusableElement, textInputInfo.flags);
3201 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3202
3203 // Anchor is not an editable navigation element, hence skipping in traversal .
3204 Element* anchor2 = document->getElementById("anchor2");
3205 EXPECT_NE(anchor2, document->focusedElement());
3206 // No next element, hence focus will stay on same element.
3207 EXPECT_EQ(contenteditable3, document->focusedElement());
3208
3209 // Backward Navigation in form2 with PREVIOUS
3210 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3211 EXPECT_EQ(input4, document->focusedElement());
3212 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3213 EXPECT_EQ(textarea5, document->focusedElement());
3214 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3215 // No previous element, hence focus will stay on same element.
3216 EXPECT_EQ(textarea5, document->focusedElement());
3217
3218 // Setting a non editable element as focus in form1, and ensuring editable n avigation is fine in forward and backward.
3219 anchor2->focus();
3220 textInputInfo = webViewImpl->textInputInfo();
3221 // No Next/Previous element for elements outside form.
3222 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
kochi 2015/08/06 02:21:00 Ditto.
AKV 2015/08/06 08:39:32 Done.
3223 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3224 // No editable element after this inside the form, hence focus won't change.
3225 EXPECT_EQ(anchor2, document->focusedElement());
3226 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3227 // Since anchor is not a form control element, next/previous element will be null, hence focus will stay same as it is.
3228 EXPECT_EQ(anchor2, document->focusedElement());
3229
3230 m_webViewHelper.reset();
3231 }
3232
3233 TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithTabIndexElements)
3234 {
3235 const std::string testFile = "advance_focus_in_form_with_tabindex_elements.h tml";
3236 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8(testFile.c_str()));
3237 WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFil e, true, 0);
3238 webViewImpl->setInitialFocus(false);
3239 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
3240 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
3241 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
3242
3243 // Forward Navigation in form3 with NEXT which has tabindex attribute which differs visual order.
3244 Element* textarea6 = document->getElementById("textarea6");
3245 textarea6->focus();
3246 WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
3247 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
3248 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3249
3250 Element* input5 = document->getElementById("input5");
3251 EXPECT_EQ(input5, document->focusedElement());
3252 textInputInfo = webViewImpl->textInputInfo();
3253 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
3254 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3255
3256 Element* contenteditable4 = document->getElementById("contenteditable4");
3257 EXPECT_EQ(contenteditable4, document->focusedElement());
3258 textInputInfo = webViewImpl->textInputInfo();
3259 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags);
3260 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3261
3262 Element* input6 = document->getElementById("input6");
3263 EXPECT_EQ(input6, document->focusedElement());
3264 textInputInfo = webViewImpl->textInputInfo();
3265 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableEleme nt, textInputInfo.flags);
3266 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3267
3268 Element* contenteditable5 = document->getElementById("contenteditable5");
3269 EXPECT_NE(contenteditable5, document->focusedElement());
3270 // No next editable element which is focusable with proper tab index, hence staying on previous focus.
3271 EXPECT_EQ(input6, document->focusedElement());
3272
3273 // Backward Navigation in form3 with PREVIOUS which has tabindex attribute w hich differs visual order.
3274 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3275 EXPECT_EQ(contenteditable4, document->focusedElement());
3276 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3277 EXPECT_EQ(input5, document->focusedElement());
3278 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3279 EXPECT_EQ(textarea6, document->focusedElement());
3280
3281 // Setting an element which has invalid tabindex and ensuring it is not modi fying further navigation.
3282 contenteditable5->focus();
3283 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3284 EXPECT_EQ(input6, document->focusedElement());
3285 contenteditable5->focus();
3286 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3287 EXPECT_EQ(textarea6, document->focusedElement());
3288
3289 m_webViewHelper.reset();
3290 }
3291
3292 TEST_F(WebViewTest, MoveFocusToNextFocusableElementInFormWithDisabledAndReadonly Elements)
3293 {
3294 const std::string testFile = "advance_focus_in_form_with_disabled_and_readon ly_elements.html";
3295 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8(testFile.c_str()));
3296 WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFil e, true, 0);
3297 webViewImpl->setInitialFocus(false);
3298 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
3299 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
3300
3301 // Forward Navigation in form4 with NEXT which has has disabled/enabled elem ents which will gets skipped during navigation.
3302 Element* contenteditable6 = document->getElementById("contenteditable6");
3303 contenteditable6->focus();
3304 WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
3305 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
3306 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3307
3308 Element* input7 = document->getElementById("input7");
3309 EXPECT_NE(input7, document->focusedElement());
3310 Element* contenteditable7 = document->getElementById("contenteditable7");
3311 EXPECT_EQ(contenteditable7, document->focusedElement());
3312 textInputInfo = webViewImpl->textInputInfo();
3313 EXPECT_EQ(WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags) ;
3314 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3315 // No more elements present further in the form in forward direction, so foc us won't change.
3316 EXPECT_EQ(contenteditable7, document->focusedElement());
3317
3318 // Backward Navigation in form4 with PREVIOUS which has has disabled/enabled elements which will gets skipped during navigation.
3319 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3320 Element* textarea7 = document->getElementById("textarea7");
3321 EXPECT_NE(textarea7, document->focusedElement());
3322 EXPECT_EQ(contenteditable6, document->focusedElement());
3323 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3324 // No more elements present further in the form in backward direction, so fo cus won't change.
3325 EXPECT_EQ(contenteditable6, document->focusedElement());
3326
3327 m_webViewHelper.reset();
3328 }
3329
3032 } // namespace blink 3330 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698