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

Unified Diff: Source/web/tests/WebViewTest.cpp

Issue 62083004: Transfer date/time value to the chooser as a double (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@datetime3
Patch Set: Added test Created 7 years, 1 month 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 side-by-side diff with in-line comments
Download patch
Index: Source/web/tests/WebViewTest.cpp
diff --git a/Source/web/tests/WebViewTest.cpp b/Source/web/tests/WebViewTest.cpp
index 90408150d37e27ed7d3a9e6ec42d253cd2c734c9..0369e65c77ac202b094ad3c175bdafb6ee278466 100644
--- a/Source/web/tests/WebViewTest.cpp
+++ b/Source/web/tests/WebViewTest.cpp
@@ -36,6 +36,7 @@
#include "URLTestHelpers.h"
#include "WebAutofillClient.h"
#include "WebContentDetectionResult.h"
+#include "WebDateTimeChooserCompletion.h"
#include "WebDocument.h"
#include "WebElement.h"
#include "WebFrame.h"
@@ -51,9 +52,13 @@
#include "core/dom/Document.h"
#include "core/dom/Element.h"
#include "core/html/HTMLDocument.h"
+#include "core/html/HTMLInputElement.h"
#include "core/loader/FrameLoadRequest.h"
#include "core/frame/FrameView.h"
+#include "core/page/Chrome.h"
#include "core/page/Settings.h"
+#include "core/platform/chromium/KeyboardCodes.h"
+#include "core/testing/MockPagePopupDriver.h"
#include "public/platform/Platform.h"
#include "public/platform/WebSize.h"
#include "public/platform/WebThread.h"
@@ -181,6 +186,30 @@ private:
WebFrameClient* m_webFrameClient;
};
+class DateTimeChooserWebViewClient : public WebViewClient {
+public:
+ WebDateTimeChooserCompletion* chooserCompletion()
+ {
+ return m_chooserCompletion;
+ }
+
+ void clearChooserCompletion()
+ {
+ m_chooserCompletion = 0;
+ }
+
+ // WebViewClient methods
+ virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTimeChooserCompletion* chooser_completion) OVERRIDE
+ {
+ m_chooserCompletion = chooser_completion;
+ return true;
+ }
+
+private:
+ WebDateTimeChooserCompletion* m_chooserCompletion;
+
+};
+
class WebViewTest : public testing::Test {
public:
WebViewTest()
@@ -1237,4 +1266,91 @@ TEST_F(WebViewTest, DispatchesDomFocusOutDomFocusInOnViewToggleFocus)
EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data());
}
+#if !ENABLE(INPUT_MULTIPLE_FIELDS_UI)
+static bool openDateTimeChooser(WebView* webView, WebCore::HTMLInputElement* inputElement)
tkent 2013/11/21 00:09:43 The return value is not used. It should be void.
keishi 2013/11/21 15:07:12 Done.
+{
+ inputElement->focus();
+
+ WebKeyboardEvent keyEvent;
+ keyEvent.windowsKeyCode = WebCore::VKEY_SPACE;
+ keyEvent.type = WebInputEvent::RawKeyDown;
+ keyEvent.setKeyIdentifierFromWindowsKeyCode();
+ webView->handleInputEvent(keyEvent);
+
+ keyEvent.type = WebInputEvent::KeyUp;
+ webView->handleInputEvent(keyEvent);
+ return true;
+}
+
+TEST_F(WebViewTest, ChooseValueFromDateTimeChooser)
+{
+ DateTimeChooserWebViewClient client;
+ std::string url = m_baseURL + "date_time_chooser.html";
+ URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html");
+ WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(url, true, 0, &client));
+
+ WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->document();
+ WebCore::Page* page = document->page();
+ OwnPtr<WebCore::MockPagePopupDriver> mockPagePopupDriver = WebCore::MockPagePopupDriver::create(page->mainFrame());
+ page->chrome().client().setPagePopupDriver(mockPagePopupDriver.get());
tkent 2013/11/21 00:09:43 Is MockPagePopupDriver needed though it's for Andr
keishi 2013/11/21 15:07:12 This was left over from my efforts to run this tes
+
+ WebCore::HTMLInputElement* inputElement;
+
+ inputElement = toHTMLInputElement(document->getElementById("date"));
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(0);
+ client.clearChooserCompletion();
+ EXPECT_STREQ("1970-01-01", inputElement->value().utf8().data());
+
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
+ client.clearChooserCompletion();
+ EXPECT_STREQ("", inputElement->value().utf8().data());
+
+ inputElement = toHTMLInputElement(document->getElementById("datetimelocal"));
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(0);
+ client.clearChooserCompletion();
+ EXPECT_STREQ("1970-01-01T00:00", inputElement->value().utf8().data());
+
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
+ client.clearChooserCompletion();
+ EXPECT_STREQ("", inputElement->value().utf8().data());
+
+ inputElement = toHTMLInputElement(document->getElementById("month"));
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(0);
+ client.clearChooserCompletion();
+ EXPECT_STREQ("1970-01", inputElement->value().utf8().data());
+
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
+ client.clearChooserCompletion();
+ EXPECT_STREQ("", inputElement->value().utf8().data());
+
+ inputElement = toHTMLInputElement(document->getElementById("time"));
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(0);
+ client.clearChooserCompletion();
+ EXPECT_STREQ("00:00", inputElement->value().utf8().data());
+
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
+ client.clearChooserCompletion();
+ EXPECT_STREQ("", inputElement->value().utf8().data());
+
+ inputElement = toHTMLInputElement(document->getElementById("week"));
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(0);
+ client.clearChooserCompletion();
+ EXPECT_STREQ("1970-W01", inputElement->value().utf8().data());
+
+ openDateTimeChooser(webViewImpl, inputElement);
+ client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quiet_NaN());
+ client.clearChooserCompletion();
+ EXPECT_STREQ("", inputElement->value().utf8().data());
+}
+#endif
+
}

Powered by Google App Engine
This is Rietveld 408576698