Merge lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests-qml into lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests

Proposed by Leo Arias
Status: Work in progress
Proposed branch: lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests-qml
Merge into: lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests
Diff against target: 224 lines (+160/-2)
4 files modified
src/app/webbrowser/Browser.qml (+2/-1)
tests/unittests/qml/CMakeLists.txt (+19/-1)
tests/unittests/qml/tst_Browser.qml (+87/-0)
tests/unittests/qml/tst_QmlTests.cpp (+52/-0)
To merge this branch: bzr merge lp:~canonical-platform-qa/webbrowser-app/webbrowser-app-private_browsing-refactor_tests-qml
Reviewer Review Type Date Requested Status
Canonical Platform QA Team Pending
Review via email: mp+258946@code.launchpad.net

Description of the change

Experimental branch.
Tests are throwing too many warnings, and the last test doesn't work yet. Also I had to import way to many things to get the file under test. Simple tests like this should be easy to write, so maybe the big Browser.qml file needs to be split.

To post a comment you must log in.
1026. By Leo Arias

Added extra tests.

1027. By Leo Arias

Reverted the po.

Revision history for this message
Olivier Tilloy (osomon) wrote :

QML tests are intended to test standalone QML components. Browser.qml is not a standalone component by any means, it’s the entire app itself. As such, I don’t think it makes sense to try and test in in a QML test.

I do agree that it would be good if we could reduce its size though, by splitting it into more standalone, reusable components (and add QML tests for those). It has been on my backlog for quite a while, but I’ve never quite gotten around to doing it, although I try not to increase its size with new code submissions, at the very least.

Suggestions on how to do that, and contributions very welcome!

Revision history for this message
Leo Arias (elopio) wrote :

Sorry for the late reply. I think that the first thing to do is to be able to replace all the models by simple list models during the tests.
I have an idea of how to do this based on some of the fakes I have used while writing simple QML tests, but it would take me a lot of time. So don't expect any contributions soon :)
What I think that would be really good is to get a video training session or a page in developer.ubuntu.com about how to put QML files under test. I'll talk to balloons.

Unmerged revisions

1027. By Leo Arias

Reverted the po.

1026. By Leo Arias

Added extra tests.

1025. By Leo Arias

Added an initial qml test for the incognito mode.

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'src/app/webbrowser/Browser.qml'
2--- src/app/webbrowser/Browser.qml 2015-05-12 03:43:11 +0000
3+++ src/app/webbrowser/Browser.qml 2015-05-13 02:22:38 +0000
4@@ -195,6 +195,7 @@
5
6 Chrome {
7 id: chrome
8+ objectName: "chrome"
9
10 visible: !recentView.visible
11
12@@ -1069,7 +1070,7 @@
13
14 Component {
15 id: leavePrivateModeDialog
16-
17+
18 LeavePrivateModeDialog {
19 id: dialogue
20 objectName: "leavePrivateModeDialog"
21
22=== modified file 'tests/unittests/qml/CMakeLists.txt'
23--- tests/unittests/qml/CMakeLists.txt 2015-02-26 17:49:24 +0000
24+++ tests/unittests/qml/CMakeLists.txt 2015-05-13 02:22:38 +0000
25@@ -7,13 +7,31 @@
26 endif()
27
28 set(TEST tst_QmlTests)
29+
30 set(SOURCES
31 ${webbrowser-common_SOURCE_DIR}/favicon-fetcher.cpp
32+ ${webbrowser-common_SOURCE_DIR}/session-storage.cpp
33+ ${webbrowser-app_SOURCE_DIR}/bookmarks-model.cpp
34+ ${webbrowser-app_SOURCE_DIR}/cache-deleter.cpp
35 ${webbrowser-app_SOURCE_DIR}/file-operations.cpp
36+ ${webbrowser-app_SOURCE_DIR}/history-domain-model.cpp
37+ ${webbrowser-app_SOURCE_DIR}/history-domainlist-chronological-model.cpp
38+ ${webbrowser-app_SOURCE_DIR}/history-domainlist-model.cpp
39+ ${webbrowser-app_SOURCE_DIR}/history-model.cpp
40+ ${webbrowser-app_SOURCE_DIR}/history-timeframe-model.cpp
41+ ${webbrowser-app_SOURCE_DIR}/limit-proxy-model.cpp
42+ ${webbrowser-app_SOURCE_DIR}/searchengine.cpp
43+ ${webbrowser-app_SOURCE_DIR}/suggestions-filter-model.cpp
44+ ${webbrowser-app_SOURCE_DIR}/tabs-model.cpp
45+ ${webbrowser-app_SOURCE_DIR}/top-sites-model.cpp
46 tst_QmlTests.cpp
47 )
48 add_executable(${TEST} ${SOURCES})
49-qt5_use_modules(${TEST} Core Gui Network Qml Quick QuickTest)
50+qt5_use_modules(${TEST} Core Gui Network Qml Quick QuickTest Sql)
51+include_directories(${unity8_SOURCE_DIR}/libs/UbuntuGestures
52+ ${unity8_SOURCE_DIR}/plugins)
53+target_link_libraries(${TEST} UbuntuGesturesQml)
54+
55 include_directories(
56 ${webbrowser-common_SOURCE_DIR}
57 ${webbrowser-app_SOURCE_DIR}
58
59=== added file 'tests/unittests/qml/tst_Browser.qml'
60--- tests/unittests/qml/tst_Browser.qml 1970-01-01 00:00:00 +0000
61+++ tests/unittests/qml/tst_Browser.qml 2015-05-13 02:22:38 +0000
62@@ -0,0 +1,87 @@
63+/*
64+ * Copyright 2015 Canonical Ltd.
65+ *
66+ * This file is part of webbrowser-app.
67+ *
68+ * webbrowser-app is free software; you can redistribute it and/or modify
69+ * it under the terms of the GNU General Public License as published by
70+ * the Free Software Foundation; version 3.
71+ *
72+ * webbrowser-app is distributed in the hope that it will be useful,
73+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
74+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
75+ * GNU General Public License for more details.
76+ *
77+ * You should have received a copy of the GNU General Public License
78+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
79+ */
80+
81+import QtQuick 2.0
82+import QtTest 1.0
83+import Ubuntu.Test 1.0
84+import "../../../src/app/webbrowser"
85+
86+Item {
87+ id: root
88+
89+ Browser {
90+ id: browser
91+ }
92+
93+ UbuntuTestCase {
94+ name: "Browser"
95+ when: windowShown
96+
97+ function cleanup() {
98+ browser.incognito = false;
99+ }
100+
101+ function test_browserMustStartInPlainMode() {
102+ verify(!browser.incognito);
103+ }
104+
105+ function test_incognitoBrowserMustUseDarkTheme() {
106+ browser.incognito = true;
107+ var chrome = findChild(browser, "chrome");
108+ verify(chrome.useDarkTheme);
109+ }
110+
111+ function test_plainBrowserMustNotUseDarkTheme() {
112+ var chrome = findChild(browser, "chrome");
113+ verify(!chrome.useDarkTheme);
114+ }
115+
116+ function test_incognitoBrowserMustShowLeaveButton() {
117+ browser.incognito = true;
118+ var privateModeButton = findChild(browser, "privatemode");
119+ compare(privateModeButton.text, i18n.tr("Leave Private"));
120+ }
121+
122+ function test_plainBrowserMustShowEnterButton() {
123+ var privateModeButton = findChild(browser, "privatemode");
124+ compare(privateModeButton.text, i18n.tr("Private Mode"));
125+ }
126+
127+ function test_triggerPrivateActionMustEnableIncognito() {
128+ var privateModeButton = findChild(browser, "privatemode");
129+ privateModeButton.trigger();
130+ verify(browser.incognito);
131+ }
132+
133+ function test_leavePrivateModeMustDisableIncognito() {
134+ browser.incognito = true;
135+ var privateModeButton = findChild(browser, "privatemode");
136+ privateModeButton.trigger();
137+
138+ var leavePrivateModeDialog = findChild(
139+ browser, "leavePrivateModeDialog");
140+ var okButton = findChild(
141+ leavePrivateModeDialog, "leavePrivateModeDialog.okButton");
142+
143+ mouseClick(okButton, centerOf(okButton));
144+
145+ verify(browser.incognito);
146+ }
147+
148+ }
149+}
150
151=== modified file 'tests/unittests/qml/tst_QmlTests.cpp'
152--- tests/unittests/qml/tst_QmlTests.cpp 2015-02-18 19:32:11 +0000
153+++ tests/unittests/qml/tst_QmlTests.cpp 2015-05-13 02:22:38 +0000
154@@ -21,8 +21,37 @@
155 #include <QtQuickTest/QtQuickTest>
156
157 // local
158+#include "bookmarks-model.h"
159+#include "cache-deleter.h"
160 #include "favicon-fetcher.h"
161 #include "file-operations.h"
162+#include "history-domainlist-chronological-model.h"
163+#include "history-domainlist-model.h"
164+#include "history-model.h"
165+#include "history-timeframe-model.h"
166+#include "limit-proxy-model.h"
167+#include "searchengine.h"
168+#include "session-storage.h"
169+#include "suggestions-filter-model.h"
170+#include "tabs-model.h"
171+#include "top-sites-model.h"
172+#include "Ubuntu/Gestures/Direction.h"
173+#include "Ubuntu/Gestures/DirectionalDragArea.h"
174+
175+
176+static QObject* CacheDeleter_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
177+{
178+ Q_UNUSED(engine);
179+ Q_UNUSED(scriptEngine);
180+ return new CacheDeleter();
181+}
182+
183+static QObject* Direction_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
184+{
185+ Q_UNUSED(engine);
186+ Q_UNUSED(scriptEngine);
187+ return new Direction();
188+}
189
190 static QObject* FileOperations_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
191 {
192@@ -35,9 +64,32 @@
193 {
194 const char* commonUri = "webbrowsercommon.private";
195 qmlRegisterType<FaviconFetcher>(commonUri, 0, 1, "FaviconFetcher");
196+ qmlRegisterType<SessionStorage>(commonUri, 0, 1, "SessionStorage");
197
198 const char* browserUri = "webbrowserapp.private";
199 qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
200+ qmlRegisterType<HistoryDomainListChronologicalModel>(browserUri, 0, 1, "HistoryDomainListChronologicalModel");
201+ qmlRegisterType<LimitProxyModel>(browserUri, 0, 1, "LimitProxyModel");
202+ qmlRegisterType<SearchEngine>(browserUri, 0, 1, "SearchEngine");
203+ qmlRegisterType<SuggestionsFilterModel>(browserUri, 0, 1, "SuggestionsFilterModel");
204+ qmlRegisterType<TabsModel>(browserUri, 0, 1, "TabsModel");
205+
206+ qmlRegisterType<HistoryModel>(browserUri, 0, 1, "HistoryModel");
207+ qmlRegisterType<HistoryTimeframeModel>(browserUri, 0, 1, "HistoryTimeframeModel");
208+ qmlRegisterType<TopSitesModel>(browserUri, 0 , 1, "TopSitesModel");
209+ qmlRegisterType<HistoryDomainListModel>(browserUri, 0, 1, "HistoryDomainListModel");
210+ qmlRegisterType<HistoryDomainListChronologicalModel>(browserUri, 0, 1, "HistoryDomainListChronologicalModel");
211+ qmlRegisterType<LimitProxyModel>(browserUri, 0 , 1, "LimitProxyModel");
212+ qmlRegisterType<TabsModel>(browserUri, 0, 1, "TabsModel");
213+ qmlRegisterType<BookmarksModel>(browserUri, 0, 1, "BookmarksModel");
214+ qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
215+ qmlRegisterType<SearchEngine>(browserUri, 0, 1, "SearchEngine");
216+ qmlRegisterSingletonType<CacheDeleter>(browserUri, 0, 1, "CacheDeleter", CacheDeleter_singleton_factory);
217+ qmlRegisterType<SuggestionsFilterModel>(browserUri, 0, 1, "SuggestionsFilterModel");
218+
219+ const char* gesturesUri = "Ubuntu.Gestures";
220+ qmlRegisterSingletonType<Direction>(gesturesUri, 0, 1, "Direction", Direction_singleton_factory);
221+ qmlRegisterType<DirectionalDragArea>(gesturesUri, 0, 1, "DirectionalDragArea");
222
223 return quick_test_main(argc, argv, "QmlTests", 0);
224 }

Subscribers

People subscribed via source and target branches

to all changes: