Changeset 126381 in webkit


Ignore:
Timestamp:
Aug 22, 2012 6:49:56 PM (12 years ago)
Author:
commit-queue@webkit.org
Message:

IndexedDB: tests for injection/extraction of idb keys
https://bugs.webkit.org/show_bug.cgi?id=94653

Patch by Alec Flett <alecflett@chromium.org> on 2012-08-22
Reviewed by Tony Chang.

Added unit tests for key injection/extraction using
SerializedScriptValue. These were moved from chromium, now
that all uses of the API are through WebKit.

  • tests/IDBKeyPathTest.cpp:

(WebCore):
(WebCore::TEST):

Location:
trunk/Source/WebKit/chromium
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/Source/WebKit/chromium/ChangeLog

    r126378 r126381  
     12012-08-22  Alec Flett  <alecflett@chromium.org>
     2
     3        IndexedDB: tests for injection/extraction of idb keys
     4        https://bugs.webkit.org/show_bug.cgi?id=94653
     5
     6        Reviewed by Tony Chang.
     7
     8        Added unit tests for key injection/extraction using
     9        SerializedScriptValue. These were moved from chromium, now
     10        that all uses of the API are through WebKit.
     11
     12        * tests/IDBKeyPathTest.cpp:
     13        (WebCore):
     14        (WebCore::TEST):
     15
    1162012-08-22  James Robinson  <jamesr@chromium.org>
    217
  • trunk/Source/WebKit/chromium/tests/IDBKeyPathTest.cpp

    r117817 r126381  
    2727#include "IDBKeyPath.h"
    2828
     29#include "IDBBindingUtilities.h"
     30#include "IDBKey.h"
     31#include "SerializedScriptValue.h"
     32
    2933#include <gtest/gtest.h>
    3034#include <wtf/Vector.h>
     
    124128}
    125129
     130TEST(IDBKeyPathTest, Extract)
     131{
     132    IDBKeyPath keyPath("foo");
     133    RefPtr<IDBKey> stringZooKey(IDBKey::createString("zoo"));
     134    RefPtr<IDBKey> invalidKey(IDBKey::createInvalid());
     135    RefPtr<SerializedScriptValue> ssv;
     136    RefPtr<IDBKey> result;
     137
     138    // keypath: "foo", value: {foo: "zoo"}, expected: "zoo"
     139    UChar dataFooZoo[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x017b};
     140    ssv = SerializedScriptValue::createFromWire(String(dataFooZoo, WTF_ARRAY_LENGTH(dataFooZoo)));
     141    result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     142    EXPECT_TRUE(stringZooKey->isEqual(result.get()));
     143
     144    // keypath: "foo", value: {foo: null}, expected: invalid
     145    UChar dataFooNull[] = {0x0353, 0x6f66, 0x306f, 0x017b};
     146    ssv = SerializedScriptValue::createFromWire(String(dataFooNull, WTF_ARRAY_LENGTH(dataFooNull)));
     147    result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     148    EXPECT_FALSE(result->isValid());
     149
     150    // keypath: "foo", value: {}, expected: null
     151    UChar dataObject[] = {0x017b};
     152    ssv = SerializedScriptValue::createFromWire(String(dataObject, WTF_ARRAY_LENGTH(dataObject)));
     153    result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     154    EXPECT_EQ(0, result.get());
     155
     156    // keypath: "foo", value: null, expected: null
     157    ssv = SerializedScriptValue::nullValue();
     158    result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     159    EXPECT_EQ(0, result.get());
     160}
     161
     162TEST(IDBKeyPathTest, IDBKeyPathPropertyNotAvailable)
     163{
     164    IDBKeyPath keyPath("PropertyNotAvailable");
     165    RefPtr<SerializedScriptValue> ssv;
     166    // {foo: "zoo", bar: null}
     167    UChar data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162,
     168                    0x3072, 0x027b};
     169    ssv = SerializedScriptValue::createFromWire(String(data, WTF_ARRAY_LENGTH(data)));
     170    RefPtr<IDBKey> result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     171    EXPECT_EQ(0, result.get());
     172
     173    // null
     174    ssv = SerializedScriptValue::nullValue();
     175    result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPath);
     176    EXPECT_EQ(0, result.get());
     177}
     178
     179TEST(IDBKeyPathTest, InjectIDBKey)
     180{
     181    // {foo: 'zoo'}
     182    const UChar initialData[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x017b};
     183    RefPtr<SerializedScriptValue> value = SerializedScriptValue::createFromWire(String(initialData, WTF_ARRAY_LENGTH(initialData)));
     184
     185    RefPtr<IDBKey> key = IDBKey::createString("myNewKey");
     186    IDBKeyPath keyPath("bar");
     187
     188    // {foo: 'zoo', bar: 'myNewKey'}
     189    const UChar expectedData[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603,
     190                                  0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f,
     191                                  0x5301, 0x6203, 0x7261, 0x013f, 0x0853,
     192                                  0x796d, 0x654e, 0x4b77, 0x7965, 0x027b};
     193    RefPtr<SerializedScriptValue> expectedValue =
     194            SerializedScriptValue::createFromWire(String(expectedData, WTF_ARRAY_LENGTH(expectedData)));
     195    RefPtr<SerializedScriptValue> result = injectIDBKeyIntoSerializedValue(key, value, keyPath);
     196    EXPECT_EQ(expectedValue->toWireString(), result->toWireString());
     197
     198    // Should fail - can't apply properties to string value of key foo
     199    keyPath = IDBKeyPath("foo.bad.path");
     200    result = injectIDBKeyIntoSerializedValue(key, value, keyPath);
     201    EXPECT_EQ(0, result.get());
     202
     203    // {foo: 'zoo', bar: {baz: 'myNewKey'}}
     204    const UChar expectedData2[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603,
     205                                   0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f,
     206                                   0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f,
     207                                   0x5302, 0x6203, 0x7a61, 0x023f, 0x0853,
     208                                   0x796d, 0x654e, 0x4b77, 0x7965, 0x017b,
     209                                   0x027b};
     210    RefPtr<SerializedScriptValue> expectedValue2 = SerializedScriptValue::createFromWire(String(expectedData2, WTF_ARRAY_LENGTH(expectedData2)));
     211    keyPath = IDBKeyPath("bar.baz");
     212    result = injectIDBKeyIntoSerializedValue(key, value, keyPath);
     213    EXPECT_EQ(expectedValue2->toWireString(), result->toWireString());
     214}
     215
    126216} // namespace
    127217
Note: See TracChangeset for help on using the changeset viewer.