Disable local storage if the standard data location is empty
authorCharles Yin <charles.yin@nokia.com>
Thu, 19 Apr 2012 03:50:39 +0000 (13:50 +1000)
committerQt by Nokia <qt-info@nokia.com>
Fri, 20 Apr 2012 06:05:15 +0000 (08:05 +0200)
Change-Id: I05ea7fa9521c807099b39e610f965a331e538f6e
Reviewed-by: Michael Brasser <michael.brasser@nokia.com>
Reviewed-by: Martin Jones <martin.jones@nokia.com>
src/imports/localstorage/plugin.cpp
src/qml/qml/qqmlengine.cpp
tests/auto/qml/qqmlengine/tst_qqmlengine.cpp
tests/auto/qml/qqmlsqldatabase/tst_qqmlsqldatabase.cpp

index 4f08e71..ac007f2 100644 (file)
@@ -567,6 +567,9 @@ void QQuickLocalStorage::openDatabaseSync(QQmlV8Function *args)
 {
 #ifndef QT_NO_SETTINGS
     QV8Engine *engine = args->engine();
+    if (engine->engine()->offlineStoragePath().isEmpty())
+        V8THROW_SQL_VOID(SQLEXCEPTION_DATABASE_ERR, QQmlEngine::tr("SQL: can't create database, offline storage is disabled."));
+
     qmlsqldatabase_initDatabasesPath(engine);
 
     QSqlDatabase database;
index 82eeb91..aee9c5c 100644 (file)
@@ -512,9 +512,10 @@ void QQmlEnginePrivate::init()
     }
 
     QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
-    offlineStoragePath = dataLocation.replace(QLatin1Char('/'), QDir::separator()) +
-                         QDir::separator() + QLatin1String("QML") +
-                         QDir::separator() + QLatin1String("OfflineStorage");
+    if (!dataLocation.isEmpty())
+        offlineStoragePath = dataLocation.replace(QLatin1Char('/'), QDir::separator())
+                           + QDir::separator() + QLatin1String("QML")
+                           + QDir::separator() + QLatin1String("OfflineStorage");
 }
 
 QQuickWorkerScriptEngine *QQmlEnginePrivate::getWorkerScriptEngine()
index 89fc8e0..c039429 100644 (file)
@@ -177,7 +177,11 @@ void tst_qqmlengine::offlineStoragePath()
 
     QQmlEngine engine;
 
-    QDir dir(QStandardPaths::writableLocation(QStandardPaths::DataLocation));
+    QString dataLocation = QStandardPaths::writableLocation(QStandardPaths::DataLocation);
+
+    QCOMPARE(dataLocation.isEmpty(), engine.offlineStoragePath().isEmpty());
+
+    QDir dir(dataLocation);
     dir.mkpath("QML");
     dir.cd("QML");
     dir.mkpath("OfflineStorage");
index c1a8a63..04fc5e1 100644 (file)
@@ -104,6 +104,8 @@ void removeRecursive(const QString& dirname)
 
 void tst_qqmlsqldatabase::initTestCase()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
     QQmlDataTest::initTestCase();
     removeRecursive(dbDir());
     QDir().mkpath(dbDir());
@@ -111,6 +113,8 @@ void tst_qqmlsqldatabase::initTestCase()
 
 void tst_qqmlsqldatabase::cleanupTestCase()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
     removeRecursive(dbDir());
 }
 
@@ -123,6 +127,9 @@ QString tst_qqmlsqldatabase::dbDir() const
 
 void tst_qqmlsqldatabase::checkDatabasePath()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
+
     // Check default storage path (we can't use it since we don't want to mess with user's data)
     QVERIFY(engine->offlineStoragePath().contains("tst_qqmlsqldatabase"));
     QVERIFY(engine->offlineStoragePath().contains("OfflineStorage"));
@@ -193,6 +200,9 @@ void tst_qqmlsqldatabase::validateAgainstWebkit()
 
 void tst_qqmlsqldatabase::testQml()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
+
     // Tests QML SQL Database support with tests
     // that have been validated against Webkit.
     //
@@ -222,6 +232,9 @@ void tst_qqmlsqldatabase::testQml_cleanopen_data()
 
 void tst_qqmlsqldatabase::testQml_cleanopen()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
+
     // Same as testQml, but clean connections between tests,
     // making it more like the tests are running in new processes.
     testQml();
@@ -235,6 +248,9 @@ void tst_qqmlsqldatabase::testQml_cleanopen()
 
 void tst_qqmlsqldatabase::totalDatabases()
 {
+    if (engine->offlineStoragePath().isEmpty())
+        QSKIP("offlineStoragePath is empty, skip this test.");
+
     QCOMPARE(QDir(dbDir()+"/Databases").entryInfoList(QDir::Files|QDir::NoDotAndDotDot).count(), total_databases_created_by_tests*2);
 }