Merge lp:~osomon/webbrowser-app/use-grabToImage into lp:webbrowser-app

Proposed by Olivier Tilloy on 2015-02-18
Status: Merged
Approved by: Olivier Tilloy on 2015-02-26
Approved revision: 913
Merged at revision: 916
Proposed branch: lp:~osomon/webbrowser-app/use-grabToImage
Merge into: lp:webbrowser-app
Diff against target: 705 lines (+71/-388)
13 files modified
debian/control (+3/-5)
src/Ubuntu/Web/plugin.cpp (+15/-1)
src/app/webbrowser/BrowserTab.qml (+22/-37)
src/app/webbrowser/CMakeLists.txt (+1/-4)
src/app/webbrowser/file-operations.cpp (+14/-1)
src/app/webbrowser/file-operations.h (+3/-1)
src/app/webbrowser/item-capture.cpp (+0/-123)
src/app/webbrowser/item-capture.h (+0/-62)
src/app/webbrowser/webbrowser-app.cpp (+0/-2)
tests/unittests/qml/CMakeLists.txt (+2/-3)
tests/unittests/qml/tst_BrowserTab.qml (+1/-21)
tests/unittests/qml/tst_ItemCapture.qml (+0/-125)
tests/unittests/qml/tst_QmlTests.cpp (+10/-3)
To merge this branch: bzr merge lp:~osomon/webbrowser-app/use-grabToImage
Reviewer Review Type Date Requested Status
Ken VanDine 2015-02-18 Approve on 2015-02-27
PS Jenkins bot continuous-integration Needs Fixing on 2015-02-26
Loïc Molinari 2015-02-18 Pending
Florian Boucault 2015-02-18 Pending
Review via email: mp+250223@code.launchpad.net

Commit Message

Use the new Item::grabToImage() API (new in Qt 5.4) to replace the custom ItemCapture element.

To post a comment you must log in.
911. By Olivier Tilloy on 2015-02-26

Merge the latest changes from trunk.

912. By Olivier Tilloy on 2015-02-26

Remove the need for dependencies on private headers.

913. By Olivier Tilloy on 2015-02-26

Explicitly bump the build dependency on Qt to 5.4.

Ken VanDine (ken-vandine) wrote :

Packaging is fine.

review: Approve

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
1=== modified file 'debian/control'
2--- debian/control 2015-02-17 20:54:04 +0000
3+++ debian/control 2015-02-26 17:54:55 +0000
4@@ -10,16 +10,14 @@
5 libqt5sql5-sqlite,
6 python-flake8,
7 python3-all,
8- qml-module-qtquick2 | qtdeclarative5-qtquick2-plugin,
9+ qml-module-qtquick2 (>= 5.4) | qtdeclarative5-qtquick2-plugin (>= 5.4),
10 qml-module-qttest | qtdeclarative5-test-plugin,
11 qml-module-qtwebkit,
12 qt5-default,
13 qt5-qmake,
14- qtbase5-dev,
15+ qtbase5-dev (>= 5.4),
16 qtbase5-dev-tools,
17- qtbase5-private-dev,
18 qtdeclarative5-dev,
19- qtdeclarative5-private-dev,
20 qtdeclarative5-ubuntu-ui-toolkit-plugin,
21 xvfb,
22 Standards-Version: 3.9.5
23@@ -36,7 +34,7 @@
24 fonts-liberation,
25 liboxideqt-qmlplugin (>= 1.4),
26 libqt5sql5-sqlite,
27- qml-module-qtquick2 | qtdeclarative5-qtquick2-plugin,
28+ qml-module-qtquick2 (>= 5.4) | qtdeclarative5-qtquick2-plugin (>= 5.4),
29 qml-module-qtquick-dialogs | qtdeclarative5-dialogs-plugin,
30 qml-module-qtquick-window2 | qtdeclarative5-window-plugin,
31 qtdeclarative5-ubuntu-ui-toolkit-plugin,
32
33=== modified file 'src/Ubuntu/Web/plugin.cpp'
34--- src/Ubuntu/Web/plugin.cpp 2014-11-26 10:38:23 +0000
35+++ src/Ubuntu/Web/plugin.cpp 2015-02-26 17:54:55 +0000
36@@ -1,5 +1,5 @@
37 /*
38- * Copyright 2013-2014 Canonical Ltd.
39+ * Copyright 2013-2015 Canonical Ltd.
40 *
41 * This file is part of webbrowser-app.
42 *
43@@ -34,6 +34,7 @@
44 {
45 Q_OBJECT
46
47+ Q_PROPERTY(QString cacheLocation READ cacheLocation NOTIFY cacheLocationChanged)
48 Q_PROPERTY(QString dataLocation READ dataLocation NOTIFY dataLocationChanged)
49 Q_PROPERTY(QString formFactor READ formFactor CONSTANT)
50 Q_PROPERTY(QString webviewDevtoolsDebugHost READ devtoolsHost CONSTANT)
51@@ -43,6 +44,7 @@
52 public:
53 UbuntuWebPluginContext(QObject* parent = 0);
54
55+ QString cacheLocation() const;
56 QString dataLocation() const;
57 QString formFactor();
58 QString devtoolsHost();
59@@ -50,6 +52,7 @@
60 QStringList hostMappingRules();
61
62 Q_SIGNALS:
63+ void cacheLocationChanged() const;
64 void dataLocationChanged() const;
65
66 private:
67@@ -66,9 +69,20 @@
68 , m_hostMappingRulesQueried(false)
69 {
70 connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
71+ this, SIGNAL(cacheLocationChanged()));
72+ connect(QCoreApplication::instance(), SIGNAL(applicationNameChanged()),
73 this, SIGNAL(dataLocationChanged()));
74 }
75
76+QString UbuntuWebPluginContext::cacheLocation() const
77+{
78+ QDir location(QStandardPaths::writableLocation(QStandardPaths::CacheLocation));
79+ if (!location.exists()) {
80+ QDir::root().mkpath(location.absolutePath());
81+ }
82+ return location.absolutePath();
83+}
84+
85 QString UbuntuWebPluginContext::dataLocation() const
86 {
87 QDir location(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
88
89=== modified file 'src/app/webbrowser/BrowserTab.qml'
90--- src/app/webbrowser/BrowserTab.qml 2014-12-17 14:48:20 +0000
91+++ src/app/webbrowser/BrowserTab.qml 2015-02-26 17:54:55 +0000
92@@ -1,5 +1,5 @@
93 /*
94- * Copyright 2014 Canonical Ltd.
95+ * Copyright 2014-2015 Canonical Ltd.
96 *
97 * This file is part of webbrowser-app.
98 *
99@@ -16,7 +16,8 @@
100 * along with this program. If not, see <http://www.gnu.org/licenses/>.
101 */
102
103-import QtQuick 2.0
104+import QtQuick 2.4
105+import Ubuntu.Web 0.2
106 import com.canonical.Oxide 1.4 as Oxide
107 import webbrowserapp.private 0.1
108
109@@ -65,44 +66,28 @@
110 destroy()
111 }
112
113- property var captureTaker
114- Component {
115- id: captureComponent
116- ItemCapture {
117- quality: 50
118- onCaptureFinished: {
119- if ((request == uniqueId) && capture.toString()) {
120- if (preview == capture) {
121- // Ensure that the preview URL actually changes,
122- // for the image to be reloaded
123- preview = ""
124- }
125- preview = capture
126- }
127- if (!webview.visible) {
128- captureTaker.destroy()
129- }
130- }
131- }
132- }
133- function createCaptureTakerIfNeeded() {
134- if (!captureTaker) {
135- captureTaker = captureComponent.createObject(webview)
136- }
137- }
138- onWebviewChanged: {
139- if (webview) {
140- createCaptureTakerIfNeeded()
141- }
142- }
143-
144 Connections {
145 target: webview
146 onVisibleChanged: {
147- if (webview.visible) {
148- createCaptureTakerIfNeeded()
149- } else {
150- captureTaker.requestCapture(uniqueId)
151+ if (!webview.visible) {
152+ webview.grabToImage(function(result) {
153+ var capturesDir = cacheLocation + "/captures"
154+ if (!FileOperations.exists(Qt.resolvedUrl(capturesDir))) {
155+ FileOperations.mkpath(Qt.resolvedUrl(capturesDir))
156+ }
157+ var filepath = capturesDir + "/" + uniqueId + ".jpg"
158+ if (result.saveToFile(filepath)) {
159+ var previewUrl = Qt.resolvedUrl(filepath)
160+ if (preview == previewUrl) {
161+ // Ensure that the preview URL actually changes,
162+ // for the image to be reloaded
163+ preview = ""
164+ }
165+ preview = previewUrl
166+ } else {
167+ preview = ""
168+ }
169+ })
170 }
171 }
172 }
173
174=== modified file 'src/app/webbrowser/CMakeLists.txt'
175--- src/app/webbrowser/CMakeLists.txt 2014-12-11 17:53:28 +0000
176+++ src/app/webbrowser/CMakeLists.txt 2015-02-26 17:54:55 +0000
177@@ -25,11 +25,8 @@
178
179 qt5_use_modules(${WEBBROWSER_APP_MODELS} Core Sql)
180
181-include_directories(${Qt5Quick_PRIVATE_INCLUDE_DIRS})
182-
183 set(WEBBROWSER_APP_SRC
184 file-operations.cpp
185- item-capture.cpp
186 searchengine.cpp
187 settings.cpp
188 webbrowser-app.cpp
189@@ -41,7 +38,7 @@
190
191 target_link_libraries(${WEBBROWSER_APP} ${COMMONLIB} ${WEBBROWSER_APP_MODELS})
192
193-qt5_use_modules(${WEBBROWSER_APP} Concurrent Core Gui Qml Quick)
194+qt5_use_modules(${WEBBROWSER_APP} Core Qml Quick)
195
196 install(TARGETS ${WEBBROWSER_APP}
197 RUNTIME DESTINATION ${CMAKE_INSTALL_BINDIR})
198
199=== modified file 'src/app/webbrowser/file-operations.cpp'
200--- src/app/webbrowser/file-operations.cpp 2014-12-11 17:04:20 +0000
201+++ src/app/webbrowser/file-operations.cpp 2015-02-26 17:54:55 +0000
202@@ -1,5 +1,5 @@
203 /*
204- * Copyright 2014 Canonical Ltd.
205+ * Copyright 2014-2015 Canonical Ltd.
206 *
207 * This file is part of webbrowser-app.
208 *
209@@ -18,7 +18,9 @@
210
211 #include "file-operations.h"
212
213+#include <QtCore/QDir>
214 #include <QtCore/QFile>
215+#include <QtCore/QFileInfo>
216 #include <QtCore/QUrl>
217
218 FileOperations::FileOperations(QObject* parent)
219@@ -26,7 +28,18 @@
220 {
221 }
222
223+bool FileOperations::exists(const QUrl& path) const
224+{
225+ // works for both files and directories
226+ return QFileInfo::exists(path.toLocalFile());
227+}
228+
229 bool FileOperations::remove(const QUrl& file) const
230 {
231 return QFile::remove(file.toLocalFile());
232 }
233+
234+bool FileOperations::mkpath(const QUrl& path) const
235+{
236+ return QDir::root().mkpath(path.toLocalFile());
237+}
238
239=== modified file 'src/app/webbrowser/file-operations.h'
240--- src/app/webbrowser/file-operations.h 2014-12-11 17:04:20 +0000
241+++ src/app/webbrowser/file-operations.h 2015-02-26 17:54:55 +0000
242@@ -1,5 +1,5 @@
243 /*
244- * Copyright 2014 Canonical Ltd.
245+ * Copyright 2014-2015 Canonical Ltd.
246 *
247 * This file is part of webbrowser-app.
248 *
249@@ -30,7 +30,9 @@
250 public:
251 explicit FileOperations(QObject* parent=0);
252
253+ Q_INVOKABLE bool exists(const QUrl& path) const;
254 Q_INVOKABLE bool remove(const QUrl& file) const;
255+ Q_INVOKABLE bool mkpath(const QUrl& path) const;
256 };
257
258 #endif // __FILE_OPERATIONS_H__
259
260=== removed file 'src/app/webbrowser/item-capture.cpp'
261--- src/app/webbrowser/item-capture.cpp 2014-12-17 07:45:32 +0000
262+++ src/app/webbrowser/item-capture.cpp 1970-01-01 00:00:00 +0000
263@@ -1,123 +0,0 @@
264-/*
265- * Copyright 2014 Canonical Ltd.
266- *
267- * This file is part of webbrowser-app.
268- *
269- * webbrowser-app is free software; you can redistribute it and/or modify
270- * it under the terms of the GNU General Public License as published by
271- * the Free Software Foundation; version 3.
272- *
273- * webbrowser-app is distributed in the hope that it will be useful,
274- * but WITHOUT ANY WARRANTY; without even the implied warranty of
275- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
276- * GNU General Public License for more details.
277- *
278- * You should have received a copy of the GNU General Public License
279- * along with this program. If not, see <http://www.gnu.org/licenses/>.
280- */
281-
282-// local
283-#include "item-capture.h"
284-
285-// Qt
286-#include <QtConcurrent/QtConcurrent>
287-#include <QtCore/QDebug>
288-#include <QtCore/QDir>
289-#include <QtCore/QMetaObject>
290-#include <QtCore/QStandardPaths>
291-#include <QtGui/QImage>
292-#include <QtQuick/private/qquickitem_p.h>
293-
294-ItemCapture::ItemCapture(QQuickItem* parent)
295- : QQuickShaderEffectSource(parent)
296- , m_quality(-1)
297-{
298- connect(this, SIGNAL(parentChanged(QQuickItem*)), SLOT(onParentChanged(QQuickItem*)));
299-
300- setScale(0);
301-
302- QDir cacheLocation(QStandardPaths::writableLocation(QStandardPaths::CacheLocation) + "/captures");
303- m_cacheLocation = cacheLocation.absolutePath();
304- if (!cacheLocation.exists()) {
305- QDir::root().mkpath(m_cacheLocation);
306- }
307-}
308-
309-const int ItemCapture::quality() const
310-{
311- return m_quality;
312-}
313-
314-void ItemCapture::setQuality(const int quality)
315-{
316- if (quality != m_quality) {
317- if ((quality >= -1) && (quality <= 100)) {
318- m_quality = quality;
319- Q_EMIT qualityChanged();
320- } else {
321- qWarning() << "Invalid value for quality, must be between 0 and 100 (or -1 for default)";
322- }
323- }
324-}
325-
326-void ItemCapture::onParentChanged(QQuickItem* parent)
327-{
328- if (sourceItem()) {
329- sourceItem()->disconnect(this);
330- }
331- QQuickItemPrivate::get(this)->anchors()->setFill(parent);
332- setSourceItem(parent);
333- if (parent) {
334- connect(parent, SIGNAL(visibleChanged()), SLOT(onParentVisibleChanged()));
335- }
336-}
337-
338-void ItemCapture::onParentVisibleChanged()
339-{
340- setLive(parentItem()->isVisible());
341-}
342-
343-QSGNode* ItemCapture::updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData)
344-{
345- QSGNode* newNode = QQuickShaderEffectSource::updatePaintNode(oldNode, updatePaintNodeData);
346- if (!m_request.isEmpty()) {
347- QString request = m_request;
348- m_request.clear();
349-#if QT_VERSION < QT_VERSION_CHECK(5, 4, 0)
350- QQuickShaderEffectTexture* texture =
351- qobject_cast<QQuickShaderEffectTexture*>(textureProvider()->texture());
352-#else
353- QSGLayer* texture =
354- qobject_cast<QSGLayer*>(textureProvider()->texture());
355-#endif
356- QImage image = texture->toImage().mirrored();
357- if (!image.isNull()) {
358- QString filePath = m_cacheLocation + "/" + request + ".jpg";
359- QtConcurrent::run(this, &ItemCapture::saveImage, image, filePath, request);
360- return newNode;
361- }
362- QMetaObject::invokeMethod(this, "captureFinished", Qt::QueuedConnection,
363- Q_ARG(QString, request), Q_ARG(QUrl, QUrl()));
364- }
365- return newNode;
366-}
367-
368-void ItemCapture::requestCapture(const QString& id)
369-{
370- if (id.contains("/")) {
371- qWarning() << "Invalid ID (contains slashes)";
372- Q_EMIT captureFinished(id, QUrl());
373- }
374- m_request = id;
375- scheduleUpdate();
376-}
377-
378-void ItemCapture::saveImage(const QImage& image, const QString& filePath, const QString& request)
379-{
380- QUrl capture;
381- if (image.save(filePath, 0, m_quality)) {
382- capture = QUrl::fromLocalFile(filePath);
383- }
384- QMetaObject::invokeMethod(this, "captureFinished", Qt::QueuedConnection,
385- Q_ARG(QString, request), Q_ARG(QUrl, capture));
386-}
387
388=== removed file 'src/app/webbrowser/item-capture.h'
389--- src/app/webbrowser/item-capture.h 2014-12-12 09:21:14 +0000
390+++ src/app/webbrowser/item-capture.h 1970-01-01 00:00:00 +0000
391@@ -1,62 +0,0 @@
392-/*
393- * Copyright 2014 Canonical Ltd.
394- *
395- * This file is part of webbrowser-app.
396- *
397- * webbrowser-app is free software; you can redistribute it and/or modify
398- * it under the terms of the GNU General Public License as published by
399- * the Free Software Foundation; version 3.
400- *
401- * webbrowser-app is distributed in the hope that it will be useful,
402- * but WITHOUT ANY WARRANTY; without even the implied warranty of
403- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
404- * GNU General Public License for more details.
405- *
406- * You should have received a copy of the GNU General Public License
407- * along with this program. If not, see <http://www.gnu.org/licenses/>.
408- */
409-
410-#ifndef __ITEM_CAPTURE_H__
411-#define __ITEM_CAPTURE_H__
412-
413-// Qt
414-#include <QtCore/QString>
415-#include <QtCore/QUrl>
416-#include <QtQuick/private/qquickshadereffectsource_p.h>
417-
418-class QImage;
419-
420-class ItemCapture : public QQuickShaderEffectSource
421-{
422- Q_OBJECT
423-
424- Q_PROPERTY(int quality READ quality WRITE setQuality NOTIFY qualityChanged)
425-
426-public:
427- ItemCapture(QQuickItem* parent=0);
428-
429- const int quality() const;
430- void setQuality(const int quality);
431-
432-public Q_SLOTS:
433- void requestCapture(const QString& id);
434-
435-Q_SIGNALS:
436- void qualityChanged() const;
437- void captureFinished(QString request, QUrl capture) const;
438-
439-protected:
440- QSGNode* updatePaintNode(QSGNode* oldNode, UpdatePaintNodeData* updatePaintNodeData);
441-
442-private Q_SLOTS:
443- void onParentChanged(QQuickItem* parent);
444- void onParentVisibleChanged();
445- void saveImage(const QImage& image, const QString& filePath, const QString& request);
446-
447-private:
448- QString m_cacheLocation;
449- QString m_request;
450- int m_quality;
451-};
452-
453-#endif // __ITEM_CAPTURE_H__
454
455=== modified file 'src/app/webbrowser/webbrowser-app.cpp'
456--- src/app/webbrowser/webbrowser-app.cpp 2015-02-18 15:44:25 +0000
457+++ src/app/webbrowser/webbrowser-app.cpp 2015-02-26 17:54:55 +0000
458@@ -25,7 +25,6 @@
459 #include "history-byvisits-model.h"
460 #include "history-domainlist-model.h"
461 #include "history-domainlist-chronological-model.h"
462-#include "item-capture.h"
463 #include "limit-proxy-model.h"
464 #include "searchengine.h"
465 #include "settings.h"
466@@ -92,7 +91,6 @@
467 qmlRegisterType<LimitProxyModel>(uri, 0 , 1, "LimitProxyModel");
468 qmlRegisterType<TabsModel>(uri, 0, 1, "TabsModel");
469 qmlRegisterType<BookmarksModel>(uri, 0, 1, "BookmarksModel");
470- qmlRegisterType<ItemCapture>(uri, 0, 1, "ItemCapture");
471 qmlRegisterSingletonType<FileOperations>(uri, 0, 1, "FileOperations", FileOperations_singleton_factory);
472
473 if (BrowserApplication::initialize("webbrowser/webbrowser-app.qml")) {
474
475=== modified file 'tests/unittests/qml/CMakeLists.txt'
476--- tests/unittests/qml/CMakeLists.txt 2014-12-03 14:35:29 +0000
477+++ tests/unittests/qml/CMakeLists.txt 2015-02-26 17:54:55 +0000
478@@ -9,15 +9,14 @@
479 set(TEST tst_QmlTests)
480 set(SOURCES
481 ${webbrowser-common_SOURCE_DIR}/favicon-fetcher.cpp
482- ${webbrowser-app_SOURCE_DIR}/item-capture.cpp
483+ ${webbrowser-app_SOURCE_DIR}/file-operations.cpp
484 tst_QmlTests.cpp
485 )
486 add_executable(${TEST} ${SOURCES})
487-qt5_use_modules(${TEST} Qml Quick QuickTest)
488+qt5_use_modules(${TEST} Core Gui Network Qml Quick QuickTest)
489 include_directories(
490 ${webbrowser-common_SOURCE_DIR}
491 ${webbrowser-app_SOURCE_DIR}
492- ${Qt5Quick_PRIVATE_INCLUDE_DIRS}
493 )
494 add_test(${TEST} ${XVFB_COMMAND} ${CMAKE_CURRENT_BINARY_DIR}/${TEST}
495 -input ${CMAKE_CURRENT_SOURCE_DIR}
496
497=== modified file 'tests/unittests/qml/tst_BrowserTab.qml'
498--- tests/unittests/qml/tst_BrowserTab.qml 2014-12-17 14:56:36 +0000
499+++ tests/unittests/qml/tst_BrowserTab.qml 2015-02-26 17:54:55 +0000
500@@ -1,5 +1,5 @@
501 /*
502- * Copyright 2014 Canonical Ltd.
503+ * Copyright 2014-2015 Canonical Ltd.
504 *
505 * This file is part of webbrowser-app.
506 *
507@@ -38,7 +38,6 @@
508 property string currentState
509 }
510 readonly property bool webviewPresent: webview
511- readonly property bool captureTakerPresent: captureTaker != undefined
512 }
513 }
514
515@@ -84,24 +83,5 @@
516 compare(tab.webview.request, "foobar")
517 tab.destroy()
518 }
519-
520- function test_capture_taker() {
521- var tab = tabComponent.createObject(root)
522- verify(!tab.captureTakerPresent)
523-
524- tab.load()
525- tryCompare(tab, 'captureTakerPresent', true)
526-
527- tab.visible = false
528- tryCompare(tab, 'captureTakerPresent', false)
529-
530- tab.visible = true
531- tryCompare(tab, 'captureTakerPresent', true)
532-
533- tab.unload()
534- tryCompare(tab, 'captureTakerPresent', false)
535-
536- tab.destroy()
537- }
538 }
539 }
540
541=== removed file 'tests/unittests/qml/tst_ItemCapture.qml'
542--- tests/unittests/qml/tst_ItemCapture.qml 2014-12-16 22:28:02 +0000
543+++ tests/unittests/qml/tst_ItemCapture.qml 1970-01-01 00:00:00 +0000
544@@ -1,125 +0,0 @@
545-/*
546- * Copyright 2014 Canonical Ltd.
547- *
548- * This file is part of webbrowser-app.
549- *
550- * webbrowser-app is free software; you can redistribute it and/or modify
551- * it under the terms of the GNU General Public License as published by
552- * the Free Software Foundation; version 3.
553- *
554- * webbrowser-app is distributed in the hope that it will be useful,
555- * but WITHOUT ANY WARRANTY; without even the implied warranty of
556- * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
557- * GNU General Public License for more details.
558- *
559- * You should have received a copy of the GNU General Public License
560- * along with this program. If not, see <http://www.gnu.org/licenses/>.
561- */
562-
563-import QtQuick 2.0
564-import QtTest 1.0
565-import webbrowserapp.private 0.1
566-
567-Item {
568- width: 200
569- height: 200
570-
571- Rectangle {
572- id: rect
573-
574- width: 123
575- height: 157
576- anchors.centerIn: parent
577-
578- gradient: Gradient {
579- GradientStop {
580- position: 0.0
581- color: "#123456"
582- }
583- GradientStop {
584- position: 1.0
585- color: "#ABCDEF"
586- }
587- }
588-
589- ItemCapture {
590- id: capture
591- onCaptureFinished: image.source = capture
592- }
593-
594- SignalSpy {
595- id: spyReady
596- target: capture
597- signalName: "scheduledUpdateCompleted"
598- }
599-
600- SignalSpy {
601- id: spyCaptured
602- target: capture
603- signalName: "captureFinished"
604- }
605- }
606-
607- Image {
608- id: image
609- }
610-
611- TestCase {
612- name: "ItemCapture"
613- when: windowShown
614-
615- function test_quality_data() {
616- return [
617- {get: -1},
618- {set: 58, get: 58},
619- {set: 122},
620- {set: -39},
621- {set: -1, get: -1},
622- {set: 0, get: 0},
623- {set: 100, get: 100}
624- ]
625- }
626-
627- function test_quality(data) {
628- var quality = capture.quality
629- if ('set' in data) {
630- capture.quality = data.set
631- }
632- if ('get' in data) {
633- compare(capture.quality, data.get)
634- } else {
635- compare(capture.quality, quality)
636- }
637- }
638-
639- function test_capture() {
640- spyReady.wait()
641- spyCaptured.clear()
642- var id = "test"
643- capture.requestCapture(id)
644- spyCaptured.wait()
645- compare(spyCaptured.signalArguments[0][0], id)
646- verify(image.source.toString())
647- compare(image.status, Image.Ready)
648- compare(image.sourceSize.width, rect.width)
649- compare(image.sourceSize.height, rect.height)
650- var reference = grabImage(rect)
651- var grabbed = grabImage(image)
652- for (var i = 0; i < rect.width; ++i) {
653- for (var j = 0; j < rect.height; ++j) {
654- compare(grabbed.pixel(i, j), reference.pixel(i, j))
655- }
656- }
657- }
658-
659- function test_capture_invalid_id() {
660- spyReady.wait()
661- spyCaptured.clear()
662- var invalid = "foo/bar"
663- capture.requestCapture(invalid)
664- spyCaptured.wait()
665- compare(spyCaptured.signalArguments[0][0], invalid)
666- verify(!spyCaptured.signalArguments[0][1].toString())
667- }
668- }
669-}
670
671=== modified file 'tests/unittests/qml/tst_QmlTests.cpp'
672--- tests/unittests/qml/tst_QmlTests.cpp 2014-12-03 14:35:29 +0000
673+++ tests/unittests/qml/tst_QmlTests.cpp 2015-02-26 17:54:55 +0000
674@@ -1,5 +1,5 @@
675 /*
676- * Copyright 2013-2014 Canonical Ltd.
677+ * Copyright 2013-2015 Canonical Ltd.
678 *
679 * This file is part of webbrowser-app.
680 *
681@@ -22,7 +22,14 @@
682
683 // local
684 #include "favicon-fetcher.h"
685-#include "item-capture.h"
686+#include "file-operations.h"
687+
688+static QObject* FileOperations_singleton_factory(QQmlEngine* engine, QJSEngine* scriptEngine)
689+{
690+ Q_UNUSED(engine);
691+ Q_UNUSED(scriptEngine);
692+ return new FileOperations();
693+}
694
695 int main(int argc, char** argv)
696 {
697@@ -30,7 +37,7 @@
698 qmlRegisterType<FaviconFetcher>(commonUri, 0, 1, "FaviconFetcher");
699
700 const char* browserUri = "webbrowserapp.private";
701- qmlRegisterType<ItemCapture>(browserUri, 0, 1, "ItemCapture");
702+ qmlRegisterSingletonType<FileOperations>(browserUri, 0, 1, "FileOperations", FileOperations_singleton_factory);
703
704 return quick_test_main(argc, argv, "QmlTests", 0);
705 }

Subscribers

People subscribed via source and target branches

to status/vote changes: