Merge lp:~gerboland/qtmir/duplicate-open-apps into lp:qtmir

Proposed by Gerry Boland
Status: Merged
Approved by: Michael Zanetti
Approved revision: 251
Merged at revision: 253
Proposed branch: lp:~gerboland/qtmir/duplicate-open-apps
Merge into: lp:qtmir
Diff against target: 134 lines (+73/-18)
4 files modified
src/modules/Unity/Application/application.cpp (+5/-0)
src/modules/Unity/Application/application.h (+1/-0)
src/modules/Unity/Application/application_manager.cpp (+24/-18)
tests/modules/ApplicationManager/application_manager_test.cpp (+43/-0)
To merge this branch: bzr merge lp:~gerboland/qtmir/duplicate-open-apps
Reviewer Review Type Date Requested Status
Michael Zanetti (community) Approve
PS Jenkins bot (community) continuous-integration Approve
Review via email: mp+235109@code.launchpad.net

Commit message

TaskController may call processStarted synchronously, so check for that in startApplication before adding

Description of the change

TaskController may call processStarted synchronously, so check for that in startApplication before adding

* Are there any related MPs required for this MP to build/function as expected? Please list.
N
 * Did you perform an exploratory manual test run of your code change and any related functionality?
Y
 * If you changed the packaging (debian), did you subscribe the ubuntu-unity team to this MP?
N/A

To post a comment you must log in.
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

 * Did you perform an exploratory manual test run of the code change and any related functionality?

yes

 * Did CI run pass? If not, please explain why.

waiting...

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/modules/Unity/Application/application.cpp'
2--- src/modules/Unity/Application/application.cpp 2014-09-11 16:18:40 +0000
3+++ src/modules/Unity/Application/application.cpp 2014-09-18 12:02:01 +0000
4@@ -162,6 +162,11 @@
5 m_pid = pid;
6 }
7
8+void Application::setArguments(const QStringList arguments)
9+{
10+ m_arguments = arguments;
11+}
12+
13 void Application::setSession(Session *newSession)
14 {
15 qCDebug(QTMIR_APPLICATIONS) << "Application::setSession - appId=" << appId() << "session=" << newSession;
16
17=== modified file 'src/modules/Unity/Application/application.h'
18--- src/modules/Unity/Application/application.h 2014-08-29 11:01:20 +0000
19+++ src/modules/Unity/Application/application.h 2014-09-18 12:02:01 +0000
20@@ -116,6 +116,7 @@
21 QString longAppId() const;
22 pid_t pid() const;
23 void setPid(pid_t pid);
24+ void setArguments(const QStringList arguments);
25 void setFocused(bool focus);
26 void setSession(Session *session);
27
28
29=== modified file 'src/modules/Unity/Application/application_manager.cpp'
30--- src/modules/Unity/Application/application_manager.cpp 2014-09-04 11:11:26 +0000
31+++ src/modules/Unity/Application/application_manager.cpp 2014-09-18 12:02:01 +0000
32@@ -439,24 +439,30 @@
33 return nullptr;
34 }
35
36- application = new Application(
37- m_taskController,
38- m_desktopFileReaderFactory->createInstance(appId, m_taskController->findDesktopFileForAppId(appId)),
39- Application::Starting,
40- arguments,
41- this);
42-
43- if (!application->isValid()) {
44- qWarning() << "Unable to instantiate application with appId" << appId;
45- return nullptr;
46- }
47-
48- // override stage if necessary
49- if (application->stage() == Application::SideStage && flags.testFlag(ApplicationManager::ForceMainStage)) {
50- application->setStage(Application::MainStage);
51- }
52-
53- add(application);
54+ // The TaskController may synchroneously callback onProcessStarting, so check if application already added
55+ application = findApplication(appId);
56+ if (application) {
57+ application->setArguments(arguments);
58+ } else {
59+ application = new Application(
60+ m_taskController,
61+ m_desktopFileReaderFactory->createInstance(appId, m_taskController->findDesktopFileForAppId(appId)),
62+ Application::Starting,
63+ arguments,
64+ this);
65+
66+ if (!application->isValid()) {
67+ qWarning() << "Unable to instantiate application with appId" << appId;
68+ return nullptr;
69+ }
70+
71+ // override stage if necessary
72+ if (application->stage() == Application::SideStage && flags.testFlag(ApplicationManager::ForceMainStage)) {
73+ application->setStage(Application::MainStage);
74+ }
75+
76+ add(application);
77+ }
78 return application;
79 }
80
81
82=== modified file 'tests/modules/ApplicationManager/application_manager_test.cpp'
83--- tests/modules/ApplicationManager/application_manager_test.cpp 2014-09-11 16:18:40 +0000
84+++ tests/modules/ApplicationManager/application_manager_test.cpp 2014-09-18 12:02:01 +0000
85@@ -687,6 +687,49 @@
86 }
87
88 /*
89+ * Test that if TaskController synchronously calls back processStarted, that ApplicationManager
90+ * does not add the app to the model twice.
91+ */
92+TEST_F(ApplicationManagerTests,synchronousProcessStartedCallDoesNotDuplicateEntryInModel)
93+{
94+ using namespace ::testing;
95+ const QString appId("testAppId");
96+ const QString name("Test App");
97+
98+ // Set up Mocks & signal watcher
99+ auto mockDesktopFileReader = new NiceMock<MockDesktopFileReader>(appId, QFileInfo());
100+ ON_CALL(*mockDesktopFileReader, loaded()).WillByDefault(Return(true));
101+ ON_CALL(*mockDesktopFileReader, appId()).WillByDefault(Return(appId));
102+ ON_CALL(*mockDesktopFileReader, name()).WillByDefault(Return(name));
103+
104+ ON_CALL(desktopFileReaderFactory, createInstance(appId, _)).WillByDefault(Return(mockDesktopFileReader));
105+
106+ ON_CALL(appController, startApplicationWithAppIdAndArgs(appId, _))
107+ .WillByDefault(Invoke(
108+ [&](const QString &appId, Unused) {
109+ applicationManager.onProcessStarting(appId);
110+ return true;
111+ }
112+ ));
113+
114+ // start the application
115+ Application *theApp = applicationManager.startApplication(appId, ApplicationManager::NoFlag);
116+
117+ // check application data
118+ EXPECT_EQ(theApp->state(), Application::Starting);
119+ EXPECT_EQ(theApp->appId(), appId);
120+ EXPECT_EQ(theApp->name(), name);
121+ EXPECT_EQ(theApp->canBeResumed(), true);
122+
123+ // check only once instance in the model
124+ EXPECT_EQ(applicationManager.count(), 1);
125+
126+ // check application in list of apps
127+ Application *theAppAgain = applicationManager.findApplication(appId);
128+ EXPECT_EQ(theAppAgain, theApp);
129+}
130+
131+/*
132 * Test that the child sessions of a webapp process are accepted
133 */
134 TEST_F(ApplicationManagerTests,webAppSecondarySessionsAccepted)

Subscribers

People subscribed via source and target branches