| OLD | NEW |
| 1 /* | 1 /* |
| 2 * Copyright (C) 2011 Google Inc. All rights reserved. | 2 * Copyright (C) 2011 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 33 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 44 | 44 |
| 45 return createIDBKeyFromScriptValueAndKeyPath(0, value, idbKeyPath); | 45 return createIDBKeyFromScriptValueAndKeyPath(0, value, idbKeyPath); |
| 46 } | 46 } |
| 47 | 47 |
| 48 void checkKeyPathNullValue(const ScriptValue& value, const String& keyPath) | 48 void checkKeyPathNullValue(const ScriptValue& value, const String& keyPath) |
| 49 { | 49 { |
| 50 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); | 50 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); |
| 51 ASSERT_FALSE(idbKey.get()); | 51 ASSERT_FALSE(idbKey.get()); |
| 52 } | 52 } |
| 53 | 53 |
| 54 bool injectKey(PassRefPtr<IDBKey> key, ScriptValue& value, const String& keyPath
) | 54 bool injectKey(NewScriptState* scriptState, PassRefPtr<IDBKey> key, ScriptValue&
value, const String& keyPath) |
| 55 { | 55 { |
| 56 IDBKeyPath idbKeyPath(keyPath); | 56 IDBKeyPath idbKeyPath(keyPath); |
| 57 EXPECT_TRUE(idbKeyPath.isValid()); | 57 EXPECT_TRUE(idbKeyPath.isValid()); |
| 58 ScriptValue keyValue = idbKeyToScriptValue(0, key); | 58 ScriptValue keyValue = idbKeyToScriptValue(scriptState, key); |
| 59 return injectV8KeyIntoV8Value(keyValue.v8Value(), value.v8Value(), idbKeyPat
h, v8::Isolate::GetCurrent()); | 59 return injectV8KeyIntoV8Value(keyValue.v8Value(), value.v8Value(), idbKeyPat
h, v8::Isolate::GetCurrent()); |
| 60 } | 60 } |
| 61 | 61 |
| 62 void checkInjection(PassRefPtr<IDBKey> prpKey, ScriptValue& value, const String&
keyPath) | 62 void checkInjection(NewScriptState* scriptState, PassRefPtr<IDBKey> prpKey, Scri
ptValue& value, const String& keyPath) |
| 63 { | 63 { |
| 64 RefPtr<IDBKey> key = prpKey; | 64 RefPtr<IDBKey> key = prpKey; |
| 65 bool result = injectKey(key, value, keyPath); | 65 bool result = injectKey(scriptState, key, value, keyPath); |
| 66 ASSERT_TRUE(result); | 66 ASSERT_TRUE(result); |
| 67 RefPtr<IDBKey> extractedKey = checkKeyFromValueAndKeyPathInternal(value, key
Path); | 67 RefPtr<IDBKey> extractedKey = checkKeyFromValueAndKeyPathInternal(value, key
Path); |
| 68 EXPECT_TRUE(key->isEqual(extractedKey.get())); | 68 EXPECT_TRUE(key->isEqual(extractedKey.get())); |
| 69 } | 69 } |
| 70 | 70 |
| 71 void checkInjectionFails(PassRefPtr<IDBKey> key, ScriptValue& value, const Strin
g& keyPath) | 71 void checkInjectionFails(NewScriptState* scriptState, PassRefPtr<IDBKey> key, Sc
riptValue& value, const String& keyPath) |
| 72 { | 72 { |
| 73 EXPECT_FALSE(injectKey(key, value, keyPath)); | 73 EXPECT_FALSE(injectKey(scriptState, key, value, keyPath)); |
| 74 } | 74 } |
| 75 | 75 |
| 76 void checkKeyPathStringValue(const ScriptValue& value, const String& keyPath, co
nst String& expected) | 76 void checkKeyPathStringValue(const ScriptValue& value, const String& keyPath, co
nst String& expected) |
| 77 { | 77 { |
| 78 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); | 78 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); |
| 79 ASSERT_TRUE(idbKey.get()); | 79 ASSERT_TRUE(idbKey.get()); |
| 80 ASSERT_EQ(IDBKey::StringType, idbKey->type()); | 80 ASSERT_EQ(IDBKey::StringType, idbKey->type()); |
| 81 ASSERT_TRUE(expected == idbKey->string()); | 81 ASSERT_TRUE(expected == idbKey->string()); |
| 82 } | 82 } |
| 83 | 83 |
| (...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 checkKeyPathStringValue(scriptValue, "foo.bar", "zee"); | 136 checkKeyPathStringValue(scriptValue, "foo.bar", "zee"); |
| 137 checkKeyPathNullValue(scriptValue, "bar"); | 137 checkKeyPathNullValue(scriptValue, "bar"); |
| 138 } | 138 } |
| 139 | 139 |
| 140 class InjectIDBKeyTest : public IDBKeyFromValueAndKeyPathTest { | 140 class InjectIDBKeyTest : public IDBKeyFromValueAndKeyPathTest { |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 TEST_F(InjectIDBKeyTest, TopLevelPropertyStringValue) | 143 TEST_F(InjectIDBKeyTest, TopLevelPropertyStringValue) |
| 144 { | 144 { |
| 145 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 145 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 146 NewScriptState* scriptState = NewScriptState::current(isolate); |
| 146 v8::Local<v8::Object> object = v8::Object::New(isolate); | 147 v8::Local<v8::Object> object = v8::Object::New(isolate); |
| 147 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); | 148 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); |
| 148 | 149 |
| 149 ScriptValue foozoo(object, isolate); | 150 ScriptValue foozoo(object, isolate); |
| 150 checkInjection(IDBKey::createString("myNewKey"), foozoo, "bar"); | 151 checkInjection(scriptState, IDBKey::createString("myNewKey"), foozoo, "bar")
; |
| 151 checkInjection(IDBKey::createNumber(1234), foozoo, "bar"); | 152 checkInjection(scriptState, IDBKey::createNumber(1234), foozoo, "bar"); |
| 152 | 153 |
| 153 checkInjectionFails(IDBKey::createString("key"), foozoo, "foo.bar"); | 154 checkInjectionFails(scriptState, IDBKey::createString("key"), foozoo, "foo.b
ar"); |
| 154 } | 155 } |
| 155 | 156 |
| 156 TEST_F(InjectIDBKeyTest, SubProperty) | 157 TEST_F(InjectIDBKeyTest, SubProperty) |
| 157 { | 158 { |
| 158 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 159 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
| 160 NewScriptState* scriptState = NewScriptState::current(isolate); |
| 159 v8::Local<v8::Object> object = v8::Object::New(isolate); | 161 v8::Local<v8::Object> object = v8::Object::New(isolate); |
| 160 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); | 162 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); |
| 161 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); | 163 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); |
| 162 object->Set(v8AtomicString(isolate, "foo"), subProperty); | 164 object->Set(v8AtomicString(isolate, "foo"), subProperty); |
| 163 | 165 |
| 164 ScriptValue scriptObject(object, isolate); | 166 ScriptValue scriptObject(object, isolate); |
| 165 checkInjection(IDBKey::createString("myNewKey"), scriptObject, "foo.baz"); | 167 checkInjection(scriptState, IDBKey::createString("myNewKey"), scriptObject,
"foo.baz"); |
| 166 checkInjection(IDBKey::createNumber(789), scriptObject, "foo.baz"); | 168 checkInjection(scriptState, IDBKey::createNumber(789), scriptObject, "foo.ba
z"); |
| 167 checkInjection(IDBKey::createDate(4567), scriptObject, "foo.baz"); | 169 checkInjection(scriptState, IDBKey::createDate(4567), scriptObject, "foo.baz
"); |
| 168 checkInjection(IDBKey::createDate(4567), scriptObject, "bar"); | 170 checkInjection(scriptState, IDBKey::createDate(4567), scriptObject, "bar"); |
| 169 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "foo.b
az"); | 171 checkInjection(scriptState, IDBKey::createArray(IDBKey::KeyArray()), scriptO
bject, "foo.baz"); |
| 170 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "bar")
; | 172 checkInjection(scriptState, IDBKey::createArray(IDBKey::KeyArray()), scriptO
bject, "bar"); |
| 171 | 173 |
| 172 checkInjectionFails(IDBKey::createString("zoo"), scriptObject, "foo.bar.baz"
); | 174 checkInjectionFails(scriptState, IDBKey::createString("zoo"), scriptObject,
"foo.bar.baz"); |
| 173 checkInjection(IDBKey::createString("zoo"), scriptObject, "foo.xyz.foo"); | 175 checkInjection(scriptState, IDBKey::createString("zoo"), scriptObject, "foo.
xyz.foo"); |
| 174 } | 176 } |
| 175 | 177 |
| 176 } // namespace | 178 } // namespace |
| OLD | NEW |