diff options
| author | Andrea Azzarone <azzaronea@gmail.com> | 2012-11-24 15:34:32 +0000 |
|---|---|---|
| committer | Tarmac <> | 2012-11-24 15:34:32 +0000 |
| commit | d806e15e1798d5aa07b896af57aa90cfca66e3cd (patch) | |
| tree | a1c2678c635f46288c566d49162a57a54766dbc8 /tests | |
| parent | 20af5c16454ce9a27346e1771d2f297b5e19f46f (diff) | |
| parent | 9b6d9328f8aac27014e7f0585a1e40312e7a1510 (diff) | |
Refactor xdnd launcher code. Fixes: https://bugs.launchpad.net/bugs/1035301.
Approved by Brandon Schaefer. (bzr r2929)
Diffstat (limited to 'tests')
| -rw-r--r-- | tests/CMakeLists.txt | 2 | ||||
| -rw-r--r-- | tests/test_launcher.cpp | 13 | ||||
| -rw-r--r-- | tests/test_launcher_controller.cpp | 56 | ||||
| -rw-r--r-- | tests/test_xdnd_manager_imp.cpp | 130 | ||||
| -rw-r--r-- | tests/test_xdnd_start_stop_notifier_imp.cpp | 107 |
5 files changed, 299 insertions, 9 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt index 5b36e4a3d..7f35cdebb 100644 --- a/tests/CMakeLists.txt +++ b/tests/CMakeLists.txt @@ -251,6 +251,8 @@ if (ENABLE_X_SUPPORT) test_unity_settings.cpp test_volume_imp.cpp test_volume_launcher_icon.cpp + test_xdnd_manager_imp.cpp + test_xdnd_start_stop_notifier_imp.cpp bamf-mock-application.c gmockmount.c gmockvolume.c diff --git a/tests/test_launcher.cpp b/tests/test_launcher.cpp index d41a1ece3..9e76866a2 100644 --- a/tests/test_launcher.cpp +++ b/tests/test_launcher.cpp @@ -26,7 +26,6 @@ using namespace testing; #include <Nux/Nux.h> #include <Nux/BaseWindow.h> -#include "launcher/DNDCollectionWindow.h" #include "launcher/MockLauncherIcon.h" #include "launcher/Launcher.h" #include "unity-shared/PanelStyle.h" @@ -63,8 +62,8 @@ public: class MockLauncher : public Launcher { public: - MockLauncher(nux::BaseWindow* parent, nux::ObjectPtr<DNDCollectionWindow> const& collection_window) - : Launcher(parent, collection_window) + MockLauncher(nux::BaseWindow* parent) + : Launcher(parent) {} AbstractLauncherIcon::Ptr MouseIconIntersection(int x, int y) const @@ -119,10 +118,9 @@ public: TestLauncher() : parent_window_(new nux::BaseWindow("TestLauncherWindow")) - , dnd_collection_window_(new DNDCollectionWindow) , model_(new LauncherModel) , options_(new Options) - , launcher_(new MockLauncher(parent_window_, dnd_collection_window_)) + , launcher_(new MockLauncher(parent_window_)) { launcher_->options = options_; launcher_->SetModel(model_); @@ -153,7 +151,6 @@ public: MockUScreen uscreen; nux::BaseWindow* parent_window_; - nux::ObjectPtr<DNDCollectionWindow> dnd_collection_window_; Settings settings; panel::Style panel_style; LauncherModel::Ptr model_; @@ -189,9 +186,7 @@ TEST_F(TestLauncher, TestQuirksDuringDnd) EXPECT_CALL(*third, ShouldHighlightOnDrag(_)) .WillRepeatedly(Return(false)); - std::list<char*> uris; - dnd_collection_window_->collected.emit(uris); - + launcher_->DndStarted(""); Utils::WaitForTimeout(1); EXPECT_FALSE(first->GetQuirk(launcher::AbstractLauncherIcon::Quirk::DESAT)); diff --git a/tests/test_launcher_controller.cpp b/tests/test_launcher_controller.cpp index 8f033b9ba..516125484 100644 --- a/tests/test_launcher_controller.cpp +++ b/tests/test_launcher_controller.cpp @@ -200,6 +200,11 @@ namespace launcher { struct TestLauncherController : public testing::Test { + TestLauncherController() + : xdnd_manager_(std::make_shared<XdndManager>()) + , lc(xdnd_manager_) + {} + virtual void SetUp() { lc.multiple_launchers = true; @@ -216,6 +221,10 @@ struct TestLauncherController : public testing::Test protected: struct MockLauncherController : Controller { + MockLauncherController(XdndManager::Ptr const& xdnd_manager) + : Controller(xdnd_manager) + {} + Controller::Impl* Impl() const { return pimpl.get(); } AbstractLauncherIcon::Ptr GetIconByDesktop(std::string const& path) const @@ -258,6 +267,7 @@ protected: Settings settings; panel::Style panel_style; MockFavoriteStore favorite_store; + XdndManager::Ptr xdnd_manager_; MockLauncherController lc; }; } @@ -1544,4 +1554,50 @@ TEST_F(TestLauncherController, UpdateSelectionChanged) ASSERT_EQ(lc.Impl()->model_->Selection()->tooltip_text(), last_selection_change); } +TEST_F(TestLauncherController, DragAndDrop_MultipleLaunchers) +{ + lc.multiple_launchers = true; + uscreen.SetupFakeMultiMonitor(); + lc.options()->hide_mode = LAUNCHER_HIDE_AUTOHIDE; + + auto check_fn = [this](int index) { + return lc.launchers()[index]->Hidden(); + }; + + xdnd_manager_->dnd_started.emit("my_awesome_file", 0); + + for (int i = 0; i < max_num_monitors; ++i) + Utils::WaitUntil(std::bind(check_fn, i), i != 0); + + xdnd_manager_->monitor_changed.emit(3); + + for (int i = 0; i < max_num_monitors; ++i) + Utils::WaitUntil(std::bind(check_fn, i), i != 3); + + xdnd_manager_->dnd_finished.emit(); + + for (int i = 0; i < max_num_monitors; ++i) + Utils::WaitUntil(std::bind(check_fn, i), true); +} + +TEST_F(TestLauncherController, DragAndDrop_SingleLauncher) +{ + lc.multiple_launchers = false; + uscreen.SetupFakeMultiMonitor(2); + lc.options()->hide_mode = LAUNCHER_HIDE_AUTOHIDE; + + auto check_fn = [this]() { + return lc.launcher().Hidden(); + }; + + xdnd_manager_->dnd_started.emit("my_awesome_file", 0); + Utils::WaitUntil(check_fn, false); + + xdnd_manager_->monitor_changed.emit(2); + Utils::WaitUntil(check_fn, false); + + xdnd_manager_->dnd_finished.emit(); + Utils::WaitUntil(check_fn, true); +} + } diff --git a/tests/test_xdnd_manager_imp.cpp b/tests/test_xdnd_manager_imp.cpp new file mode 100644 index 000000000..1e4f3a8ab --- /dev/null +++ b/tests/test_xdnd_manager_imp.cpp @@ -0,0 +1,130 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2012 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> +*/ + +#include <gmock/gmock.h> +using namespace testing; + +#include "launcher/XdndManagerImp.h" +#include "launcher/XdndCollectionWindow.h" +#include "launcher/XdndStartStopNotifier.h" + +#include "test_utils.h" + +#include <Nux/Nux.h> +#include <X11/Xlib.h> + +namespace { + +class MockXdndStartStopNotifier : public unity::XdndStartStopNotifier { +public: + typedef std::shared_ptr<MockXdndStartStopNotifier> Ptr; +}; + +class MockXdndCollectionWindow : public unity::XdndCollectionWindow { +public: + typedef std::shared_ptr<MockXdndCollectionWindow> Ptr; + + MOCK_METHOD0(Collect, void(void)); + MOCK_METHOD0(Deactivate, void(void)); +}; + +class TestXdndManager : public Test { +public: + TestXdndManager() + : xdnd_start_stop_notifier_(new MockXdndStartStopNotifier()) + , xdnd_collection_window_(new MockXdndCollectionWindow()) + , xdnd_manager(xdnd_start_stop_notifier_, xdnd_collection_window_) + {} + + void SetUp() + { + // Evil hack to avoid crashes. + XEvent xevent; + xevent.type = ClientMessage; + xevent.xany.display = nux::GetGraphicsDisplay()->GetX11Display(); + xevent.xclient.message_type = XInternAtom(xevent.xany.display, "XdndEnter", false); + xevent.xclient.data.l[1] = 5 >> 24; + + nux::GetGraphicsDisplay()->ProcessXEvent(xevent, true); + } + + MockXdndStartStopNotifier::Ptr xdnd_start_stop_notifier_; + MockXdndCollectionWindow::Ptr xdnd_collection_window_; + unity::XdndManagerImp xdnd_manager; +}; + +TEST_F(TestXdndManager, SignalDndStartedAndFinished) +{ + std::vector<std::string> mimes; + mimes.push_back("text/uri-list"); + mimes.push_back("hello/world"); + + auto emit_collected_signal = [&] () { + xdnd_collection_window_->collected.emit(mimes); + }; + + EXPECT_CALL(*xdnd_collection_window_, Collect()) + .Times(1) + .WillOnce(Invoke(emit_collected_signal)); + + bool dnd_started_emitted = false; + xdnd_manager.dnd_started.connect([&] (std::string const& /*data*/, int /*monitor*/) { + dnd_started_emitted = true; + }); + + xdnd_start_stop_notifier_->started.emit(); + Utils::WaitUntil(dnd_started_emitted); + + EXPECT_CALL(*xdnd_collection_window_, Deactivate()) + .Times(1); + + bool dnd_finished_emitted = false; + xdnd_manager.dnd_finished.connect([&] () { + dnd_finished_emitted = true; + }); + + xdnd_start_stop_notifier_->finished.emit(); + Utils::WaitUntil(dnd_finished_emitted); +} + +TEST_F(TestXdndManager, SignalDndStarted_InvalidMimes) +{ + std::vector<std::string> mimes; + mimes.push_back("hello/world"); + mimes.push_back("invalid/mimes"); + + auto emit_collected_signal = [&] () { + xdnd_collection_window_->collected.emit(mimes); + }; + + EXPECT_CALL(*xdnd_collection_window_, Collect()) + .Times(1) + .WillOnce(Invoke(emit_collected_signal)); + + bool dnd_started_emitted = false; + xdnd_manager.dnd_started.connect([&] (std::string const& /*data*/, int /*monitor*/) { + dnd_started_emitted = true; + }); + + xdnd_start_stop_notifier_->started.emit(); + + EXPECT_FALSE(dnd_started_emitted); +} + +} diff --git a/tests/test_xdnd_start_stop_notifier_imp.cpp b/tests/test_xdnd_start_stop_notifier_imp.cpp new file mode 100644 index 000000000..621010447 --- /dev/null +++ b/tests/test_xdnd_start_stop_notifier_imp.cpp @@ -0,0 +1,107 @@ +// -*- Mode: C++; indent-tabs-mode: nil; tab-width: 2 -*- +/* +* Copyright (C) 2012 Canonical Ltd +* +* This program is free software: you can redistribute it and/or modify +* it under the terms of the GNU General Public License version 3 as +* published by the Free Software Foundation. +* +* This program is distributed in the hope that it will be useful, +* but WITHOUT ANY WARRANTY; without even the implied warranty of +* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +* GNU General Public License for more details. +* +* You should have received a copy of the GNU General Public License +* along with this program. If not, see <http://www.gnu.org/licenses/>. +* +* Authored by: Andrea Azzarone <andrea.azzarone@canonical.com> +*/ + +#include <gmock/gmock.h> +using namespace testing; + +#include "XdndStartStopNotifierImp.h" + +#include <Nux/Nux.h> +#include <X11/Xlib.h> +//#include <X11/extensions/XTest.h> + +#include "unity-shared/WindowManager.h" +#include "test_utils.h" + +namespace { + +struct TestXdndStartStopNotifierImp : public Test { + TestXdndStartStopNotifierImp() + : display_(nux::GetGraphicsDisplay()->GetX11Display()) + , selection_(XInternAtom(display_, "XdndSelection", false)) + { + Window root = DefaultRootWindow(display_); + owner_= XCreateSimpleWindow(display_, root, -1000, -1000, 10, 10, 0, 0, 0); + } + + Display* display_; + Atom selection_; + Window owner_; + + unity::XdndStartStopNotifierImp xdnd_start_stop_notifier; +}; + +TEST_F(TestXdndStartStopNotifierImp, DISABLED_SignalStarted) +{ + bool signal_received = false; + xdnd_start_stop_notifier.started.connect([&](){ + signal_received = true; + }); + + XSetSelectionOwner(display_, selection_, owner_, CurrentTime); + //XTestFakeButtonEvent(display_, 1, True, CurrentTime); + auto& wm = unity::WindowManager::Default(); + wm.window_mapped.emit(0); + + Utils::WaitUntil(signal_received); + //XTestFakeButtonEvent(display_, 1, False, CurrentTime); +} + +TEST_F(TestXdndStartStopNotifierImp, DISABLED_SignalFinished) +{ + bool signal_received = false; + xdnd_start_stop_notifier.finished.connect([&](){ + signal_received = true; + }); + + XSetSelectionOwner(display_, selection_, owner_, CurrentTime); + //XTestFakeButtonEvent(display_, 1, True, CurrentTime); + auto& wm = unity::WindowManager::Default(); + wm.window_mapped.emit(0); + + Utils::WaitForTimeoutMSec(500); + + XSetSelectionOwner(display_, selection_, None, CurrentTime); + //XTestFakeButtonEvent(display_, 1, False, CurrentTime); + wm.window_unmapped.emit(0); + + Utils::WaitUntil(signal_received); +} + +TEST_F(TestXdndStartStopNotifierImp, DISABLED_SignalFinished_QT) +{ + bool signal_received = false; + xdnd_start_stop_notifier.finished.connect([&](){ + signal_received = true; + }); + + XSetSelectionOwner(display_, selection_, owner_, CurrentTime); + //XTestFakeButtonEvent(display_, 1, True, CurrentTime); + auto& wm = unity::WindowManager::Default(); + wm.window_mapped.emit(0); + + Utils::WaitForTimeoutMSec(500); + + //XTestFakeButtonEvent(display_, 1, False, CurrentTime); + wm.window_unmapped.emit(0); + + Utils::WaitUntil(signal_received); +} + +} |
