~unity-team/unity8/slim-greeter

« back to all changes in this revision

Viewing changes to tests/plugins/Unity/Launcher/launchermodeltest.cpp

  • Committer: Michael Terry
  • Date: 2015-02-12 15:45:21 UTC
  • mfrom: (1432.1.178 unity8)
  • Revision ID: michael.terry@canonical.com-20150212154521-1qpg3t501ljj88lj
MergeĀ fromĀ trunk

Show diffs side-by-side

added added

removed removed

Lines of Context:
1
1
/*
2
 
 * Copyright 2013 Canonical Ltd.
 
2
 * Copyright 2013-2014 Canonical Ltd.
3
3
 *
4
4
 * This program is free software; you can redistribute it and/or modify
5
5
 * it under the terms of the GNU Lesser General Public License as published by
25
25
#include "launchermodel.h"
26
26
#include "dbusinterface.h"
27
27
#include "gsettings.h"
 
28
#include "asadapter.h"
 
29
#include "AccountsServiceDBusAdaptor.h"
28
30
 
29
31
#include <QtTest>
30
32
#include <QDBusInterface>
129
131
    LauncherModel *launcherModel;
130
132
    MockAppManager *appManager;
131
133
 
 
134
    QList<QVariantMap> getASConfig() {
 
135
        AccountsServiceDBusAdaptor *as = launcherModel->m_asAdapter->m_accounts;
 
136
        return as->getUserProperty("", "", "LauncherItems").value<QList<QVariantMap>>();
 
137
    }
 
138
 
132
139
private Q_SLOTS:
133
140
 
134
141
    void initTestCase() {
467
474
        QCOMPARE(launcherModel->get(1)->appId(), QString("abs-icon"));
468
475
        QCOMPARE(spy.count(), 2);
469
476
    }
 
477
 
 
478
    void testAddSyncsToAS() {
 
479
        // Make sure launcher and AS are in sync when we start the test
 
480
        QCOMPARE(launcherModel->rowCount(), getASConfig().count());
 
481
 
 
482
        int oldCount = launcherModel->rowCount();
 
483
        appManager->addApplication(new MockApp("rel-icon"));
 
484
        QCOMPARE(launcherModel->rowCount(), oldCount + 1);
 
485
        QCOMPARE(launcherModel->rowCount(), getASConfig().count());
 
486
    }
 
487
 
 
488
    void testRemoveSyncsToAS() {
 
489
        // Make sure launcher and AS are in sync when we start the test
 
490
        QCOMPARE(launcherModel->rowCount(), getASConfig().count());
 
491
 
 
492
        int oldCount = launcherModel->rowCount();
 
493
        appManager->stopApplication("abs-icon");
 
494
        QCOMPARE(launcherModel->rowCount(), oldCount - 1);
 
495
        QCOMPARE(launcherModel->rowCount(), getASConfig().count());
 
496
    }
 
497
 
 
498
    void testMoveSyncsToAS() {
 
499
        // Make sure launcher and AS are in sync when we start the test
 
500
        QCOMPARE(launcherModel->rowCount(), getASConfig().count());
 
501
 
 
502
        for (int i = 0; i < launcherModel->rowCount(); i++) {
 
503
            QString launcherAppId = launcherModel->get(i)->appId();
 
504
            QString asAppId = getASConfig().at(i).value("id").toString();
 
505
            QCOMPARE(launcherAppId, asAppId);
 
506
        }
 
507
 
 
508
        launcherModel->move(0, 1);
 
509
 
 
510
        for (int i = 0; i < launcherModel->rowCount(); i++) {
 
511
            QString launcherAppId = launcherModel->get(i)->appId();
 
512
            QString asAppId = getASConfig().at(i).value("id").toString();
 
513
            QCOMPARE(launcherAppId, asAppId);
 
514
        }
 
515
    }
 
516
 
 
517
    void testCountChangeSyncsToAS() {
 
518
        // Find the index of the abs-icon app
 
519
        int index = launcherModel->findApplication("abs-icon");
 
520
 
 
521
        // Make sure it's invisible and 0 at the beginning
 
522
        QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), false);
 
523
        QCOMPARE(getASConfig().at(index).value("count").toInt(), 0);
 
524
 
 
525
        // Change the count of the abs-icon app through D-Bus
 
526
        QDBusInterface interface("com.canonical.Unity.Launcher", "/com/canonical/Unity/Launcher/abs_2Dicon", "org.freedesktop.DBus.Properties");
 
527
        interface.call("Set", "com.canonical.Unity.Launcher.Item", "count", QVariant::fromValue(QDBusVariant(55)));
 
528
        interface.call("Set", "com.canonical.Unity.Launcher.Item", "countVisible", QVariant::fromValue(QDBusVariant(true)));
 
529
 
 
530
        // Make sure it changed to visible and 55
 
531
        QCOMPARE(getASConfig().at(index).value("countVisible").toBool(), true);
 
532
        QCOMPARE(getASConfig().at(index).value("count").toInt(), 55);
 
533
    }
470
534
};
471
535
 
472
536
QTEST_GUILESS_MAIN(LauncherModelTest)