~alan-griffiths/qtmir/MirServer-is-an-implementation-detail

« back to all changes in this revision

Viewing changes to tests/modules/ApplicationManager/application_manager_test.cpp

  • Committer: CI Train Bot
  • Author(s): Daniel d'Andrada
  • Date: 2016-04-13 18:38:36 UTC
  • mfrom: (466.2.3 removeApplicationScreenshot)
  • Revision ID: ci-train-bot@canonical.com-20160413183836-k6cnj7sdzj3mp7qn
Remove application screenshot provider

It's no longer needed now that QML provides a "item-snapshot" feature.

Besides, it has no purpose in a surface-based window management.
Approved by: Lukáš Tinkl, Gerry Boland

Show diffs side-by-side

added added

removed removed

Lines of Context:
16
16
 
17
17
#define MIR_INCLUDE_DEPRECATED_EVENT_HEADER
18
18
 
19
 
#include <thread>
20
19
#include <condition_variable>
21
20
#include <QSignalSpy>
22
21
 
23
 
#include <Unity/Application/applicationscreenshotprovider.h>
24
22
#include <Unity/Application/timer.h>
25
23
 
26
24
#include <fake_desktopfilereader.h>
1570
1568
    EXPECT_EQ(1, applicationManager.count());
1571
1569
}
1572
1570
 
1573
 
/*
1574
 
 * Test that screenshotting callback works cross thread.
1575
 
 */
1576
 
TEST_F(ApplicationManagerTests, threadedScreenshot)
1577
 
{
1578
 
    using namespace testing;
1579
 
    const QString appId("webapp");
1580
 
    const pid_t procId = 5551;
1581
 
 
1582
 
    std::mutex mutex;
1583
 
    std::condition_variable cv;
1584
 
    bool done = false;
1585
 
 
1586
 
    ON_CALL(*taskController, primaryPidForAppId(appId)).WillByDefault(Return(procId));
1587
 
    ON_CALL(desktopFileReaderFactory, createInstance(appId, _)).WillByDefault(Invoke(createMockDesktopFileReader));
1588
 
 
1589
 
    EXPECT_CALL(*taskController, start(appId, _))
1590
 
        .Times(1)
1591
 
        .WillOnce(Return(true));
1592
 
 
1593
 
    applicationManager.startApplication(appId);
1594
 
    applicationManager.onProcessStarting(appId);
1595
 
    auto session = std::make_shared<MockSession>("", procId);
1596
 
    bool authed = true;
1597
 
    applicationManager.authorizeSession(procId, authed);
1598
 
    onSessionStarting(session);
1599
 
 
1600
 
    ON_CALL(*session, take_snapshot(_)).WillByDefault(Invoke(
1601
 
        [&](mir::scene::SnapshotCallback const& callback)
1602
 
        {
1603
 
            std::thread ([&, callback]() {
1604
 
                std::unique_lock<std::mutex> lk(mutex);
1605
 
 
1606
 
                mir::scene::Snapshot snapshot{mir::geometry::Size{0,0},
1607
 
                                              mir::geometry::Stride{0},
1608
 
                                              nullptr};
1609
 
 
1610
 
                callback(snapshot);
1611
 
 
1612
 
                done = true;
1613
 
                lk.unlock();
1614
 
                cv.notify_one();
1615
 
            }).detach();
1616
 
        }));
1617
 
 
1618
 
    auto mockSurface = std::make_shared<ms::MockSurface>();
1619
 
    EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));
1620
 
 
1621
 
    {
1622
 
        ApplicationScreenshotProvider screenshotProvider(&applicationManager);
1623
 
        QSize actualSize;
1624
 
        QSize requestedSize;
1625
 
        QString imageId(appId + "/123456");
1626
 
        screenshotProvider.requestImage(imageId, &actualSize, requestedSize);
1627
 
    }
1628
 
 
1629
 
    {
1630
 
        std::unique_lock<decltype(mutex)> lk(mutex);
1631
 
        cv.wait(lk, [&] { return done; } );
1632
 
        EXPECT_TRUE(done);
1633
 
    }
1634
 
 
1635
 
    EXPECT_CALL(*taskController, stop(appId))
1636
 
        .Times(1)
1637
 
        .WillOnce(Return(true));
1638
 
 
1639
 
    applicationManager.stopApplication(appId);
1640
 
}
1641
 
 
1642
 
/*
1643
 
 * Test that screenshotting callback works when application has been deleted
1644
 
 */
1645
 
TEST_F(ApplicationManagerTests, threadedScreenshotAfterAppDelete)
1646
 
{
1647
 
    using namespace testing;
1648
 
    const pid_t procId1 = 5551;
1649
 
 
1650
 
    std::mutex mutex;
1651
 
    std::condition_variable cv;
1652
 
    bool done = false;
1653
 
 
1654
 
    auto application = startApplication(procId1, "webapp");
1655
 
    auto session = std::dynamic_pointer_cast<MockSession>(application->session()->session());
1656
 
    ON_CALL(*session, take_snapshot(_)).WillByDefault(Invoke(
1657
 
        [&](mir::scene::SnapshotCallback const& callback)
1658
 
        {
1659
 
            std::thread ([&, callback]() {
1660
 
                mir::scene::Snapshot snapshot{mir::geometry::Size{0,0},
1661
 
                                              mir::geometry::Stride{0},
1662
 
                                              nullptr};
1663
 
 
1664
 
                // stop the application before calling the callback
1665
 
                applicationManager.stopApplication(application->appId());
1666
 
 
1667
 
                callback(snapshot);
1668
 
 
1669
 
                done = true;
1670
 
                cv.notify_one();
1671
 
            }).detach();
1672
 
        }));
1673
 
 
1674
 
    auto mockSurface = std::make_shared<ms::MockSurface>();
1675
 
    EXPECT_CALL(*session, default_surface()).WillRepeatedly(Return(mockSurface));
1676
 
 
1677
 
    {
1678
 
        ApplicationScreenshotProvider screenshotProvider(&applicationManager);
1679
 
        QSize actualSize;
1680
 
        QSize requestedSize;
1681
 
        QString imageId("webapp/123456");
1682
 
        screenshotProvider.requestImage(imageId, &actualSize, requestedSize);
1683
 
    }
1684
 
 
1685
 
    {
1686
 
        std::unique_lock<decltype(mutex)> lk(mutex);
1687
 
        cv.wait(lk, [&] { return done; } );
1688
 
    }
1689
 
}
1690
 
 
1691
1571
TEST_F(ApplicationManagerTests, lifecycleExemptAppIsNotSuspended)
1692
1572
{
1693
1573
    using namespace ::testing;