Changeset 59540 in webkit


Ignore:
Timestamp:
May 15, 2010 9:36:56 AM (14 years ago)
Author:
eric@webkit.org
Message:

2010-05-15 Eric Uhrhane <ericu@chromium.org>

Reviewed by Dmitry Titov.

Add bindings for async DB API in Workers.
https://bugs.webkit.org/show_bug.cgi?id=34992

  • storage/change-version-handle-reuse.html: Refactored to share code with the worker version of the test.
  • storage/change-version-handle-reuse-expected.html: Removed reference to reloading, which this test doesn't do.
  • storage/change-version-handle-reuse.js: This is the extracted shared core of the test.
  • storage/execute-sql-args.html: Refactored to share code with the worker version of the test.
  • storage/execute-sql-args.js: This is the extracted shared core of the test.

These are the worker versions of the tests; they're tiny shims around shared code.

  • fast/workers/storage/execute-sql-args-worker-expected.txt: Added.
  • fast/workers/storage/execute-sql-args-worker.html: Added.
  • fast/workers/storage/change-version-handle-reuse-worker-expected.txt: Added.
  • fast/workers/storage/change-version-handle-reuse-worker.html: Added. This file gets included from worker database tests; it does all the boilerplate that's needed on the DOM side.
  • fast/workers/storage/resources/database-worker-controller.js: Added. This file is the boilerplate for the worker side of the database tests. It will import and run the actual test on command, and will report back completion and exceptions.
  • fast/workers/storage/resources/database-worker.js: Added.

2010-05-15 Eric Uhrhane <ericu@chromium.org>

Reviewed by Dmitry Titov.

Add bindings for async DB API in Workers.
https://bugs.webkit.org/show_bug.cgi?id=34992

Tests: storage/change-version-handle-reuse-worker.html

storage/execute-sql-args-worker.html

  • bindings/js/JSWorkerContextCustom.cpp: Add openDatabase binding. (WebCore::JSWorkerContext::openDatabase):
  • bindings/v8/custom/V8WorkerContextCustom.cpp: Add openDatabase stub; Chromium will need work both in V8 and in the browser process before we can turn this on there. (WebCore::V8WorkerContext::openDatabaseCallback):

Add NoStaticTables flags to all objects now shared with workers.

  • storage/Database.idl:
  • storage/SQLError.idl:
  • storage/SQLResultSet.idl:
  • storage/SQLResultSetRowList.idl:
  • storage/SQLTransaction.idl:
  • workers/WorkerContext.h: Add databaseExceededQuota.
  • workers/WorkerContext.cpp: (WebCore::WorkerContext::databaseExceededQuota): Add stub implementation for testing; you just get 5MB for now. (WebCore::WorkerContext::openDatabase): Remove invalid assertion.

Add the IDL for the call to openDatabase.

  • workers/WorkerContext.idl:
Location:
trunk
Files:
5 added
10 edited
3 copied

Legend:

Unmodified
Added
Removed
  • trunk/LayoutTests/ChangeLog

    r59535 r59540  
     12010-05-15  Eric Uhrhane  <ericu@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Add bindings for async DB API in Workers.
     6        https://bugs.webkit.org/show_bug.cgi?id=34992
     7
     8        * storage/change-version-handle-reuse.html: Refactored to share code with the worker version of the test.
     9        * storage/change-version-handle-reuse-expected.html: Removed reference to reloading, which this test doesn't do.
     10        * storage/change-version-handle-reuse.js: This is the extracted shared core of the test.
     11        * storage/execute-sql-args.html: Refactored to share code with the worker version of the test.
     12        * storage/execute-sql-args.js: This is the extracted shared core of the test.
     13
     14        These are the worker versions of the tests; they're tiny shims around shared code.
     15        * fast/workers/storage/execute-sql-args-worker-expected.txt: Added.
     16        * fast/workers/storage/execute-sql-args-worker.html: Added.
     17        * fast/workers/storage/change-version-handle-reuse-worker-expected.txt: Added.
     18        * fast/workers/storage/change-version-handle-reuse-worker.html: Added.
     19        This file gets included from worker database tests; it does all the boilerplate that's needed on the DOM side.
     20        * fast/workers/storage/resources/database-worker-controller.js: Added.
     21        This file is the boilerplate for the worker side of the database tests.  It will import and run the actual test on command, and will report back completion and exceptions.
     22        * fast/workers/storage/resources/database-worker.js: Added.
     23
    1242010-05-15  Xan Lopez  <xlopez@igalia.com>
    225
  • trunk/LayoutTests/fast/workers/storage/change-version-handle-reuse-worker-expected.txt

    r59539 r59540  
    1 This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions. Also, reloading the page should not cause an assertion failure.
     1This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions.
    22changeVersion: transaction callback
    33changeVersion: success callback
  • trunk/LayoutTests/storage/change-version-handle-reuse-expected.txt

    r58597 r59540  
    1 This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions. Also, reloading the page should not cause an assertion failure.
     1This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions.
    22changeVersion: transaction callback
    33changeVersion: success callback
  • trunk/LayoutTests/storage/change-version-handle-reuse.html

    r58597 r59540  
    11<html>
    22<head>
     3<script src="change-version-handle-reuse.js"></script>
    34<script>
     5
     6var DB_TEST_SUFFIX = "_dom";
     7
    48function log(message)
    59{
    6     document.getElementById("result").innerText += message + "\n";
     10    document.getElementById("console").innerText += message + "\n";
    711}
    812
    9 function finishTest()
    10 {
    11     log("TEST COMPLETE.");
    12 
    13     if (window.layoutTestController)
    14         layoutTestController.notifyDone();
    15 }
    16 
    17 function runTest()
     13function setupAndRunTest()
    1814{
    1915    if (window.layoutTestController) {
     
    2218    }
    2319 
    24     document.getElementById("result").innerText = "";
     20    document.getElementById("console").innerText = "";
    2521 
    26     try {
    27         db = openDatabase("ChangeVersion", "", "Test that changing a database version doesn\'t kill our handle to it", 1);
    28         var version = db.version;
    29         var newVersion = version ? (parseInt(version) + 1).toString() : "1";
    30         db.changeVersion(version, newVersion, function(tx) {
    31             log("changeVersion: transaction callback");
    32         }, function(error) {
    33             log("changeVersion: error callback: " + error.message);
    34         }, function() {
    35             log("changeVersion: success callback");
    36         });
    37        
    38         setTimeout(runTest2, 1000);
    39        
    40     } catch (e) {
    41         log("changeVersion exception: " + e);
    42         finishTest();
    43     }
    44 }
    45  
    46 function runTest2()
    47 {
    48     try {
    49         db.transaction(function(tx) {
    50             tx.executeSql("SELECT * from FooBar", [], function(tx) {
    51                 log("transaction: statement callback");
    52                 finishTest();
    53             }, function(tx, error) {
    54                 log("transaction: statement error callback: " + error.message);
    55                 finishTest();
    56             });
    57         });
    58     } catch (e) {
    59         log("transaction exception: " + e);
    60         finishTest();
    61     }
     22    runTest();
    6223}
    6324</script>
    6425</head>
    65 <body onload="runTest()">
    66 <div>This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions. Also, reloading the page should not cause an assertion failure.
    67 <pre id="result">
     26<body onload="setupAndRunTest()">
     27<div>This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions.
     28<pre id="console">
    6829FAILURE: test didn't run.
    6930</pre>
  • trunk/LayoutTests/storage/change-version-handle-reuse.js

    r59539 r59540  
    1 <html>
    2 <head>
    3 <script>
    4 function log(message)
    5 {
    6     document.getElementById("result").innerText += message + "\n";
    7 }
    8 
    91function finishTest()
    102{
     
    179function runTest()
    1810{
    19     if (window.layoutTestController) {
    20         layoutTestController.waitUntilDone();
    21         layoutTestController.dumpAsText();
    22     }
    23  
    24     document.getElementById("result").innerText = "";
    25  
    2611    try {
    27         db = openDatabase("ChangeVersion", "", "Test that changing a database version doesn\'t kill our handle to it", 1);
     12        db = openDatabase("ChangeVersion" + DB_TEST_SUFFIX, "", "Test that changing a database version doesn't kill our handle to it", 1);
    2813        var version = db.version;
    2914        var newVersion = version ? (parseInt(version) + 1).toString() : "1";
     
    3419        }, function() {
    3520            log("changeVersion: success callback");
     21            runTest2();
    3622        });
    37        
    38         setTimeout(runTest2, 1000);
    3923       
    4024    } catch (e) {
     
    6145    }
    6246}
    63 </script>
    64 </head>
    65 <body onload="runTest()">
    66 <div>This tests that a database can be accessed after changing its version. You should see an error about FooBar table below, not about mismatching versions. Also, reloading the page should not cause an assertion failure.
    67 <pre id="result">
    68 FAILURE: test didn't run.
    69 </pre>
    70 </body>
    71 </html>
  • trunk/LayoutTests/storage/execute-sql-args.html

    r58597 r59540  
    22
    33<head>
     4<script src="execute-sql-args.js"></script>
    45<script>
    56
    6 var throwOnToStringObject = { };
    7 throwOnToStringObject.toString = function () { throw "Cannot call toString on this object." };
     7var DB_TEST_SUFFIX = "_dom";
    88
    9 var throwOnGetLengthObject = { };
    10 throwOnGetLengthObject.__defineGetter__("length", function () { throw "Cannot get length of this object."; });
    11 
    12 var throwOnGetZeroObject = { length: 1 };
    13 throwOnGetZeroObject.__defineGetter__("0", function () { throw "Cannot get 0 property of this object."; });
    14 
    15 var expectNoException = [
    16     'null',
    17     'undefined',
    18     '0',
    19     '""',
    20     '"", null',
    21     '"", undefined',
    22     '"", []',
    23     '"", [ "arg0" ]',
    24     '"", { }',
    25     '"", { length: 0 }',
    26     '"", { length: 1, 0: "arg0" }',
    27     '"", null, null',
    28     '"", null, undefined',
    29     '"", null, { }',
    30     '"", null, null, null',
    31     '"", null, null, undefined',
    32     '"", null, null, { }',
    33 ];
    34 
    35 var expectException = [
    36     '',
    37     'throwOnToStringObject',
    38     '"", throwOnGetLengthObject',
    39     '"", throwOnGetZeroObject',
    40     '"", [ throwOnToStringObject ]',
    41     '"", 0',
    42     '"", ""',
    43     '"", null, 0',
    44     '"", null, ""',
    45     '"", null, null, 0',
    46     '"", null, null, ""',
    47 ];
    48 
    49 function writeMessageToLog(message)
     9function log(message)
    5010{
    5111    document.getElementById("console").innerText += message + "\n";
    5212}
    5313
    54 function tryExecuteSql(transaction, parameterList)
    55 {
    56     try {
    57         eval('transaction.executeSql(' + parameterList + ')');
    58         return null;
    59     } catch (exception) {
    60         return exception;
    61     }
    62 }
    63 
    64 function runTransactionTest(transaction, parameterList, expectException)
    65 {
    66     var exception = tryExecuteSql(transaction, parameterList);
    67     if (expectException) {
    68         if (exception)
    69             writeMessageToLog("PASS. executeSql(" + parameterList + ") threw an exception as expected.");
    70         else
    71             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") did not throw an exception");
    72     } else {
    73         if (exception)
    74             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") threw an exception: " + exception);
    75         else
    76             writeMessageToLog("PASS. executeSql(" + parameterList + ") did not throw an exception");
    77     }
    78 }
    79 
    80 function runTransactionTests(transaction)
    81 {
    82     for (i in expectNoException)
    83         runTransactionTest(transaction, expectNoException[i], false);
    84     for (i in expectException)
    85         runTransactionTest(transaction, expectException[i], true);
    86 
    87     if (window.layoutTestController)
    88         layoutTestController.notifyDone();
    89 }
    90 
    91 function runTest()
     14function setupAndRunTest()
    9215{
    9316    if (window.layoutTestController) {
     
    9518        layoutTestController.waitUntilDone();
    9619    }
    97 
    98     var db = openDatabase("ExecuteSQLArgsTest", "1.0", "Test of handling of the arguments to SQLTransaction.executeSql", 1);
    99     db.transaction(runTransactionTests);
     20    runTest();
    10021}
    10122
     
    10324</head>
    10425
    105 <body onload="runTest()">
     26<body onload="setupAndRunTest()">
    10627<pre id="console"></pre>
    10728</body>
  • trunk/LayoutTests/storage/execute-sql-args.js

    r59539 r59540  
    1 <html>
    2 
    3 <head>
    4 <script>
    5 
    61var throwOnToStringObject = { };
    72throwOnToStringObject.toString = function () { throw "Cannot call toString on this object." };
     
    4742];
    4843
    49 function writeMessageToLog(message)
    50 {
    51     document.getElementById("console").innerText += message + "\n";
    52 }
    53 
    5444function tryExecuteSql(transaction, parameterList)
    5545{
     
    6757    if (expectException) {
    6858        if (exception)
    69             writeMessageToLog("PASS. executeSql(" + parameterList + ") threw an exception as expected.");
     59            log("PASS. executeSql(" + parameterList + ") threw an exception as expected.");
    7060        else
    71             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") did not throw an exception");
     61            log("*FAIL*. executeSql(" + parameterList + ") did not throw an exception");
    7262    } else {
    7363        if (exception)
    74             writeMessageToLog("*FAIL*. executeSql(" + parameterList + ") threw an exception: " + exception);
     64            log("*FAIL*. executeSql(" + parameterList + ") threw an exception: " + exception);
    7565        else
    76             writeMessageToLog("PASS. executeSql(" + parameterList + ") did not throw an exception");
     66            log("PASS. executeSql(" + parameterList + ") did not throw an exception");
    7767    }
    7868}
     
    9181function runTest()
    9282{
    93     if (window.layoutTestController) {
    94         layoutTestController.dumpAsText();
    95         layoutTestController.waitUntilDone();
    96     }
    9783
    98     var db = openDatabase("ExecuteSQLArgsTest", "1.0", "Test of handling of the arguments to SQLTransaction.executeSql", 1);
     84    var db = openDatabase("ExecuteSQLArgsTest" + DB_TEST_SUFFIX, "1.0", "Test of handling of the arguments to SQLTransaction.executeSql", 1);
    9985    db.transaction(runTransactionTests);
    10086}
    101 
    102 </script>
    103 </head>
    104 
    105 <body onload="runTest()">
    106 <pre id="console"></pre>
    107 </body>
    108 
    109 </html>
  • trunk/WebCore/ChangeLog

    r59537 r59540  
     12010-05-15  Eric Uhrhane  <ericu@chromium.org>
     2
     3        Reviewed by Dmitry Titov.
     4
     5        Add bindings for async DB API in Workers.
     6        https://bugs.webkit.org/show_bug.cgi?id=34992
     7
     8        Tests: storage/change-version-handle-reuse-worker.html
     9               storage/execute-sql-args-worker.html
     10
     11        * bindings/js/JSWorkerContextCustom.cpp: Add openDatabase binding.
     12        (WebCore::JSWorkerContext::openDatabase):
     13
     14        * bindings/v8/custom/V8WorkerContextCustom.cpp: Add openDatabase stub; Chromium will need work both in V8 and in the browser process before we can turn this on there.
     15        (WebCore::V8WorkerContext::openDatabaseCallback):
     16
     17        Add NoStaticTables flags to all objects now shared with workers.
     18        * storage/Database.idl:
     19        * storage/SQLError.idl:
     20        * storage/SQLResultSet.idl:
     21        * storage/SQLResultSetRowList.idl:
     22        * storage/SQLTransaction.idl:
     23       
     24        * workers/WorkerContext.h: Add databaseExceededQuota.
     25        * workers/WorkerContext.cpp:
     26        (WebCore::WorkerContext::databaseExceededQuota): Add stub implementation for testing; you just get 5MB for now.
     27        (WebCore::WorkerContext::openDatabase): Remove invalid assertion.
     28
     29        Add the IDL for the call to openDatabase.
     30        * workers/WorkerContext.idl:
     31
    1322010-05-15  Leandro Pereira  <leandro@profusion.mobi>
    233
  • trunk/WebCore/bindings/js/JSWorkerContextCustom.cpp

    r59113 r59540  
    3131
    3232#if ENABLE(DATABASE)
     33#include "Database.h"
     34#include "JSDatabase.h"
    3335#include "JSDatabaseCallback.h"
    3436#include "JSDatabaseSync.h"
     
    148150
    149151#if ENABLE(DATABASE)
    150 JSValue JSWorkerContext::openDatabaseSync(ExecState* exec, const ArgList& args)
    151 {
     152JSValue JSWorkerContext::openDatabase(ExecState* exec, const ArgList& args)
     153{ 
    152154    if (args.size() < 4) {
    153155        setDOMException(exec, SYNTAX_ERR);
     
    181183        creationCallback = JSDatabaseCallback::create(asObject(args.at(4)), globalObject());
    182184    }
     185 
     186    ExceptionCode ec = 0;
     187    JSValue result = toJS(exec, globalObject(), WTF::getPtr(impl()->openDatabase(name, version, displayName, estimatedSize, creationCallback.release(), ec)));
     188    setDOMException(exec, ec);
     189    return result;
     190}
     191 
     192JSValue JSWorkerContext::openDatabaseSync(ExecState* exec, const ArgList& args)
     193{
     194    if (args.size() < 4) {
     195        setDOMException(exec, SYNTAX_ERR);
     196        return jsUndefined();
     197    }
     198
     199    String name = ustringToString(args.at(0).toString(exec));
     200    if (exec->hadException())
     201        return jsUndefined();
     202
     203    String version = ustringToString(args.at(1).toString(exec));
     204    if (exec->hadException())
     205        return jsUndefined();
     206
     207    String displayName = ustringToString(args.at(2).toString(exec));
     208    if (exec->hadException())
     209        return jsUndefined();
     210
     211    // args.at(3) = estimated size
     212    unsigned long estimatedSize = args.at(3).toUInt32(exec);
     213    if (exec->hadException())
     214        return jsUndefined();
     215
     216    RefPtr<DatabaseCallback> creationCallback;
     217    if (args.size() >= 5) {
     218        if (!args.at(4).isObject()) {
     219            setDOMException(exec, TYPE_MISMATCH_ERR);
     220            return jsUndefined();
     221        }
     222
     223        creationCallback = JSDatabaseCallback::create(asObject(args.at(4)), globalObject());
     224    }
    183225
    184226    ExceptionCode ec = 0;
  • trunk/WebCore/bindings/v8/custom/V8WorkerContextCustom.cpp

    r59096 r59540  
    3535
    3636#if ENABLE(DATABASE)
     37#include "V8Database.h"
    3738#include "V8DatabaseCallback.h"
    3839#include "V8DatabaseSync.h"
     
    143144
    144145#if ENABLE(DATABASE)
     146v8::Handle<v8::Value> V8WorkerContext::openDatabaseCallback(const v8::Arguments& args)
     147{
     148    INC_STATS("DOM.WorkerContext.openDatabase()");
     149    // Implementation coming soon.
     150    return throwError(NOT_SUPPORTED_ERR);
     151}
     152
    145153v8::Handle<v8::Value> V8WorkerContext::openDatabaseSyncCallback(const v8::Arguments& args)
    146154{
  • trunk/WebCore/workers/WorkerContext.cpp

    r58989 r59540  
    3333
    3434#include "ActiveDOMObject.h"
     35#include "DatabaseTracker.h"
    3536#include "DOMTimer.h"
    3637#include "DOMWindow.h"
     
    271272PassRefPtr<Database> WorkerContext::openDatabase(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
    272273{
     274    if (!securityOrigin()->canAccessDatabase() || !Database::isAvailable()) {
     275        ec = SECURITY_ERR;
     276        return 0;
     277    }
     278
     279    return Database::openDatabase(this, name, version, displayName, estimatedSize, creationCallback, ec);
     280}
     281
     282void WorkerContext::databaseExceededQuota(const String&)
     283{
     284#if !PLATFORM(CHROMIUM)
     285    // FIXME: This needs a real implementation; this is a temporary solution for testing.
     286    const unsigned long long defaultQuota = 5 * 1024 * 1024;
     287    DatabaseTracker::tracker().setQuota(securityOrigin(), defaultQuota);
     288#endif
     289}
     290
     291PassRefPtr<DatabaseSync> WorkerContext::openDatabaseSync(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
     292{
    273293    if (!securityOrigin()->canAccessDatabase()) {
    274294        ec = SECURITY_ERR;
     
    276296    }
    277297
    278     ASSERT(Database::isAvailable());
    279     if (!Database::isAvailable())
    280         return 0;
    281 
    282     return Database::openDatabase(this, name, version, displayName, estimatedSize, creationCallback, ec);
    283 }
    284 
    285 PassRefPtr<DatabaseSync> WorkerContext::openDatabaseSync(const String& name, const String& version, const String& displayName, unsigned long estimatedSize, PassRefPtr<DatabaseCallback> creationCallback, ExceptionCode& ec)
    286 {
    287     if (!securityOrigin()->canAccessDatabase()) {
    288         ec = SECURITY_ERR;
    289         return 0;
    290     }
    291 
    292298    ASSERT(DatabaseSync::isAvailable());
    293299    if (!DatabaseSync::isAvailable())
  • trunk/WebCore/workers/WorkerContext.h

    r58989 r59540  
    111111        // Not implemented yet.
    112112        virtual bool isDatabaseReadOnly() const { return false; }
    113         // Not implemented yet.
    114         virtual void databaseExceededQuota(const String&) { }
     113        // Not implemented for real yet.
     114        virtual void databaseExceededQuota(const String&);
    115115#endif
    116116        virtual bool isContextThread() const;
  • trunk/WebCore/workers/WorkerContext.idl

    r58989 r59540  
    5050        [Custom] void importScripts(/*[Variadic] in DOMString urls */);
    5151                 attribute [Replaceable] WorkerNavigator navigator;
    52 
    5352#if defined(ENABLE_DATABASE) && ENABLE_DATABASE
    54         // Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize);
    55         [EnableAtRuntime, Custom] DatabaseSync openDatabaseSync(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in DatabaseCallback creationCallback);
     53        [EnabledAtRuntime, Custom] Database openDatabase(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in DatabaseCallback creationCallback)
     54            raises(DOMException);
     55        [EnabledAtRuntime, Custom] DatabaseSync openDatabaseSync(in DOMString name, in DOMString version, in DOMString displayName, in unsigned long estimatedSize, in DatabaseCallback creationCallback);
    5656#endif
    5757
Note: See TracChangeset for help on using the changeset viewer.