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
=== modified file 'src/app/webbrowser/Browser.qml'
--- src/app/webbrowser/Browser.qml 2015-05-12 03:43:11 +0000
+++ src/app/webbrowser/Browser.qml 2015-05-13 02:22:38 +0000
@@ -195,6 +195,7 @@
195195
196 Chrome {196 Chrome {
197 id: chrome197 id: chrome
198 objectName: "chrome"
198199
199 visible: !recentView.visible200 visible: !recentView.visible
200201
@@ -1069,7 +1070,7 @@
10691070
1070 Component {1071 Component {
1071 id: leavePrivateModeDialog1072 id: leavePrivateModeDialog
1072 1073
1073 LeavePrivateModeDialog {1074 LeavePrivateModeDialog {
1074 id: dialogue1075 id: dialogue
1075 objectName: "leavePrivateModeDialog"1076 objectName: "leavePrivateModeDialog"
10761077
=== modified file 'tests/unittests/qml/CMakeLists.txt'
--- tests/unittests/qml/CMakeLists.txt 2015-02-26 17:49:24 +0000
+++ tests/unittests/qml/CMakeLists.txt 2015-05-13 02:22:38 +0000
@@ -7,13 +7,31 @@
7endif()7endif()
88
9set(TEST tst_QmlTests)9set(TEST tst_QmlTests)
10
10set(SOURCES11set(SOURCES
11 ${webbrowser-common_SOURCE_DIR}/favicon-fetcher.cpp12 ${webbrowser-common_SOURCE_DIR}/favicon-fetcher.cpp
13 ${webbrowser-common_SOURCE_DIR}/session-storage.cpp
14 ${webbrowser-app_SOURCE_DIR}/bookmarks-model.cpp
15 ${webbrowser-app_SOURCE_DIR}/cache-deleter.cpp
12 ${webbrowser-app_SOURCE_DIR}/file-operations.cpp16 ${webbrowser-app_SOURCE_DIR}/file-operations.cpp
17 ${webbrowser-app_SOURCE_DIR}/history-domain-model.cpp
18 ${webbrowser-app_SOURCE_DIR}/history-domainlist-chronological-model.cpp
19 ${webbrowser-app_SOURCE_DIR}/history-domainlist-model.cpp
20 ${webbrowser-app_SOURCE_DIR}/history-model.cpp
21 ${webbrowser-app_SOURCE_DIR}/history-timeframe-model.cpp
22 ${webbrowser-app_SOURCE_DIR}/limit-proxy-model.cpp
23 ${webbrowser-app_SOURCE_DIR}/searchengine.cpp
24 ${webbrowser-app_SOURCE_DIR}/suggestions-filter-model.cpp
25 ${webbrowser-app_SOURCE_DIR}/tabs-model.cpp
26 ${webbrowser-app_SOURCE_DIR}/top-sites-model.cpp
13 tst_QmlTests.cpp27 tst_QmlTests.cpp
14)28)
15add_executable(${TEST} ${SOURCES})29add_executable(${TEST} ${SOURCES})
16qt5_use_modules(${TEST} Core Gui Network Qml Quick QuickTest)30qt5_use_modules(${TEST} Core Gui Network Qml Quick QuickTest Sql)
31include_directories(${unity8_SOURCE_DIR}/libs/UbuntuGestures
32 ${unity8_SOURCE_DIR}/plugins)
33target_link_libraries(${TEST} UbuntuGesturesQml)
34
17include_directories(35include_directories(
18 ${webbrowser-common_SOURCE_DIR}36 ${webbrowser-common_SOURCE_DIR}
19 ${webbrowser-app_SOURCE_DIR}37 ${webbrowser-app_SOURCE_DIR}
2038
=== added file 'tests/unittests/qml/tst_Browser.qml'
--- tests/unittests/qml/tst_Browser.qml 1970-01-01 00:00:00 +0000
+++ tests/unittests/qml/tst_Browser.qml 2015-05-13 02:22:38 +0000
@@ -0,0 +1,87 @@
1/*
2 * Copyright 2015 Canonical Ltd.
3 *
4 * This file is part of webbrowser-app.
5 *
6 * webbrowser-app is free software; you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation; version 3.
9 *
10 * webbrowser-app is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
13 * GNU General Public License for more details.
14 *
15 * You should have received a copy of the GNU General Public License
16 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 */
18
19import QtQuick 2.0
20import QtTest 1.0
21import Ubuntu.Test 1.0
22import "../../../src/app/webbrowser"
23
24Item {
25 id: root
26
27 Browser {
28 id: browser
29 }
30
31 UbuntuTestCase {
32 name: "Browser"
33 when: windowShown
34
35 function cleanup() {
36 browser.incognito = false;
37 }
38
39 function test_browserMustStartInPlainMode() {
40 verify(!browser.incognito);
41 }
42
43 function test_incognitoBrowserMustUseDarkTheme() {
44 browser.incognito = true;
45 var chrome = findChild(browser, "chrome");
46 verify(chrome.useDarkTheme);
47 }
48
49 function test_plainBrowserMustNotUseDarkTheme() {
50 var chrome = findChild(browser, "chrome");
51 verify(!chrome.useDarkTheme);
52 }
53
54 function test_incognitoBrowserMustShowLeaveButton() {
55 browser.incognito = true;
56 var privateModeButton = findChild(browser, "privatemode");
57 compare(privateModeButton.text, i18n.tr("Leave Private"));
58 }
59
60 function test_plainBrowserMustShowEnterButton() {
61 var privateModeButton = findChild(browser, "privatemode");
62 compare(privateModeButton.text, i18n.tr("Private Mode"));
63 }
64
65 function test_triggerPrivateActionMustEnableIncognito() {
66 var privateModeButton = findChild(browser, "privatemode");
67 privateModeButton.trigger();
68 verify(browser.incognito);
69 }
70
71 function test_leavePrivateModeMustDisableIncognito() {
72 browser.incognito = true;
73 var privateModeButton = findChild(browser, "privatemode");
74 privateModeButton.trigger();
75
76 var leavePrivateModeDialog = findChild(
77 browser, "leavePrivateModeDialog");
78 var okButton = findChild(
79 leavePrivateModeDialog, "leavePrivateModeDialog.okButton");
80
81 mouseClick(okButton, centerOf(okButton));
82
83 verify(browser.incognito);
84 }
85
86 }
87}
088
=== modified file 'tests/unittests/qml/tst_QmlTests.cpp'
--- tests/unittests/qml/tst_QmlTests.cpp 2015-02-18 19:32:11 +0000
+++ tests/unittests/qml/tst_QmlTests.cpp 2015-05-13 02:22:38 +0000
@@ -21,8 +21,37 @@
21#include <QtQuickTest/QtQuickTest>21#include <QtQuickTest/QtQuickTest>
2222
23// local23// local
24#include "bookmarks-model.h"
25#include "cache-deleter.h"
24#include "favicon-fetcher.h"26#include "favicon-fetcher.h"
25#include "file-operations.h"27#include "file-operations.h"
28#include "history-domainlist-chronological-model.h"
29#include "history-domainlist-model.h"
30#include "history-model.h"
31#include "history-timeframe-model.h"
32#include "limit-proxy-model.h"
33#include "searchengine.h"
34#include "session-storage.h"
35#include "suggestions-filter-model.h"
36#include "tabs-model.h"
37#include "top-sites-model.h"
38#include "Ubuntu/Gestures/Direction.h"
39#include "Ubuntu/Gestures/DirectionalDragArea.h"
40
41
42static QObject* CacheDeleter_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
43{
44 Q_UNUSED(engine);
45 Q_UNUSED(scriptEngine);
46 return new CacheDeleter();
47}
48
49static QObject* Direction_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
50{
51 Q_UNUSED(engine);
52 Q_UNUSED(scriptEngine);
53 return new Direction();
54}
2655
27static QObject* FileOperations_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)56static QObject* FileOperations_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
28{57{
@@ -35,9 +64,32 @@
35{64{
36 const char* commonUri = "webbrowsercommon.private";65 const char* commonUri = "webbrowsercommon.private";
37 qmlRegisterType<FaviconFetcher>(commonUri, 0, 1, "FaviconFetcher");66 qmlRegisterType<FaviconFetcher>(commonUri, 0, 1, "FaviconFetcher");
67 qmlRegisterType<SessionStorage>(commonUri, 0, 1, "SessionStorage");
3868
39 const char* browserUri = "webbrowserapp.private";69 const char* browserUri = "webbrowserapp.private";
40 qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);70 qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
71 qmlRegisterType<HistoryDomainListChronologicalModel>(browserUri, 0, 1, "HistoryDomainListChronologicalModel");
72 qmlRegisterType<LimitProxyModel>(browserUri, 0, 1, "LimitProxyModel");
73 qmlRegisterType<SearchEngine>(browserUri, 0, 1, "SearchEngine");
74 qmlRegisterType<SuggestionsFilterModel>(browserUri, 0, 1, "SuggestionsFilterModel");
75 qmlRegisterType<TabsModel>(browserUri, 0, 1, "TabsModel");
76
77 qmlRegisterType<HistoryModel>(browserUri, 0, 1, "HistoryModel");
78 qmlRegisterType<HistoryTimeframeModel>(browserUri, 0, 1, "HistoryTimeframeModel");
79 qmlRegisterType<TopSitesModel>(browserUri, 0 , 1, "TopSitesModel");
80 qmlRegisterType<HistoryDomainListModel>(browserUri, 0, 1, "HistoryDomainListModel");
81 qmlRegisterType<HistoryDomainListChronologicalModel>(browserUri, 0, 1, "HistoryDomainListChronologicalModel");
82 qmlRegisterType<LimitProxyModel>(browserUri, 0 , 1, "LimitProxyModel");
83 qmlRegisterType<TabsModel>(browserUri, 0, 1, "TabsModel");
84 qmlRegisterType<BookmarksModel>(browserUri, 0, 1, "BookmarksModel");
85 qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
86 qmlRegisterType<SearchEngine>(browserUri, 0, 1, "SearchEngine");
87 qmlRegisterSingletonType<CacheDeleter>(browserUri, 0, 1, "CacheDeleter", CacheDeleter_singleton_factory);
88 qmlRegisterType<SuggestionsFilterModel>(browserUri, 0, 1, "SuggestionsFilterModel");
89
90 const char* gesturesUri = "Ubuntu.Gestures";
91 qmlRegisterSingletonType<Direction>(gesturesUri, 0, 1, "Direction", Direction_singleton_factory);
92 qmlRegisterType<DirectionalDragArea>(gesturesUri, 0, 1, "DirectionalDragArea");
4193
42 return quick_test_main(argc, argv, "QmlTests", 0);94 return quick_test_main(argc, argv, "QmlTests", 0);
43}95}

Subscribers

People subscribed via source and target branches

to all changes: