| OLD | NEW |
| (Empty) |
| 1 /* | |
| 2 * Copyright (C) 2010 Google Inc. All rights reserved. | |
| 3 * | |
| 4 * Redistribution and use in source and binary forms, with or without | |
| 5 * modification, are permitted provided that the following conditions are | |
| 6 * met: | |
| 7 * | |
| 8 * * Redistributions of source code must retain the above copyright | |
| 9 * notice, this list of conditions and the following disclaimer. | |
| 10 * * Redistributions in binary form must reproduce the above | |
| 11 * copyright notice, this list of conditions and the following disclaimer | |
| 12 * in the documentation and/or other materials provided with the | |
| 13 * distribution. | |
| 14 * * Neither the name of Google Inc. nor the names of its | |
| 15 * contributors may be used to endorse or promote products derived from | |
| 16 * this software without specific prior written permission. | |
| 17 * | |
| 18 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS | |
| 19 * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT | |
| 20 * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR | |
| 21 * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT | |
| 22 * OWNER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, | |
| 23 * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT | |
| 24 * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, | |
| 25 * DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY | |
| 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | |
| 27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | |
| 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | |
| 29 */ | |
| 30 | |
| 31 #include "config.h" | |
| 32 | |
| 33 #include "core/dom/Element.h" | |
| 34 #include "core/frame/FrameView.h" | |
| 35 #include "core/frame/Settings.h" | |
| 36 #include "core/html/HTMLSelectElement.h" | |
| 37 #include "core/page/EventHandler.h" | |
| 38 #include "core/rendering/RenderMenuList.h" | |
| 39 #include "core/testing/URLTestHelpers.h" | |
| 40 #include "platform/KeyboardCodes.h" | |
| 41 #include "platform/PlatformMouseEvent.h" | |
| 42 #include "platform/PopupMenu.h" | |
| 43 #include "platform/PopupMenuClient.h" | |
| 44 #include "platform/RuntimeEnabledFeatures.h" | |
| 45 #include "platform/graphics/Color.h" | |
| 46 #include "platform/scroll/ScrollbarTheme.h" | |
| 47 #include "public/platform/Platform.h" | |
| 48 #include "public/platform/WebScreenInfo.h" | |
| 49 #include "public/platform/WebString.h" | |
| 50 #include "public/platform/WebURL.h" | |
| 51 #include "public/platform/WebURLRequest.h" | |
| 52 #include "public/platform/WebURLResponse.h" | |
| 53 #include "public/platform/WebUnitTestSupport.h" | |
| 54 #include "public/web/WebDocument.h" | |
| 55 #include "public/web/WebElement.h" | |
| 56 #include "public/web/WebFrame.h" | |
| 57 #include "public/web/WebFrameClient.h" | |
| 58 #include "public/web/WebInputEvent.h" | |
| 59 #include "public/web/WebSettings.h" | |
| 60 #include "public/web/WebView.h" | |
| 61 #include "public/web/WebViewClient.h" | |
| 62 #include "v8.h" | |
| 63 #include "web/PopupContainer.h" | |
| 64 #include "web/PopupListBox.h" | |
| 65 #include "web/PopupMenuChromium.h" | |
| 66 #include "web/WebLocalFrameImpl.h" | |
| 67 #include "web/WebPopupMenuImpl.h" | |
| 68 #include "web/WebViewImpl.h" | |
| 69 #include "web/tests/FrameTestHelpers.h" | |
| 70 #include <gtest/gtest.h> | |
| 71 | |
| 72 using namespace blink; | |
| 73 using namespace blink; | |
| 74 using blink::URLTestHelpers::toKURL; | |
| 75 | |
| 76 namespace { | |
| 77 | |
| 78 class TestPopupMenuClient : public PopupMenuClient { | |
| 79 public: | |
| 80 // Item at index 0 is selected by default. | |
| 81 TestPopupMenuClient() : m_selectIndex(0), m_node(0), m_listSize(10) { } | |
| 82 virtual ~TestPopupMenuClient() {} | |
| 83 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) | |
| 84 { | |
| 85 m_selectIndex = listIndex; | |
| 86 if (m_node) { | |
| 87 HTMLSelectElement* select = toHTMLSelectElement(m_node); | |
| 88 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f
ireEvents); | |
| 89 } | |
| 90 } | |
| 91 virtual void selectionChanged(unsigned, bool) {} | |
| 92 virtual void selectionCleared() {} | |
| 93 | |
| 94 virtual String itemText(unsigned listIndex) const | |
| 95 { | |
| 96 String str("Item "); | |
| 97 str.append(String::number(listIndex)); | |
| 98 return str; | |
| 99 } | |
| 100 virtual String itemLabel(unsigned) const { return String(); } | |
| 101 virtual String itemIcon(unsigned) const { return String(); } | |
| 102 virtual String itemToolTip(unsigned listIndex) const { return itemText(listI
ndex); } | |
| 103 virtual String itemAccessibilityText(unsigned listIndex) const { return item
Text(listIndex); } | |
| 104 virtual bool itemIsEnabled(unsigned listIndex) const { return m_disabledInde
xSet.find(listIndex) == m_disabledIndexSet.end(); } | |
| 105 virtual PopupMenuStyle itemStyle(unsigned listIndex) const | |
| 106 { | |
| 107 FontDescription fontDescription; | |
| 108 fontDescription.setComputedSize(12.0); | |
| 109 Font font(fontDescription); | |
| 110 font.update(nullptr); | |
| 111 return PopupMenuStyle(Color::black, Color::white, font, true, false, Len
gth(), TextDirection(), false /* has text direction override */); | |
| 112 } | |
| 113 virtual PopupMenuStyle menuStyle() const { return itemStyle(0); } | |
| 114 virtual int clientInsetLeft() const { return 0; } | |
| 115 virtual int clientInsetRight() const { return 0; } | |
| 116 virtual LayoutUnit clientPaddingLeft() const { return 0; } | |
| 117 virtual LayoutUnit clientPaddingRight() const { return 0; } | |
| 118 virtual int listSize() const { return m_listSize; } | |
| 119 virtual int selectedIndex() const { return m_selectIndex; } | |
| 120 virtual void popupDidHide() { } | |
| 121 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } | |
| 122 virtual bool itemIsLabel(unsigned listIndex) const { return false; } | |
| 123 virtual bool itemIsSelected(unsigned listIndex) const { return listIndex ==
m_selectIndex; } | |
| 124 virtual bool valueShouldChangeOnHotTrack() const { return false; } | |
| 125 virtual void setTextFromItem(unsigned listIndex) { } | |
| 126 | |
| 127 virtual FontSelector* fontSelector() const { return 0; } | |
| 128 virtual HostWindow* hostWindow() const { return 0; } | |
| 129 | |
| 130 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrie
ntation, ScrollbarControlSize) { return nullptr; } | |
| 131 | |
| 132 void setDisabledIndex(unsigned index) { m_disabledIndexSet.insert(index); } | |
| 133 void setFocusedNode(Node* node) { m_node = node; } | |
| 134 void setListSize(int listSize) { m_listSize = listSize; } | |
| 135 | |
| 136 private: | |
| 137 unsigned m_selectIndex; | |
| 138 std::set<unsigned> m_disabledIndexSet; | |
| 139 Node* m_node; | |
| 140 int m_listSize; | |
| 141 }; | |
| 142 | |
| 143 class TestWebWidgetClient : public WebWidgetClient { | |
| 144 public: | |
| 145 ~TestWebWidgetClient() { } | |
| 146 }; | |
| 147 | |
| 148 class TestWebPopupMenuImpl : public WebPopupMenuImpl { | |
| 149 public: | |
| 150 static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client) | |
| 151 { | |
| 152 return adoptRef(new TestWebPopupMenuImpl(client)); | |
| 153 } | |
| 154 | |
| 155 ~TestWebPopupMenuImpl() { } | |
| 156 | |
| 157 private: | |
| 158 TestWebPopupMenuImpl(WebWidgetClient* client) : WebPopupMenuImpl(client) { } | |
| 159 }; | |
| 160 | |
| 161 class PopupTestWebViewClient : public FrameTestHelpers::TestWebViewClient { | |
| 162 public: | |
| 163 PopupTestWebViewClient() : m_webPopupMenu(TestWebPopupMenuImpl::create(&m_we
bWidgetClient)) { } | |
| 164 ~PopupTestWebViewClient() { } | |
| 165 | |
| 166 virtual WebWidget* createPopupMenu(WebPopupType) { return m_webPopupMenu.get
(); } | |
| 167 | |
| 168 // We need to override this so that the popup menu size is not 0 | |
| 169 // (the layout code checks to see if the popup fits on the screen). | |
| 170 virtual WebScreenInfo screenInfo() | |
| 171 { | |
| 172 WebScreenInfo screenInfo; | |
| 173 screenInfo.availableRect.height = 2000; | |
| 174 screenInfo.availableRect.width = 2000; | |
| 175 return screenInfo; | |
| 176 } | |
| 177 | |
| 178 private: | |
| 179 TestWebWidgetClient m_webWidgetClient; | |
| 180 RefPtr<TestWebPopupMenuImpl> m_webPopupMenu; | |
| 181 }; | |
| 182 | |
| 183 class SelectPopupMenuTest : public testing::Test { | |
| 184 public: | |
| 185 SelectPopupMenuTest() | |
| 186 : baseURL("http://www.test.com/") | |
| 187 { | |
| 188 } | |
| 189 | |
| 190 protected: | |
| 191 virtual void SetUp() | |
| 192 { | |
| 193 m_helper.initialize(false, 0, &m_webviewClient); | |
| 194 m_popupMenu = adoptRef(new PopupMenuChromium(*mainFrame()->frame(), &m_p
opupMenuClient)); | |
| 195 } | |
| 196 | |
| 197 virtual void TearDown() | |
| 198 { | |
| 199 m_popupMenu = nullptr; | |
| 200 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | |
| 201 } | |
| 202 | |
| 203 // Returns true if there currently is a select popup in the WebView. | |
| 204 bool popupOpen() const { return webView()->selectPopup(); } | |
| 205 | |
| 206 int selectedIndex() const { return m_popupMenuClient.selectedIndex(); } | |
| 207 | |
| 208 void showPopup() | |
| 209 { | |
| 210 m_popupMenu->show(FloatQuad(FloatRect(0, 0, 100, 100)), IntSize(100, 100
), 0); | |
| 211 ASSERT_TRUE(popupOpen()); | |
| 212 } | |
| 213 | |
| 214 void hidePopup() | |
| 215 { | |
| 216 m_popupMenu->hide(); | |
| 217 EXPECT_FALSE(popupOpen()); | |
| 218 } | |
| 219 | |
| 220 void simulateKeyDownEvent(int keyCode) | |
| 221 { | |
| 222 simulateKeyEvent(WebInputEvent::RawKeyDown, keyCode); | |
| 223 } | |
| 224 | |
| 225 void simulateKeyUpEvent(int keyCode) | |
| 226 { | |
| 227 simulateKeyEvent(WebInputEvent::KeyUp, keyCode); | |
| 228 } | |
| 229 | |
| 230 // Simulates a key event on the WebView. | |
| 231 // The WebView forwards the event to the select popup if one is open. | |
| 232 void simulateKeyEvent(WebInputEvent::Type eventType, int keyCode) | |
| 233 { | |
| 234 WebKeyboardEvent keyEvent; | |
| 235 keyEvent.windowsKeyCode = keyCode; | |
| 236 keyEvent.type = eventType; | |
| 237 webView()->handleInputEvent(keyEvent); | |
| 238 } | |
| 239 | |
| 240 // Simulates a mouse event on the select popup. | |
| 241 void simulateLeftMouseDownEvent(const IntPoint& point) | |
| 242 { | |
| 243 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ousePressed, | |
| 244 1, false, false, false, false, 0); | |
| 245 webView()->selectPopup()->handleMouseDownEvent(mouseEvent); | |
| 246 } | |
| 247 void simulateLeftMouseUpEvent(const IntPoint& point) | |
| 248 { | |
| 249 PlatformMouseEvent mouseEvent(point, point, LeftButton, PlatformEvent::M
ouseReleased, | |
| 250 1, false, false, false, false, 0); | |
| 251 webView()->selectPopup()->handleMouseReleaseEvent(mouseEvent); | |
| 252 } | |
| 253 | |
| 254 void registerMockedURLLoad(const std::string& fileName) | |
| 255 { | |
| 256 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); | |
| 257 } | |
| 258 | |
| 259 void loadFrame(WebFrame* frame, const std::string& fileName) | |
| 260 { | |
| 261 FrameTestHelpers::loadFrame(frame, baseURL + fileName); | |
| 262 } | |
| 263 | |
| 264 WebViewImpl* webView() const { return m_helper.webViewImpl(); } | |
| 265 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } | |
| 266 | |
| 267 protected: | |
| 268 PopupTestWebViewClient m_webviewClient; | |
| 269 TestPopupMenuClient m_popupMenuClient; | |
| 270 RefPtr<PopupMenu> m_popupMenu; | |
| 271 std::string baseURL; | |
| 272 | |
| 273 private: | |
| 274 FrameTestHelpers::WebViewHelper m_helper; | |
| 275 }; | |
| 276 | |
| 277 // Tests that show/hide and repeats. Select popups are reused in web pages when | |
| 278 // they are reopened, that what this is testing. | |
| 279 TEST_F(SelectPopupMenuTest, ShowThenHide) | |
| 280 { | |
| 281 for (int i = 0; i < 3; i++) { | |
| 282 showPopup(); | |
| 283 hidePopup(); | |
| 284 } | |
| 285 } | |
| 286 | |
| 287 // Tests that showing a select popup and deleting it does not cause problem. | |
| 288 // This happens in real-life if a page navigates while a select popup is showing
. | |
| 289 TEST_F(SelectPopupMenuTest, ShowThenDelete) | |
| 290 { | |
| 291 showPopup(); | |
| 292 // Nothing else to do, TearDown() deletes the popup. | |
| 293 } | |
| 294 | |
| 295 // Tests that losing focus closes the select popup. | |
| 296 TEST_F(SelectPopupMenuTest, ShowThenLoseFocus) | |
| 297 { | |
| 298 showPopup(); | |
| 299 // Simulate losing focus. | |
| 300 webView()->setFocus(false); | |
| 301 | |
| 302 // Popup should have closed. | |
| 303 EXPECT_FALSE(popupOpen()); | |
| 304 } | |
| 305 | |
| 306 // Tests that pressing ESC closes the popup. | |
| 307 TEST_F(SelectPopupMenuTest, ShowThenPressESC) | |
| 308 { | |
| 309 showPopup(); | |
| 310 simulateKeyDownEvent(VKEY_ESCAPE); | |
| 311 // Popup should have closed. | |
| 312 EXPECT_FALSE(popupOpen()); | |
| 313 } | |
| 314 | |
| 315 // Tests selecting an item with the arrows and enter/esc/tab. | |
| 316 TEST_F(SelectPopupMenuTest, SelectWithKeys) | |
| 317 { | |
| 318 showPopup(); | |
| 319 // Simulate selecting the 2nd item by pressing Down, Down, enter. | |
| 320 simulateKeyDownEvent(VKEY_DOWN); | |
| 321 simulateKeyDownEvent(VKEY_DOWN); | |
| 322 simulateKeyDownEvent(VKEY_RETURN); | |
| 323 | |
| 324 // Popup should have closed. | |
| 325 EXPECT_TRUE(!popupOpen()); | |
| 326 EXPECT_EQ(2, selectedIndex()); | |
| 327 | |
| 328 // It should work as well with ESC. | |
| 329 showPopup(); | |
| 330 simulateKeyDownEvent(VKEY_DOWN); | |
| 331 simulateKeyDownEvent(VKEY_ESCAPE); | |
| 332 EXPECT_FALSE(popupOpen()); | |
| 333 EXPECT_EQ(3, selectedIndex()); | |
| 334 | |
| 335 // It should work as well with TAB. | |
| 336 showPopup(); | |
| 337 simulateKeyDownEvent(VKEY_DOWN); | |
| 338 simulateKeyDownEvent(VKEY_TAB); | |
| 339 EXPECT_FALSE(popupOpen()); | |
| 340 EXPECT_EQ(4, selectedIndex()); | |
| 341 } | |
| 342 | |
| 343 // Tests that selecting an item with the mouse does select the item and close | |
| 344 // the popup. | |
| 345 TEST_F(SelectPopupMenuTest, ClickItem) | |
| 346 { | |
| 347 showPopup(); | |
| 348 | |
| 349 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | |
| 350 // menuItemHeight * 1.5 means the Y position on the item at index 1. | |
| 351 IntPoint row1Point(2, menuItemHeight * 1.5); | |
| 352 // Simulate a click down/up on the first item. | |
| 353 simulateLeftMouseDownEvent(row1Point); | |
| 354 simulateLeftMouseUpEvent(row1Point); | |
| 355 | |
| 356 // Popup should have closed and the item at index 1 selected. | |
| 357 EXPECT_FALSE(popupOpen()); | |
| 358 EXPECT_EQ(1, selectedIndex()); | |
| 359 } | |
| 360 | |
| 361 // Tests that moving the mouse over an item and then clicking outside the select
popup | |
| 362 // leaves the seleted item unchanged. | |
| 363 TEST_F(SelectPopupMenuTest, MouseOverItemClickOutside) | |
| 364 { | |
| 365 showPopup(); | |
| 366 | |
| 367 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | |
| 368 // menuItemHeight * 1.5 means the Y position on the item at index 1. | |
| 369 IntPoint row1Point(2, menuItemHeight * 1.5); | |
| 370 // Simulate the mouse moving over the first item. | |
| 371 PlatformMouseEvent mouseEvent(row1Point, row1Point, NoButton, PlatformEvent:
:MouseMoved, | |
| 372 1, false, false, false, false, 0); | |
| 373 webView()->selectPopup()->handleMouseMoveEvent(mouseEvent); | |
| 374 | |
| 375 // Click outside the popup. | |
| 376 simulateLeftMouseDownEvent(IntPoint(1000, 1000)); | |
| 377 | |
| 378 // Popup should have closed and item 0 should still be selected. | |
| 379 EXPECT_FALSE(popupOpen()); | |
| 380 EXPECT_EQ(0, selectedIndex()); | |
| 381 } | |
| 382 | |
| 383 // Tests that selecting an item with the keyboard and then clicking outside the
select | |
| 384 // popup does select that item. | |
| 385 TEST_F(SelectPopupMenuTest, SelectItemWithKeyboardItemClickOutside) | |
| 386 { | |
| 387 showPopup(); | |
| 388 | |
| 389 // Simulate selecting the 2nd item by pressing Down, Down. | |
| 390 simulateKeyDownEvent(VKEY_DOWN); | |
| 391 simulateKeyDownEvent(VKEY_DOWN); | |
| 392 | |
| 393 // Click outside the popup. | |
| 394 simulateLeftMouseDownEvent(IntPoint(1000, 1000)); | |
| 395 | |
| 396 // Popup should have closed and the item should have been selected. | |
| 397 EXPECT_FALSE(popupOpen()); | |
| 398 EXPECT_EQ(2, selectedIndex()); | |
| 399 } | |
| 400 | |
| 401 TEST_F(SelectPopupMenuTest, DISABLED_SelectItemEventFire) | |
| 402 { | |
| 403 registerMockedURLLoad("select_event.html"); | |
| 404 webView()->settings()->setJavaScriptEnabled(true); | |
| 405 loadFrame(mainFrame(), "select_event.html"); | |
| 406 | |
| 407 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 408 | |
| 409 showPopup(); | |
| 410 | |
| 411 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | |
| 412 // menuItemHeight * 0.5 means the Y position on the item at index 0. | |
| 413 IntPoint row1Point(2, menuItemHeight * 0.5); | |
| 414 simulateLeftMouseDownEvent(row1Point); | |
| 415 simulateLeftMouseUpEvent(row1Point); | |
| 416 | |
| 417 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | |
| 418 | |
| 419 // mousedown event is held by select node, and we don't simulate the event f
or the node. | |
| 420 // So we can only see mouseup and click event. | |
| 421 EXPECT_STREQ("upclick", element.innerText().utf8().data()); | |
| 422 | |
| 423 // Disable the item at index 1. | |
| 424 m_popupMenuClient.setDisabledIndex(1); | |
| 425 | |
| 426 showPopup(); | |
| 427 // menuItemHeight * 1.5 means the Y position on the item at index 1. | |
| 428 row1Point.setY(menuItemHeight * 1.5); | |
| 429 simulateLeftMouseDownEvent(row1Point); | |
| 430 simulateLeftMouseUpEvent(row1Point); | |
| 431 | |
| 432 // The item at index 1 is disabled, so the text should not be changed. | |
| 433 EXPECT_STREQ("upclick", element.innerText().utf8().data()); | |
| 434 | |
| 435 showPopup(); | |
| 436 // menuItemHeight * 2.5 means the Y position on the item at index 2. | |
| 437 row1Point.setY(menuItemHeight * 2.5); | |
| 438 simulateLeftMouseDownEvent(row1Point); | |
| 439 simulateLeftMouseUpEvent(row1Point); | |
| 440 | |
| 441 // The item is changed to the item at index 2, from index 0, so change event
is fired. | |
| 442 EXPECT_STREQ("upclickchangeupclick", element.innerText().utf8().data()); | |
| 443 } | |
| 444 | |
| 445 TEST_F(SelectPopupMenuTest, FLAKY_SelectItemKeyEvent) | |
| 446 { | |
| 447 registerMockedURLLoad("select_event.html"); | |
| 448 webView()->settings()->setJavaScriptEnabled(true); | |
| 449 loadFrame(mainFrame(), "select_event.html"); | |
| 450 | |
| 451 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 452 | |
| 453 showPopup(); | |
| 454 | |
| 455 // Siumulate to choose the item at index 1 with keyboard. | |
| 456 simulateKeyDownEvent(VKEY_DOWN); | |
| 457 simulateKeyDownEvent(VKEY_DOWN); | |
| 458 simulateKeyDownEvent(VKEY_RETURN); | |
| 459 | |
| 460 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | |
| 461 // We only can see change event but no other mouse related events. | |
| 462 EXPECT_STREQ("change", element.innerText().utf8().data()); | |
| 463 } | |
| 464 | |
| 465 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnChange) | |
| 466 { | |
| 467 // Make sure no crash, even if select node is removed on 'change' event hand
ler. | |
| 468 registerMockedURLLoad("select_event_remove_on_change.html"); | |
| 469 webView()->settings()->setJavaScriptEnabled(true); | |
| 470 loadFrame(mainFrame(), "select_event_remove_on_change.html"); | |
| 471 | |
| 472 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 473 | |
| 474 showPopup(); | |
| 475 | |
| 476 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | |
| 477 // menuItemHeight * 1.5 means the Y position on the item at index 1. | |
| 478 IntPoint row1Point(2, menuItemHeight * 1.5); | |
| 479 simulateLeftMouseDownEvent(row1Point); | |
| 480 simulateLeftMouseUpEvent(row1Point); | |
| 481 | |
| 482 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | |
| 483 EXPECT_STREQ("change", element.innerText().utf8().data()); | |
| 484 } | |
| 485 | |
| 486 TEST_F(SelectPopupMenuTest, SelectItemRemoveSelectOnClick) | |
| 487 { | |
| 488 // Make sure no crash, even if select node is removed on 'click' event handl
er. | |
| 489 registerMockedURLLoad("select_event_remove_on_click.html"); | |
| 490 webView()->settings()->setJavaScriptEnabled(true); | |
| 491 loadFrame(mainFrame(), "select_event_remove_on_click.html"); | |
| 492 | |
| 493 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 494 | |
| 495 showPopup(); | |
| 496 | |
| 497 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | |
| 498 // menuItemHeight * 1.5 means the Y position on the item at index 1. | |
| 499 IntPoint row1Point(2, menuItemHeight * 1.5); | |
| 500 simulateLeftMouseDownEvent(row1Point); | |
| 501 simulateLeftMouseUpEvent(row1Point); | |
| 502 | |
| 503 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | |
| 504 EXPECT_STREQ("click", element.innerText().utf8().data()); | |
| 505 } | |
| 506 | |
| 507 #if OS(ANDROID) | |
| 508 TEST_F(SelectPopupMenuTest, DISABLED_PopupListBoxWithOverlayScrollbarEnabled) | |
| 509 #else | |
| 510 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarEnabled) | |
| 511 #endif | |
| 512 { | |
| 513 Settings::setMockScrollbarsEnabled(true); | |
| 514 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | |
| 515 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
| 516 registerMockedURLLoad("select_rtl.html"); | |
| 517 loadFrame(mainFrame(), "select_rtl.html"); | |
| 518 | |
| 519 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 520 m_popupMenuClient.setListSize(30); | |
| 521 | |
| 522 showPopup(); | |
| 523 PopupContainer* container = webView()->selectPopup(); | |
| 524 PopupListBox* listBox = container->listBox(); | |
| 525 | |
| 526 EXPECT_EQ(container->width(), listBox->contentsSize().width() + 2); | |
| 527 Settings::setMockScrollbarsEnabled(false); | |
| 528 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); | |
| 529 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
| 530 } | |
| 531 | |
| 532 #if OS(ANDROID) | |
| 533 TEST_F(SelectPopupMenuTest, DISABLED_PopupListBoxWithOverlayScrollbarDisabled) | |
| 534 #else | |
| 535 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarDisabled) | |
| 536 #endif | |
| 537 { | |
| 538 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
| 539 registerMockedURLLoad("select_rtl.html"); | |
| 540 loadFrame(mainFrame(), "select_rtl.html"); | |
| 541 | |
| 542 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
| 543 m_popupMenuClient.setListSize(30); | |
| 544 | |
| 545 showPopup(); | |
| 546 PopupContainer* container = webView()->selectPopup(); | |
| 547 PopupListBox* listBox = container->listBox(); | |
| 548 | |
| 549 EXPECT_EQ(container->width(), listBox->contentsSize().width() + ScrollbarThe
me::theme()->scrollbarThickness() + 2); | |
| 550 } | |
| 551 | |
| 552 class SelectPopupMenuStyleTest : public testing::Test { | |
| 553 public: | |
| 554 SelectPopupMenuStyleTest() | |
| 555 : baseURL("http://www.test.com/") | |
| 556 { | |
| 557 } | |
| 558 | |
| 559 protected: | |
| 560 virtual void SetUp() OVERRIDE | |
| 561 { | |
| 562 m_helper.initialize(false, 0, &m_webviewClient); | |
| 563 } | |
| 564 | |
| 565 virtual void TearDown() OVERRIDE | |
| 566 { | |
| 567 Platform::current()->unitTestSupport()->unregisterAllMockedURLs(); | |
| 568 } | |
| 569 | |
| 570 // Returns true if there currently is a select popup in the WebView. | |
| 571 bool popupOpen() const { return webView()->selectPopup(); } | |
| 572 | |
| 573 void registerMockedURLLoad(const std::string& fileName) | |
| 574 { | |
| 575 URLTestHelpers::registerMockedURLLoad(toKURL(baseURL + fileName), WebStr
ing::fromUTF8(fileName.c_str()), WebString::fromUTF8("popup/"), WebString::fromU
TF8("text/html")); | |
| 576 } | |
| 577 | |
| 578 void loadFrame(WebFrame* frame, const std::string& fileName) | |
| 579 { | |
| 580 FrameTestHelpers::loadFrame(frame, baseURL + fileName); | |
| 581 } | |
| 582 | |
| 583 WebViewImpl* webView() const { return m_helper.webViewImpl(); } | |
| 584 WebLocalFrameImpl* mainFrame() const { return m_helper.webViewImpl()->mainFr
ameImpl(); } | |
| 585 | |
| 586 protected: | |
| 587 PopupTestWebViewClient m_webviewClient; | |
| 588 RefPtr<PopupMenu> m_popupMenu; | |
| 589 std::string baseURL; | |
| 590 | |
| 591 private: | |
| 592 FrameTestHelpers::WebViewHelper m_helper; | |
| 593 }; | |
| 594 | |
| 595 #if OS(MACOSX) || OS(ANDROID) | |
| 596 TEST_F(SelectPopupMenuStyleTest, DISABLED_PopupListBoxRTLRowWidth) | |
| 597 #else | |
| 598 TEST_F(SelectPopupMenuStyleTest, PopupListBoxRTLRowWidth) | |
| 599 #endif | |
| 600 { | |
| 601 registerMockedURLLoad("select_rtl_width.html"); | |
| 602 loadFrame(mainFrame(), "select_rtl_width.html"); | |
| 603 HTMLSelectElement* select = toHTMLSelectElement(mainFrame()->frame()->docume
nt()->focusedElement()); | |
| 604 RenderMenuList* menuList = toRenderMenuList(select->renderer()); | |
| 605 ASSERT(menuList); | |
| 606 menuList->showPopup(); | |
| 607 ASSERT(popupOpen()); | |
| 608 PopupListBox* listBox = webView()->selectPopup()->listBox(); | |
| 609 int ltrWidth = listBox->getRowBaseWidth(0); | |
| 610 int rtlWidth = listBox->getRowBaseWidth(1); | |
| 611 EXPECT_LT(rtlWidth, ltrWidth); | |
| 612 } | |
| 613 | |
| 614 } // namespace | |
| OLD | NEW |