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

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 review comments in unit tests. Created 5 years, 5 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 3031 matching lines...) Expand 10 before | Expand all | Expand 10 after
3042 ASSERT_EQ(4ul, renders.size()); 3042 ASSERT_EQ(4ul, renders.size());
3043 for (size_t i = 0; i < renders.size(); ++i) { 3043 for (size_t i = 0; i < renders.size(); ++i) {
3044 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0; 3044 double docStartTime = frame->domWindow()->document()->loader()->timing() .monotonicTimeToZeroBasedDocumentTime(renderPairs[i].startTime) * 1000.0;
3045 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime()); 3045 ASSERT_DOUBLE_EQ(docStartTime, renders[i]->startTime());
3046 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0; 3046 double docFinishTime = frame->domWindow()->document()->loader()->timing( ).monotonicTimeToZeroBasedDocumentTime(renderPairs[i].finishTime) * 1000.0;
3047 double docDuration = docFinishTime - docStartTime; 3047 double docDuration = docFinishTime - docStartTime;
3048 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration()); 3048 ASSERT_DOUBLE_EQ(docDuration, renders[i]->duration());
3049 } 3049 }
3050 } 3050 }
3051 3051
3052 TEST_F(WebViewTest, MoveFocusToNextFocusableElementInForm)
3053 {
3054 const std::string testFile = "advance_focus_in_form.html";
3055 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8(testFile.c_str()));
3056 WebView* webViewImpl = m_webViewHelper.initializeAndLoad(m_baseURL + testFil e, true, 0);
3057 webViewImpl->setInitialFocus(false);
3058 WebLocalFrameImpl* frame = toWebLocalFrameImpl(webViewImpl->mainFrame());
3059 HTMLDocument* document = toHTMLDocument(frame->frame()->document());
3060 const int defaultTextInputFlags = WebTextInputFlagAutocapitalizeSentences;
3061
3062 // Forward Navigation in form1 with NEXT
3063 Element* input1 = document->getElementById("input1");
3064 document->setFocusedElement(input1);
kochi 2015/07/03 04:10:34 You can also do this by "input1->focus();". Eleme
AKV 2015/07/26 15:56:34 Thanks Done.
3065 WebTextInputInfo textInputInfo = webViewImpl->textInputInfo();
3066 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
3067 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3068
3069 Element* contenteditable1 = document->getElementById("contenteditable1");
3070 EXPECT_EQ(contenteditable1, document->focusedElement());
3071 textInputInfo = webViewImpl->textInputInfo();
3072 EXPECT_EQ(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags);
3073 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3074
3075 Element* input2 = document->getElementById("input2");
3076 EXPECT_EQ(input2, document->focusedElement());
3077 textInputInfo = webViewImpl->textInputInfo();
3078 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement | WebTextInputFlagListeningToKeybo ardEvents, textInputInfo.flags);
3079 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3080
3081 Element* textarea1 = document->getElementById("textarea1");
3082 EXPECT_EQ(textarea1, document->focusedElement());
3083 textInputInfo = webViewImpl->textInputInfo();
3084 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
3085 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3086
3087 Element* input3 = document->getElementById("input3");
3088 EXPECT_EQ(input3, document->focusedElement());
3089 textInputInfo = webViewImpl->textInputInfo();
3090 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
3091 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3092
3093 Element* textarea2 = document->getElementById("textarea2");
3094 EXPECT_EQ(textarea2, document->focusedElement());
3095 textInputInfo = webViewImpl->textInputInfo();
3096 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagHavePreviousFocusableEleme nt, textInputInfo.flags);
3097 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3098 // No next element, hence focus will stay on same element.
3099 EXPECT_EQ(textarea2, document->focusedElement());
3100
3101 // Backward Navigation in form1 with PREVIOUS
3102 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3103 EXPECT_EQ(input3, document->focusedElement());
3104 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3105 EXPECT_EQ(textarea1, document->focusedElement());
3106 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3107 EXPECT_EQ(input2, document->focusedElement());
3108 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3109 EXPECT_EQ(contenteditable1, document->focusedElement());
3110 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3111 EXPECT_EQ(input1, document->focusedElement());
3112 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3113 // No previous element, hence focus will stay on same element.
3114 EXPECT_EQ(input1, document->focusedElement());
3115
3116 // Navigation of elements which is not part of any forms.
3117 Element* contenteditable2 = document->getElementById("contenteditable2");
3118 document->setFocusedElement(contenteditable2);
3119 textInputInfo = webViewImpl->textInputInfo();
3120 // No Next/Previous element for elements outside form.
3121 EXPECT_NE(WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePre viousFocusableElement, textInputInfo.flags);
3122 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3123 EXPECT_EQ(contenteditable2, document->focusedElement());
3124 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
kochi 2015/07/03 04:10:34 Could you add a comment here why you expect the fo
AKV 2015/07/26 15:56:34 Done.
3125 EXPECT_EQ(contenteditable2, document->focusedElement());
3126
3127 Element* textarea3 = document->getElementById("textarea3");
3128 document->setFocusedElement(textarea3);
3129 textInputInfo = webViewImpl->textInputInfo();
3130 // No Next/Previous element for elements outside form.
3131 EXPECT_NE(defaultTextInputFlags | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusableElement, textInputInfo.flags);
3132 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3133 EXPECT_EQ(textarea3, document->focusedElement());
3134 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3135 EXPECT_EQ(textarea3, document->focusedElement());
3136
3137 // Forward Navigation in form2 with NEXT
3138 Element* textarea4 = document->getElementById("textarea4");
3139 document->setFocusedElement(textarea4);
3140 textInputInfo = webViewImpl->textInputInfo();
3141 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement, textInputInfo.flags);
3142 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3143
3144 Element* input4 = document->getElementById("input4");
3145 EXPECT_EQ(input4, document->focusedElement());
3146 textInputInfo = webViewImpl->textInputInfo();
3147 EXPECT_EQ(defaultTextInputFlags | WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHaveNextFocusableElement | WebTextInputFlagHavePreviousFocusab leElement, textInputInfo.flags);
3148 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3149
3150 Element* contenteditable3 = document->getElementById("contenteditable3");
3151 EXPECT_EQ(contenteditable3, document->focusedElement());
3152 textInputInfo = webViewImpl->textInputInfo();
3153 EXPECT_EQ(WebTextInputFlagListeningToKeyboardEvents | WebTextInputFlagHavePr eviousFocusableElement, textInputInfo.flags);
3154 webViewImpl->advanceFocusInForm(WebFocusTypeForward);
3155 // No next element, hence focus will stay on same element.
3156 EXPECT_EQ(contenteditable3, document->focusedElement());
3157
3158 // Backward Navigation in form2 with PREVIOUS
3159 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3160 EXPECT_EQ(input4, document->focusedElement());
3161 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3162 EXPECT_EQ(textarea4, document->focusedElement());
3163 webViewImpl->advanceFocusInForm(WebFocusTypeBackward);
3164 // No previous element, hence focus will stay on same element.
3165 EXPECT_EQ(textarea4, document->focusedElement());
3166
3167 m_webViewHelper.reset();
3168 }
3169
3052 } // namespace blink 3170 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698