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

Unified 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 side-by-side diff with in-line comments
Download patch
« no previous file with comments | « Source/web/ExternalPopupMenu.cpp ('k') | Source/web/web.gypi » ('j') | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: Source/web/ExternalPopupMenuTest.cpp
diff --git a/Source/web/ExternalPopupMenuTest.cpp b/Source/web/ExternalPopupMenuTest.cpp
new file mode 100644
index 0000000000000000000000000000000000000000..33a9a0a5af42e792b9a3df6f4a5f40a7d154fe65
--- /dev/null
+++ b/Source/web/ExternalPopupMenuTest.cpp
@@ -0,0 +1,96 @@
+// Copyright (c) 2014 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "config.h"
+#include "web/ExternalPopupMenu.h"
+
+#include "platform/PopupMenu.h"
+#include "platform/PopupMenuClient.h"
+#include "public/web/WebPopupMenuInfo.h"
+#include <gtest/gtest.h>
+
+using namespace blink;
+
+namespace {
+
+const size_t kListSize = 7;
+
+class TestPopupMenuClient : public PopupMenuClient {
+public:
+ TestPopupMenuClient() : m_listSize(0) { }
+ virtual ~TestPopupMenuClient() { }
+
+ virtual void valueChanged(unsigned listIndex, bool fireEvents = true) OVERRIDE { }
+ virtual void selectionChanged(unsigned listIndex, bool fireEvents = true) OVERRIDE { }
+ virtual void selectionCleared() OVERRIDE { }
+
+ virtual String itemText(unsigned listIndex) const OVERRIDE { return emptyString(); }
+ virtual String itemToolTip(unsigned listIndex) const OVERRIDE { return emptyString(); }
+ virtual String itemAccessibilityText(unsigned listIndex) const OVERRIDE { return emptyString(); }
+ virtual bool itemIsEnabled(unsigned listIndex) const OVERRIDE { return true; }
+ virtual PopupMenuStyle itemStyle(unsigned listIndex) const OVERRIDE
+ {
+ FontDescription fontDescription;
+ fontDescription.setComputedSize(12.0);
+ Font font(fontDescription);
+ font.update(nullptr);
+ bool displayNone = m_displayNoneIndexSet.find(listIndex) != m_displayNoneIndexSet.end();
+ return PopupMenuStyle(Color::black, Color::white, font, true, displayNone, Length(), TextDirection(), false);
+ }
+ virtual PopupMenuStyle menuStyle() const OVERRIDE { return itemStyle(0); }
+ virtual LayoutUnit clientPaddingLeft() const OVERRIDE { return 0; }
+ virtual LayoutUnit clientPaddingRight() const OVERRIDE { return 0; }
+ virtual int listSize() const OVERRIDE { return m_listSize; }
+ virtual int selectedIndex() const OVERRIDE { return 0; }
+ virtual void popupDidHide() OVERRIDE { }
+ virtual bool itemIsSeparator(unsigned listIndex) const OVERRIDE { return false;}
+ virtual bool itemIsLabel(unsigned listIndex) const OVERRIDE { return false; }
+ virtual bool itemIsSelected(unsigned listIndex) const OVERRIDE { return listIndex == 0;}
+ virtual void setTextFromItem(unsigned listIndex) OVERRIDE { }
+ virtual bool multiple() const OVERRIDE { return false; }
+
+ void setListSize(size_t size) { m_listSize = size; }
+ void setDisplayNoneIndex(unsigned index) { m_displayNoneIndexSet.insert(index); }
+private:
+ size_t m_listSize;
+ std::set<unsigned> m_displayNoneIndexSet;
+};
+
+class ExternalPopupMenuDisplayNoneItemsTest : public testing::Test {
+public:
+ ExternalPopupMenuDisplayNoneItemsTest() { }
+
+protected:
+ virtual void SetUp() OVERRIDE
+ {
+ m_popupMenuClient.setListSize(kListSize);
+
+ // Set the 4th an 5th items to have "display: none" property
+ m_popupMenuClient.setDisplayNoneIndex(3);
+ m_popupMenuClient.setDisplayNoneIndex(4);
+ }
+
+ TestPopupMenuClient m_popupMenuClient;
+};
+
+TEST_F(ExternalPopupMenuDisplayNoneItemsTest, PopupMenuInfoSizeTest)
+{
+ WebPopupMenuInfo info;
+ ExternalPopupMenu::getPopupMenuInfo(info, m_popupMenuClient);
+ EXPECT_EQ(5U, info.items.size());
+}
+
+TEST_F(ExternalPopupMenuDisplayNoneItemsTest, IndexMappingTest)
+{
+ // 6th indexed item in popupmenu would be the 4th item in ExternalPopupMenu,
+ // and vice-versa.
+ EXPECT_EQ(4, ExternalPopupMenu::toExternalPopupMenuItemIndex(6, m_popupMenuClient));
+ EXPECT_EQ(6, ExternalPopupMenu::toPopupMenuItemIndex(4, m_popupMenuClient));
+
+ // Invalid index, methods should return -1.
+ EXPECT_EQ(-1, ExternalPopupMenu::toExternalPopupMenuItemIndex(8, m_popupMenuClient));
+ EXPECT_EQ(-1, ExternalPopupMenu::toPopupMenuItemIndex(8, m_popupMenuClient));
+}
+
+} // namespace
« 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