~canonical-platform-qa/ubuntu-system-settings-online-accounts/launch_fixture

« back to all changes in this revision

Viewing changes to tests/click-hooks/tst_online_accounts_hooks.cpp

  • Committer: CI bot
  • Author(s): Alberto Mardegan
  • Date: 2014-06-12 13:37:46 UTC
  • mfrom: (107.1.19 master)
  • Revision ID: ps-jenkins@lists.canonical.com-20140612133746-l203pxlimfpevv6r
New version

- Use signon-ui-service, to fix co-installation with of signon-ui. 

Show diffs side-by-side

added added

removed removed

Lines of Context:
41
41
    void testNoFiles();
42
42
    void testValidHooks_data();
43
43
    void testValidHooks();
 
44
    void testRemoval();
 
45
    void testUpdate();
44
46
 
45
47
private:
46
48
    void clearHooksDir();
47
49
    void clearInstallDir();
48
50
    bool runHookProcess();
49
51
    void writeHookFile(const QString &name, const QString &contents);
 
52
    void writeInstalledFile(const QString &name, const QString &contents);
50
53
 
51
54
private:
52
55
    QDir m_testDir;
91
94
    file.write(contents.toUtf8());
92
95
}
93
96
 
 
97
void OnlineAccountsHooksTest::writeInstalledFile(const QString &name,
 
98
                                                 const QString &contents)
 
99
{
 
100
    QFileInfo fileInfo(name);
 
101
    m_installDir.mkpath(fileInfo.path());
 
102
    QFile file(m_installDir.filePath(name));
 
103
    if (!file.open(QIODevice::WriteOnly | QIODevice::Text)) {
 
104
        qWarning() << "Could not write file" << name;
 
105
        return;
 
106
    }
 
107
 
 
108
    file.write(contents.toUtf8());
 
109
}
 
110
 
94
111
void OnlineAccountsHooksTest::initTestCase()
95
112
{
96
113
    qputenv("XDG_DATA_HOME", TEST_DIR);
223
240
    QCOMPARE(profileElement.text(), profile);
224
241
}
225
242
 
 
243
void OnlineAccountsHooksTest::testRemoval()
 
244
{
 
245
    clearHooksDir();
 
246
    clearInstallDir();
 
247
 
 
248
    QString stillInstalled("applications/com.ubuntu.test_StillInstalled.application");
 
249
    writeInstalledFile(stillInstalled,
 
250
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
251
        "<application>\n"
 
252
        "  <description>My application</description>\n"
 
253
        "  <service-types>\n"
 
254
        "    <service-type>some type</service-type>\n"
 
255
        "  </service-types>\n"
 
256
        "  <profile>com-ubuntu.test_StillInstalled_2.0</profile>\n"
 
257
        "</application>");
 
258
    QVERIFY(m_installDir.exists(stillInstalled));
 
259
 
 
260
    QString myApp("applications/com.ubuntu.test_MyApp.application");
 
261
    writeInstalledFile(myApp,
 
262
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
263
        "<application>\n"
 
264
        "  <description>My application</description>\n"
 
265
        "  <service-types>\n"
 
266
        "    <service-type>some type</service-type>\n"
 
267
        "  </service-types>\n"
 
268
        "  <profile>com-ubuntu.test_MyApp_3.0</profile>\n"
 
269
        "</application>");
 
270
    QVERIFY(m_installDir.exists(myApp));
 
271
 
 
272
    QString noProfile("applications/com.ubuntu.test_NoProfile.application");
 
273
    writeInstalledFile(noProfile,
 
274
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
275
        "<application>\n"
 
276
        "  <description>My application</description>\n"
 
277
        "  <service-types>\n"
 
278
        "    <service-type>some type</service-type>\n"
 
279
        "  </service-types>\n"
 
280
        "</application>");
 
281
    QVERIFY(m_installDir.exists(noProfile));
 
282
 
 
283
    writeHookFile("com-ubuntu.test_StillInstalled_2.0.application",
 
284
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
285
        "<application>\n"
 
286
        "  <description>My application</description>\n"
 
287
        "  <service-types>\n"
 
288
        "    <service-type>some type</service-type>\n"
 
289
        "  </service-types>\n"
 
290
        "</application>");
 
291
 
 
292
    QVERIFY(runHookProcess());
 
293
 
 
294
    QVERIFY(m_installDir.exists(stillInstalled));
 
295
    QVERIFY(!m_installDir.exists(myApp));
 
296
    QVERIFY(m_installDir.exists(noProfile));
 
297
}
 
298
 
 
299
void OnlineAccountsHooksTest::testUpdate()
 
300
{
 
301
    clearHooksDir();
 
302
    clearInstallDir();
 
303
 
 
304
    writeHookFile("com-ubuntu.test_MyApp_1.0.application",
 
305
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
306
        "<application>\n"
 
307
        "  <description>My application</description>\n"
 
308
        "  <service-types>\n"
 
309
        "    <service-type>some type</service-type>\n"
 
310
        "  </service-types>\n"
 
311
        "</application>");
 
312
 
 
313
    QVERIFY(runHookProcess());
 
314
 
 
315
    QString installedName("applications/com-ubuntu.test_MyApp.application");
 
316
 
 
317
    // check that the file has been created, and with the correct profile
 
318
    QFile file(m_installDir.absoluteFilePath(installedName));
 
319
    QVERIFY(file.open(QIODevice::ReadOnly));
 
320
 
 
321
    // check that's a valid XML file
 
322
    QDomDocument doc;
 
323
    QVERIFY(doc.setContent(&file));
 
324
    QDomElement root = doc.documentElement();
 
325
    QCOMPARE(root.firstChildElement("profile").text(),
 
326
             QString("com-ubuntu.test_MyApp_1.0"));
 
327
 
 
328
    /* Now remove the hook file and write a newer version of it */
 
329
    clearHooksDir();
 
330
    writeHookFile("com-ubuntu.test_MyApp_1.1.application",
 
331
        "<?xml version=\"1.0\" encoding=\"UTF-8\" ?>\n"
 
332
        "<application>\n"
 
333
        "  <description>My application</description>\n"
 
334
        "  <service-types>\n"
 
335
        "    <service-type>some type</service-type>\n"
 
336
        "  </service-types>\n"
 
337
        "</application>");
 
338
 
 
339
    QVERIFY(runHookProcess());
 
340
 
 
341
    // check that the file has been updated with the correct profile
 
342
    file.close();
 
343
    file.setFileName(m_installDir.absoluteFilePath(installedName));
 
344
    QVERIFY(file.open(QIODevice::ReadOnly));
 
345
    QVERIFY(doc.setContent(&file));
 
346
    root = doc.documentElement();
 
347
    QCOMPARE(root.firstChildElement("profile").text(),
 
348
             QString("com-ubuntu.test_MyApp_1.1"));
 
349
}
 
350
 
226
351
QTEST_MAIN(OnlineAccountsHooksTest);
227
352
 
228
353
#include "tst_online_accounts_hooks.moc"