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 15 matching lines...) Expand all Loading... |
26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 26 * THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
27 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE | 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. | 28 * OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
29 */ | 29 */ |
30 | 30 |
31 #include "config.h" | 31 #include "config.h" |
32 | 32 |
33 #include "RuntimeEnabledFeatures.h" | 33 #include "RuntimeEnabledFeatures.h" |
34 #include "core/dom/Element.h" | 34 #include "core/dom/Element.h" |
35 #include "core/frame/FrameView.h" | 35 #include "core/frame/FrameView.h" |
36 #include "core/frame/Settings.h" | |
37 #include "core/html/HTMLSelectElement.h" | 36 #include "core/html/HTMLSelectElement.h" |
38 #include "core/page/EventHandler.h" | 37 #include "core/page/EventHandler.h" |
39 #include "platform/KeyboardCodes.h" | 38 #include "platform/KeyboardCodes.h" |
40 #include "platform/PlatformMouseEvent.h" | 39 #include "platform/PlatformMouseEvent.h" |
41 #include "platform/PopupMenu.h" | 40 #include "platform/PopupMenu.h" |
42 #include "platform/PopupMenuClient.h" | 41 #include "platform/PopupMenuClient.h" |
43 #include "platform/graphics/Color.h" | 42 #include "platform/graphics/Color.h" |
44 #include "platform/scroll/ScrollbarTheme.h" | |
45 #include "public/platform/Platform.h" | 43 #include "public/platform/Platform.h" |
46 #include "public/platform/WebScreenInfo.h" | 44 #include "public/platform/WebScreenInfo.h" |
47 #include "public/platform/WebString.h" | 45 #include "public/platform/WebString.h" |
48 #include "public/platform/WebURL.h" | 46 #include "public/platform/WebURL.h" |
49 #include "public/platform/WebURLRequest.h" | 47 #include "public/platform/WebURLRequest.h" |
50 #include "public/platform/WebURLResponse.h" | 48 #include "public/platform/WebURLResponse.h" |
51 #include "public/platform/WebUnitTestSupport.h" | 49 #include "public/platform/WebUnitTestSupport.h" |
52 #include "public/web/WebDocument.h" | 50 #include "public/web/WebDocument.h" |
53 #include "public/web/WebElement.h" | 51 #include "public/web/WebElement.h" |
54 #include "public/web/WebFrame.h" | 52 #include "public/web/WebFrame.h" |
55 #include "public/web/WebFrameClient.h" | 53 #include "public/web/WebFrameClient.h" |
56 #include "public/web/WebInputEvent.h" | 54 #include "public/web/WebInputEvent.h" |
57 #include "public/web/WebSettings.h" | 55 #include "public/web/WebSettings.h" |
58 #include "public/web/WebView.h" | 56 #include "public/web/WebView.h" |
59 #include "public/web/WebViewClient.h" | 57 #include "public/web/WebViewClient.h" |
60 #include "v8.h" | 58 #include "v8.h" |
61 #include "web/PopupContainer.h" | 59 #include "web/PopupContainer.h" |
62 #include "web/PopupListBox.h" | |
63 #include "web/PopupMenuChromium.h" | 60 #include "web/PopupMenuChromium.h" |
64 #include "web/WebLocalFrameImpl.h" | 61 #include "web/WebLocalFrameImpl.h" |
65 #include "web/WebPopupMenuImpl.h" | 62 #include "web/WebPopupMenuImpl.h" |
66 #include "web/WebViewImpl.h" | 63 #include "web/WebViewImpl.h" |
67 #include "web/tests/FrameTestHelpers.h" | 64 #include "web/tests/FrameTestHelpers.h" |
68 #include "web/tests/URLTestHelpers.h" | 65 #include "web/tests/URLTestHelpers.h" |
69 #include <gtest/gtest.h> | 66 #include <gtest/gtest.h> |
70 | 67 |
71 using namespace WebCore; | 68 using namespace WebCore; |
72 using namespace blink; | 69 using namespace blink; |
73 using blink::URLTestHelpers::toKURL; | 70 using blink::URLTestHelpers::toKURL; |
74 | 71 |
75 namespace { | 72 namespace { |
76 | 73 |
77 class TestPopupMenuClient : public PopupMenuClient { | 74 class TestPopupMenuClient : public PopupMenuClient { |
78 public: | 75 public: |
79 // Item at index 0 is selected by default. | 76 // Item at index 0 is selected by default. |
80 TestPopupMenuClient() : m_selectIndex(0), m_node(0), m_listSize(10) { } | 77 TestPopupMenuClient() : m_selectIndex(0), m_node(0) { } |
81 virtual ~TestPopupMenuClient() {} | 78 virtual ~TestPopupMenuClient() {} |
82 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) | 79 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) |
83 { | 80 { |
84 m_selectIndex = listIndex; | 81 m_selectIndex = listIndex; |
85 if (m_node) { | 82 if (m_node) { |
86 HTMLSelectElement* select = toHTMLSelectElement(m_node); | 83 HTMLSelectElement* select = toHTMLSelectElement(m_node); |
87 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f
ireEvents); | 84 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f
ireEvents); |
88 } | 85 } |
89 } | 86 } |
90 virtual void selectionChanged(unsigned, bool) {} | 87 virtual void selectionChanged(unsigned, bool) {} |
(...skipping 16 matching lines...) Expand all Loading... |
107 fontDescription.setComputedSize(12.0); | 104 fontDescription.setComputedSize(12.0); |
108 Font font(fontDescription); | 105 Font font(fontDescription); |
109 font.update(nullptr); | 106 font.update(nullptr); |
110 return PopupMenuStyle(Color::black, Color::white, font, true, false, Len
gth(), TextDirection(), false /* has text direction override */); | 107 return PopupMenuStyle(Color::black, Color::white, font, true, false, Len
gth(), TextDirection(), false /* has text direction override */); |
111 } | 108 } |
112 virtual PopupMenuStyle menuStyle() const { return itemStyle(0); } | 109 virtual PopupMenuStyle menuStyle() const { return itemStyle(0); } |
113 virtual int clientInsetLeft() const { return 0; } | 110 virtual int clientInsetLeft() const { return 0; } |
114 virtual int clientInsetRight() const { return 0; } | 111 virtual int clientInsetRight() const { return 0; } |
115 virtual LayoutUnit clientPaddingLeft() const { return 0; } | 112 virtual LayoutUnit clientPaddingLeft() const { return 0; } |
116 virtual LayoutUnit clientPaddingRight() const { return 0; } | 113 virtual LayoutUnit clientPaddingRight() const { return 0; } |
117 virtual int listSize() const { return m_listSize; } | 114 virtual int listSize() const { return 10; } |
118 virtual int selectedIndex() const { return m_selectIndex; } | 115 virtual int selectedIndex() const { return m_selectIndex; } |
119 virtual void popupDidHide() { } | 116 virtual void popupDidHide() { } |
120 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } | 117 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } |
121 virtual bool itemIsLabel(unsigned listIndex) const { return false; } | 118 virtual bool itemIsLabel(unsigned listIndex) const { return false; } |
122 virtual bool itemIsSelected(unsigned listIndex) const { return listIndex ==
m_selectIndex; } | 119 virtual bool itemIsSelected(unsigned listIndex) const { return listIndex ==
m_selectIndex; } |
123 virtual bool valueShouldChangeOnHotTrack() const { return false; } | 120 virtual bool valueShouldChangeOnHotTrack() const { return false; } |
124 virtual void setTextFromItem(unsigned listIndex) { } | 121 virtual void setTextFromItem(unsigned listIndex) { } |
125 | 122 |
126 virtual FontSelector* fontSelector() const { return 0; } | 123 virtual FontSelector* fontSelector() const { return 0; } |
127 virtual HostWindow* hostWindow() const { return 0; } | 124 virtual HostWindow* hostWindow() const { return 0; } |
128 | 125 |
129 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrie
ntation, ScrollbarControlSize) { return nullptr; } | 126 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrie
ntation, ScrollbarControlSize) { return nullptr; } |
130 | 127 |
131 void setDisabledIndex(unsigned index) { m_disabledIndexSet.insert(index); } | 128 void setDisabledIndex(unsigned index) { m_disabledIndexSet.insert(index); } |
132 void setFocusedNode(Node* node) { m_node = node; } | 129 void setFocusedNode(Node* node) { m_node = node; } |
133 void setListSize(int listSize) { m_listSize = listSize; } | |
134 | 130 |
135 private: | 131 private: |
136 unsigned m_selectIndex; | 132 unsigned m_selectIndex; |
137 std::set<unsigned> m_disabledIndexSet; | 133 std::set<unsigned> m_disabledIndexSet; |
138 Node* m_node; | 134 Node* m_node; |
139 int m_listSize; | |
140 }; | 135 }; |
141 | 136 |
142 class TestWebWidgetClient : public WebWidgetClient { | 137 class TestWebWidgetClient : public WebWidgetClient { |
143 public: | 138 public: |
144 ~TestWebWidgetClient() { } | 139 ~TestWebWidgetClient() { } |
145 }; | 140 }; |
146 | 141 |
147 class TestWebPopupMenuImpl : public WebPopupMenuImpl { | 142 class TestWebPopupMenuImpl : public WebPopupMenuImpl { |
148 public: | 143 public: |
149 static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client) | 144 static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client) |
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
496 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); | 491 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); |
497 // 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. |
498 IntPoint row1Point(2, menuItemHeight * 1.5); | 493 IntPoint row1Point(2, menuItemHeight * 1.5); |
499 simulateLeftMouseDownEvent(row1Point); | 494 simulateLeftMouseDownEvent(row1Point); |
500 simulateLeftMouseUpEvent(row1Point); | 495 simulateLeftMouseUpEvent(row1Point); |
501 | 496 |
502 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); | 497 WebElement element = webView()->mainFrame()->document().getElementById("mess
age"); |
503 EXPECT_STREQ("click", element.innerText().utf8().data()); | 498 EXPECT_STREQ("click", element.innerText().utf8().data()); |
504 } | 499 } |
505 | 500 |
506 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarEnabled) | |
507 { | |
508 Settings::setMockScrollbarsEnabled(true); | |
509 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true); | |
510 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
511 registerMockedURLLoad("select_rtl.html"); | |
512 loadFrame(mainFrame(), "select_rtl.html"); | |
513 | |
514 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
515 m_popupMenuClient.setListSize(30); | |
516 | |
517 showPopup(); | |
518 PopupContainer* container = webView()->selectPopup(); | |
519 PopupListBox* listBox = container->listBox(); | |
520 | |
521 EXPECT_EQ(container->width(), listBox->contentsSize().width() + 2); | |
522 Settings::setMockScrollbarsEnabled(false); | |
523 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false); | |
524 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
525 } | |
526 | |
527 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarDisabled) | |
528 { | |
529 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars()); | |
530 registerMockedURLLoad("select_rtl.html"); | |
531 loadFrame(mainFrame(), "select_rtl.html"); | |
532 | |
533 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl
ement()); | |
534 m_popupMenuClient.setListSize(30); | |
535 | |
536 showPopup(); | |
537 PopupContainer* container = webView()->selectPopup(); | |
538 PopupListBox* listBox = container->listBox(); | |
539 | |
540 EXPECT_EQ(container->width(), listBox->contentsSize().width() + ScrollbarThe
me::theme()->scrollbarThickness() + 2); | |
541 } | |
542 | |
543 } // namespace | 501 } // namespace |
OLD | NEW |