diff options
author | Jim Raykowski <raykowj@gmail.com> | 2023-01-14 12:06:10 -0900 |
---|---|---|
committer | Xisco Fauli <xiscofauli@libreoffice.org> | 2023-02-21 20:20:03 +0000 |
commit | 88e29df0c216c300b9388ee2822003da2bee8679 (patch) | |
tree | bc54289b1975d9c192ea34246cbd4e526a7983c3 | |
parent | b05104facac18f40f34043be304f616530fc3a22 (diff) |
tdf#152921 add uitest
Change-Id: I6d3e6d8503c23549b04f5aaace6a90de9f3ced5e
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/145522
Tested-by: Jenkins
Reviewed-by: Xisco Fauli <xiscofauli@libreoffice.org>
-rw-r--r-- | include/sfx2/sidebar/TabBar.hxx | 2 | ||||
-rw-r--r-- | sfx2/Library_sfx.mk | 1 | ||||
-rw-r--r-- | sfx2/source/sidebar/TabBar.cxx | 9 | ||||
-rw-r--r-- | sfx2/source/sidebar/uiobject.cxx | 61 | ||||
-rw-r--r-- | sfx2/source/sidebar/uiobject.hxx | 32 | ||||
-rw-r--r-- | sw/qa/uitest/sidebar/tdf152921.py | 70 |
6 files changed, 175 insertions, 0 deletions
diff --git a/include/sfx2/sidebar/TabBar.hxx b/include/sfx2/sidebar/TabBar.hxx index fcbced33fa98..30da7852706f 100644 --- a/include/sfx2/sidebar/TabBar.hxx +++ b/include/sfx2/sidebar/TabBar.hxx @@ -39,6 +39,7 @@ class SidebarController; */ class TabBar final : public InterimItemWindow { + friend class TabBarUIObject; public: /** DeckMenuData has entries for display name, and a flag: - isCurrentDeck for the deck selection data @@ -85,6 +86,7 @@ public: /// Enables/Disables the menu button. Used by LoKit. void EnableMenuButton(const bool bEnable); + virtual FactoryFunction GetUITestFactory() const override; private: css::uno::Reference<css::frame::XFrame> mxFrame; diff --git a/sfx2/Library_sfx.mk b/sfx2/Library_sfx.mk index 7b1dee935ff3..72f6bbaa9f0c 100644 --- a/sfx2/Library_sfx.mk +++ b/sfx2/Library_sfx.mk @@ -287,6 +287,7 @@ $(eval $(call gb_Library_add_exception_objects,sfx,\ sfx2/source/sidebar/TitleBar \ sfx2/source/sidebar/Theme \ sfx2/source/sidebar/Tools \ + sfx2/source/sidebar/uiobject\ sfx2/source/sidebar/UnoPanel \ sfx2/source/sidebar/UnoPanels \ sfx2/source/sidebar/UnoDeck \ diff --git a/sfx2/source/sidebar/TabBar.cxx b/sfx2/source/sidebar/TabBar.cxx index bd73322f9496..6b77096898c7 100644 --- a/sfx2/source/sidebar/TabBar.cxx +++ b/sfx2/source/sidebar/TabBar.cxx @@ -35,6 +35,8 @@ #include <svtools/acceleratorexecute.hxx> #include <osl/diagnose.h> +#include "uiobject.hxx" + using namespace css; using namespace css::uno; @@ -58,6 +60,8 @@ TabBar::TabBar(vcl::Window* pParentWindow, , maPopupMenuProvider(std::move(aPopupMenuProvider)) , pParentSidebarController(rParentSidebarController) { + set_id("TabBar"); // for uitest + InitControlBase(mxMenuButton.get()); mxTempToplevel->move(mxContents.get(), m_xContainer.get()); @@ -378,6 +382,11 @@ void TabBar::EnableMenuButton(const bool bEnable) mxMenuButton->set_sensitive(bEnable); } +FactoryFunction TabBar::GetUITestFactory() const +{ + return TabBarUIObject::create; +} + } // end of namespace sfx2::sidebar /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/sidebar/uiobject.cxx b/sfx2/source/sidebar/uiobject.cxx new file mode 100644 index 000000000000..13c21d2220b5 --- /dev/null +++ b/sfx2/source/sidebar/uiobject.cxx @@ -0,0 +1,61 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include "uiobject.hxx" +#include <sfx2/sidebar/SidebarController.hxx> + +namespace sfx2::sidebar +{ +TabBarUIObject::TabBarUIObject(const VclPtr<TabBar>& xTabBar) + : WindowUIObject(xTabBar) + , mxTabBar(xTabBar) +{ +} + +StringMap TabBarUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + OUString rsHighlightedTabsIds; + for (auto const& item : mxTabBar->maItems) + { + if (item->mxButton->get_item_active("toggle")) + { + if (!rsHighlightedTabsIds.isEmpty()) + rsHighlightedTabsIds += ","; + rsHighlightedTabsIds += item->msDeckId; + } + } + aMap["HighlightedTabsIds"] = rsHighlightedTabsIds; + return aMap; +} + +void TabBarUIObject::execute(const OUString& rAction, const StringMap& rParameters) +{ + if (rAction == "CLICK") + { + if (rParameters.find("POS") != rParameters.end()) + mxTabBar->pParentSidebarController->OpenThenToggleDeck( + mxTabBar->GetDeckIdForIndex(rParameters.find("POS")->second.toInt32())); + } + else + WindowUIObject::execute(rAction, rParameters); +} + +std::unique_ptr<UIObject> TabBarUIObject::create(vcl::Window* pWindow) +{ + TabBar* pTabBar = dynamic_cast<TabBar*>(pWindow); + assert(pTabBar); + return std::unique_ptr<UIObject>(new TabBarUIObject(pTabBar)); +} + +OUString TabBarUIObject::get_name() const { return "TabBarUIObject"; } + +} // namespace sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sfx2/source/sidebar/uiobject.hxx b/sfx2/source/sidebar/uiobject.hxx new file mode 100644 index 000000000000..8c7ae5eaabdb --- /dev/null +++ b/sfx2/source/sidebar/uiobject.hxx @@ -0,0 +1,32 @@ +/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */ +/* + * This file is part of the LibreOffice project. + * + * This Source Code Form is subject to the terms of the Mozilla Public + * License, v. 2.0. If a copy of the MPL was not distributed with this + * file, You can obtain one at http://mozilla.org/MPL/2.0/. + */ + +#include <vcl/uitest/uiobject.hxx> +#include <sfx2/sidebar/TabBar.hxx> + +namespace sfx2::sidebar +{ +class TabBarUIObject : public WindowUIObject +{ + VclPtr<sfx2::sidebar::TabBar> mxTabBar; + + virtual OUString get_name() const override; + +public: + TabBarUIObject(const VclPtr<TabBar>& xTabBar); + + virtual void execute(const OUString& rAction, const StringMap& rParameters) override; + virtual StringMap get_state() override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); +}; + +} // namespace sidebar + +/* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/sw/qa/uitest/sidebar/tdf152921.py b/sw/qa/uitest/sidebar/tdf152921.py new file mode 100644 index 000000000000..a313343f5690 --- /dev/null +++ b/sw/qa/uitest/sidebar/tdf152921.py @@ -0,0 +1,70 @@ +# -*- tab-width: 4; indent-tabs-mode: nil; py-indent-offset: 4 -*- +# +# This file is part of the LibreOffice project. +# +# This Source Code Form is subject to the terms of the Mozilla Public +# License, v. 2.0. If a copy of the MPL was not distributed with this +# file, You can obtain one at http://mozilla.org/MPL/2.0/. +# + +from uitest.framework import UITestCase +from libreoffice.uno.propertyvalue import mkPropertyValues +from uitest.uihelper.common import get_state_as_dict + +class tdf152921(UITestCase): + + def test_tdf152921(self): + with self.ui_test.create_doc_in_start_center("writer"): + xWriterEdit = self.xUITest.getTopFocusWindow().getChild("writer_edit") + + # open the sidebar if need, it should already be open on a clean run + if 'TabBar' not in xWriterEdit.Children: + self.xUITest.executeCommand(".uno:Sidebar") + + xTabBar = xWriterEdit.getChild('TabBar') + + # make sure only the tabbar is visible, no deck + xDeckTitleToolBar = xWriterEdit.getChild('toolbar') + xDeckTitleToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) + # tabbar is visible, deck is not + # without the patch this assert would fail, a tab would be highlighted + self.assertFalse(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + + # open a panel and assert that a tab is highlighted, also assert that only one tab is + # highlighted, only a single tab should ever be highlighted + xWriterEdit.executeAction("SIDEBAR", mkPropertyValues({"PANEL": "TextPropertyPanel"})) + self.assertTrue(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + self.assertEqual(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'].split(",")), 1) + + # click on the 'Close Sidebar Deck' button in the deck title tool bar + xDeckTitleToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) + # without the patch this assert would fail, a tab would be highlighted + self.assertFalse(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + + # open a deck by simulating a click on a tab in the tabbar + xTabBar.executeAction("CLICK", mkPropertyValues({"POS": "4"})) + self.assertTrue(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + self.assertEqual(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'].split(",")), 1) + + # close it by clicking on the same tab + xTabBar.executeAction("CLICK", mkPropertyValues({"POS": "4"})) + # tabbar is visible, deck is not + # without the patch this assert would fail, a tab would be highlighted + self.assertFalse(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + + # open a deck + xTabBar.executeAction("CLICK", mkPropertyValues({"POS": "3"})) + self.assertTrue(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + self.assertEqual(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'].split(",")), 1) + + # open a different deck + xTabBar.executeAction("CLICK", mkPropertyValues({"POS": "1"})) + self.assertTrue(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + self.assertEqual(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'].split(",")), 1) + + # click on the 'Close Sidebar Deck' button + xDeckTitleToolBar.executeAction("CLICK", mkPropertyValues({"POS": "0"})) + # without the patch this assert would fail, a tab would be highlighted + self.assertFalse(len(get_state_as_dict(xTabBar)['HighlightedTabsIds'])) + +# vim: set shiftwidth=4 softtabstop=4 expandtab: |