| OLD | NEW |
| 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2014 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "config.h" | 5 #include "config.h" |
| 6 #include "web/ExternalPopupMenu.h" | 6 #include "web/ExternalPopupMenu.h" |
| 7 | 7 |
| 8 #include "platform/PopupMenu.h" | 8 #include "platform/PopupMenu.h" |
| 9 #include "platform/PopupMenuClient.h" | 9 #include "platform/PopupMenuClient.h" |
| 10 #include "public/web/WebPopupMenuInfo.h" | 10 #include "public/web/WebPopupMenuInfo.h" |
| 11 #include <gtest/gtest.h> | 11 #include <gtest/gtest.h> |
| 12 | 12 |
| 13 using namespace blink; | 13 using namespace blink; |
| 14 | 14 |
| 15 namespace { | 15 namespace { |
| 16 | 16 |
| 17 const size_t kListSize = 7; | 17 const size_t kListSize = 7; |
| 18 | 18 |
| 19 class TestPopupMenuClient : public PopupMenuClient { | 19 class TestPopupMenuClient : public PopupMenuClient { |
| 20 public: | 20 public: |
| 21 TestPopupMenuClient() : m_listSize(0) { } | 21 TestPopupMenuClient() : m_listSize(0) { } |
| 22 virtual ~TestPopupMenuClient() { } | 22 virtual ~TestPopupMenuClient() { } |
| 23 | 23 |
| 24 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRI
DE { } | 24 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) overri
de { } |
| 25 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) OV
ERRIDE { } | 25 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) ov
erride { } |
| 26 virtual void selectionCleared() OVERRIDE { } | 26 virtual void selectionCleared() override { } |
| 27 | 27 |
| 28 virtual String itemText(unsigned listIndex) const OVERRIDE { return emptyStr
ing(); } | 28 virtual String itemText(unsigned listIndex) const override { return emptyStr
ing(); } |
| 29 virtual String itemToolTip(unsigned listIndex) const OVERRIDE { return empty
String(); } | 29 virtual String itemToolTip(unsigned listIndex) const override { return empty
String(); } |
| 30 virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE { re
turn emptyString(); } | 30 virtual String itemAccessibilityText(unsigned listIndex) const override { re
turn emptyString(); } |
| 31 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE { return true;
} | 31 virtual bool itemIsEnabled(unsigned listIndex) const override { return true;
} |
| 32 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE | 32 virtual PopupMenuStyle itemStyle(unsigned listIndex) const override |
| 33 { | 33 { |
| 34 FontDescription fontDescription; | 34 FontDescription fontDescription; |
| 35 fontDescription.setComputedSize(12.0); | 35 fontDescription.setComputedSize(12.0); |
| 36 Font font(fontDescription); | 36 Font font(fontDescription); |
| 37 font.update(nullptr); | 37 font.update(nullptr); |
| 38 bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNon
eIndexSet.end(); | 38 bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNon
eIndexSet.end(); |
| 39 return PopupMenuStyle(Color::black, Color::white, font, true, displayNon
e, Length(), TextDirection(), false); | 39 return PopupMenuStyle(Color::black, Color::white, font, true, displayNon
e, Length(), TextDirection(), false); |
| 40 } | 40 } |
| 41 virtual PopupMenuStyle menuStyle() const OVERRIDE { return itemStyle(0); } | 41 virtual PopupMenuStyle menuStyle() const override { return itemStyle(0); } |
| 42 virtual LayoutUnit clientPaddingLeft() const OVERRIDE { return 0; } | 42 virtual LayoutUnit clientPaddingLeft() const override { return 0; } |
| 43 virtual LayoutUnit clientPaddingRight() const OVERRIDE { return 0; } | 43 virtual LayoutUnit clientPaddingRight() const override { return 0; } |
| 44 virtual int listSize() const OVERRIDE { return m_listSize; } | 44 virtual int listSize() const override { return m_listSize; } |
| 45 virtual int selectedIndex() const OVERRIDE { return 0; } | 45 virtual int selectedIndex() const override { return 0; } |
| 46 virtual void popupDidHide() OVERRIDE { } | 46 virtual void popupDidHide() override { } |
| 47 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE { return fal
se;} | 47 virtual bool itemIsSeparator(unsigned listIndex) const override { return fal
se;} |
| 48 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE { return false;
} | 48 virtual bool itemIsLabel(unsigned listIndex) const override { return false;
} |
| 49 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE { return list
Index == 0;} | 49 virtual bool itemIsSelected(unsigned listIndex) const override { return list
Index == 0;} |
| 50 virtual void setTextFromItem(unsigned listIndex) OVERRIDE { } | 50 virtual void setTextFromItem(unsigned listIndex) override { } |
| 51 virtual bool multiple() const OVERRIDE { return false; } | 51 virtual bool multiple() const override { return false; } |
| 52 | 52 |
| 53 void setListSize(size_t size) { m_listSize = size; } | 53 void setListSize(size_t size) { m_listSize = size; } |
| 54 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } | 54 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde
x); } |
| 55 private: | 55 private: |
| 56 size_t m_listSize; | 56 size_t m_listSize; |
| 57 std::set<unsigned> m_displayNoneIndexSet; | 57 std::set<unsigned> m_displayNoneIndexSet; |
| 58 }; | 58 }; |
| 59 | 59 |
| 60 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { | 60 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test { |
| 61 public: | 61 public: |
| 62 ExternalPopupMenuDisplayNoneItemsTest() { } | 62 ExternalPopupMenuDisplayNoneItemsTest() { } |
| 63 | 63 |
| 64 protected: | 64 protected: |
| 65 virtual void SetUp() OVERRIDE | 65 virtual void SetUp() override |
| 66 { | 66 { |
| 67 m_popupMenuClient.setListSize(kListSize); | 67 m_popupMenuClient.setListSize(kListSize); |
| 68 | 68 |
| 69 // Set the 4th an 5th items to have "display: none" property | 69 // Set the 4th an 5th items to have "display: none" property |
| 70 m_popupMenuClient.setDisplayNoneIndex(3); | 70 m_popupMenuClient.setDisplayNoneIndex(3); |
| 71 m_popupMenuClient.setDisplayNoneIndex(4); | 71 m_popupMenuClient.setDisplayNoneIndex(4); |
| 72 } | 72 } |
| 73 | 73 |
| 74 TestPopupMenuClient m_popupMenuClient; | 74 TestPopupMenuClient m_popupMenuClient; |
| 75 }; | 75 }; |
| (...skipping 11 matching lines...) Expand all Loading... |
| 87 // and vice-versa. | 87 // and vice-versa. |
| 88 EXPECT_EQ(4, ExternalPopupMenu::toExternalPopupMenuItemIndex(6, m_popupMenuC
lient)); | 88 EXPECT_EQ(4, ExternalPopupMenu::toExternalPopupMenuItemIndex(6, m_popupMenuC
lient)); |
| 89 EXPECT_EQ(6, ExternalPopupMenu::toPopupMenuItemIndex(4, m_popupMenuClient)); | 89 EXPECT_EQ(6, ExternalPopupMenu::toPopupMenuItemIndex(4, m_popupMenuClient)); |
| 90 | 90 |
| 91 // Invalid index, methods should return -1. | 91 // Invalid index, methods should return -1. |
| 92 EXPECT_EQ(-1, ExternalPopupMenu::toExternalPopupMenuItemIndex(8, m_popupMenu
Client)); | 92 EXPECT_EQ(-1, ExternalPopupMenu::toExternalPopupMenuItemIndex(8, m_popupMenu
Client)); |
| 93 EXPECT_EQ(-1, ExternalPopupMenu::toPopupMenuItemIndex(8, m_popupMenuClient))
; | 93 EXPECT_EQ(-1, ExternalPopupMenu::toPopupMenuItemIndex(8, m_popupMenuClient))
; |
| 94 } | 94 } |
| 95 | 95 |
| 96 } // namespace | 96 } // namespace |
| OLD | NEW |