summaryrefslogtreecommitdiff
path: root/tests
diff options
Diffstat (limited to 'tests')
-rw-r--r--tests/CMakeLists.txt3
-rw-r--r--tests/test_file_manager_launcher_icon.cpp202
-rw-r--r--tests/test_xdnd_start_stop_notifier_imp.cpp22
3 files changed, 215 insertions, 12 deletions
diff --git a/tests/CMakeLists.txt b/tests/CMakeLists.txt
index d1f58d33c..a19a1512d 100644
--- a/tests/CMakeLists.txt
+++ b/tests/CMakeLists.txt
@@ -8,7 +8,7 @@ file (COPY ${CMAKE_CURRENT_SOURCE_DIR}/data DESTINATION ${CMAKE_BINARY_DIR}/test
#
# Unit tests
#
-set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.99.0;libupstart;")
+set (TEST_DEPS "${UNITY_PLUGIN_DEPS};unity>=4.99.0;libupstart;xtst")
pkg_check_modules (TEST_UNIT_DEPS REQUIRED ${TEST_DEPS})
string (REPLACE ";" " " TEST_UNIT_DEPS_CFLAGS_OTHER "${TEST_UNIT_CFLAGS_OTHER}")
@@ -224,6 +224,7 @@ if (ENABLE_X_SUPPORT)
test_error_preview.cpp
test_edge_barrier_controller.cpp
test_expo_launcher_icon.cpp
+ test_file_manager_launcher_icon.cpp
test_filter_widgets.cpp
test_glib_dbus_server.cpp
test_gnome_session_manager.cpp
diff --git a/tests/test_file_manager_launcher_icon.cpp b/tests/test_file_manager_launcher_icon.cpp
new file mode 100644
index 000000000..fe1471ec2
--- /dev/null
+++ b/tests/test_file_manager_launcher_icon.cpp
@@ -0,0 +1,202 @@
+/*
+ * Copyright 2016 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 warranties of
+ * MERCHANTABILITY, SATISFACTORY QUALITY 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
+ * version 3 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 "FileManagerLauncherIcon.h"
+#include "UnityCore/DesktopUtilities.h"
+
+#include "test_mock_devices.h"
+#include "test_mock_filemanager.h"
+#include "mock-application.h"
+
+using namespace unity;
+using namespace unity::launcher;
+using namespace testmocks;
+
+namespace
+{
+
+const std::string TRASH_URI = "trash:";
+const std::string TRASH_PATH = "file://" + DesktopUtilities::GetUserTrashDirectory();
+
+struct TestFileManagerLauncherIcon : public Test
+{
+ TestFileManagerLauncherIcon()
+ : app_(std::make_shared<MockApplication::Nice>())
+ , fm_(std::make_shared<MockFileManager::Nice>())
+ , dev_ (std::make_shared<MockDeviceLauncherSection>(2))
+ , icon_(new FileManagerLauncherIcon(app_, dev_, fm_))
+ {
+ }
+
+ MockApplication::Ptr app_;
+ MockFileManager::Ptr fm_;
+ DeviceLauncherSection::Ptr dev_;
+ FileManagerLauncherIcon::Ptr icon_;
+};
+
+TEST_F(TestFileManagerLauncherIcon, IconType)
+{
+ EXPECT_EQ(icon_->GetIconType(), AbstractLauncherIcon::IconType::APPLICATION);
+}
+
+TEST_F(TestFileManagerLauncherIcon, NoWindow)
+{
+ EXPECT_FALSE(icon_->IsVisible());
+}
+
+TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_TrashUri)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(TRASH_URI));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_FALSE(icon_->IsVisible());
+ EXPECT_FALSE(icon_->IsRunning());
+}
+
+TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_TrashPath)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(TRASH_PATH));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_FALSE(icon_->IsVisible());
+ EXPECT_FALSE(icon_->IsRunning());
+}
+
+TEST_F(TestFileManagerLauncherIcon, NoManagedWindow_Device)
+{
+ auto const& device_icons = dev_->GetIcons();
+ ASSERT_EQ(2, device_icons.size());
+
+ device_icons.at(0)->Activate(ActionArg());
+
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(device_icons.at(0)->GetVolumeUri()));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_FALSE(icon_->IsVisible());
+ EXPECT_FALSE(icon_->IsRunning());
+}
+
+TEST_F(TestFileManagerLauncherIcon, ManagedWindows)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return("/usr/bin"));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_TRUE(icon_->IsVisible());
+ EXPECT_TRUE(icon_->IsRunning());
+}
+
+TEST_F(TestFileManagerLauncherIcon, ManagedWindows_EmptyLocation)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(""));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_TRUE(icon_->IsVisible());
+ EXPECT_TRUE(icon_->IsRunning());
+}
+
+TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialog)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(1);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(""));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ win->visible_ = false;
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ EXPECT_TRUE(icon_->IsVisible());
+ EXPECT_TRUE(icon_->IsRunning());
+}
+
+
+TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialogAndManagedWindow)
+{
+ EXPECT_CALL(*fm_, LocationForWindow(_)).Times(3);
+ ON_CALL(*fm_, LocationForWindow(_)).WillByDefault(Return(""));
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ win->visible_ = false;
+ app_->windows_.push_back(win);
+ app_->window_opened.emit(win);
+
+ EXPECT_TRUE(icon_->IsVisible());
+ EXPECT_TRUE(icon_->IsRunning());
+ EXPECT_EQ(2, icon_->WindowsVisibleOnMonitor(0));
+}
+
+TEST_F(TestFileManagerLauncherIcon, ManagedWindows_CopyDialogAndNoManagedWindow)
+{
+ {
+ InSequence s;
+
+ EXPECT_CALL(*fm_, LocationForWindow(_))
+ .Times(1)
+ .WillOnce(Return(""));
+
+ EXPECT_CALL(*fm_, LocationForWindow(_))
+ .Times(1)
+ .WillOnce(Return(""));
+
+ EXPECT_CALL(*fm_, LocationForWindow(_))
+ .Times(1)
+ .WillOnce(Return(TRASH_PATH));
+ }
+
+ auto win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ app_->windows_ = { win };
+ app_->window_opened.emit(win);
+
+ win = std::make_shared<MockApplicationWindow::Nice>(g_random_int());
+ win->visible_ = false;
+ app_->windows_.push_back(win);
+ app_->window_opened.emit(win);
+
+ EXPECT_TRUE(icon_->IsVisible());
+ EXPECT_TRUE(icon_->IsRunning());
+ EXPECT_EQ(1, icon_->WindowsVisibleOnMonitor(0));
+}
+
+}
diff --git a/tests/test_xdnd_start_stop_notifier_imp.cpp b/tests/test_xdnd_start_stop_notifier_imp.cpp
index 9811664ee..c8bf74b26 100644
--- a/tests/test_xdnd_start_stop_notifier_imp.cpp
+++ b/tests/test_xdnd_start_stop_notifier_imp.cpp
@@ -24,7 +24,7 @@ using namespace testing;
#include <Nux/Nux.h>
#include <X11/Xlib.h>
-//#include <X11/extensions/XTest.h>
+#include <X11/extensions/XTest.h>
#include "unity-shared/WindowManager.h"
#include "test_utils.h"
@@ -47,7 +47,7 @@ struct TestXdndStartStopNotifierImp : public Test {
unity::XdndStartStopNotifierImp xdnd_start_stop_notifier;
};
-TEST_F(TestXdndStartStopNotifierImp, UNSTABLE_TEST(SignalStarted))
+TEST_F(TestXdndStartStopNotifierImp, SignalStarted)
{
bool signal_received = false;
xdnd_start_stop_notifier.started.connect([&](){
@@ -55,15 +55,15 @@ TEST_F(TestXdndStartStopNotifierImp, UNSTABLE_TEST(SignalStarted))
});
XSetSelectionOwner(display_, selection_, owner_, CurrentTime);
- //XTestFakeButtonEvent(display_, 1, True, 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);
+ XTestFakeButtonEvent(display_, 1, False, CurrentTime);
}
-TEST_F(TestXdndStartStopNotifierImp, UNSTABLE_TEST(SignalFinished))
+TEST_F(TestXdndStartStopNotifierImp, SignalFinished)
{
bool signal_received = false;
xdnd_start_stop_notifier.finished.connect([&](){
@@ -71,34 +71,34 @@ TEST_F(TestXdndStartStopNotifierImp, UNSTABLE_TEST(SignalFinished))
});
XSetSelectionOwner(display_, selection_, owner_, CurrentTime);
- //XTestFakeButtonEvent(display_, 1, True, 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);
+ XTestFakeButtonEvent(display_, 1, False, CurrentTime);
wm.window_unmapped.emit(0);
Utils::WaitUntil(signal_received);
}
-TEST_F(TestXdndStartStopNotifierImp, DISABLED_SignalFinished_QT)
+TEST_F(TestXdndStartStopNotifierImp, SignalFinished_QT)
{
bool signal_received = false;
- xdnd_start_stop_notifier.finished.connect([&](){
+ xdnd_start_stop_notifier.finished.connect([&signal_received] {
signal_received = true;
});
XSetSelectionOwner(display_, selection_, owner_, CurrentTime);
- //XTestFakeButtonEvent(display_, 1, True, CurrentTime);
+ XTestFakeButtonEvent(display_, 1, True, CurrentTime);
auto& wm = unity::WindowManager::Default();
wm.window_mapped.emit(0);
Utils::WaitForTimeoutMSec(500);
- //XTestFakeButtonEvent(display_, 1, False, CurrentTime);
+ XTestFakeButtonEvent(display_, 1, False, CurrentTime);
wm.window_unmapped.emit(0);
Utils::WaitUntil(signal_received);