[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:09:15 UTC 2010


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

    2010-07-28  Marcus Bulach  <bulach at chromium.org>
    
            Reviewed by Adam Barth.
    
            Implement IDBKeyPath parser.
            https://bugs.webkit.org/show_bug.cgi?id=42976
    
            IDBKeyPath is an internal class, exposed only for unit tests for now.
            It'll allow indexed database implementation to traverse a given key path and obtain the corresponding properties
            from a SerializedScriptValue.
    
            * WebCore.gypi:
            * storage/IDBKeyPath.cpp: Added.
            (WebCore::IDBKeyPath::create):
            (WebCore::IDBKeyPath::IDBKeyPath):
            (WebCore::IDBKeyPath::~IDBKeyPath):
            (WebCore::IDBKeyPath::hasNext):
            (WebCore::IDBKeyPath::next):
            (WebCore::IDBKeyPath::identifier):
            (WebCore::IDBKeyPath::hasIndex):
            (WebCore::IDBKeyPath::indexValue):
            (WebCore::IDBKeyPath::parserError):
            (WebCore::IDBKeyPath::parse):
            (WebCore::IDBKeyPath::Lexer::lex):
            (WebCore::isSafeIdentifierStartCharacter):
            (WebCore::isSafeIdentifierCharacter):
            (WebCore::IDBKeyPath::Lexer::lexIdentifier):
            (WebCore::IDBKeyPath::Lexer::lexNumber):
            * storage/IDBKeyPath.h: Added.
            (WebCore::IDBKeyPath::Token::Token):
            (WebCore::IDBKeyPath::):
            (WebCore::IDBKeyPath::Lexer::Lexer):
            (WebCore::IDBKeyPath::Lexer::next):
            (WebCore::IDBKeyPath::Lexer::currentToken):
    2010-07-28  Marcus Bulach  <bulach at chromium.org>
    
            Reviewed by Adam Barth.
    
            Implement IDBKeyPath parser.
            https://bugs.webkit.org/show_bug.cgi?id=42976
    
            IDBKeyPath is an internal class, exposed only for unit tests for now.
            It'll allow indexed database implementation to traverse a given key path and obtain the corresponding properties
            from a SerializedScriptValue.
    
            * WebKit.gyp:
            * tests/IDBKeyPathTest.cpp: Added.
            (WebCore::ExpectedToken::ExpectedToken):
            (WebCore::checkKeyPath):
            (WebCore::TEST):
    
    git-svn-id: http://svn.webkit.org/repository/webkit/trunk@65417 268f45cc-cd09-0410-ab3c-d52691b4dbfc

diff --git a/WebCore/ChangeLog b/WebCore/ChangeLog
index 3adff1d..970fb36 100644
--- a/WebCore/ChangeLog
+++ b/WebCore/ChangeLog
@@ -1,3 +1,38 @@
+2010-07-28  Marcus Bulach  <bulach at chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Implement IDBKeyPath parser.
+        https://bugs.webkit.org/show_bug.cgi?id=42976
+
+        IDBKeyPath is an internal class, exposed only for unit tests for now.
+        It'll allow indexed database implementation to traverse a given key path and obtain the corresponding properties
+        from a SerializedScriptValue.
+
+        * WebCore.gypi:
+        * storage/IDBKeyPath.cpp: Added.
+        (WebCore::IDBKeyPath::create):
+        (WebCore::IDBKeyPath::IDBKeyPath):
+        (WebCore::IDBKeyPath::~IDBKeyPath):
+        (WebCore::IDBKeyPath::hasNext):
+        (WebCore::IDBKeyPath::next):
+        (WebCore::IDBKeyPath::identifier):
+        (WebCore::IDBKeyPath::hasIndex):
+        (WebCore::IDBKeyPath::indexValue):
+        (WebCore::IDBKeyPath::parserError):
+        (WebCore::IDBKeyPath::parse):
+        (WebCore::IDBKeyPath::Lexer::lex):
+        (WebCore::isSafeIdentifierStartCharacter):
+        (WebCore::isSafeIdentifierCharacter):
+        (WebCore::IDBKeyPath::Lexer::lexIdentifier):
+        (WebCore::IDBKeyPath::Lexer::lexNumber):
+        * storage/IDBKeyPath.h: Added.
+        (WebCore::IDBKeyPath::Token::Token):
+        (WebCore::IDBKeyPath::):
+        (WebCore::IDBKeyPath::Lexer::Lexer):
+        (WebCore::IDBKeyPath::Lexer::next):
+        (WebCore::IDBKeyPath::Lexer::currentToken):
+
 2010-08-13  Steve Block  <steveblock at google.com>
 
         Reviewed by Alexey Proskuryakov.
diff --git a/WebCore/WebCore.gypi b/WebCore/WebCore.gypi
index 174dde3..08c95f0 100644
--- a/WebCore/WebCore.gypi
+++ b/WebCore/WebCore.gypi
@@ -3548,6 +3548,8 @@
             'storage/IDBIndexBackendImpl.h',
             'storage/IDBKey.cpp',
             'storage/IDBKey.h',
+            'storage/IDBKeyPath.cpp',
+            'storage/IDBKeyPath.h',
             'storage/IDBKeyRange.cpp',
             'storage/IDBKeyRange.h',
             'storage/IDBKeyTree.h',
diff --git a/WebCore/storage/IDBKeyPath.cpp b/WebCore/storage/IDBKeyPath.cpp
new file mode 100644
index 0000000..8833da0
--- /dev/null
+++ b/WebCore/storage/IDBKeyPath.cpp
@@ -0,0 +1,269 @@
+/*
+ * 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 "IDBKeyPath.h"
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include <wtf/ASCIICType.h>
+#include <wtf/dtoa.h>
+
+namespace WebCore {
+
+class IDBKeyPathLexer {
+public:
+    enum TokenType {
+        TokenLeftBracket,
+        TokenRightBracket,
+        TokenIdentifier,
+        TokenNumber,
+        TokenDot,
+        TokenEnd,
+        TokenError
+    };
+
+    explicit IDBKeyPathLexer(const String& s)
+        : m_string(s)
+        , m_ptr(s.characters())
+        , m_end(s.characters() + s.length())
+        , m_currentTokenType(TokenError)
+    {
+    }
+
+    TokenType currentTokenType() const { return m_currentTokenType; }
+
+    TokenType nextTokenType()
+    {
+        m_currentTokenType = lex(m_currentElement);
+        return m_currentTokenType;
+    }
+
+    const IDBKeyPathElement& currentElement() { return m_currentElement; }
+
+private:
+    TokenType lex(IDBKeyPathElement&);
+    TokenType lexIdentifier(IDBKeyPathElement&);
+    TokenType lexNumber(IDBKeyPathElement&);
+    IDBKeyPathElement m_currentElement;
+    String m_string;
+    const UChar* m_ptr;
+    const UChar* m_end;
+    TokenType m_currentTokenType;
+};
+
+IDBKeyPathLexer::TokenType IDBKeyPathLexer::lex(IDBKeyPathElement& element)
+{
+    while (m_ptr < m_end && isASCIISpace(*m_ptr))
+        ++m_ptr;
+
+    if (m_ptr >= m_end)
+        return TokenEnd;
+
+    ASSERT(m_ptr < m_end);
+    switch (*m_ptr) {
+    case '[':
+        ++m_ptr;
+        return TokenLeftBracket;
+    case ']':
+        ++m_ptr;
+        return TokenRightBracket;
+    case '.':
+        ++m_ptr;
+        return TokenDot;
+    case '0':
+    case '1':
+    case '2':
+    case '3':
+    case '4':
+    case '5':
+    case '6':
+    case '7':
+    case '8':
+    case '9':
+        return lexNumber(element);
+    default:
+        return lexIdentifier(element);
+    }
+    return TokenError;
+}
+
+static inline bool isSafeIdentifierStartCharacter(UChar c)
+{
+    return isASCIIAlpha(c) || (c == '_') || (c == '$');
+}
+
+static inline bool isSafeIdentifierCharacter(UChar c)
+{
+    return isASCIIAlphanumeric(c) || (c == '_') || (c == '$');
+}
+
+IDBKeyPathLexer::TokenType IDBKeyPathLexer::lexIdentifier(IDBKeyPathElement& element)
+{
+    const UChar* start = m_ptr;
+    if (m_ptr < m_end && isSafeIdentifierStartCharacter(*m_ptr))
+        ++m_ptr;
+    else
+        return TokenError;
+
+    while (m_ptr < m_end && isSafeIdentifierCharacter(*m_ptr))
+        ++m_ptr;
+
+    element.type = IDBKeyPathElement::IsNamed;
+    element.identifier = String(start, m_ptr - start);
+    return TokenIdentifier;
+}
+
+IDBKeyPathLexer::TokenType IDBKeyPathLexer::lexNumber(IDBKeyPathElement& element)
+{
+    if (m_ptr >= m_end)
+        return TokenError;
+
+    const UChar* start = m_ptr;
+    // [0-9]*
+    while (m_ptr < m_end && isASCIIDigit(*m_ptr))
+        ++m_ptr;
+
+    String numberAsString;
+    numberAsString = String(start, m_ptr - start);
+    bool ok = false;
+    unsigned number = numberAsString.toUIntStrict(&ok);
+    if (!ok)
+        return TokenError;
+
+    element.type = IDBKeyPathElement::IsIndexed;
+    element.index = number;
+    return TokenNumber;
+}
+
+void IDBParseKeyPath(const String& keyPath, Vector<IDBKeyPathElement>& elements, IDBKeyPathParseError& error)
+{
+    // This is a simplified parser loosely based on LiteralParser.
+    // An IDBKeyPath is defined as a sequence of:
+    // identifierA{.identifierB{[numeric_value]}
+    // where "{}" represents an optional part
+    // The basic state machine is:
+    // Start => {Identifier, Array}
+    // Identifier => {Dot, Array, End}
+    // Array => {Start, Dot, End}
+    // Dot => {Identifier}
+    // It bails out as soon as it finds an error, but doesn't discard the bits it managed to parse.
+    enum ParserState { Identifier, Array, Dot, End };
+
+    IDBKeyPathLexer lexer(keyPath);
+    IDBKeyPathLexer::TokenType tokenType = lexer.nextTokenType();
+    ParserState state;
+    if (tokenType == IDBKeyPathLexer::TokenIdentifier)
+        state = Identifier;
+    else if (tokenType == IDBKeyPathLexer::TokenLeftBracket)
+        state = Array;
+    else if (tokenType == IDBKeyPathLexer::TokenEnd)
+        state = End;
+    else {
+        error = IDBKeyPathParseErrorStart;
+        return;
+    }
+
+    while (1) {
+        switch (state) {
+        case Identifier : {
+            IDBKeyPathLexer::TokenType tokenType = lexer.currentTokenType();
+            ASSERT(tokenType == IDBKeyPathLexer::TokenIdentifier);
+
+            IDBKeyPathElement element = lexer.currentElement();
+            ASSERT(element.type == IDBKeyPathElement::IsNamed);
+            elements.append(element);
+
+            tokenType = lexer.nextTokenType();
+            if (tokenType == IDBKeyPathLexer::TokenDot)
+                state = Dot;
+            else if (tokenType == IDBKeyPathLexer::TokenLeftBracket)
+                state = Array;
+            else if (tokenType == IDBKeyPathLexer::TokenEnd)
+                state = End;
+            else {
+                error = IDBKeyPathParseErrorIdentifier;
+                return;
+            }
+            break;
+        }
+        case Array : {
+            IDBKeyPathLexer::TokenType tokenType = lexer.currentTokenType();
+            ASSERT(tokenType == IDBKeyPathLexer::TokenLeftBracket);
+
+            tokenType = lexer.nextTokenType();
+            if (tokenType != IDBKeyPathLexer::TokenNumber) {
+                error = IDBKeyPathParseErrorArrayIndex;
+                return;
+            }
+
+            ASSERT(tokenType == IDBKeyPathLexer::TokenNumber);
+            IDBKeyPathElement element = lexer.currentElement();
+            ASSERT(element.type == IDBKeyPathElement::IsIndexed);
+            elements.append(element);
+
+            tokenType = lexer.nextTokenType();
+            if (tokenType != IDBKeyPathLexer::TokenRightBracket) {
+                error = IDBKeyPathParseErrorArrayIndex;
+                return;
+            }
+
+            tokenType = lexer.nextTokenType();
+            if (tokenType == IDBKeyPathLexer::TokenDot)
+                state = Dot;
+            else if (tokenType == IDBKeyPathLexer::TokenLeftBracket)
+                state = Array;
+            else if (tokenType == IDBKeyPathLexer::TokenEnd)
+                state = End;
+            else {
+                error = IDBKeyPathParseErrorAfterArray;
+                return;
+            }
+            break;
+        }
+        case Dot: {
+            IDBKeyPathLexer::TokenType tokenType = lexer.currentTokenType();
+            ASSERT(tokenType == IDBKeyPathLexer::TokenDot);
+
+            tokenType = lexer.nextTokenType();
+            if (tokenType != IDBKeyPathLexer::TokenIdentifier) {
+                error = IDBKeyPathParseErrorDot;
+                return;
+            }
+
+            state = Identifier;
+            break;
+        }
+        case End: {
+            error = IDBKeyPathParseErrorNone;
+            return;
+        }
+        }
+    }
+}
+
+} // namespace WebCore
+
+#endif // ENABLE(INDEXED_DATABASE)
diff --git a/WebCore/storage/IDBKeyPath.h b/WebCore/storage/IDBKeyPath.h
new file mode 100644
index 0000000..7787980
--- /dev/null
+++ b/WebCore/storage/IDBKeyPath.h
@@ -0,0 +1,64 @@
+/*
+ * 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 IDBKeyPath_h
+#define IDBKeyPath_h
+
+#if ENABLE(INDEXED_DATABASE)
+
+#include <wtf/PassRefPtr.h>
+#include <wtf/RefCounted.h>
+#include <wtf/Vector.h>
+#include <wtf/text/WTFString.h>
+
+namespace WebCore {
+
+struct IDBKeyPathElement {
+    enum Type {
+        IsIndexed,
+        IsNamed,
+    };
+
+    Type type;
+    unsigned index;
+    String identifier;
+};
+
+enum IDBKeyPathParseError {
+    IDBKeyPathParseErrorNone,
+    IDBKeyPathParseErrorStart,
+    IDBKeyPathParseErrorIdentifier,
+    IDBKeyPathParseErrorArrayIndex,
+    IDBKeyPathParseErrorAfterArray,
+    IDBKeyPathParseErrorDot,
+};
+
+void IDBParseKeyPath(const String&, Vector<IDBKeyPathElement>&, IDBKeyPathParseError&);
+
+} // namespace WebCore
+
+#endif
+
+#endif // IDBKeyPath_h
diff --git a/WebKit/chromium/ChangeLog b/WebKit/chromium/ChangeLog
index dcc8039..708a98c 100644
--- a/WebKit/chromium/ChangeLog
+++ b/WebKit/chromium/ChangeLog
@@ -1,3 +1,20 @@
+2010-07-28  Marcus Bulach  <bulach at chromium.org>
+
+        Reviewed by Adam Barth.
+
+        Implement IDBKeyPath parser.
+        https://bugs.webkit.org/show_bug.cgi?id=42976
+
+        IDBKeyPath is an internal class, exposed only for unit tests for now.
+        It'll allow indexed database implementation to traverse a given key path and obtain the corresponding properties
+        from a SerializedScriptValue.
+
+        * WebKit.gyp:
+        * tests/IDBKeyPathTest.cpp: Added.
+        (WebCore::ExpectedToken::ExpectedToken):
+        (WebCore::checkKeyPath):
+        (WebCore::TEST):
+
 2010-08-16  Pavel Feldman  <pfeldman at chromium.org>
 
         Reviewed by Joseph Pecoraro.
diff --git a/WebKit/chromium/WebKit.gyp b/WebKit/chromium/WebKit.gyp
index 123aed5..a04d1eb 100644
--- a/WebKit/chromium/WebKit.gyp
+++ b/WebKit/chromium/WebKit.gyp
@@ -703,6 +703,7 @@
                     ],
                     'sources': [
                         'tests/DragImageTest.cpp',
+                        'tests/IDBKeyPathTest.cpp',
                         'tests/KeyboardTest.cpp',
                         'tests/KURLTest.cpp',
                         'tests/RunAllTests.cpp',
diff --git a/WebKit/chromium/tests/IDBKeyPathTest.cpp b/WebKit/chromium/tests/IDBKeyPathTest.cpp
new file mode 100644
index 0000000..ac10f4f
--- /dev/null
+++ b/WebKit/chromium/tests/IDBKeyPathTest.cpp
@@ -0,0 +1,205 @@
+/*
+ * 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 "IDBKeyPath.h"
+
+#include <gtest/gtest.h>
+#include <wtf/Vector.h>
+
+#if ENABLE(INDEXED_DATABASE)
+
+using namespace WebCore;
+
+namespace {
+
+IDBKeyPathElement ExpectedToken(const String& identifier, bool isIndexed, int index)
+{
+    IDBKeyPathElement expected;
+    if (isIndexed) {
+        expected.type = IDBKeyPathElement::IsIndexed;
+        expected.index = index;
+    } else {
+        expected.type = IDBKeyPathElement::IsNamed;
+        expected.identifier = identifier;
+    }
+    return expected;
+}
+
+void checkKeyPath(const String& keyPath, const Vector<IDBKeyPathElement>& expected, int parserError)
+{
+
+    IDBKeyPathParseError error;
+    Vector<IDBKeyPathElement> idbKeyPathElements;
+    IDBParseKeyPath(keyPath, idbKeyPathElements, error);
+    ASSERT_EQ(parserError, error);
+    if (error != IDBKeyPathParseErrorNone)
+        return;
+    ASSERT_EQ(expected.size(), idbKeyPathElements.size());
+    for (int i = 0; i < expected.size(); ++i) {
+        ASSERT_TRUE(expected[i].type == idbKeyPathElements[i].type) << i;
+        if (expected[i].type == IDBKeyPathElement::IsIndexed)
+            ASSERT_EQ(expected[i].index, idbKeyPathElements[i].index) << i;
+        else if (expected[i].type == IDBKeyPathElement::IsNamed)
+            ASSERT_TRUE(expected[i].identifier == idbKeyPathElements[i].identifier) << i;
+        else
+            ASSERT_TRUE(false) << "Invalid IDBKeyPathElement type";
+    }
+}
+
+TEST(IDBKeyPathTest, ValidKeyPath0)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("foo.bar.zoo");
+    expected.append(ExpectedToken("foo", false, 0));
+    expected.append(ExpectedToken("bar", false, 0));
+    expected.append(ExpectedToken("zoo", false, 0));
+    checkKeyPath(keyPath, expected, 0);
+}
+
+TEST(IDBKeyPathTest, ValidKeyPath1)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[34][20].foo[2].bar");
+    expected.append(ExpectedToken("a", false, 0));
+    expected.append(ExpectedToken(String(), true, 34));
+    expected.append(ExpectedToken(String(), true, 20));
+    expected.append(ExpectedToken("foo", false, 0));
+    expected.append(ExpectedToken(String(), true, 2));
+    expected.append(ExpectedToken("bar", false, 0));
+    checkKeyPath(keyPath, expected, 0);
+}
+
+TEST(IDBKeyPathTest, ValidKeyPath2)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("foo[ 34 ].Zoo_[00023]\t._c");
+    expected.append(ExpectedToken("foo", false, 0));
+    expected.append(ExpectedToken(String(), true, 34));
+    expected.append(ExpectedToken("Zoo_", false, 0));
+    expected.append(ExpectedToken(String(), true, 23));
+    expected.append(ExpectedToken("_c", false, 0));
+    checkKeyPath(keyPath, expected, 0);
+}
+
+TEST(IDBKeyPathTest, ValidKeyPath3)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("foo[ 34 ]");
+    expected.append(ExpectedToken("foo", false, 0));
+    expected.append(ExpectedToken(String(), true, 34));
+    checkKeyPath(keyPath, expected, 0);
+}
+
+TEST(IDBKeyPathTest, ValidKeyPath4)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("[ 34 ]");
+    expected.append(ExpectedToken(String(), true, 34));
+    checkKeyPath(keyPath, expected, 0);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath2)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[[34]].b[2].c");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 3);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath3)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[[34].b[2].c");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 3);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath5)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[[34.b[2].c");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 3);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath6)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("+a[34].b[2].c");
+    checkKeyPath(keyPath, expected, 1);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath7)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("%a[34].b[2].c");
+    checkKeyPath(keyPath, expected, 1);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath8)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a{[34]}.b[2].c");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 2);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath9)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a..b[2].c");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 5);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath10)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[34]b.foo[2].bar");
+    expected.append(ExpectedToken("a", false, 0));
+    expected.append(ExpectedToken(String(), true, 34));
+    checkKeyPath(keyPath, expected, 4);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath11)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[-1]");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 3);
+}
+
+TEST(IDBKeyPathTest, InvalidKeyPath12)
+{
+    Vector<IDBKeyPathElement> expected;
+    String keyPath("a[9999999999999999999999999999999999]");
+    expected.append(ExpectedToken("a", false, 0));
+    checkKeyPath(keyPath, expected, 3);
+}
+
+} // namespace
+
+#endif // ENABLE(INDEXED_DATABASE)

-- 
WebKit Debian packaging



More information about the Pkg-webkit-commits mailing list