OLD | NEW |
1 /* | 1 /* |
2 * Copyright (C) 2010 Google Inc. All rights reserved. | 2 * Copyright (C) 2010 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 232 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
243 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ouseReleased, | 243 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ouseReleased, |
244 1, false, false, false, false, 0); | 244 1, false, false, false, false, 0); |
245 webView()->selectPopup()->handleMouseReleaseEvent(mouseEvent); | 245 webView()->selectPopup()->handleMouseReleaseEvent(mouseEvent); |
246 } | 246 } |
247 | 247 |
248 void registerMockedURLLoad(const std::string& fileName) | 248 void registerMockedURLLoad(const std::string& fileName) |
249 { | 249 { |
250 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); | 250 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); |
251 } | 251 } |
252 | 252 |
| 253 void serveRequests() |
| 254 { |
| 255 Platform::current()->unitTestSupport()->serveAsynchronousMockedRequests(
); |
| 256 } |
| 257 |
253 void loadFrame(WebFrame* frame, const std::string& fileName) | 258 void loadFrame(WebFrame* frame, const std::string& fileName) |
254 { | 259 { |
255 FrameTestHelpers::loadFrame(frame, baseURL + fileName); | 260 WebURLRequest urlRequest; |
| 261 urlRequest.initialize(); |
| 262 urlRequest.setURL(WebURL(toKURL(baseURL + fileName))); |
| 263 frame->loadRequest(urlRequest); |
256 } | 264 } |
257 | 265 |
258 WebViewImpl* webView() const { return m_helper.webViewImpl(); } | 266 WebViewImpl* webView() const { return m_helper.webViewImpl(); } |
259 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } | 267 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } |
260 | 268 |
261 protected: | 269 protected: |
262 PopupTestWebViewClient m_webviewClient; | 270 PopupTestWebViewClient m_webviewClient; |
263 TestPopupMenuClient m_popupMenuClient; | 271 TestPopupMenuClient m_popupMenuClient; |
264 RefPtr<PopupMenu> m_popupMenu; | 272 RefPtr<PopupMenu> m_popupMenu; |
265 std::string baseURL; | 273 std::string baseURL; |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
390 // Popup should have closed and the item should have been selected. | 398 // Popup should have closed and the item should have been selected. |
391 EXPECT_FALSE(popupOpen()); | 399 EXPECT_FALSE(popupOpen()); |
392 EXPECT_EQ(2, selectedIndex()); | 400 EXPECT_EQ(2, selectedIndex()); |
393 } | 401 } |
394 | 402 |
395 TEST_F(SelectPopupMenuTest, DISABLED_SelectItemEventFire) | 403 TEST_F(SelectPopupMenuTest, DISABLED_SelectItemEventFire) |
396 { | 404 { |
397 registerMockedURLLoad("select_event.html"); | 405 registerMockedURLLoad("select_event.html"); |
398 webView()->settings()->setJavaScriptEnabled(true); | 406 webView()->settings()->setJavaScriptEnabled(true); |
399 loadFrame(mainFrame(), "select_event.html"); | 407 loadFrame(mainFrame(), "select_event.html"); |
| 408 serveRequests(); |
400 | 409 |
401 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | 410 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); |
402 | 411 |
403 showPopup(); | 412 showPopup(); |
404 | 413 |
405 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | 414 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); |
406 // menuItemHeight * 0.5 means the Y position on the item at index 0. | 415 // menuItemHeight * 0.5 means the Y position on the item at index 0. |
407 IntPoint row1Point(2, menuItemHeight * 0.5); | 416 IntPoint row1Point(2, menuItemHeight * 0.5); |
408 simulateLeftMouseDownEvent(row1Point); | 417 simulateLeftMouseDownEvent(row1Point); |
409 simulateLeftMouseUpEvent(row1Point); | 418 simulateLeftMouseUpEvent(row1Point); |
(...skipping 24 matching lines...) Expand all Loading... |
434 | 443 |
435 // The item is changed to the item at index 2, from index 0, so change event
is fired. | 444 // The item is changed to the item at index 2, from index 0, so change event
is fired. |
436 EXPECT_STREQ("upclickchangeupclick", element.innerText().utf8().data()); | 445 EXPECT_STREQ("upclickchangeupclick", element.innerText().utf8().data()); |
437 } | 446 } |
438 | 447 |
439 TEST_F(SelectPopupMenuTest, FLAKY_SelectItemKeyEvent) | 448 TEST_F(SelectPopupMenuTest, FLAKY_SelectItemKeyEvent) |
440 { | 449 { |
441 registerMockedURLLoad("select_event.html"); | 450 registerMockedURLLoad("select_event.html"); |
442 webView()->settings()->setJavaScriptEnabled(true); | 451 webView()->settings()->setJavaScriptEnabled(true); |
443 loadFrame(mainFrame(), "select_event.html"); | 452 loadFrame(mainFrame(), "select_event.html"); |
| 453 serveRequests(); |
444 | 454 |
445 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | 455 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); |
446 | 456 |
447 showPopup(); | 457 showPopup(); |
448 | 458 |
449 // Siumulate to choose the item at index 1 with keyboard. | 459 // Siumulate to choose the item at index 1 with keyboard. |
450 simulateKeyDownEvent(VKEY_DOWN); | 460 simulateKeyDownEvent(VKEY_DOWN); |
451 simulateKeyDownEvent(VKEY_DOWN); | 461 simulateKeyDownEvent(VKEY_DOWN); |
452 simulateKeyDownEvent(VKEY_RETURN); | 462 simulateKeyDownEvent(VKEY_RETURN); |
453 | 463 |
454 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | 464 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); |
455 // We only can see change event but no other mouse related events. | 465 // We only can see change event but no other mouse related events. |
456 EXPECT_STREQ("change", element.innerText().utf8().data()); | 466 EXPECT_STREQ("change", element.innerText().utf8().data()); |
457 } | 467 } |
458 | 468 |
459 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnChange) | 469 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnChange) |
460 { | 470 { |
461 // Make sure no crash, even if select node is removed on 'change' event hand
ler. | 471 // Make sure no crash, even if select node is removed on 'change' event hand
ler. |
462 registerMockedURLLoad("select_event_remove_on_change.html"); | 472 registerMockedURLLoad("select_event_remove_on_change.html"); |
463 webView()->settings()->setJavaScriptEnabled(true); | 473 webView()->settings()->setJavaScriptEnabled(true); |
464 loadFrame(mainFrame(), "select_event_remove_on_change.html"); | 474 loadFrame(mainFrame(), "select_event_remove_on_change.html"); |
| 475 serveRequests(); |
465 | 476 |
466 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | 477 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); |
467 | 478 |
468 showPopup(); | 479 showPopup(); |
469 | 480 |
470 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | 481 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); |
471 // menuItemHeight * 1.5 means the Y position on the item at index 1. | 482 // menuItemHeight * 1.5 means the Y position on the item at index 1. |
472 IntPoint row1Point(2, menuItemHeight * 1.5); | 483 IntPoint row1Point(2, menuItemHeight * 1.5); |
473 simulateLeftMouseDownEvent(row1Point); | 484 simulateLeftMouseDownEvent(row1Point); |
474 simulateLeftMouseUpEvent(row1Point); | 485 simulateLeftMouseUpEvent(row1Point); |
475 | 486 |
476 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | 487 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); |
477 EXPECT_STREQ("change", element.innerText().utf8().data()); | 488 EXPECT_STREQ("change", element.innerText().utf8().data()); |
478 } | 489 } |
479 | 490 |
480 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnClick) | 491 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnClick) |
481 { | 492 { |
482 // Make sure no crash, even if select node is removed on 'click' event handl
er. | 493 // Make sure no crash, even if select node is removed on 'click' event handl
er. |
483 registerMockedURLLoad("select_event_remove_on_click.html"); | 494 registerMockedURLLoad("select_event_remove_on_click.html"); |
484 webView()->settings()->setJavaScriptEnabled(true); | 495 webView()->settings()->setJavaScriptEnabled(true); |
485 loadFrame(mainFrame(), "select_event_remove_on_click.html"); | 496 loadFrame(mainFrame(), "select_event_remove_on_click.html"); |
| 497 serveRequests(); |
486 | 498 |
487 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | 499 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); |
488 | 500 |
489 showPopup(); | 501 showPopup(); |
490 | 502 |
491 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | 503 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); |
492 // menuItemHeight * 1.5 means the Y position on the item at index 1. | 504 // menuItemHeight * 1.5 means the Y position on the item at index 1. |
493 IntPoint row1Point(2, menuItemHeight * 1.5); | 505 IntPoint row1Point(2, menuItemHeight * 1.5); |
494 simulateLeftMouseDownEvent(row1Point); | 506 simulateLeftMouseDownEvent(row1Point); |
495 simulateLeftMouseUpEvent(row1Point); | 507 simulateLeftMouseUpEvent(row1Point); |
496 | 508 |
497 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | 509 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); |
498 EXPECT_STREQ("click", element.innerText().utf8().data()); | 510 EXPECT_STREQ("click", element.innerText().utf8().data()); |
499 } | 511 } |
500 | 512 |
501 } // namespace | 513 } // namespace |
OLD | NEW |