Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(110)

Side by Side Diff: Source/web/tests/PopupMenuTest.cpp

Issue 341543002: Reland 176261: Fix for select PopupMenuList appearance in rtl mode with overlay-scrollbar enabled. (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@master
Patch Set: Created 6 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/web/PopupListBox.cpp ('k') | Source/web/tests/data/popup/select_rtl.html » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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
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"
36 #include "core/html/HTMLSelectElement.h" 37 #include "core/html/HTMLSelectElement.h"
37 #include "core/page/EventHandler.h" 38 #include "core/page/EventHandler.h"
38 #include "platform/KeyboardCodes.h" 39 #include "platform/KeyboardCodes.h"
39 #include "platform/PlatformMouseEvent.h" 40 #include "platform/PlatformMouseEvent.h"
40 #include "platform/PopupMenu.h" 41 #include "platform/PopupMenu.h"
41 #include "platform/PopupMenuClient.h" 42 #include "platform/PopupMenuClient.h"
42 #include "platform/graphics/Color.h" 43 #include "platform/graphics/Color.h"
44 #include "platform/scroll/ScrollbarTheme.h"
43 #include "public/platform/Platform.h" 45 #include "public/platform/Platform.h"
44 #include "public/platform/WebScreenInfo.h" 46 #include "public/platform/WebScreenInfo.h"
45 #include "public/platform/WebString.h" 47 #include "public/platform/WebString.h"
46 #include "public/platform/WebURL.h" 48 #include "public/platform/WebURL.h"
47 #include "public/platform/WebURLRequest.h" 49 #include "public/platform/WebURLRequest.h"
48 #include "public/platform/WebURLResponse.h" 50 #include "public/platform/WebURLResponse.h"
49 #include "public/platform/WebUnitTestSupport.h" 51 #include "public/platform/WebUnitTestSupport.h"
50 #include "public/web/WebDocument.h" 52 #include "public/web/WebDocument.h"
51 #include "public/web/WebElement.h" 53 #include "public/web/WebElement.h"
52 #include "public/web/WebFrame.h" 54 #include "public/web/WebFrame.h"
53 #include "public/web/WebFrameClient.h" 55 #include "public/web/WebFrameClient.h"
54 #include "public/web/WebInputEvent.h" 56 #include "public/web/WebInputEvent.h"
55 #include "public/web/WebSettings.h" 57 #include "public/web/WebSettings.h"
56 #include "public/web/WebView.h" 58 #include "public/web/WebView.h"
57 #include "public/web/WebViewClient.h" 59 #include "public/web/WebViewClient.h"
58 #include "v8.h" 60 #include "v8.h"
59 #include "web/PopupContainer.h" 61 #include "web/PopupContainer.h"
62 #include "web/PopupListBox.h"
60 #include "web/PopupMenuChromium.h" 63 #include "web/PopupMenuChromium.h"
61 #include "web/WebLocalFrameImpl.h" 64 #include "web/WebLocalFrameImpl.h"
62 #include "web/WebPopupMenuImpl.h" 65 #include "web/WebPopupMenuImpl.h"
63 #include "web/WebViewImpl.h" 66 #include "web/WebViewImpl.h"
64 #include "web/tests/FrameTestHelpers.h" 67 #include "web/tests/FrameTestHelpers.h"
65 #include "web/tests/URLTestHelpers.h" 68 #include "web/tests/URLTestHelpers.h"
66 #include <gtest/gtest.h> 69 #include <gtest/gtest.h>
67 70
68 using namespace WebCore; 71 using namespace WebCore;
69 using namespace blink; 72 using namespace blink;
70 using blink::URLTestHelpers::toKURL; 73 using blink::URLTestHelpers::toKURL;
71 74
72 namespace { 75 namespace {
73 76
74 class TestPopupMenuClient : public PopupMenuClient { 77 class TestPopupMenuClient : public PopupMenuClient {
75 public: 78 public:
76 // Item at index 0 is selected by default. 79 // Item at index 0 is selected by default.
77 TestPopupMenuClient() : m_selectIndex(0), m_node(0) { } 80 TestPopupMenuClient() : m_selectIndex(0), m_node(0), m_listSize(10) { }
78 virtual ~TestPopupMenuClient() {} 81 virtual ~TestPopupMenuClient() {}
79 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) 82 virtual void valueChanged(unsigned listIndex, bool fireEvents = true)
80 { 83 {
81 m_selectIndex = listIndex; 84 m_selectIndex = listIndex;
82 if (m_node) { 85 if (m_node) {
83 HTMLSelectElement* select = toHTMLSelectElement(m_node); 86 HTMLSelectElement* select = toHTMLSelectElement(m_node);
84 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f ireEvents); 87 select->optionSelectedByUser(select->listToOptionIndex(listIndex), f ireEvents);
85 } 88 }
86 } 89 }
87 virtual void selectionChanged(unsigned, bool) {} 90 virtual void selectionChanged(unsigned, bool) {}
(...skipping 16 matching lines...) Expand all
104 fontDescription.setComputedSize(12.0); 107 fontDescription.setComputedSize(12.0);
105 Font font(fontDescription); 108 Font font(fontDescription);
106 font.update(nullptr); 109 font.update(nullptr);
107 return PopupMenuStyle(Color::black, Color::white, font, true, false, Len gth(), TextDirection(), false /* has text direction override */); 110 return PopupMenuStyle(Color::black, Color::white, font, true, false, Len gth(), TextDirection(), false /* has text direction override */);
108 } 111 }
109 virtual PopupMenuStyle menuStyle() const { return itemStyle(0); } 112 virtual PopupMenuStyle menuStyle() const { return itemStyle(0); }
110 virtual int clientInsetLeft() const { return 0; } 113 virtual int clientInsetLeft() const { return 0; }
111 virtual int clientInsetRight() const { return 0; } 114 virtual int clientInsetRight() const { return 0; }
112 virtual LayoutUnit clientPaddingLeft() const { return 0; } 115 virtual LayoutUnit clientPaddingLeft() const { return 0; }
113 virtual LayoutUnit clientPaddingRight() const { return 0; } 116 virtual LayoutUnit clientPaddingRight() const { return 0; }
114 virtual int listSize() const { return 10; } 117 virtual int listSize() const { return m_listSize; }
115 virtual int selectedIndex() const { return m_selectIndex; } 118 virtual int selectedIndex() const { return m_selectIndex; }
116 virtual void popupDidHide() { } 119 virtual void popupDidHide() { }
117 virtual bool itemIsSeparator(unsigned listIndex) const { return false; } 120 virtual bool itemIsSeparator(unsigned listIndex) const { return false; }
118 virtual bool itemIsLabel(unsigned listIndex) const { return false; } 121 virtual bool itemIsLabel(unsigned listIndex) const { return false; }
119 virtual bool itemIsSelected(unsigned listIndex) const { return listIndex == m_selectIndex; } 122 virtual bool itemIsSelected(unsigned listIndex) const { return listIndex == m_selectIndex; }
120 virtual bool valueShouldChangeOnHotTrack() const { return false; } 123 virtual bool valueShouldChangeOnHotTrack() const { return false; }
121 virtual void setTextFromItem(unsigned listIndex) { } 124 virtual void setTextFromItem(unsigned listIndex) { }
122 125
123 virtual FontSelector* fontSelector() const { return 0; } 126 virtual FontSelector* fontSelector() const { return 0; }
124 virtual HostWindow* hostWindow() const { return 0; } 127 virtual HostWindow* hostWindow() const { return 0; }
125 128
126 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrie ntation, ScrollbarControlSize) { return nullptr; } 129 virtual PassRefPtr<Scrollbar> createScrollbar(ScrollableArea*, ScrollbarOrie ntation, ScrollbarControlSize) { return nullptr; }
127 130
128 void setDisabledIndex(unsigned index) { m_disabledIndexSet.insert(index); } 131 void setDisabledIndex(unsigned index) { m_disabledIndexSet.insert(index); }
129 void setFocusedNode(Node* node) { m_node = node; } 132 void setFocusedNode(Node* node) { m_node = node; }
133 void setListSize(int listSize) { m_listSize = listSize; }
130 134
131 private: 135 private:
132 unsigned m_selectIndex; 136 unsigned m_selectIndex;
133 std::set<unsigned> m_disabledIndexSet; 137 std::set<unsigned> m_disabledIndexSet;
134 Node* m_node; 138 Node* m_node;
139 int m_listSize;
135 }; 140 };
136 141
137 class TestWebWidgetClient : public WebWidgetClient { 142 class TestWebWidgetClient : public WebWidgetClient {
138 public: 143 public:
139 ~TestWebWidgetClient() { } 144 ~TestWebWidgetClient() { }
140 }; 145 };
141 146
142 class TestWebPopupMenuImpl : public WebPopupMenuImpl { 147 class TestWebPopupMenuImpl : public WebPopupMenuImpl {
143 public: 148 public:
144 static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client) 149 static PassRefPtr<TestWebPopupMenuImpl> create(WebWidgetClient* client)
(...skipping 346 matching lines...) Expand 10 before | Expand all | Expand 10 after
491 int menuItemHeight = webView()->selectPopup()->menuItemHeight(); 496 int menuItemHeight = webView()->selectPopup()->menuItemHeight();
492 // menuItemHeight * 1.5 means the Y position on the item at index 1. 497 // menuItemHeight * 1.5 means the Y position on the item at index 1.
493 IntPoint row1Point(2, menuItemHeight * 1.5); 498 IntPoint row1Point(2, menuItemHeight * 1.5);
494 simulateLeftMouseDownEvent(row1Point); 499 simulateLeftMouseDownEvent(row1Point);
495 simulateLeftMouseUpEvent(row1Point); 500 simulateLeftMouseUpEvent(row1Point);
496 501
497 WebElement element = webView()->mainFrame()->document().getElementById("mess age"); 502 WebElement element = webView()->mainFrame()->document().getElementById("mess age");
498 EXPECT_STREQ("click", element.innerText().utf8().data()); 503 EXPECT_STREQ("click", element.innerText().utf8().data());
499 } 504 }
500 505
506 #if OS(ANDROID)
507 TEST_F(SelectPopupMenuTest, DISABLED_PopupListBoxWithOverlayScrollbarEnabled)
508 #else
509 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarEnabled)
510 #endif
511 {
512 Settings::setMockScrollbarsEnabled(true);
513 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(true);
514 EXPECT_TRUE(ScrollbarTheme::theme()->usesOverlayScrollbars());
515 registerMockedURLLoad("select_rtl.html");
516 loadFrame(mainFrame(), "select_rtl.html");
517
518 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl ement());
519 m_popupMenuClient.setListSize(30);
520
521 showPopup();
522 PopupContainer* container = webView()->selectPopup();
523 PopupListBox* listBox = container->listBox();
524
525 EXPECT_EQ(container->width(), listBox->contentsSize().width() + 2);
526 Settings::setMockScrollbarsEnabled(false);
527 RuntimeEnabledFeatures::setOverlayScrollbarsEnabled(false);
528 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars());
529 }
530
531 #if OS(ANDROID)
532 TEST_F(SelectPopupMenuTest, DISABLED_PopupListBoxWithOverlayScrollbarDisabled)
533 #else
534 TEST_F(SelectPopupMenuTest, PopupListBoxWithOverlayScrollbarDisabled)
535 #endif
536 {
537 EXPECT_FALSE(ScrollbarTheme::theme()->usesOverlayScrollbars());
538 registerMockedURLLoad("select_rtl.html");
539 loadFrame(mainFrame(), "select_rtl.html");
540
541 m_popupMenuClient.setFocusedNode(mainFrame()->frame()->document()->focusedEl ement());
542 m_popupMenuClient.setListSize(30);
543
544 showPopup();
545 PopupContainer* container = webView()->selectPopup();
546 PopupListBox* listBox = container->listBox();
547
548 EXPECT_EQ(container->width(), listBox->contentsSize().width() + ScrollbarThe me::theme()->scrollbarThickness() + 2);
549 }
550
501 } // namespace 551 } // namespace
OLDNEW
« no previous file with comments | « Source/web/PopupListBox.cpp ('k') | Source/web/tests/data/popup/select_rtl.html » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698