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