Merge lp:~mardy/ubuntu-system-settings-online-accounts/app-from-profile into lp:~mardy/ubuntu-system-settings-online-accounts/master

Proposed by Alberto Mardegan
Status: Merged
Approved by: Alberto Mardegan
Approved revision: 125
Merged at revision: 126
Proposed branch: lp:~mardy/ubuntu-system-settings-online-accounts/app-from-profile
Merge into: lp:~mardy/ubuntu-system-settings-online-accounts/master
Diff against target: 162 lines (+99/-6)
3 files modified
src/application-manager.cpp (+25/-6)
src/application-manager.h (+2/-0)
tests/online-accounts-ui/tst_application_manager.cpp (+72/-0)
To merge this branch: bzr merge lp:~mardy/ubuntu-system-settings-online-accounts/app-from-profile
Reviewer Review Type Date Requested Status
Justin McPherson (community) Approve
Alberto Mardegan Pending
Review via email: mp+222282@code.launchpad.net

Commit message

Add ApplicationManager::applicationFromProfile()

Description of the change

Add ApplicationManager::applicationFromProfile()

To post a comment you must log in.
Revision history for this message
Justin McPherson (justinmcp) :
review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/application-manager.cpp'
2--- src/application-manager.cpp 2014-05-14 13:31:42 +0000
3+++ src/application-manager.cpp 2014-06-06 07:21:21 +0000
4@@ -22,7 +22,6 @@
5 #include "application-manager.h"
6 #include "debug.h"
7
8-#include <Accounts/Application>
9 #include <QDomDocument>
10 #include <QDomElement>
11 #include <QFile>
12@@ -134,11 +133,9 @@
13 QString applicationId = claimedAppId;
14 Accounts::Application application =
15 AccountManager::instance()->application(applicationId);
16- if (!application.isValid() && profile.startsWith(applicationId)) {
17- /* Handle the case where in the future we might decide to use the full
18- * profile (including the version number) as application id. */
19- applicationId = profile;
20- application = AccountManager::instance()->application(applicationId);
21+ if (!application.isValid()) {
22+ application = applicationFromProfile(profile);
23+ applicationId = application.name();
24 }
25
26 /* Make sure that the app is who it claims to be */
27@@ -217,3 +214,25 @@
28 }
29 return newAcl;
30 }
31+
32+Accounts::Application
33+ApplicationManager::applicationFromProfile(const QString &profile)
34+{
35+ /* If the profile is not a click package profile, we have no way of knowing
36+ * what application it is. */
37+ QStringList components = profile.split('_');
38+ if (components.count() != 3) return Accounts::Application();
39+
40+ /* First try to see if we can use the full profile as app ID; if not, strip
41+ * out the version, and if that fails as well then use only the package
42+ * name. */
43+ AccountManager *manager = AccountManager::instance();
44+ Accounts::Application application = manager->application(profile);
45+ if (application.isValid()) return application;
46+
47+ QString applicationId = components[0] + "_" + components[1];
48+ application = manager->application(applicationId);
49+ if (application.isValid()) return application;
50+
51+ return manager->application(components[0]);
52+}
53
54=== modified file 'src/application-manager.h'
55--- src/application-manager.h 2014-05-14 13:31:42 +0000
56+++ src/application-manager.h 2014-06-06 07:21:21 +0000
57@@ -21,6 +21,7 @@
58 #ifndef OAU_APPLICATION_MANAGER_H
59 #define OAU_APPLICATION_MANAGER_H
60
61+#include <Accounts/Application>
62 #include <QObject>
63 #include <QStringList>
64 #include <QVariantMap>
65@@ -45,6 +46,7 @@
66 const QString &appId) const;
67 Q_INVOKABLE QStringList removeApplicationFromAcl(const QStringList &acl,
68 const QString &appId) const;
69+ Accounts::Application applicationFromProfile(const QString &profile);
70
71 protected:
72 explicit ApplicationManager(QObject *parent = 0);
73
74=== modified file 'tests/online-accounts-ui/tst_application_manager.cpp'
75--- tests/online-accounts-ui/tst_application_manager.cpp 2014-05-14 13:31:42 +0000
76+++ tests/online-accounts-ui/tst_application_manager.cpp 2014-06-06 07:21:21 +0000
77@@ -51,6 +51,8 @@
78 void testAclAdd();
79 void testAclRemove_data();
80 void testAclRemove();
81+ void testApplicationFromProfile_data();
82+ void testApplicationFromProfile();
83
84 private:
85 void clearApplicationsDir();
86@@ -360,6 +362,76 @@
87 QCOMPARE(acl.toSet(), newAcl.toSet());
88 }
89
90+void ApplicationManagerTest::testApplicationFromProfile_data()
91+{
92+ QTest::addColumn<QString>("applicationId");
93+ QTest::addColumn<QString>("contents");
94+ QTest::addColumn<QString>("profile");
95+ QTest::addColumn<bool>("isValid");
96+
97+ QTest::newRow("id-same-as-profile") <<
98+ "com.ubuntu.test_MyApp_0.2" <<
99+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
100+ "<application id=\"com.ubuntu.test_MyApp\">\n"
101+ " <description>My application</description>\n"
102+ " <profile>com.ubuntu.test_MyApp_0.2</profile>\n"
103+ "</application>" <<
104+ "com.ubuntu.test_MyApp_0.2" <<
105+ true;
106+
107+ QTest::newRow("id-with-no-version") <<
108+ "com.ubuntu.test_MyApp2" <<
109+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
110+ "<application id=\"com.ubuntu.test_MyApp2\">\n"
111+ " <description>My application 2</description>\n"
112+ " <profile>com.ubuntu.test_MyApp2_0.2</profile>\n"
113+ "</application>" <<
114+ "com.ubuntu.test_MyApp2_0.2" <<
115+ true;
116+
117+ QTest::newRow("id-is-just-package") <<
118+ "com.ubuntu.test" <<
119+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
120+ "<application id=\"com.ubuntu.test_MyApp3\">\n"
121+ " <description>My application 3</description>\n"
122+ " <profile>com.ubuntu.test_MyApp3_0.2</profile>\n"
123+ "</application>" <<
124+ "com.ubuntu.test_MyApp3_0.2" <<
125+ true;
126+
127+ QTest::newRow("not found") <<
128+ "com.ubuntu.test_MyApp5" <<
129+ "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
130+ "<application id=\"com.ubuntu.test_MyApp4\">\n"
131+ " <description>My application 4</description>\n"
132+ " <profile>com.ubuntu.test_MyApp4_0.2</profile>\n"
133+ "</application>" <<
134+ "com.ubuntu.test_MyApp4_0.2" <<
135+ false;
136+}
137+
138+void ApplicationManagerTest::testApplicationFromProfile()
139+{
140+ clearApplicationsDir();
141+
142+ QFETCH(QString, applicationId);
143+ QFETCH(QString, contents);
144+ QFETCH(QString, profile);
145+ QFETCH(bool, isValid);
146+
147+ writeAccountsFile(applicationId + ".application", contents);
148+
149+ ApplicationManager manager;
150+
151+ Accounts::Application app = manager.applicationFromProfile(profile);
152+ if (!isValid) {
153+ QVERIFY(!app.isValid());
154+ } else {
155+ QVERIFY(app.isValid());
156+ QCOMPARE(app.name(), applicationId);
157+ }
158+}
159+
160 QTEST_MAIN(ApplicationManagerTest);
161
162 #include "tst_application_manager.moc"

Subscribers

People subscribed via source and target branches

to all changes: