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

Side by Side Diff: Source/web/ExternalPopupMenuTest.cpp

Issue 475723002: Remove blank items from ExternalPopupMenu (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@validityCheck
Patch Set: Rebase Created 6 years, 4 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/ExternalPopupMenu.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
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
3 // found in the LICENSE file.
4
5 #include "config.h"
6 #include "web/ExternalPopupMenu.h"
7
8 #include "platform/PopupMenu.h"
9 #include "platform/PopupMenuClient.h"
10 #include "public/web/WebPopupMenuInfo.h"
11 #include <gtest/gtest.h>
12
13 using namespace blink;
14
15 namespace {
16
17 const size_t kListSize = 7;
18
19 class TestPopupMenuClient : public PopupMenuClient {
20 public:
21 TestPopupMenuClient() : m_listSize(0) { }
22 virtual ~TestPopupMenuClient() { }
23
24 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRI DE { }
25 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) OV ERRIDE { }
26 virtual void selectionCleared() OVERRIDE { }
27
28 virtual String itemText(unsigned listIndex) const OVERRIDE { return emptyStr ing(); }
29 virtual String itemToolTip(unsigned listIndex) const OVERRIDE { return empty String(); }
30 virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE { re turn emptyString(); }
31 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE { return true; }
32 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE
33 {
34 FontDescription fontDescription;
35 fontDescription.setComputedSize(12.0);
36 Font font(fontDescription);
37 font.update(nullptr);
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);
40 }
41 virtual PopupMenuStyle menuStyle() const OVERRIDE { return itemStyle(0); }
42 virtual LayoutUnit clientPaddingLeft() const OVERRIDE { return 0; }
43 virtual LayoutUnit clientPaddingRight() const OVERRIDE { return 0; }
44 virtual int listSize() const OVERRIDE { return m_listSize; }
45 virtual int selectedIndex() const OVERRIDE { return 0; }
46 virtual void popupDidHide() OVERRIDE { }
47 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE { return fal se;}
48 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE { return false; }
49 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE { return list Index == 0;}
50 virtual void setTextFromItem(unsigned listIndex) OVERRIDE { }
51 virtual bool multiple() const OVERRIDE { return false; }
52
53 void setListSize(size_t size) { m_listSize = size; }
54 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde x); }
55 private:
56 size_t m_listSize;
57 std::set<unsigned> m_displayNoneIndexSet;
58 };
59
60 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test {
61 public:
62 ExternalPopupMenuDisplayNoneItemsTest() { }
63
64 protected:
65 virtual void SetUp() OVERRIDE
66 {
67 m_popupMenuClient.setListSize(kListSize);
68
69 // Set the 4th an 5th items to have "display: none" property
70 m_popupMenuClient.setDisplayNoneIndex(3);
71 m_popupMenuClient.setDisplayNoneIndex(4);
72 }
73
74 TestPopupMenuClient m_popupMenuClient;
75 };
76
77 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest)
78 {
79 WebPopupMenuInfo info;
80 ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient);
81 EXPECT_EQ(5U, info.items.size());
82 }
83
84 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, IndexMappingTest)
85 {
86 // 6th indexed item in popupmenu would be the 4th item in ExternalPopupMenu,
87 // and vice-versa.
88 EXPECT_EQ(4, ExternalPopupMenu::toExternalPopupMenuItemIndex(6, m_popupMenuC lient));
89 EXPECT_EQ(6, ExternalPopupMenu::toPopupMenuItemIndex(4, m_popupMenuClient));
90
91 // Invalid index, methods should return -1.
92 EXPECT_EQ(-1, ExternalPopupMenu::toExternalPopupMenuItemIndex(8, m_popupMenu Client));
93 EXPECT_EQ(-1, ExternalPopupMenu::toPopupMenuItemIndex(8, m_popupMenuClient)) ;
94 }
95
96 } // namespace
OLDNEW
« no previous file with comments | « Source/web/ExternalPopupMenu.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698