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 18 matching lines...) Expand all Loading... |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 #include "WebView.h" | 32 #include "WebView.h" |
33 | 33 |
34 #include <gtest/gtest.h> | 34 #include <gtest/gtest.h> |
35 #include "FrameTestHelpers.h" | 35 #include "FrameTestHelpers.h" |
36 #include "URLTestHelpers.h" | 36 #include "URLTestHelpers.h" |
37 #include "WebAutofillClient.h" | 37 #include "WebAutofillClient.h" |
38 #include "WebContentDetectionResult.h" | 38 #include "WebContentDetectionResult.h" |
| 39 #include "WebDateTimeChooserCompletion.h" |
39 #include "WebDocument.h" | 40 #include "WebDocument.h" |
40 #include "WebElement.h" | 41 #include "WebElement.h" |
41 #include "WebFrame.h" | 42 #include "WebFrame.h" |
42 #include "WebFrameClient.h" | 43 #include "WebFrameClient.h" |
43 #include "WebFrameImpl.h" | 44 #include "WebFrameImpl.h" |
44 #include "WebHelperPluginImpl.h" | 45 #include "WebHelperPluginImpl.h" |
45 #include "WebHitTestResult.h" | 46 #include "WebHitTestResult.h" |
46 #include "WebInputEvent.h" | 47 #include "WebInputEvent.h" |
47 #include "WebSettings.h" | 48 #include "WebSettings.h" |
48 #include "WebViewClient.h" | 49 #include "WebViewClient.h" |
49 #include "WebViewImpl.h" | 50 #include "WebViewImpl.h" |
50 #include "WebWidget.h" | 51 #include "WebWidget.h" |
51 #include "core/dom/Document.h" | 52 #include "core/dom/Document.h" |
52 #include "core/dom/Element.h" | 53 #include "core/dom/Element.h" |
53 #include "core/html/HTMLDocument.h" | 54 #include "core/html/HTMLDocument.h" |
| 55 #include "core/html/HTMLInputElement.h" |
54 #include "core/loader/FrameLoadRequest.h" | 56 #include "core/loader/FrameLoadRequest.h" |
55 #include "core/frame/FrameView.h" | 57 #include "core/frame/FrameView.h" |
| 58 #include "core/page/Chrome.h" |
56 #include "core/page/Settings.h" | 59 #include "core/page/Settings.h" |
| 60 #include "core/platform/chromium/KeyboardCodes.h" |
57 #include "public/platform/Platform.h" | 61 #include "public/platform/Platform.h" |
58 #include "public/platform/WebSize.h" | 62 #include "public/platform/WebSize.h" |
59 #include "public/platform/WebThread.h" | 63 #include "public/platform/WebThread.h" |
60 #include "public/platform/WebUnitTestSupport.h" | 64 #include "public/platform/WebUnitTestSupport.h" |
61 #include "public/web/WebWidgetClient.h" | 65 #include "public/web/WebWidgetClient.h" |
62 | 66 |
63 using namespace blink; | 67 using namespace blink; |
64 using blink::FrameTestHelpers::runPendingTasks; | 68 using blink::FrameTestHelpers::runPendingTasks; |
65 using blink::URLTestHelpers::toKURL; | 69 using blink::URLTestHelpers::toKURL; |
66 | 70 |
(...skipping 107 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
174 { | 178 { |
175 } | 179 } |
176 | 180 |
177 void setWebFrameClient(WebFrameClient* client) { m_webFrameClient = client;
} | 181 void setWebFrameClient(WebFrameClient* client) { m_webFrameClient = client;
} |
178 | 182 |
179 private: | 183 private: |
180 WebWidget* m_helperPluginWebWidget; | 184 WebWidget* m_helperPluginWebWidget; |
181 WebFrameClient* m_webFrameClient; | 185 WebFrameClient* m_webFrameClient; |
182 }; | 186 }; |
183 | 187 |
| 188 class DateTimeChooserWebViewClient : public WebViewClient { |
| 189 public: |
| 190 WebDateTimeChooserCompletion* chooserCompletion() |
| 191 { |
| 192 return m_chooserCompletion; |
| 193 } |
| 194 |
| 195 void clearChooserCompletion() |
| 196 { |
| 197 m_chooserCompletion = 0; |
| 198 } |
| 199 |
| 200 // WebViewClient methods |
| 201 virtual bool openDateTimeChooser(const WebDateTimeChooserParams&, WebDateTim
eChooserCompletion* chooser_completion) OVERRIDE |
| 202 { |
| 203 m_chooserCompletion = chooser_completion; |
| 204 return true; |
| 205 } |
| 206 |
| 207 private: |
| 208 WebDateTimeChooserCompletion* m_chooserCompletion; |
| 209 |
| 210 }; |
| 211 |
184 class WebViewTest : public testing::Test { | 212 class WebViewTest : public testing::Test { |
185 public: | 213 public: |
186 WebViewTest() | 214 WebViewTest() |
187 : m_baseURL("http://www.test.com/") | 215 : m_baseURL("http://www.test.com/") |
188 { | 216 { |
189 } | 217 } |
190 | 218 |
191 virtual void TearDown() | 219 virtual void TearDown() |
192 { | 220 { |
193 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | 221 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); |
(...skipping 1037 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1231 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "domfocusou
t_domfocusin_events.html", true, 0); | 1259 WebView* webView = m_webViewHelper.initializeAndLoad(m_baseURL + "domfocusou
t_domfocusin_events.html", true, 0); |
1232 | 1260 |
1233 webView->setFocus(true); | 1261 webView->setFocus(true); |
1234 webView->setFocus(false); | 1262 webView->setFocus(false); |
1235 webView->setFocus(true); | 1263 webView->setFocus(true); |
1236 | 1264 |
1237 WebElement element = webView->mainFrame()->document().getElementById("messag
e"); | 1265 WebElement element = webView->mainFrame()->document().getElementById("messag
e"); |
1238 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data()); | 1266 EXPECT_STREQ("DOMFocusOutDOMFocusIn", element.innerText().utf8().data()); |
1239 } | 1267 } |
1240 | 1268 |
| 1269 #if !ENABLE(INPUT_MULTIPLE_FIELDS_UI) |
| 1270 static void openDateTimeChooser(WebView* webView, WebCore::HTMLInputElement* inp
utElement) |
| 1271 { |
| 1272 inputElement->focus(); |
| 1273 |
| 1274 WebKeyboardEvent keyEvent; |
| 1275 keyEvent.windowsKeyCode = WebCore::VKEY_SPACE; |
| 1276 keyEvent.type = WebInputEvent::RawKeyDown; |
| 1277 keyEvent.setKeyIdentifierFromWindowsKeyCode(); |
| 1278 webView->handleInputEvent(keyEvent); |
| 1279 |
| 1280 keyEvent.type = WebInputEvent::KeyUp; |
| 1281 webView->handleInputEvent(keyEvent); |
1241 } | 1282 } |
| 1283 |
| 1284 TEST_F(WebViewTest, ChooseValueFromDateTimeChooser) |
| 1285 { |
| 1286 DateTimeChooserWebViewClient client; |
| 1287 std::string url = m_baseURL + "date_time_chooser.html"; |
| 1288 URLTestHelpers::registerMockedURLLoad(toKURL(url), "date_time_chooser.html")
; |
| 1289 WebViewImpl* webViewImpl = toWebViewImpl(m_webViewHelper.initializeAndLoad(u
rl, true, 0, &client)); |
| 1290 |
| 1291 WebCore::Document* document = webViewImpl->mainFrameImpl()->frame()->documen
t(); |
| 1292 WebCore::Page* page = document->page(); |
| 1293 |
| 1294 WebCore::HTMLInputElement* inputElement; |
| 1295 |
| 1296 inputElement = toHTMLInputElement(document->getElementById("date")); |
| 1297 openDateTimeChooser(webViewImpl, inputElement); |
| 1298 client.chooserCompletion()->didChooseValue(0); |
| 1299 client.clearChooserCompletion(); |
| 1300 EXPECT_STREQ("1970-01-01", inputElement->value().utf8().data()); |
| 1301 |
| 1302 openDateTimeChooser(webViewImpl, inputElement); |
| 1303 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1304 client.clearChooserCompletion(); |
| 1305 EXPECT_STREQ("", inputElement->value().utf8().data()); |
| 1306 |
| 1307 inputElement = toHTMLInputElement(document->getElementById("datetimelocal"))
; |
| 1308 openDateTimeChooser(webViewImpl, inputElement); |
| 1309 client.chooserCompletion()->didChooseValue(0); |
| 1310 client.clearChooserCompletion(); |
| 1311 EXPECT_STREQ("1970-01-01T00:00", inputElement->value().utf8().data()); |
| 1312 |
| 1313 openDateTimeChooser(webViewImpl, inputElement); |
| 1314 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1315 client.clearChooserCompletion(); |
| 1316 EXPECT_STREQ("", inputElement->value().utf8().data()); |
| 1317 |
| 1318 inputElement = toHTMLInputElement(document->getElementById("month")); |
| 1319 openDateTimeChooser(webViewImpl, inputElement); |
| 1320 client.chooserCompletion()->didChooseValue(0); |
| 1321 client.clearChooserCompletion(); |
| 1322 EXPECT_STREQ("1970-01", inputElement->value().utf8().data()); |
| 1323 |
| 1324 openDateTimeChooser(webViewImpl, inputElement); |
| 1325 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1326 client.clearChooserCompletion(); |
| 1327 EXPECT_STREQ("", inputElement->value().utf8().data()); |
| 1328 |
| 1329 inputElement = toHTMLInputElement(document->getElementById("time")); |
| 1330 openDateTimeChooser(webViewImpl, inputElement); |
| 1331 client.chooserCompletion()->didChooseValue(0); |
| 1332 client.clearChooserCompletion(); |
| 1333 EXPECT_STREQ("00:00", inputElement->value().utf8().data()); |
| 1334 |
| 1335 openDateTimeChooser(webViewImpl, inputElement); |
| 1336 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1337 client.clearChooserCompletion(); |
| 1338 EXPECT_STREQ("", inputElement->value().utf8().data()); |
| 1339 |
| 1340 inputElement = toHTMLInputElement(document->getElementById("week")); |
| 1341 openDateTimeChooser(webViewImpl, inputElement); |
| 1342 client.chooserCompletion()->didChooseValue(0); |
| 1343 client.clearChooserCompletion(); |
| 1344 EXPECT_STREQ("1970-W01", inputElement->value().utf8().data()); |
| 1345 |
| 1346 openDateTimeChooser(webViewImpl, inputElement); |
| 1347 client.chooserCompletion()->didChooseValue(std::numeric_limits<double>::quie
t_NaN()); |
| 1348 client.clearChooserCompletion(); |
| 1349 EXPECT_STREQ("", inputElement->value().utf8().data()); |
| 1350 } |
| 1351 #endif |
| 1352 |
| 1353 } |
OLD | NEW |