summaryrefslogtreecommitdiffstats
path: root/tests
diff options
context:
space:
mode:
authorGerry Boland <gerry.boland@canonical.com>2015-05-13 10:40:03 +0100
committerGerry Boland <gerry.boland@canonical.com>2015-05-13 10:40:03 +0100
commita36d99e78c2407aa540a04abb07352dec8e90a04 (patch)
tree43795aa9ba4e566ceca51830a88c2182afd85717 /tests
parent547885b2e21328ef79b8da7d9baf51d37cc63e5c (diff)
parent604609b7d8923a72a01c9ad621381717b80ac1e4 (diff)
Merge trunk & fix conflicts
Diffstat (limited to 'tests')
-rw-r--r--tests/mirserver/QtEventFeeder/mock_qtwindowsystem.h5
-rw-r--r--tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp112
-rw-r--r--tests/modules/ApplicationManager/application_manager_test.cpp59
-rw-r--r--tests/modules/common/mock_settings.h41
-rw-r--r--tests/modules/common/qtmir_test.h5
5 files changed, 212 insertions, 10 deletions
diff --git a/tests/mirserver/QtEventFeeder/mock_qtwindowsystem.h b/tests/mirserver/QtEventFeeder/mock_qtwindowsystem.h
index ec4a80d..b37a675 100644
--- a/tests/mirserver/QtEventFeeder/mock_qtwindowsystem.h
+++ b/tests/mirserver/QtEventFeeder/mock_qtwindowsystem.h
@@ -50,6 +50,11 @@ MATCHER(IsReleased, std::string(negation ? "isn't" : "is") + " released")
return arg.state == Qt::TouchPointReleased;
}
+MATCHER(IsStationary, std::string(negation ? "isn't" : "is") + " stationary")
+{
+ return arg.state == Qt::TouchPointStationary;
+}
+
MATCHER(StateIsMoved, "state " + std::string(negation ? "isn't" : "is") + " 'moved'")
{
return arg.state == Qt::TouchPointMoved;
diff --git a/tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp b/tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp
index df81c74..10c0634 100644
--- a/tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp
+++ b/tests/mirserver/QtEventFeeder/qteventfeeder_test.cpp
@@ -40,12 +40,14 @@ using ::testing::Return;
// own gmock extensions
using ::testing::IsPressed;
+using ::testing::IsStationary;
using ::testing::IsReleased;
using ::testing::HasId;
using ::testing::StateIsMoved;
namespace mev = mir::events;
+// used by google mock in error messages
void PrintTo(const struct QWindowSystemInterface::TouchPoint& touchPoint, ::std::ostream* os) {
*os << "TouchPoint("
<< "id=" << touchPoint.id
@@ -53,6 +55,12 @@ void PrintTo(const struct QWindowSystemInterface::TouchPoint& touchPoint, ::std:
<< ")";
}
+::std::ostream& operator<<(::std::ostream& os, QTouchDevice*) {
+ // actually don't care about its contents. Just to avoit having a raw
+ // pointer address being printed in google mock error messages.
+ return os << "QTouchDevice*";
+}
+
class QtEventFeederTest : public ::testing::Test {
protected:
void SetUp() override;
@@ -98,7 +106,7 @@ void QtEventFeederTest::setIrrelevantMockWindowSystemExpectations()
Then, Mir sends a MirEvent([touch(id=1,state=pressed)]). In MirEvents, every single active touch
point must be listed in the event even if it didn't change at all in the meantime. So that's a bug.
But instead of crashing or forwarding the bogus event stream down to Qt, QtEventFeeder should attempt
- to fix the situation by synthesizing a touch[id=1,state=released] to be send along with the
+ to fix the situation by synthesizing a touch[id=0,state=released] to be send along with the
touch(id=1,state=pressed) it got. So that Qt receives a correct touch event stream.
*/
TEST_F(QtEventFeederTest, GenerateMissingTouchEnd)
@@ -111,27 +119,114 @@ TEST_F(QtEventFeederTest, GenerateMissingTouchEnd)
IsPressed()))),_)).Times(1);
auto ev1 = mev::make_event(MirInputDeviceId(), 123*1000000, 0);
- mev::add_touch(*ev1, /* touch ID */ 0, mir_touch_action_down, mir_touch_tooltype_unknown,
- 10, 10, 10, 1, 1, 10);
+ mev::add_touch(*ev1, 0 /* touch ID */, mir_touch_action_down, mir_touch_tooltype_unknown,
+ 10, 10, 10 /* x, y, pressure */,
+ 1, 1, 10 /* touch major, minor, size */);
qtEventFeeder->dispatch(*ev1);
ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
setIrrelevantMockWindowSystemExpectations();
- EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,_,AllOf(SizeIs(2),
- Contains(AllOf(HasId(0),IsReleased())),
- Contains(AllOf(HasId(1),IsPressed()))
- ),_)).Times(1);
+ // There can be only one pressed or released touch per event
+ {
+ InSequence sequence;
+
+ EXPECT_CALL(*mockWindowSystem,
+ handleTouchEvent(_,_,AllOf(SizeIs(1),
+ Contains(AllOf(HasId(0),IsReleased()))
+ ),_)).Times(1);
+
+ EXPECT_CALL(*mockWindowSystem,
+ handleTouchEvent(_,_,AllOf(SizeIs(1),
+ Contains(AllOf(HasId(1),IsPressed()))
+ ),_)).Times(1);
+ }
auto ev2 = mev::make_event(MirInputDeviceId(), 125*1000000, 0);
mev::add_touch(*ev2, 1 /* touch ID */, mir_touch_action_down, mir_touch_tooltype_unknown,
- 10, 10, 10, 1, 1, 10);
+ 20, 20, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
qtEventFeeder->dispatch(*ev2);
ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
}
+TEST_F(QtEventFeederTest, GenerateMissingTouchEnd2)
+{
+
+ setIrrelevantMockWindowSystemExpectations();
+
+ auto ev1 = mev::make_event(MirInputDeviceId(), 123*1000000, 0);
+ mev::add_touch(*ev1, 0 /* touch ID */, mir_touch_action_down, mir_touch_tooltype_unknown,
+ 10, 10, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
+
+ EXPECT_CALL(*mockWindowSystem, handleTouchEvent(_,_,AllOf(SizeIs(1),
+ Contains(AllOf(HasId(0),
+ IsPressed()))),_)).Times(1);
+ qtEventFeeder->dispatch(*ev1);
+
+ ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
+
+ // ---
+
+ setIrrelevantMockWindowSystemExpectations();
+
+ auto ev2 = mev::make_event(MirInputDeviceId(), 124*1000000, 0);
+ mev::add_touch(*ev2, 0 /* touch ID */, mir_touch_action_change, mir_touch_tooltype_unknown,
+ 10, 10, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
+ mev::add_touch(*ev2, 1 /* touch ID */, mir_touch_action_down, mir_touch_tooltype_unknown,
+ 20, 20, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
+
+ EXPECT_CALL(*mockWindowSystem,
+ handleTouchEvent(_,_,AllOf(SizeIs(2),
+ Contains(AllOf(HasId(0), StateIsMoved())),
+ Contains(AllOf(HasId(1), IsPressed()))
+ ),_)).Times(1);
+ qtEventFeeder->dispatch(*ev2);
+
+ ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
+
+ // ---
+
+ setIrrelevantMockWindowSystemExpectations();
+
+ // touch 0 disappeared and touch 2 got pressed
+ auto ev3 = mev::make_event(MirInputDeviceId(), 125*1000000, 0);
+ mev::add_touch(*ev3, 1 /* touch ID */, mir_touch_action_change, mir_touch_tooltype_unknown,
+ 20, 20, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
+ mev::add_touch(*ev3, 2 /* touch ID */, mir_touch_action_down, mir_touch_tooltype_unknown,
+ 30, 30, 10 /* x, y, pressure*/,
+ 1, 1, 10 /* touch major, minor, size */);
+
+ // There can be only one pressed or released touch per event
+ {
+ InSequence sequence;
+
+ // first release touch 0
+ EXPECT_CALL(*mockWindowSystem,
+ handleTouchEvent(_,_,AllOf(SizeIs(2),
+ Contains(AllOf(HasId(0), IsReleased())),
+ Contains(AllOf(HasId(1), IsStationary()))
+ ),_)).Times(1);
+
+ // then press touch 2
+ EXPECT_CALL(*mockWindowSystem,
+ handleTouchEvent(_,_,AllOf(SizeIs(2),
+ Contains(AllOf(HasId(1), StateIsMoved())),
+ Contains(AllOf(HasId(2), IsPressed()))
+ ),_)).Times(1);
+
+ }
+ qtEventFeeder->dispatch(*ev3);
+
+ ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
+}
+
TEST_F(QtEventFeederTest, PressSameTouchTwice)
{
setIrrelevantMockWindowSystemExpectations();
@@ -160,4 +255,3 @@ TEST_F(QtEventFeederTest, PressSameTouchTwice)
ASSERT_TRUE(Mock::VerifyAndClearExpectations(mockWindowSystem));
}
-
diff --git a/tests/modules/ApplicationManager/application_manager_test.cpp b/tests/modules/ApplicationManager/application_manager_test.cpp
index fa73b81..751000d 100644
--- a/tests/modules/ApplicationManager/application_manager_test.cpp
+++ b/tests/modules/ApplicationManager/application_manager_test.cpp
@@ -2235,6 +2235,65 @@ TEST_F(ApplicationManagerTests, focusMainStageAfterSideStage)
applicationManager.focusApplication(webbrowserAppId);
}
+TEST_F(ApplicationManagerTests,lifecycle_exempt_appId_is_not_suspended)
+{
+ using namespace ::testing;
+ quint64 a_procId = 5921;
+ const char an_app_id[] = "some_app";
+ QByteArray a_cmd( "/usr/bin/app1 --desktop_file_hint=some_app");
+ std::shared_ptr<mir::scene::Surface> aSurface(nullptr);
+
+ ON_CALL(procInfo,command_line(_)).WillByDefault(Return(a_cmd));
+
+ ON_CALL(appController,appIdHasProcessId(_,_)).WillByDefault(Return(false));
+
+ bool authed = true;
+
+ std::shared_ptr<mir::scene::Session> first_session = std::make_shared<MockSession>("Oo", a_procId);
+ std::shared_ptr<mir::scene::Session> second_session = std::make_shared<MockSession>("oO", a_procId);
+ applicationManager.authorizeSession(a_procId, authed);
+
+ onSessionStarting(first_session);
+ applicationManager.onSessionCreatedSurface(first_session.get(), aSurface);
+ onSessionStarting(second_session);
+
+ Application * the_app = applicationManager.findApplication(an_app_id);
+ applicationManager.focusApplication(an_app_id);
+
+ // Add to other apps to the list (Not "some_app")
+ QVariantList lifecycleExemptAppIds;
+ lifecycleExemptAppIds << "one_app" << "another_app";
+ ON_CALL(settings,get(_)).WillByDefault(Return(lifecycleExemptAppIds));
+ settings.changed("lifecycleExemptAppids");
+
+ EXPECT_EQ(Application::Running, the_app->state());
+
+ applicationManager.setSuspended(true);
+
+ // And expect "some_app" to get suspended
+ EXPECT_EQ(Application::Suspended, the_app->state());
+
+ applicationManager.setSuspended(false);
+
+ EXPECT_EQ(Application::Running, the_app->state());
+
+ // Now add "some_app" to the exception list
+ lifecycleExemptAppIds << "some_app";
+ ON_CALL(settings,get(_)).WillByDefault(Return(lifecycleExemptAppIds));
+ settings.changed("lifecycleExemptAppids");
+
+ EXPECT_EQ(Application::Running, the_app->state());
+
+ applicationManager.setSuspended(true);
+
+ // And expect it to be running still
+ EXPECT_EQ(Application::Running, the_app->state());
+
+ applicationManager.setSuspended(false);
+
+ EXPECT_EQ(Application::Running, the_app->state());
+}
+
/*
* Test lifecycle exempt applications have their wakelocks released when shell tries to suspend them
*/
diff --git a/tests/modules/common/mock_settings.h b/tests/modules/common/mock_settings.h
new file mode 100644
index 0000000..0cb7097
--- /dev/null
+++ b/tests/modules/common/mock_settings.h
@@ -0,0 +1,41 @@
+/*
+ * Copyright (C) 2015 Canonical, Ltd.
+ *
+ * This program is free software: you can redistribute it and/or modify it under
+ * the terms of the GNU Lesser 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
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ */
+
+#ifndef MOCK_SETTINGS_H
+#define MOCK_SETTINGS_H
+
+#include <Unity/Application/settings_interface.h>
+
+#include <gmock/gmock.h>
+
+namespace testing
+{
+struct MockSettings : public qtmir::SettingsInterface
+{
+ MockSettings()
+ {
+ QVariantList lifecycleExemptAppIds;
+ lifecycleExemptAppIds << "com.ubuntu.music";
+ ON_CALL(*this, get(_))
+ .WillByDefault(
+ Return(lifecycleExemptAppIds));
+
+ }
+ MOCK_CONST_METHOD1(get, QVariant(const QString &));
+};
+
+} // namespace testing
+#endif // MOCK_SETTINGS_H
diff --git a/tests/modules/common/qtmir_test.h b/tests/modules/common/qtmir_test.h
index f8e8a89..59b9dac 100644
--- a/tests/modules/common/qtmir_test.h
+++ b/tests/modules/common/qtmir_test.h
@@ -36,6 +36,7 @@
#include "mock_prompt_session_manager.h"
#include "mock_prompt_session.h"
#include "mock_shared_wakelock.h"
+#include "mock_settings.h"
namespace ms = mir::scene;
using namespace qtmir;
@@ -102,7 +103,8 @@ public:
QSharedPointer<DesktopFileReader::Factory>(
&desktopFileReaderFactory,
[](DesktopFileReader::Factory*){}),
- QSharedPointer<ProcInfo>(&procInfo,[](ProcInfo *){})
+ QSharedPointer<ProcInfo>(&procInfo,[](ProcInfo *){}),
+ QSharedPointer<MockSettings>(&settings,[](MockSettings *){})
}
, sessionManager{
mirServer,
@@ -149,6 +151,7 @@ public:
testing::NiceMock<testing::MockProcInfo> procInfo;
testing::NiceMock<testing::MockDesktopFileReaderFactory> desktopFileReaderFactory;
testing::NiceMock<testing::MockSharedWakelock> sharedWakelock;
+ testing::NiceMock<testing::MockSettings> settings;
QSharedPointer<FakeMirServer> mirServer;
MirShell *mirShell{nullptr};
QSharedPointer<TaskController> taskController;