~loic.molinari/ubuntu-ui-toolkit/ubuntu-ui-toolkit-private-shapes

« back to all changes in this revision

Viewing changes to tests/unit_x11/tst_components/tst_popover.qml

  • Committer: Christian Dywan
  • Date: 2014-04-30 10:22:44 UTC
  • mfrom: (1000.17.3 staging)
  • mto: (1000.41.5 staging)
  • mto: This revision was merged to the branch mainline in revision 1022.
  • Revision ID: christian.dywan@canonical.com-20140430102244-uti97msd0thmk31d
MergeĀ lp:~ubuntu-sdk-team/ubuntu-ui-toolkit/staging

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/*
 
2
 * Copyright 2014 Canonical Ltd.
 
3
 *
 
4
 * This program is free software; you can redistribute it and/or modify
 
5
 * it under the terms of the GNU Lesser General Public License as published by
 
6
 * the Free Software Foundation; version 3.
 
7
 *
 
8
 * This program is distributed in the hope that it will be useful,
 
9
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 
10
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 
11
 * GNU Lesser General Public License for more details.
 
12
 *
 
13
 * You should have received a copy of the GNU Lesser General Public License
 
14
 * along with this program.  If not, see <http://www.gnu.org/licenses/>.
 
15
 */
 
16
import QtQuick 2.0
 
17
import QtTest 1.0
 
18
import Ubuntu.Test 0.1
 
19
import Ubuntu.Components 0.1
 
20
import Ubuntu.Components.Popups 0.1
 
21
 
 
22
MainView {
 
23
    id: main
 
24
    width: units.gu(40)
 
25
    height: units.gu(71)
 
26
 
 
27
    Button {
 
28
        id: caller
 
29
        anchors.centerIn: parent
 
30
        text: "Press me"
 
31
        onClicked: {
 
32
            var popover = PopupUtils.open(popoverComponent, caller);
 
33
            popoverSpy.target = testCase.findChild(popover, "popover_foreground");
 
34
            popoverSpy.clear();
 
35
        }
 
36
    }
 
37
 
 
38
    // spy to listen on the popover foreground's hideCompleted() signal
 
39
    SignalSpy {
 
40
        id: popoverSpy
 
41
        signalName: "hideCompleted"
 
42
    }
 
43
 
 
44
    Component {
 
45
        id: popoverComponent
 
46
        Popover {
 
47
            objectName: "popover"
 
48
            Rectangle {
 
49
                width: units.gu(20)
 
50
                height: units.gu(20)
 
51
                color: "blue"
 
52
            }
 
53
        }
 
54
    }
 
55
 
 
56
    UbuntuTestCase {
 
57
        id: testCase
 
58
        name: "PopoverTests"
 
59
        when: windowShown
 
60
 
 
61
        function cleanup() {
 
62
            popoverSpy.target = null;
 
63
            popoverSpy.clear();
 
64
        }
 
65
 
 
66
        function test_dismiss_on_click_data() {
 
67
            return [
 
68
                        {button: Qt.LeftButton},
 
69
                        {button: Qt.MiddleButton},
 
70
                        {button: Qt.RightButton},
 
71
                    ];
 
72
        }
 
73
 
 
74
        function test_dismiss_on_click(data) {
 
75
            mouseClick(caller, caller.width / 2, caller.height / 2);
 
76
            waitForRendering(caller);
 
77
            verify(popoverSpy.target !== null, "The popover did not open");
 
78
            // dismiss
 
79
            mouseClick(main, 10, 10, data.button);
 
80
            popoverSpy.wait();
 
81
        }
 
82
    }
 
83
}