From b561a0a4ffa72fe1d43305dce90030d94316924b Mon Sep 17 00:00:00 2001 From: Albert Astals Cid Date: Thu, 26 Sep 2013 10:56:03 +0200 Subject: Always call callCompleted in QQmlDataBlob::tryDone We need this since it could happen that in QQmlComponentPrivate::loadUrl we did QQmlTypeData *data = QQmlEnginePrivate::get(engine)->typeLoader.getType(url, loaderMode); and got a sync QQmlTypeData even if we asked for async, and thus the async loader was never notified when it finished and we were never loaded. Situation in which this can happen is: * ListView with an async Loader as delegate * Loader loads two items A and B, while A is a B * Item 0 of the ListView triggers an async loading of A that triggers the sync loading of B * Item 1 of the ListView triggers an async loading of B * Since B is already being loaded (though in sync), we just add ourselves to the people that want to be notified * sync loading of B is done and QQmlDataBlob::tryDone does not call the callbacks because it's sync * Item 1 is never finished loading Change-Id: I52a0979a1d3cfcfe73a71196bf24f491d6cf8e9a Reviewed-by: Simon Hausmann --- tests/auto/qml/qml.pro | 1 + tests/auto/qml/qqmltypeloader/SlowImport/Slow.pro | 12 ++++ .../auto/qml/qqmltypeloader/SlowImport/plugin.cpp | 51 +++++++++++++++ tests/auto/qml/qqmltypeloader/SlowImport/plugin.h | 57 +++++++++++++++++ tests/auto/qml/qqmltypeloader/SlowImport/qmldir | 2 + tests/auto/qml/qqmltypeloader/SlowImport/slow.cpp | 50 +++++++++++++++ tests/auto/qml/qqmltypeloader/SlowImport/slow.h | 53 ++++++++++++++++ tests/auto/qml/qqmltypeloader/data/GenericView.qml | 54 ++++++++++++++++ tests/auto/qml/qqmltypeloader/data/NiceView.qml | 45 +++++++++++++ .../qml/qqmltypeloader/data/test_load_complete.qml | 66 +++++++++++++++++++ tests/auto/qml/qqmltypeloader/qqmltypeloader.pro | 2 + .../auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp | 74 ++++++++++++++++++++++ .../auto/qml/qqmltypeloader/tst_qqmltypeloader.pro | 11 ++++ 13 files changed, 478 insertions(+) create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/Slow.pro create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/plugin.cpp create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/plugin.h create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/qmldir create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/slow.cpp create mode 100644 tests/auto/qml/qqmltypeloader/SlowImport/slow.h create mode 100644 tests/auto/qml/qqmltypeloader/data/GenericView.qml create mode 100644 tests/auto/qml/qqmltypeloader/data/NiceView.qml create mode 100644 tests/auto/qml/qqmltypeloader/data/test_load_complete.qml create mode 100644 tests/auto/qml/qqmltypeloader/qqmltypeloader.pro create mode 100644 tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp create mode 100644 tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro (limited to 'tests/auto') diff --git a/tests/auto/qml/qml.pro b/tests/auto/qml/qml.pro index 2036f1cd7a..eec6584472 100644 --- a/tests/auto/qml/qml.pro +++ b/tests/auto/qml/qml.pro @@ -50,6 +50,7 @@ PRIVATETESTS += \ qqmllistcompositor \ qqmllistmodel \ qqmllistmodelworkerscript \ + qqmltypeloader \ qqmlparser \ qquickworkerscript \ qqmlbundle \ diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/Slow.pro b/tests/auto/qml/qqmltypeloader/SlowImport/Slow.pro new file mode 100644 index 0000000000..e76dbd1237 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/Slow.pro @@ -0,0 +1,12 @@ +TEMPLATE = lib +TARGET = Slow +INCLUDEPATH += . +QT += quick qml + +# Input +HEADERS += plugin.h slow.h +SOURCES += plugin.cpp slow.cpp + +DESTDIR = ../Slow +IMPORT_FILES = qmldir +include (../../../shared/imports.pri) diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/plugin.cpp b/tests/auto/qml/qqmltypeloader/SlowImport/plugin.cpp new file mode 100644 index 0000000000..f184dff165 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/plugin.cpp @@ -0,0 +1,51 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "plugin.h" + +#include "slow.h" +#include + +void SlowPlugin::registerTypes(const char *uri) +{ + Q_ASSERT(uri == QLatin1String("Slow")); + qmlRegisterType(uri, 1, 0, "SlowStuff"); +} diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/plugin.h b/tests/auto/qml/qqmltypeloader/SlowImport/plugin.h new file mode 100644 index 0000000000..ed467a848c --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/plugin.h @@ -0,0 +1,57 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SLOW_PLUGIN_H +#define SLOW_PLUGIN_H + +#include +#include + +class SlowPlugin : public QQmlExtensionPlugin +{ + Q_OBJECT + Q_PLUGIN_METADATA(IID "org.qt-project.Qt.QQmlExtensionInterface") + +public: + void registerTypes(const char *uri); +}; + +#endif diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/qmldir b/tests/auto/qml/qqmltypeloader/SlowImport/qmldir new file mode 100644 index 0000000000..f07f777b8f --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/qmldir @@ -0,0 +1,2 @@ +module Slow +plugin Slow diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/slow.cpp b/tests/auto/qml/qqmltypeloader/SlowImport/slow.cpp new file mode 100644 index 0000000000..080293bbf1 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/slow.cpp @@ -0,0 +1,50 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include "slow.h" + +#include + +SlowStuff::SlowStuff() +{ + QThread::usleep(500000); +} + diff --git a/tests/auto/qml/qqmltypeloader/SlowImport/slow.h b/tests/auto/qml/qqmltypeloader/SlowImport/slow.h new file mode 100644 index 0000000000..6f7a64573d --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/SlowImport/slow.h @@ -0,0 +1,53 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#ifndef SLOWSTUFF_H +#define SLOWSTUFF_H + +#include + +class SlowStuff : public QObject +{ +public: + SlowStuff(); +}; + +#endif \ No newline at end of file diff --git a/tests/auto/qml/qqmltypeloader/data/GenericView.qml b/tests/auto/qml/qqmltypeloader/data/GenericView.qml new file mode 100644 index 0000000000..487761275e --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/GenericView.qml @@ -0,0 +1,54 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 +import Slow 1.0 + +Item { + Rectangle { + color: "red" + width: 100 + height: 100 + } + SlowStuff { + + } +} diff --git a/tests/auto/qml/qqmltypeloader/data/NiceView.qml b/tests/auto/qml/qqmltypeloader/data/NiceView.qml new file mode 100644 index 0000000000..ced623b685 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/NiceView.qml @@ -0,0 +1,45 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +GenericView { +} diff --git a/tests/auto/qml/qqmltypeloader/data/test_load_complete.qml b/tests/auto/qml/qqmltypeloader/data/test_load_complete.qml new file mode 100644 index 0000000000..82b2278950 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/data/test_load_complete.qml @@ -0,0 +1,66 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +import QtQuick 2.0 + +ListView { + width: 400 + height: 500 + model: 2 + + id: test + property int created: 0 + property int loaded: 0 + + delegate: Loader { + width: ListView.view.width + height: 100 + asynchronous: true + source: index == 0 ? "NiceView.qml" : "GenericView.qml" + + onLoaded: { + test.loaded++ + } + Component.onCompleted: { + test.created++ + } + } +} \ No newline at end of file diff --git a/tests/auto/qml/qqmltypeloader/qqmltypeloader.pro b/tests/auto/qml/qqmltypeloader/qqmltypeloader.pro new file mode 100644 index 0000000000..6b9c117b8d --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/qqmltypeloader.pro @@ -0,0 +1,2 @@ +TEMPLATE = subdirs +SUBDIRS += tst_qqmltypeloader.pro SlowImport/Slow.pro diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp new file mode 100644 index 0000000000..e44d5aa8d5 --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.cpp @@ -0,0 +1,74 @@ +/**************************************************************************** +** +** Copyright (C) 2013 Canonical Limited and/or its subsidiary(-ies). +** Contact: http://www.qt-project.org/legal +** +** This file is part of the test suite of the Qt Toolkit. +** +** $QT_BEGIN_LICENSE:LGPL$ +** Commercial License Usage +** Licensees holding valid commercial Qt licenses may use this file in +** accordance with the commercial license agreement provided with the +** Software or, alternatively, in accordance with the terms contained in +** a written agreement between you and Digia. For licensing terms and +** conditions see http://qt.digia.com/licensing. For further information +** use the contact form at http://qt.digia.com/contact-us. +** +** GNU Lesser General Public License Usage +** Alternatively, this file may be used under the terms of the GNU Lesser +** General Public License version 2.1 as published by the Free Software +** Foundation and appearing in the file LICENSE.LGPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU Lesser General Public License version 2.1 requirements +** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html. +** +** In addition, as a special exception, Digia gives you certain additional +** rights. These rights are described in the Digia Qt LGPL Exception +** version 1.1, included in the file LGPL_EXCEPTION.txt in this package. +** +** GNU General Public License Usage +** Alternatively, this file may be used under the terms of the GNU +** General Public License version 3.0 as published by the Free Software +** Foundation and appearing in the file LICENSE.GPL included in the +** packaging of this file. Please review the following information to +** ensure the GNU General Public License version 3.0 requirements will be +** met: http://www.gnu.org/copyleft/gpl.html. +** +** +** $QT_END_LICENSE$ +** +****************************************************************************/ + +#include +#include +#include +#include +#include "../../shared/util.h" + +class tst_QQMLTypeLoader : public QQmlDataTest +{ + Q_OBJECT + +private slots: + void testLoadComplete(); +}; + +void tst_QQMLTypeLoader::testLoadComplete() +{ + QQuickView *window = new QQuickView(); + window->engine()->addImportPath(QT_TESTCASE_BUILDDIR); + qDebug() << window->engine()->importPathList(); + window->setGeometry(0,0,240,320); + window->setSource(testFileUrl("test_load_complete.qml")); + window->show(); + QVERIFY(QTest::qWaitForWindowExposed(window)); + + QObject *rootObject = window->rootObject(); + QTRY_VERIFY(rootObject != 0); + QTRY_COMPARE(rootObject->property("created").toInt(), 2); + QTRY_COMPARE(rootObject->property("loaded").toInt(), 2); +} + +QTEST_MAIN(tst_QQMLTypeLoader) + +#include "tst_qqmltypeloader.moc" diff --git a/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro new file mode 100644 index 0000000000..9e2261df8d --- /dev/null +++ b/tests/auto/qml/qqmltypeloader/tst_qqmltypeloader.pro @@ -0,0 +1,11 @@ +CONFIG += testcase +TARGET = tst_qqmltypeloader +QT += qml testlib qml-private quick +macx:CONFIG -= app_bundle + +SOURCES += tst_qqmltypeloader.cpp + +include (../../shared/util.pri) + +CONFIG += parallel_test +DEFINES += QT_DISABLE_DEPRECATED_BEFORE=0 -- cgit v1.2.3