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

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

Issue 103863007: Let WebViewImpl::textInputInfo() query the focused element when selection is empty (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: added unit test Created 7 years 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
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/input_field_focused.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 int expectedWidth, int expectedHeight, 227 int expectedWidth, int expectedHeight,
228 HorizontalScrollbarState expectedHorizontalState, Vertic alScrollbarState expectedVerticalState); 228 HorizontalScrollbarState expectedHorizontalState, Vertic alScrollbarState expectedVerticalState);
229 229
230 void testTextInputType(WebTextInputType expectedType, const std::string& htm lFile); 230 void testTextInputType(WebTextInputType expectedType, const std::string& htm lFile);
231 void testInputMode(const WebString& expectedInputMode, const std::string& ht mlFile); 231 void testInputMode(const WebString& expectedInputMode, const std::string& ht mlFile);
232 232
233 std::string m_baseURL; 233 std::string m_baseURL;
234 FrameTestHelpers::WebViewHelper m_webViewHelper; 234 FrameTestHelpers::WebViewHelper m_webViewHelper;
235 }; 235 };
236 236
237 class FocusedNodeChangedObserverWebViewClient : public WebViewClient {
238 public:
239 void setWebView(WebView* webView) { m_webView = webView; }
240 WebTextInputInfo textInputInfoOnFocusedNodeChanged() const { return m_textIn putInfoOnFocusedNodeChanged; }
241 private:
242 void focusedNodeChanged(const WebNode&) OVERRIDE { m_textInputInfoOnFocusedN odeChanged = m_webView->textInputInfo(); }
243
244 WebView* m_webView;
245 WebTextInputInfo m_textInputInfoOnFocusedNodeChanged;
246 };
247
237 TEST_F(WebViewTest, SetBaseBackgroundColor) 248 TEST_F(WebViewTest, SetBaseBackgroundColor)
238 { 249 {
239 const WebColor kWhite = 0xFFFFFFFF; 250 const WebColor kWhite = 0xFFFFFFFF;
240 const WebColor kBlue = 0xFF0000FF; 251 const WebColor kBlue = 0xFF0000FF;
241 const WebColor kDarkCyan = 0xFF227788; 252 const WebColor kDarkCyan = 0xFF227788;
242 const WebColor kTranslucentPutty = 0x80BFB196; 253 const WebColor kTranslucentPutty = 0x80BFB196;
243 254
244 WebView* webView = m_webViewHelper.initialize(); 255 WebView* webView = m_webViewHelper.initialize();
245 EXPECT_EQ(kWhite, webView->backgroundColor()); 256 EXPECT_EQ(kWhite, webView->backgroundColor());
246 257
(...skipping 300 matching lines...) Expand 10 before | Expand all | Expand 10 after
547 EXPECT_EQ(8, info.compositionEnd); 558 EXPECT_EQ(8, info.compositionEnd);
548 559
549 webView->confirmComposition(WebWidget::DoNotKeepSelection); 560 webView->confirmComposition(WebWidget::DoNotKeepSelection);
550 info = webView->textInputInfo(); 561 info = webView->textInputInfo();
551 EXPECT_EQ(8, info.selectionStart); 562 EXPECT_EQ(8, info.selectionStart);
552 EXPECT_EQ(8, info.selectionEnd); 563 EXPECT_EQ(8, info.selectionEnd);
553 EXPECT_EQ(-1, info.compositionStart); 564 EXPECT_EQ(-1, info.compositionStart);
554 EXPECT_EQ(-1, info.compositionEnd); 565 EXPECT_EQ(-1, info.compositionEnd);
555 } 566 }
556 567
568 TEST_F(WebViewTest, TextInputInfoOnInputFocused)
569 {
570 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("input_field_focused.html"));
571 FocusedNodeChangedObserverWebViewClient client;
572 WebView* webView = m_webViewHelper.initialize(true, 0, &client);
573 client.setWebView(webView);
574
575 WebCore::KURL url = toKURL(m_baseURL + "input_field_focused.html");
576 webView->mainFrame()->loadRequest(WebURLRequest(WebURL(url)));
577 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests();
578
579 WebTextInputInfo info = client.textInputInfoOnFocusedNodeChanged();
580 EXPECT_EQ(WebTextInputTypeText, info.type);
581 }
582
557 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition) 583 TEST_F(WebViewTest, InsertNewLinePlacementAfterConfirmComposition)
558 { 584 {
559 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html")); 585 URLTestHelpers::registerMockedURLFromBaseURL(WebString::fromUTF8(m_baseURL.c _str()), WebString::fromUTF8("text_area_populated.html"));
560 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_ populated.html"); 586 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "text_area_ populated.html");
561 webView->setInitialFocus(false); 587 webView->setInitialFocus(false);
562 588
563 WebVector<WebCompositionUnderline> emptyUnderlines; 589 WebVector<WebCompositionUnderline> emptyUnderlines;
564 590
565 webView->setEditableSelectionOffsets(4, 4); 591 webView->setEditableSelectionOffsets(4, 4);
566 webView->setCompositionFromExistingText(8, 12, emptyUnderlines); 592 webView->setCompositionFromExistingText(8, 12, emptyUnderlines);
(...skipping 776 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 EXPECT_STREQ("1970-W01", inputElement->value().utf8().data()); 1369 EXPECT_STREQ("1970-W01", inputElement->value().utf8().data());
1344 1370
1345 openDateTimeChooser(webViewImpl, inputElement); 1371 openDateTimeChooser(webViewImpl, inputElement);
1346 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie t_NaN()); 1372 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie t_NaN());
1347 client.clearChooserCompletion(); 1373 client.clearChooserCompletion();
1348 EXPECT_STREQ("", inputElement->value().utf8().data()); 1374 EXPECT_STREQ("", inputElement->value().utf8().data());
1349 } 1375 }
1350 #endif 1376 #endif
1351 1377
1352 } 1378 }
OLDNEW
« no previous file with comments | « Source/web/WebViewImpl.cpp ('k') | Source/web/tests/data/input_field_focused.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698