Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(397)

Side by Side Diff: Source/WebKit/chromium/tests/IDBKeyPathTest.cpp

Issue 11348011: Revert 128789 - IndexedDB: Use ScriptValue instead of SerializedScriptValue for get/openCursor (Closed) Base URL: http://svn.webkit.org/repository/webkit/branches/chromium/1271/
Patch Set: Created 8 years, 1 month ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 /* 1 /*
2 * Copyright (C) 2010 Google Inc. All rights reserved. 2 * Copyright (C) 2010 Google Inc. All rights reserved.
3 * 3 *
4 * Redistribution and use in source and binary forms, with or without 4 * Redistribution and use in source and binary forms, with or without
5 * modification, are permitted provided that the following conditions 5 * modification, are permitted provided that the following conditions
6 * are met: 6 * are met:
7 * 7 *
8 * 1. Redistributions of source code must retain the above copyright 8 * 1. Redistributions of source code must retain the above copyright
9 * notice, this list of conditions and the following disclaimer. 9 * notice, this list of conditions and the following disclaimer.
10 * 2. Redistributions in binary form must reproduce the above copyright 10 * 2. Redistributions in binary form must reproduce the above copyright
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 } 120 }
121 121
122 TEST(IDBKeyPathTest, InvalidKeyPath5) 122 TEST(IDBKeyPathTest, InvalidKeyPath5)
123 { 123 {
124 Vector<String> expected; 124 Vector<String> expected;
125 String keyPath("foo..bar..baz"); 125 String keyPath("foo..bar..baz");
126 expected.append(String("foo")); 126 expected.append(String("foo"));
127 checkKeyPath(keyPath, expected, 3); 127 checkKeyPath(keyPath, expected, 3);
128 } 128 }
129 129
130 TEST(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_LEN GTH(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_LE NGTH(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_LEN GTH(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
162 TEST(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(da ta)));
170 RefPtr<IDBKey> result = createIDBKeyFromSerializedValueAndKeyPath(ssv, keyPa th);
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
179 TEST(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::create FromWire(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
130 } // namespace 216 } // namespace
131 217
132 #endif // ENABLE(INDEXED_DATABASE) 218 #endif // ENABLE(INDEXED_DATABASE)
OLDNEW
« no previous file with comments | « Source/WebKit/chromium/tests/IDBBindingUtilitiesTest.cpp ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698