include/vcl/menubtn.hxx | 5 ++ include/vcl/uitest/uiobject.hxx | 23 ++++++++++++ uitest/writer_tests8/customizeDialog.py | 28 ++++++++++++++ vcl/source/control/menubtn.cxx | 12 ++++++ vcl/source/uitest/uiobject.cxx | 60 ++++++++++++++++++++++++++++++++ 5 files changed, 128 insertions(+)
New commits: commit 66ec91730d8b7b416ed6c5e8cf88658baafee91e Author: Ahmed ElShreif <aelshre...@gmail.com> AuthorDate: Tue Jul 28 05:20:47 2020 +0200 Commit: Ahmed ElShreif <aelshre...@gmail.com> CommitDate: Thu Aug 6 03:06:33 2020 +0200 uitest : Add demo for gear button menu in Tools->Customize Change-Id: I3f0596ad044560a424ca6786197c250bff2429bb Reviewed-on: https://gerrit.libreoffice.org/c/core/+/99568 Tested-by: Jenkins Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/uitest/writer_tests8/customizeDialog.py b/uitest/writer_tests8/customizeDialog.py index dfc6ae771e1b..5b6ab664346a 100644 --- a/uitest/writer_tests8/customizeDialog.py +++ b/uitest/writer_tests8/customizeDialog.py @@ -104,4 +104,32 @@ class ConfigureDialog(UITestCase): self.ui_test.close_doc() + def test_gear_button_menu(self): + self.ui_test.create_doc_in_start_center("writer") + + self.ui_test.execute_dialog_through_command(".uno:ConfigureDialog") + def close_dialog(dlg): + CancelBtn = dlg.getChild("cancel") + self.ui_test.close_dialog_through_button(CancelBtn) + + # Open the New Menu Dialog with id = 0 + xDialog = self.xUITest.getTopFocusWindow() + xmenugearbtn=xDialog.getChild("menugearbtn") + def show_dialog0(): + xmenugearbtn.executeAction("OPENFROMLIST", mkPropertyValues({"POS": "0" })) + self.ui_test.execute_blocking_action( action=show_dialog0, dialog_handler=close_dialog) + + # Open the Rename Menu Dialog with id = 2 + xDialog = self.xUITest.getTopFocusWindow() + xmenugearbtn=xDialog.getChild("menugearbtn") + def show_dialog2(): + xmenugearbtn.executeAction("OPENFROMLIST", mkPropertyValues({"POS": "2"})) + self.ui_test.execute_blocking_action( action=show_dialog2, dialog_handler=close_dialog) + + xDialog = self.xUITest.getTopFocusWindow() + xcancBtn = xDialog.getChild("cancel") + self.ui_test.close_dialog_through_button(xcancBtn) + + self.ui_test.close_doc() + # vim: set shiftwidth=4 softtabstop=4 expandtab: commit 8517c19410dde16b951d66a13d0ffa385f877d7a Author: Ahmed ElShreif <aelshre...@gmail.com> AuthorDate: Sat Jul 18 17:56:27 2020 +0200 Commit: Ahmed ElShreif <aelshre...@gmail.com> CommitDate: Thu Aug 6 03:06:19 2020 +0200 uitest : Add support for Menu Button objects This will help us test MenuButton like "gear button menu in Tools->Customize" You can test this type of button by excuting this actions: >>var_name.executeAction("OPENLIST", mkPropertyValues({})) >>var_name.executeAction("CLOSELIST", mkPropertyValues({})) >>var_name.executeAction("OPENFROMLIST", mkPropertyValues({"POS": "0" })) Then you can check on it using this lines: >>get_state_as_dict(var_name)["Label"] Change-Id: I189759d9c32237a9a34ee82cfde9611eedff4f3f Reviewed-on: https://gerrit.libreoffice.org/c/core/+/98996 Tested-by: Jenkins Reviewed-by: Markus Mohrhard <markus.mohrh...@googlemail.com> diff --git a/include/vcl/menubtn.hxx b/include/vcl/menubtn.hxx index 609d3d031aab..ea6916a48629 100644 --- a/include/vcl/menubtn.hxx +++ b/include/vcl/menubtn.hxx @@ -84,6 +84,11 @@ public: void SetActivateHdl( const Link<MenuButton *, void>& rLink ) { maActivateHdl = rLink; } void SetSelectHdl( const Link<MenuButton *, void>& rLink ) { maSelectHdl = rLink; } + + virtual FactoryFunction GetUITestFactory() const override; + + void SetCurItemId(); + }; diff --git a/include/vcl/uitest/uiobject.hxx b/include/vcl/uitest/uiobject.hxx index 1797c9156aba..c5b3f07dbe75 100644 --- a/include/vcl/uitest/uiobject.hxx +++ b/include/vcl/uitest/uiobject.hxx @@ -35,6 +35,7 @@ class SpinButton; class SpinField; class VerticalTabControl; class VclMultiLineEdit; +class MenuButton; class ToolBox; typedef std::map<const OUString, OUString> StringMap; @@ -504,6 +505,28 @@ private: virtual OUString get_name() const override; }; +class MenuButtonUIObject final : public WindowUIObject +{ + VclPtr<MenuButton> mxMenuButton; + +public: + + MenuButtonUIObject(const VclPtr<MenuButton>& xMenuButton); + virtual ~MenuButtonUIObject() override; + + virtual StringMap get_state() override; + + virtual void execute(const OUString& rAction, + const StringMap& rParameters) override; + + static std::unique_ptr<UIObject> create(vcl::Window* pWindow); + +private: + + virtual OUString get_name() const override; +}; + + #endif /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ diff --git a/vcl/source/control/menubtn.cxx b/vcl/source/control/menubtn.cxx index 7402d361f4b8..4acf4ffddc82 100644 --- a/vcl/source/control/menubtn.cxx +++ b/vcl/source/control/menubtn.cxx @@ -24,6 +24,7 @@ #include <vcl/timer.hxx> #include <vcl/menubtn.hxx> #include <vcl/settings.hxx> +#include <vcl/uitest/uiobject.hxx> void MenuButton::ImplInit( vcl::Window* pParent, WinBits nStyle ) { @@ -229,6 +230,17 @@ void MenuButton::SetPopover(Window* pWindow) mpFloatingWindow = pWindow; } + +FactoryFunction MenuButton::GetUITestFactory() const +{ + return MenuButtonUIObject::create; +} + +void MenuButton::SetCurItemId(){ + mnCurItemId = mpMenu->GetCurItemId(); + msCurItemIdent = mpMenu->GetCurItemIdent(); +} + //class MenuToggleButton ---------------------------------------------------- MenuToggleButton::MenuToggleButton( vcl::Window* pParent, WinBits nWinBits ) diff --git a/vcl/source/uitest/uiobject.cxx b/vcl/source/uitest/uiobject.cxx index 806f6ab23e70..1b501e2676e5 100644 --- a/vcl/source/uitest/uiobject.cxx +++ b/vcl/source/uitest/uiobject.cxx @@ -26,6 +26,7 @@ #include <vcl/toolkit/dialog.hxx> #include <vcl/toolkit/field.hxx> #include <vcl/edit.hxx> +#include <vcl/menubtn.hxx> #include <vcl/vclmedit.hxx> #include <vcl/uitest/logger.hxx> #include <uiobject-internal.hxx> @@ -1612,4 +1613,63 @@ std::unique_ptr<UIObject> ToolBoxUIObject::create(vcl::Window* pWindow) return std::unique_ptr<UIObject>(new ToolBoxUIObject(pToolBox)); } +MenuButtonUIObject::MenuButtonUIObject(const VclPtr<MenuButton>& xMenuButton): + WindowUIObject(xMenuButton), + mxMenuButton(xMenuButton) +{ +} + +MenuButtonUIObject::~MenuButtonUIObject() +{ +} + +StringMap MenuButtonUIObject::get_state() +{ + StringMap aMap = WindowUIObject::get_state(); + aMap["Label"] = mxMenuButton->GetDisplayText(); + return aMap; +} + +void MenuButtonUIObject::execute(const OUString& rAction, + const StringMap& rParameters) +{ + if (rAction == "CLICK") + { + mxMenuButton->Check(!mxMenuButton->IsChecked()); + mxMenuButton->Toggle(); + } + else if (rAction == "OPENLIST") + { + mxMenuButton->ExecuteMenu(); + } + else if (rAction == "OPENFROMLIST") + { + auto itr = rParameters.find("POS"); + sal_uInt32 nPos = itr->second.toUInt32(); + + sal_uInt32 nId = mxMenuButton->GetPopupMenu()->GetItemId(nPos); + mxMenuButton->GetPopupMenu()->SetSelectedEntry(nId); + mxMenuButton->SetCurItemId(); + mxMenuButton->Select(); + } + else if (rAction == "CLOSELIST") + { + mxMenuButton->GetPopupMenu()->EndExecute(); + } + else + WindowUIObject::execute(rAction, rParameters); +} + +OUString MenuButtonUIObject::get_name() const +{ + return "MenuButtonUIObject"; +} + +std::unique_ptr<UIObject> MenuButtonUIObject::create(vcl::Window* pWindow) +{ + MenuButton* pMenuButton = dynamic_cast<MenuButton*>(pWindow); + assert(pMenuButton); + return std::unique_ptr<UIObject>(new MenuButtonUIObject(pMenuButton)); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits