[SCM] WebKit Debian packaging branch, debian/experimental, updated. upstream/1.3.3-9427-gc2be6fc

bulach at chromium.org bulach at chromium.org
Wed Dec 22 12:10:21 UTC 2010


The following commit has been merged in the debian/experimental branch:
commit c9eb84f63d9279b91781cfb6e09a2e5f6997c3a8
Author: bulach at chromium.org <bulach at chromium.org@268f45cc-cd09-0410-ab3c-d52691b4dbfc>
Date:   Mon Aug 16 17:30:58 2010 +0000

    2010-08-16  Marcus Bulach  <bulach at chromium.org>
    
            Reviewed by Jeremy Orlow.
    
            Implements IDBKeyPath extractor.
            https://bugs.webkit.org/show_bug.cgi?id=43276
    
            Unit-test IDBKeyPathExtractorTest.cpp.
            LayoutTests will arrive as IndexedDB infrastructure is fleshed out.
    
            * bindings/v8/IDBBindingUtilities.cpp:
            (WebCore::getValueFrom):
            (WebCore::createIDBKeyFromSerializedValueAndKeyPath):
            * bindings/v8/IDBBindingUtilities.h:
    2010-08-16  Marcus Bulach  <bulach at chromium.org>
    
            Reviewed by Jeremy Orlow.
    
            Implements IDBKeyPath extractor.
            https://bugs.webkit.org/show_bug.cgi?id=43276
    
            Unit-test IDBKeyPathExtractorTest.cpp.
            LayoutTests will arrive as IndexedDB infrastructure is fleshed out.
    
            * WebKit.gyp:
            * public/WebIDBKey.h:
            * public/WebIDBKeyPath.h: Added.
            (WebKit::WebIDBKeyPath::WebIDBKeyPath):
            (WebKit::WebIDBKeyPath::~WebIDBKeyPath):
            * public/WebPrivateOwnPtr.h: Added.
            (WebKit::WebPrivateOwnPtr::WebPrivateOwnPtr):
            (WebKit::WebPrivateOwnPtr::~WebPrivateOwnPtr):
            (WebKit::WebPrivateOwnPtr::reset):
            (WebKit::WebPrivateOwnPtr::get):
            (WebKit::WebPrivateOwnPtr::operator->):
            * src/WebIDBKey.cpp:
            (WebKit::WebIDBKey::createFromValueAndKeyPath):
            * src/WebIDBKeyPath.cpp: Added.
            (WebKit::WebIDBKeyPath::create):
            (WebKit::WebIDBKeyPath::WebIDBKeyPath):
            (WebKit::WebIDBKeyPath::parseError):
            (WebKit::WebIDBKeyPath::assign):
            (WebKit::WebIDBKeyPath::reset):
            (WebKit::WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&):
            * tests/IDBBindingUtilitiesTest.cpp: Added.
            (WebCore::LocalContext::LocalContext):
            (WebCore::LocalContext::~LocalContext):
            (WebCore::checkKeyFromValueAndKeyPathInternal):
            (WebCore::checkKeyPathNullValue):
            (WebCore::checkKeyPathStringValue):
            (WebCore::checkKeyPathNumberValue):
            (WebCore::TEST):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65439 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index c95fb4a..6034452 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,18 @@
+2010-08-16  Marcus Bulach  <bulach at chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        Implements IDBKeyPath extractor.
+        https://bugs.webkit.org/show_bug.cgi?id=43276
+
+        Unit-test IDBKeyPathExtractorTest.cpp.
+        LayoutTests will arrive as IndexedDB infrastructure is fleshed out.
+
+        * bindings/v8/IDBBindingUtilities.cpp:
+        (WebCore::getValueFrom):
+        (WebCore::createIDBKeyFromSerializedValueAndKeyPath):
+        * bindings/v8/IDBBindingUtilities.h:
+
 2010-08-13  Gustavo Noronha Silva  <gustavo.noronha at collabora.co.uk>
 
         Reviewed by Kenneth Rohde Christiansen and Martin Robinson.
diff --git a/WebCore/bindings/v8/IDBBindingUtilities.cpp b/WebCore/bindings/v8/IDBBindingUtilities.cpp
index 4b38a61..a000a7d 100644
--- a/WebCore/bindings/v8/IDBBindingUtilities.cpp
+++ b/WebCore/bindings/v8/IDBBindingUtilities.cpp
@@ -29,7 +29,10 @@
 #if ENABLE(INDEXED_DATABASE)
 
 #include "IDBKey.h"
+#include "IDBKeyPath.h"
+#include "SerializedScriptValue.h"
 #include "V8Binding.h"
+#include <wtf/Vector.h>
 
 namespace WebCore {
 
@@ -45,6 +48,37 @@ PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value> value)
     return 0;
 }
 
+template<typename T>
+bool getValueFrom(T indexOrName, v8::Handle<v8::Value>& v8Value)
+{
+    v8::Local<v8::Object> object = v8Value->ToObject();
+    if (!object->Has(indexOrName))
+        return false;
+    v8Value = object->Get(indexOrName);
+    return true;
+}
+
+PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value, const Vector<IDBKeyPathElement>& keyPath)
+{
+    v8::HandleScope scope;
+    v8::Handle<v8::Value> v8Value(value->deserialize());
+    for (size_t i = 0; i < keyPath.size(); ++i) {
+        switch (keyPath[i].type) {
+        case IDBKeyPathElement::IsIndexed:
+            if (!v8Value->IsArray() || !getValueFrom(keyPath[i].index, v8Value))
+                return 0;
+            break;
+        case IDBKeyPathElement::IsNamed:
+            if (!v8Value->IsObject() || !getValueFrom(v8String(keyPath[i].identifier), v8Value))
+                return 0;
+            break;
+        default:
+            ASSERT_NOT_REACHED();
+        }
+    }
+    return createIDBKeyFromValue(v8Value);
+}
+
 } // namespace WebCore
 
 #endif
diff --git a/WebCore/bindings/v8/IDBBindingUtilities.h b/WebCore/bindings/v8/IDBBindingUtilities.h
index 76f2bba..1a794b0 100644
--- a/WebCore/bindings/v8/IDBBindingUtilities.h
+++ b/WebCore/bindings/v8/IDBBindingUtilities.h
@@ -34,8 +34,11 @@
 namespace WebCore {
 
 class IDBKey;
+class SerializedScriptValue;
+struct IDBKeyPathElement;
 
 PassRefPtr<IDBKey> createIDBKeyFromValue(v8::Handle<v8::Value>);
+PassRefPtr<IDBKey> createIDBKeyFromSerializedValueAndKeyPath(PassRefPtr<SerializedScriptValue> value,  const Vector<IDBKeyPathElement, 0>& keyPath);
 
 }
 
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index 708a98c..9e358d2 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,43 @@
+2010-08-16  Marcus Bulach  <bulach at chromium.org>
+
+        Reviewed by Jeremy Orlow.
+
+        Implements IDBKeyPath extractor.
+        https://bugs.webkit.org/show_bug.cgi?id=43276
+
+        Unit-test IDBKeyPathExtractorTest.cpp.
+        LayoutTests will arrive as IndexedDB infrastructure is fleshed out.
+
+
+        * WebKit.gyp:
+        * public/WebIDBKey.h:
+        * public/WebIDBKeyPath.h: Added.
+        (WebKit::WebIDBKeyPath::WebIDBKeyPath):
+        (WebKit::WebIDBKeyPath::~WebIDBKeyPath):
+        * public/WebPrivateOwnPtr.h: Added.
+        (WebKit::WebPrivateOwnPtr::WebPrivateOwnPtr):
+        (WebKit::WebPrivateOwnPtr::~WebPrivateOwnPtr):
+        (WebKit::WebPrivateOwnPtr::reset):
+        (WebKit::WebPrivateOwnPtr::get):
+        (WebKit::WebPrivateOwnPtr::operator->):
+        * src/WebIDBKey.cpp:
+        (WebKit::WebIDBKey::createFromValueAndKeyPath):
+        * src/WebIDBKeyPath.cpp: Added.
+        (WebKit::WebIDBKeyPath::create):
+        (WebKit::WebIDBKeyPath::WebIDBKeyPath):
+        (WebKit::WebIDBKeyPath::parseError):
+        (WebKit::WebIDBKeyPath::assign):
+        (WebKit::WebIDBKeyPath::reset):
+        (WebKit::WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&):
+        * tests/IDBBindingUtilitiesTest.cpp: Added.
+        (WebCore::LocalContext::LocalContext):
+        (WebCore::LocalContext::~LocalContext):
+        (WebCore::checkKeyFromValueAndKeyPathInternal):
+        (WebCore::checkKeyPathNullValue):
+        (WebCore::checkKeyPathStringValue):
+        (WebCore::checkKeyPathNumberValue):
+        (WebCore::TEST):
+
 2010-07-28  Marcus Bulach  <bulach at chromium.org>
 
         Reviewed by Adam Barth.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index a04d1eb..e58912e 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -186,6 +186,7 @@
                 'public/WebIDBKeyRange.h',
                 'public/WebIDBIndex.h',
                 'public/WebIDBKey.h',
+                'public/WebIDBKeyPath.h',
                 'public/WebIDBObjectStore.h',
                 'public/WebInputElement.h',
                 'public/WebInputEvent.h',
@@ -225,6 +226,7 @@
                 'public/WebPopupMenuInfo.h',
                 'public/WebPopupType.h',
                 'public/WebPrivatePtr.h',
+                'public/WebPrivateOwnPtr.h',
                 'public/WebRange.h',
                 'public/WebRect.h',
                 'public/WebRegularExpression.h',
@@ -430,6 +432,7 @@
                 'src/WebIDBIndexImpl.cpp',
                 'src/WebIDBIndexImpl.h',
                 'src/WebIDBKey.cpp',
+                'src/WebIDBKeyPath.cpp',
                 'src/WebIDBKeyRange.cpp',
                 'src/WebIDBObjectStoreImpl.cpp',
                 'src/WebIDBObjectStoreImpl.h',
@@ -703,6 +706,7 @@
                     ],
                     'sources': [
                         'tests/DragImageTest.cpp',
+                        'tests/IDBBindingUtilitiesTest.cpp',
                         'tests/IDBKeyPathTest.cpp',
                         'tests/KeyboardTest.cpp',
                         'tests/KURLTest.cpp',
diff --git a/WebKit/chromium/public/WebIDBKey.h b/WebKit/chromium/public/WebIDBKey.h
index 1cf336d..32caa10 100644
--- a/WebKit/chromium/public/WebIDBKey.h
+++ b/WebKit/chromium/public/WebIDBKey.h
@@ -34,12 +34,16 @@ namespace WebCore { class IDBKey; }
 
 namespace WebKit {
 
+class WebIDBKeyPath;
+class WebSerializedScriptValue;
+
 class WebIDBKey {
 public:
     ~WebIDBKey() { reset(); }
   
     WEBKIT_API static WebIDBKey createNull();
     WEBKIT_API static WebIDBKey createInvalid();
+    WEBKIT_API static WebIDBKey createFromValueAndKeyPath(const WebSerializedScriptValue&, const WebIDBKeyPath&);
 
     WebIDBKey(const WebString& string) { assign(string); }
     WebIDBKey(int32_t number) { assign(number); }
diff --git a/WebKit/chromium/public/WebIDBKeyPath.h b/WebKit/chromium/public/WebIDBKeyPath.h
new file mode 100644
index 0000000..d08ec63
--- /dev/null
+++ b/WebKit/chromium/public/WebIDBKeyPath.h
@@ -0,0 +1,68 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebIDBKeyPath_h
+#define WebIDBKeyPath_h
+
+#include "WebCommon.h"
+#include "WebPrivateOwnPtr.h"
+#include "WebVector.h"
+
+namespace WebCore { struct IDBKeyPathElement; }
+
+namespace WTF { template<typename T, size_t inlineCapacity> class Vector; }
+
+namespace WebKit {
+
+class WebString;
+
+class WebIDBKeyPath {
+public:
+    static WebIDBKeyPath create(const WebString&);
+    WebIDBKeyPath(const WebIDBKeyPath& keyPath) { assign(keyPath); }
+    ~WebIDBKeyPath() { reset(); }
+
+    WEBKIT_API int parseError() const;
+    WEBKIT_API void assign(const WebIDBKeyPath&);
+    WEBKIT_API void reset();
+
+#if WEBKIT_IMPLEMENTATION
+    operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>& () const;
+#endif
+
+private:
+    WebIDBKeyPath();
+
+#if WEBKIT_IMPLEMENTATION
+    WebIDBKeyPath(const WTF::Vector<WebCore::IDBKeyPathElement, 0>&, int parseError);
+#endif
+
+    WebPrivateOwnPtr<WTF::Vector<WebCore::IDBKeyPathElement, 0> > m_private;
+    int m_parseError;
+};
+
+} // namespace WebKit
+
+#endif // WebIDBKeyPath_h
diff --git a/WebKit/chromium/public/WebPrivateOwnPtr.h b/WebKit/chromium/public/WebPrivateOwnPtr.h
new file mode 100644
index 0000000..4bcabcf
--- /dev/null
+++ b/WebKit/chromium/public/WebPrivateOwnPtr.h
@@ -0,0 +1,75 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#ifndef WebPrivateOwnPtr_h
+#define WebPrivateOwnPtr_h
+
+#include "WebCommon.h"
+
+namespace WebKit {
+
+// This class is an implementation detail of the WebKit API.  It exists
+// to help simplify the implementation of WebKit interfaces that merely
+// wrap a pointer to a WebCore class. It's similar to WebPrivatePtr, but it
+// wraps a naked pointer rather than a reference counted.
+// Note: you must call reset(0) on the implementation side in order to delete
+// the WebCore pointer.
+template <typename T>
+class WebPrivateOwnPtr {
+public:
+    WebPrivateOwnPtr() : m_ptr(0) {}
+    ~WebPrivateOwnPtr() { WEBKIT_ASSERT(!m_ptr); }
+
+#if WEBKIT_IMPLEMENTATION
+    explicit WebPrivateOwnPtr(T* ptr)
+        : m_ptr(ptr)
+    {
+    }
+
+    void reset(T* ptr)
+    {
+        delete m_ptr;
+        m_ptr = ptr;
+    }
+
+    T* get() const { return m_ptr; }
+
+    T* operator->() const
+    {
+        WEBKIT_ASSERT(m_ptr);
+        return m_ptr;
+    }
+#endif // WEBKIT_IMPLEMENTATION
+
+private:
+    T* m_ptr;
+
+    WebPrivateOwnPtr(const WebPrivateOwnPtr&);
+    void operator=(const WebPrivateOwnPtr&);
+};
+
+} // namespace WebKit
+
+#endif
diff --git a/WebKit/chromium/src/WebIDBKey.cpp b/WebKit/chromium/src/WebIDBKey.cpp
index 1c4c685..413a9e6 100644
--- a/WebKit/chromium/src/WebIDBKey.cpp
+++ b/WebKit/chromium/src/WebIDBKey.cpp
@@ -30,7 +30,12 @@
 
 #if ENABLE(INDEXED_DATABASE)
 
+#include "IDBBindingUtilities.h"
 #include "IDBKey.h"
+#include "IDBKeyPath.h"
+#include "SerializedScriptValue.h"
+#include "WebIDBKeyPath.h"
+#include "WebSerializedScriptValue.h"
 
 using namespace WebCore;
 
@@ -50,6 +55,13 @@ WebIDBKey WebIDBKey::createInvalid()
     return key;
 }
 
+WebIDBKey WebIDBKey::createFromValueAndKeyPath(const WebSerializedScriptValue& serializedScriptValue, const WebIDBKeyPath& idbKeyPath)
+{
+    if (serializedScriptValue.isNull())
+        return WebIDBKey::createInvalid();
+    return WebCore::createIDBKeyFromSerializedValueAndKeyPath(serializedScriptValue, idbKeyPath);
+}
+
 void WebIDBKey::assign(const WebIDBKey& value)
 {
     m_private = value.m_private;
diff --git a/WebKit/chromium/src/WebIDBKeyPath.cpp b/WebKit/chromium/src/WebIDBKeyPath.cpp
new file mode 100644
index 0000000..9eb33d6
--- /dev/null
+++ b/WebKit/chromium/src/WebIDBKeyPath.cpp
@@ -0,0 +1,77 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "WebIDBKeyPath.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include "IDBKeyPath.h"
+#include "WebString.h"
+#include "WebVector.h"
+#include <wtf/Vector.h>
+
+using namespace WebCore;
+
+namespace WebKit {
+
+WebIDBKeyPath WebIDBKeyPath::create(const WebString& keyPath)
+{
+    WTF::Vector<IDBKeyPathElement> idbElements;
+    IDBKeyPathParseError idbError;
+    IDBParseKeyPath(keyPath, idbElements, idbError);
+    return WebIDBKeyPath(idbElements, static_cast<int>(idbError));
+}
+
+WebIDBKeyPath::WebIDBKeyPath(const WTF::Vector<IDBKeyPathElement>& elements, int parseError)
+    : m_private(new WTF::Vector<IDBKeyPathElement>(elements))
+    , m_parseError(parseError)
+{
+}
+
+int WebIDBKeyPath::parseError() const
+{
+    return m_parseError;
+}
+
+void WebIDBKeyPath::assign(const WebIDBKeyPath& keyPath)
+{
+    m_parseError = keyPath.m_parseError;
+    m_private.reset(new WTF::Vector<IDBKeyPathElement>(keyPath));
+}
+
+void WebIDBKeyPath::reset()
+{
+    m_private.reset(0);
+}
+
+WebIDBKeyPath::operator const WTF::Vector<WebCore::IDBKeyPathElement, 0>&() const
+{
+    return *m_private.get();
+}
+
+} // namespace WebKit
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp b/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp
new file mode 100644
index 0000000..1b7f156
--- /dev/null
+++ b/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp
@@ -0,0 +1,165 @@
+/*
+ * Copyright (C) 2010 Google Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ *
+ * 1.  Redistributions of source code must retain the above copyright
+ *     notice, this list of conditions and the following disclaimer.
+ * 2.  Redistributions in binary form must reproduce the above copyright
+ *     notice, this list of conditions and the following disclaimer in the
+ *     documentation and/or other materials provided with the distribution.
+ *
+ * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY
+ * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
+ * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
+ * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY
+ * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES;
+ * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
+ * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
+ * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
+ * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
+ */
+
+#include "config.h"
+#include "IDBBindingUtilities.h"
+#include "IDBKey.h"
+#include "IDBKeyPath.h"
+#include "SerializedScriptValue.h"
+
+#include <gtest/gtest.h>
+#include <wtf/Vector.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+using namespace WebCore;
+
+namespace {
+
+class LocalContext {
+public:
+    LocalContext()
+        : m_context(v8::Context::New())
+    {
+        m_context->Enter();
+    }
+
+    virtual ~LocalContext()
+    {
+        m_context->Exit();
+        m_context.Dispose();
+    }
+
+private:
+    v8::Locker m_locker;
+    v8::HandleScope m_scope;
+    v8::Persistent<v8::Context> m_context;
+};
+
+PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(SerializedScriptValue* value, const String& keyPath)
+{
+    Vector<IDBKeyPathElement> idbKeyPath;
+    IDBKeyPathParseError parseError;
+    IDBParseKeyPath(keyPath, idbKeyPath, parseError);
+    EXPECT_EQ(IDBKeyPathParseErrorNone, parseError);
+    return createIDBKeyFromSerializedValueAndKeyPath(value, idbKeyPath);
+}
+
+void checkKeyPathNullValue(SerializedScriptValue* value, const String& keyPath)
+{
+    RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath);
+    ASSERT_FALSE(idbKey.get());
+}
+
+void checkKeyPathStringValue(SerializedScriptValue* value, const String& keyPath, const String& expected)
+{
+    RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath);
+    ASSERT_TRUE(idbKey.get());
+    ASSERT_EQ(IDBKey::StringType, idbKey->type());
+    ASSERT_TRUE(expected == idbKey->string());
+}
+
+void checkKeyPathNumberValue(SerializedScriptValue* value, const String& keyPath, int expected)
+{
+    RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath);
+    ASSERT_TRUE(idbKey.get());
+    ASSERT_EQ(IDBKey::NumberType, idbKey->type());
+    ASSERT_TRUE(expected == idbKey->number());
+}
+
+TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue)
+{
+    LocalContext v8context;
+    v8::Local<v8::Object> object = v8::Object::New();
+    object->Set(v8::String::New("foo"), v8::String::New("zoo"));
+
+    RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object);
+
+    checkKeyPathStringValue(serializedScriptValue.get(), "foo", "zoo");
+    checkKeyPathNullValue(serializedScriptValue.get(), "bar");
+    checkKeyPathNullValue(serializedScriptValue.get(), "[3]");
+}
+
+TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue)
+{
+    LocalContext v8context;
+    v8::Local<v8::Object> object = v8::Object::New();
+    object->Set(v8::String::New("foo"), v8::Number::New(456));
+
+    RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object);
+
+    checkKeyPathNumberValue(serializedScriptValue.get(), "foo", 456);
+    checkKeyPathNullValue(serializedScriptValue.get(), "bar");
+    checkKeyPathNullValue(serializedScriptValue.get(), "[3]");
+}
+
+TEST(IDBKeyFromValueAndKeyPathTest, TopLevelArrayElement)
+{
+    LocalContext v8context;
+    v8::Local<v8::Array> array = v8::Array::New();
+    array->Set(3, v8::String::New("zoo"));
+
+    RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(array);
+
+    checkKeyPathStringValue(serializedScriptValue.get(), "[3]", "zoo");
+    checkKeyPathNullValue(serializedScriptValue.get(), "foo");
+    checkKeyPathNullValue(serializedScriptValue.get(), "bar");
+}
+
+TEST(IDBKeyFromValueAndKeyPathTest, SubProperty)
+{
+    LocalContext v8context;
+    v8::Local<v8::Object> object = v8::Object::New();
+    v8::Local<v8::Object> subProperty = v8::Object::New();
+    subProperty->Set(v8::String::New("bar"), v8::String::New("zee"));
+    object->Set(v8::String::New("foo"), subProperty);
+
+    RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object);
+
+    checkKeyPathStringValue(serializedScriptValue.get(), "foo.bar", "zee");
+    checkKeyPathNullValue(serializedScriptValue.get(), "bar");
+    checkKeyPathNullValue(serializedScriptValue.get(), "[3]");
+}
+
+TEST(IDBKeyFromValueAndKeyPathTest, Array2D)
+{
+    LocalContext v8context;
+    v8::Local<v8::Object> object = v8::Object::New();
+    v8::Local<v8::Array> array = v8::Array::New();
+    v8::Local<v8::Array> subArray = v8::Array::New();
+    subArray->Set(7, v8::String::New("zee"));
+    array->Set(3, subArray);
+    object->Set(v8::String::New("foo"), array);
+
+    RefPtr<SerializedScriptValue> serializedScriptValue = SerializedScriptValue::create(object);
+
+    checkKeyPathStringValue(serializedScriptValue.get(), "foo[3][7]", "zee");
+    checkKeyPathNullValue(serializedScriptValue.get(), "bar");
+    checkKeyPathNullValue(serializedScriptValue.get(), "[4]");
+}
+
+} // namespace
+
+#endif // ENABLE(INDEXED_DATABASE)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list