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

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

Issue 475723002: Remove blank items from ExternalPopupMenu (Closed) Base URL: https://chromium.googlesource.com/chromium/blink.git@validityCheck
Patch Set: Add unit tests 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
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"
tkent 2014/08/21 00:53:33 The main header file for this file is ExternalPopu
spartha 2014/08/21 10:05:44 Done.
6
7 #include "platform/PopupMenu.h"
8
9 #include "platform/PopupMenuClient.h"
10 #include "public/web/WebPopupMenuInfo.h"
11 #include "web/ExternalPopupMenu.h"
12 #include <gtest/gtest.h>
13
14 using namespace blink;
tkent 2014/08/21 00:53:33 See #4 of http://www.chromium.org/blink/coding-sty
spartha 2014/08/21 10:05:44 I have changed the namespace usage pattern. Most o
15
16 namespace {
17
18 const size_t kListSize = 7;
19
20 class TestPopupMenuClient : public PopupMenuClient {
21 public:
22 TestPopupMenuClient() : m_listSize(0) { }
23 virtual ~TestPopupMenuClient() { }
24
25 virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRI DE { }
26 virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) OV ERRIDE { }
27 virtual void selectionCleared() OVERRIDE { }
28
29 virtual String itemText(unsigned listIndex) const OVERRIDE { return emptyStr ing(); }
30 virtual String itemToolTip(unsigned listIndex) const OVERRIDE { return empty String(); }
31 virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE { re turn emptyString(); }
32 virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE { return true; }
33 virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE
34 {
35 FontDescription fontDescription;
36 fontDescription.setComputedSize(12.0);
37 Font font(fontDescription);
38 font.update(nullptr);
39 bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNon eIndexSet.end();
40 return PopupMenuStyle(Color::black, Color::white, font, true, displayNon e, Length(), TextDirection(), false /* has text direction override */);
41 }
42 virtual PopupMenuStyle menuStyle() const OVERRIDE { return itemStyle(0); }
43 virtual LayoutUnit clientPaddingLeft() const OVERRIDE { return 0; }
44 virtual LayoutUnit clientPaddingRight() const OVERRIDE { return 0; }
45 virtual int listSize() const OVERRIDE { return m_listSize; }
46 virtual int selectedIndex() const OVERRIDE { return 0; }
47 virtual void popupDidHide() OVERRIDE { }
48 virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE { return fal se;}
49 virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE { return false; }
50 virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE { return list Index == 0;}
51 virtual void setTextFromItem(unsigned listIndex) OVERRIDE { }
52 virtual bool multiple() const OVERRIDE { return false; }
53
54 void setListSize(size_t size) { m_listSize = size; }
55 void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(inde x); }
56 private:
57 size_t m_listSize;
58 std::set<unsigned> m_displayNoneIndexSet;
59 };
60
61 } // namespace
62
63 namespace blink {
64
65 class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test {
66 public:
67 ExternalPopupMenuDisplayNoneItemsTest() { }
68
69 protected:
70 virtual void SetUp() OVERRIDE
71 {
72 m_popupMenuClient.setListSize(kListSize);
73
74 // Set the 4th an 5th items to have "display: none" property
75 m_popupMenuClient.setDisplayNoneIndex(3);
76 m_popupMenuClient.setDisplayNoneIndex(4);
77 }
78 virtual void TearDown() OVERRIDE { }
tkent 2014/08/21 00:53:33 Remove this. It's unnecessary.
spartha 2014/08/21 10:05:44 Done.
79
80 TestPopupMenuClient m_popupMenuClient;
81 };
82
83 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest)
84 {
85 WebPopupMenuInfo info;
86 ExternalPopupMenu::getPopupMenuInfo(&info, &m_popupMenuClient);
87 EXPECT_EQ(5U, info.items.size());
88 }
89
90 TEST_F(ExternalPopupMenuDisplayNoneItemsTest, IndexMappingTest)
91 {
92 // 6th indexed item in popupmenu would be the 4th item in ExternalPopupMenu,
93 // and vice-versa.
94 EXPECT_EQ(4, ExternalPopupMenu::toExternalPopupMenuItemIndex(6, &m_popupMenu Client));
95 EXPECT_EQ(6, ExternalPopupMenu::toPopupMenuItemIndex(4, &m_popupMenuClient)) ;
96
97 // Invalid index, methods should return -1.
98 EXPECT_EQ(-1, ExternalPopupMenu::toExternalPopupMenuItemIndex(8, &m_popupMen uClient));
99 EXPECT_EQ(-1, ExternalPopupMenu::toPopupMenuItemIndex(8, &m_popupMenuClient) );
100 }
101
102 } // namespace blink
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698