Merge lp:~unity-team/unity/phablet.test_greeter-clock into lp:unity/phablet

Proposed by Andrea Cimitan
Status: Merged
Approved by: Michael Zanetti
Approved revision: no longer in the source branch.
Merged at revision: 593
Proposed branch: lp:~unity-team/unity/phablet.test_greeter-clock
Merge into: lp:unity/phablet
Diff against target: 144 lines (+96/-0)
4 files modified
Greeter/Clock.qml (+5/-0)
tests/unittests/CMakeLists.txt (+2/-0)
tests/unittests/Greeter/CMakeLists.txt (+1/-0)
tests/unittests/Greeter/tst_Clock.qml (+88/-0)
To merge this branch: bzr merge lp:~unity-team/unity/phablet.test_greeter-clock
Reviewer Review Type Date Requested Status
PS Jenkins bot (community) continuous-integration Approve
Michael Zanetti (community) Approve
Review via email: mp+157859@code.launchpad.net

Commit message

Add tests for Greeter's Clock

Description of the change

Add tests for Greeter's Clock

To post a comment you must log in.
Revision history for this message
Michael Zanetti (mzanetti) wrote :

* I'd say it would make sense to change __date to something predefined and then actually check if the labels also change to the wanted value

* The code itself updates the clock only once per minute... That's not enough precision for a clock imho... I'd say 5 seconds or something would better (Just a notice as we are touching the code anyways... You decide if you want to fix that now or not)

I would probably add something like this:

- set clock to invisible => timer is stopped
- change __date to something else than the current date
- set clock to visible
- check if time is updated properly

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Andrea Cimitan (cimi) wrote :

> * I'd say it would make sense to change __date to something predefined and
> then actually check if the labels also change to the wanted value
>
> * The code itself updates the clock only once per minute... That's not enough
> precision for a clock imho... I'd say 5 seconds or something would better
> (Just a notice as we are touching the code anyways... You decide if you want
> to fix that now or not)
>
> I would probably add something like this:
>
> - set clock to invisible => timer is stopped
> - change __date to something else than the current date
> - set clock to visible
> - check if time is updated properly

We save battery by not updating the clock every 5 seconds... isn't it?

Revision history for this message
Michael Zanetti (mzanetti) wrote :

> We save battery by not updating the clock every 5 seconds... isn't it?

In general yes, try to avoid frequently ticking timers. However, Its better to have a very precise timer that is enabled when needed and disabled when not needed.

For that short amount of time when the user actually looks on the lockscreen, a precision of one minute is way too long. I would actually even use half a second or something like that - because in that time frame the user wants to know what time it is now, and not what time it was a minute ago.

Looking through the code, the timer is stopped while the device is unlocked, which is good. The only thing that concerns me right now, is that currently the the timer might be active while the device is locked and the screen is off - that would need to be checked. Once we are sure the timer is stopped when the screen is off, we can easily use a one second interval or something like that. If the timer keeps on ticking while the device is locked, even one minute is still too frequent.

Revision history for this message
Michał Sawicz (saviq) wrote :

We need to capture the requirement for a Clock component (as in date/time as properties of that component) at a given precision.

Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) wrote :

lgtm

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michał Sawicz (saviq) wrote :

Please merge trunk.

Revision history for this message
Michael Zanetti (mzanetti) wrote :

42 -add_subdirectory(plugins)
43 \ No newline at end of file
44 +add_subdirectory(plugins)

probably not harmful for us in practive, but I've seen weird failures because of things like this in the past.

Revision history for this message
Michał Sawicz (saviq) wrote :

Yeah but that actually _added_ the newline, isn't that what we want?

Revision history for this message
Michael Zanetti (mzanetti) wrote :

lgtm

review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Approve (continuous-integration)
Revision history for this message
PS Jenkins bot (ps-jenkins) wrote :
review: Needs Fixing (continuous-integration)
Revision history for this message
Michael Zanetti (mzanetti) :
review: Approve
Revision history for this message
PS Jenkins bot (ps-jenkins) :
review: Approve (continuous-integration)

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'Greeter/Clock.qml'
2--- Greeter/Clock.qml 2013-01-15 11:37:07 +0000
3+++ Greeter/Clock.qml 2013-04-12 15:39:38 +0000
4@@ -24,8 +24,11 @@
5 implicitHeight: childrenRect.height
6
7 property date __date
8+ property alias __timerInterval: timer.interval
9+ readonly property bool __timerRunning: timer.running
10
11 Timer {
12+ id: timer
13 interval: 1000 * 60
14 running: clock.enabled && clock.visible && clock.opacity != 0
15 repeat: true
16@@ -38,6 +41,7 @@
17
18 Label {
19 id: timeLabel
20+ objectName: "timeLabel"
21
22 anchors.horizontalCenter: parent.horizontalCenter
23 font.pixelSize: units.gu(7.5)
24@@ -49,6 +53,7 @@
25
26 Label {
27 id: dateLabel
28+ objectName: "dateLabel"
29
30 anchors.horizontalCenter: parent.horizontalCenter
31 fontSize: "medium"
32
33=== modified file 'tests/unittests/CMakeLists.txt'
34--- tests/unittests/CMakeLists.txt 2013-04-12 13:15:12 +0000
35+++ tests/unittests/CMakeLists.txt 2013-04-12 15:39:38 +0000
36@@ -4,6 +4,8 @@
37 set(qmltest_DEFAULT_PROPERTIES PROPERTIES ENVIRONMENT "QT_QPA_PLATFORM=minimal")
38
39 add_subdirectory(Components)
40+add_subdirectory(Greeter)
41 add_subdirectory(Panel)
42 add_subdirectory(SideStage)
43 add_subdirectory(plugins)
44+
45
46=== added directory 'tests/unittests/Greeter'
47=== added file 'tests/unittests/Greeter/CMakeLists.txt'
48--- tests/unittests/Greeter/CMakeLists.txt 1970-01-01 00:00:00 +0000
49+++ tests/unittests/Greeter/CMakeLists.txt 2013-04-12 15:39:38 +0000
50@@ -0,0 +1,1 @@
51+add_qml_test(Clock)
52
53=== added file 'tests/unittests/Greeter/tst_Clock.qml'
54--- tests/unittests/Greeter/tst_Clock.qml 1970-01-01 00:00:00 +0000
55+++ tests/unittests/Greeter/tst_Clock.qml 2013-04-12 15:39:38 +0000
56@@ -0,0 +1,88 @@
57+/*
58+ * Copyright 2013 Canonical Ltd.
59+ *
60+ * This program is free software; you can redistribute it and/or modify
61+ * it under the terms of the GNU General Public License as published by
62+ * the Free Software Foundation; version 3.
63+ *
64+ * This program is distributed in the hope that it will be useful,
65+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
66+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
67+ * GNU General Public License for more details.
68+ *
69+ * You should have received a copy of the GNU General Public License
70+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
71+ */
72+
73+import QtQuick 2.0
74+import QtTest 1.0
75+import "../../qmluitests"
76+import "../../../Greeter"
77+import Ubuntu.Components 0.1
78+
79+Rectangle {
80+ width: units.gu(60)
81+ height: units.gu(40)
82+ color: "black"
83+
84+ Clock {
85+ id: clock
86+ anchors {
87+ top: parent.top
88+ topMargin: units.gu(2)
89+ horizontalCenter: parent.horizontalCenter
90+ }
91+ }
92+
93+ UnityTestCase {
94+ name: "Clock"
95+
96+ function test_customDate() {
97+ var dateObj = new Date("October 13, 1975 11:13:00")
98+ var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
99+ var timeString = Qt.formatTime(dateObj)
100+
101+ clock.__timerInterval = 60000
102+ clock.__date = dateObj
103+ var dateLabel = findChild(clock, "dateLabel")
104+ compare(dateLabel.text, dateString, "Not the expected date")
105+ var timeLabel = findChild(clock, "timeLabel")
106+ compare(timeLabel.text, timeString, "Not the expected time")
107+ }
108+
109+ function test_dateUpdate() {
110+ var dateObj = new Date("October 13, 1975 11:13:00")
111+ var dateString = Qt.formatDate(dateObj, Qt.DefaultLocaleLongDate)
112+ var timeString = Qt.formatTime(dateObj)
113+
114+ clock.enabled = false
115+ compare(clock.__timerRunning, false, "Timer should not be running")
116+ clock.__date = dateObj
117+ clock.__timerInterval = 5
118+ wait(5) // spin event loop (only that would trigger the timer and reveal eventual bugs)
119+ var dateLabel = findChild(clock, "dateLabel")
120+ compare(dateLabel.text, dateString, "Not the expected date")
121+ var timeLabel = findChild(clock, "timeLabel")
122+ compare(timeLabel.text, timeString, "Not the expected time")
123+
124+ clock.enabled = true
125+ compare(clock.__timerRunning, true, "Timer should be running")
126+ wait(0) // spin event loop to trigger the timer
127+ verify(dateLabel.text !== dateString)
128+ if (timeLabel.text == "11:13") wait(60000) // next test will fail at 11:13, wait 1 minute
129+ verify(timeLabel.text !== timeString)
130+ }
131+
132+ function test_timerRunning() {
133+ // tests for clock.enabled property are already in test_dateUpdate()
134+ clock.opacity = 0.0
135+ compare(clock.__timerRunning, false, "Timer should not be running")
136+ clock.opacity = 1.0
137+ compare(clock.__timerRunning, true, "Timer should be running")
138+ clock.visible = false
139+ compare(clock.__timerRunning, false, "Timer should not be running")
140+ clock.visible = true
141+ compare(clock.__timerRunning, true, "Timer should be running")
142+ }
143+ }
144+}

Subscribers

People subscribed via source and target branches

to all changes: