~zsombi/ubuntu-ui-toolkit/fixOptionSelectorFocus

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_touchregistry/tst_TouchRegistry.cpp

  • Committer: Tarmac
  • Author(s): Albert Astals Cid
  • Date: 2016-04-12 11:53:21 UTC
  • mfrom: (1908.5.1 staging)
  • Revision ID: tarmac-20160412115321-wm5at541v42ht2nr
Fix Bug caused by candidates getting removed during ownership resolution

Ported from unity8 codebase.

Approved by ubuntu-sdk-build-bot, Zsombor Egri.

Show diffs side-by-side

added added

removed removed

Lines of Context:
42
42
    QSet<int> ownedTouches;
43
43
    QSet<int> lostTouches;
44
44
    QList<TouchMemento> unownedTouchEvents;
 
45
 
 
46
Q_SIGNALS:
 
47
    void gainedOwnership();
 
48
    void lostOwnership();
45
49
};
46
50
 
47
51
class tst_TouchRegistry : public QObject
68
72
    void removeOldUndecidedCandidates();
69
73
    void interimOwnerWontGetUnownedTouchEvents();
70
74
    void candidateVanishes();
 
75
    void candicateOwnershipReentrace();
71
76
 
72
77
private:
73
78
    TouchRegistry *touchRegistry;
864
869
    QVERIFY(mainCandidate.ownedTouches.contains(0));
865
870
}
866
871
 
 
872
/*
 
873
  Regression test for canidate reentrance
 
874
 
 
875
  Bug caused by candidates getting removed during ownership resolution
 
876
 */
 
877
void tst_TouchRegistry::candicateOwnershipReentrace()
 
878
{
 
879
    DummyCandidate mainCandidate;
 
880
    DummyCandidate candicate2;
 
881
    DummyCandidate candicate3;
 
882
 
 
883
    {
 
884
        QList<QTouchEvent::TouchPoint> touchPoints;
 
885
        touchPoints.append(QTouchEvent::TouchPoint(0));
 
886
        touchPoints[0].setState(Qt::TouchPointPressed);
 
887
        QTouchEvent touchEvent(QEvent::TouchBegin,
 
888
                               0 /* device */,
 
889
                               Qt::NoModifier,
 
890
                               Qt::TouchPointPressed,
 
891
                               touchPoints);
 
892
        touchRegistry->update(&touchEvent);
 
893
    }
 
894
 
 
895
    // Re-entrance!
 
896
    connect(&candicate2, &DummyCandidate::lostOwnership, this, [&]() {
 
897
        touchRegistry->removeCandidateOwnerForTouch(0, &candicate2);
 
898
    });
 
899
 
 
900
    touchRegistry->addCandidateOwnerForTouch(0, &mainCandidate);
 
901
    touchRegistry->addCandidateOwnerForTouch(0, &candicate2);
 
902
    touchRegistry->addCandidateOwnerForTouch(0, &candicate3);
 
903
 
 
904
    {
 
905
        QList<QTouchEvent::TouchPoint> touchPoints;
 
906
        touchPoints.append(QTouchEvent::TouchPoint(0));
 
907
        touchPoints[0].setState(Qt::TouchPointMoved);
 
908
        QTouchEvent touchEvent(QEvent::TouchUpdate,
 
909
                               0 /* device */,
 
910
                               Qt::NoModifier,
 
911
                               Qt::TouchPointMoved,
 
912
                               touchPoints);
 
913
        touchRegistry->update(&touchEvent);
 
914
    }
 
915
 
 
916
    touchRegistry->requestTouchOwnership(0, &mainCandidate);
 
917
 
 
918
    QCOMPARE(mainCandidate.ownedTouches.count(), 1);
 
919
    QCOMPARE(candicate2.lostTouches.count(), 1);
 
920
    QCOMPARE(candicate3.lostTouches.count(), 1);
 
921
}
 
922
 
867
923
////////////// TouchMemento //////////
868
924
 
869
925
TouchMemento::TouchMemento(const QTouchEvent *touchEvent)
897
953
 
898
954
        if (touchOwnershipEvent->gained()) {
899
955
            ownedTouches.insert(touchOwnershipEvent->touchId());
 
956
            Q_EMIT gainedOwnership();
900
957
        } else {
901
958
            lostTouches.insert(touchOwnershipEvent->touchId());
 
959
            Q_EMIT lostOwnership();
902
960
        }
903
961
        return true;
904
962
    } else if (e->type() == UnownedTouchEvent::unownedTouchEventType()) {