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 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
86 ASSERT_EQ(IDBKey::NumberType, idbKey->type()); | 86 ASSERT_EQ(IDBKey::NumberType, idbKey->type()); |
87 ASSERT_TRUE(expected == idbKey->number()); | 87 ASSERT_TRUE(expected == idbKey->number()); |
88 } | 88 } |
89 | 89 |
90 class IDBKeyFromValueAndKeyPathTest : public testing::Test { | 90 class IDBKeyFromValueAndKeyPathTest : public testing::Test { |
91 public: | 91 public: |
92 IDBKeyFromValueAndKeyPathTest() | 92 IDBKeyFromValueAndKeyPathTest() |
93 : m_scope(v8::Isolate::GetCurrent()) | 93 : m_scope(v8::Isolate::GetCurrent()) |
94 { | 94 { |
95 } | 95 } |
| 96 |
| 97 ScriptState* scriptState() const { return m_scope.scriptState(); } |
| 98 |
96 private: | 99 private: |
97 V8TestingScope m_scope; | 100 V8TestingScope m_scope; |
98 }; | 101 }; |
99 | 102 |
100 TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) | 103 TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) |
101 { | 104 { |
102 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 105 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
103 v8::Local<v8::Object> object = v8::Object::New(isolate); | 106 v8::Local<v8::Object> object = v8::Object::New(isolate); |
104 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); | 107 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); |
105 | 108 |
106 ScriptValue scriptValue(ScriptState::current(isolate), object); | 109 ScriptValue scriptValue(scriptState(), object); |
107 | 110 |
108 checkKeyPathStringValue(isolate, scriptValue, "foo", "zoo"); | 111 checkKeyPathStringValue(isolate, scriptValue, "foo", "zoo"); |
109 checkKeyPathNullValue(isolate, scriptValue, "bar"); | 112 checkKeyPathNullValue(isolate, scriptValue, "bar"); |
110 } | 113 } |
111 | 114 |
112 TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) | 115 TEST_F(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) |
113 { | 116 { |
114 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 117 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
115 v8::Local<v8::Object> object = v8::Object::New(isolate); | 118 v8::Local<v8::Object> object = v8::Object::New(isolate); |
116 object->Set(v8AtomicString(isolate, "foo"), v8::Number::New(isolate, 456)); | 119 object->Set(v8AtomicString(isolate, "foo"), v8::Number::New(isolate, 456)); |
117 | 120 |
118 ScriptValue scriptValue(ScriptState::current(isolate), object); | 121 ScriptValue scriptValue(scriptState(), object); |
119 | 122 |
120 checkKeyPathNumberValue(isolate, scriptValue, "foo", 456); | 123 checkKeyPathNumberValue(isolate, scriptValue, "foo", 456); |
121 checkKeyPathNullValue(isolate, scriptValue, "bar"); | 124 checkKeyPathNullValue(isolate, scriptValue, "bar"); |
122 } | 125 } |
123 | 126 |
124 TEST_F(IDBKeyFromValueAndKeyPathTest, SubProperty) | 127 TEST_F(IDBKeyFromValueAndKeyPathTest, SubProperty) |
125 { | 128 { |
126 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 129 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
127 v8::Local<v8::Object> object = v8::Object::New(isolate); | 130 v8::Local<v8::Object> object = v8::Object::New(isolate); |
128 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); | 131 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); |
129 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); | 132 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); |
130 object->Set(v8AtomicString(isolate, "foo"), subProperty); | 133 object->Set(v8AtomicString(isolate, "foo"), subProperty); |
131 | 134 |
132 ScriptValue scriptValue(ScriptState::current(isolate), object); | 135 ScriptValue scriptValue(scriptState(), object); |
133 | 136 |
134 checkKeyPathStringValue(isolate, scriptValue, "foo.bar", "zee"); | 137 checkKeyPathStringValue(isolate, scriptValue, "foo.bar", "zee"); |
135 checkKeyPathNullValue(isolate, scriptValue, "bar"); | 138 checkKeyPathNullValue(isolate, scriptValue, "bar"); |
136 } | 139 } |
137 | 140 |
138 class InjectIDBKeyTest : public IDBKeyFromValueAndKeyPathTest { | 141 class InjectIDBKeyTest : public IDBKeyFromValueAndKeyPathTest { |
139 }; | 142 }; |
140 | 143 |
141 TEST_F(InjectIDBKeyTest, TopLevelPropertyStringValue) | 144 TEST_F(InjectIDBKeyTest, TopLevelPropertyStringValue) |
142 { | 145 { |
143 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 146 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
144 ScriptState* scriptState = ScriptState::current(isolate); | |
145 v8::Local<v8::Object> object = v8::Object::New(isolate); | 147 v8::Local<v8::Object> object = v8::Object::New(isolate); |
146 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); | 148 object->Set(v8AtomicString(isolate, "foo"), v8AtomicString(isolate, "zoo")); |
147 | 149 |
148 ScriptValue foozoo(scriptState, object); | 150 ScriptValue foozoo(scriptState(), object); |
149 checkInjection(scriptState, IDBKey::createString("myNewKey"), foozoo, "bar")
; | 151 checkInjection(scriptState(), IDBKey::createString("myNewKey"), foozoo, "bar
"); |
150 checkInjection(scriptState, IDBKey::createNumber(1234), foozoo, "bar"); | 152 checkInjection(scriptState(), IDBKey::createNumber(1234), foozoo, "bar"); |
151 | 153 |
152 checkInjectionFails(scriptState, IDBKey::createString("key"), foozoo, "foo.b
ar"); | 154 checkInjectionFails(scriptState(), IDBKey::createString("key"), foozoo, "foo
.bar"); |
153 } | 155 } |
154 | 156 |
155 TEST_F(InjectIDBKeyTest, SubProperty) | 157 TEST_F(InjectIDBKeyTest, SubProperty) |
156 { | 158 { |
157 v8::Isolate* isolate = v8::Isolate::GetCurrent(); | 159 v8::Isolate* isolate = v8::Isolate::GetCurrent(); |
158 ScriptState* scriptState = ScriptState::current(isolate); | |
159 v8::Local<v8::Object> object = v8::Object::New(isolate); | 160 v8::Local<v8::Object> object = v8::Object::New(isolate); |
160 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); | 161 v8::Local<v8::Object> subProperty = v8::Object::New(isolate); |
161 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); | 162 subProperty->Set(v8AtomicString(isolate, "bar"), v8AtomicString(isolate, "ze
e")); |
162 object->Set(v8AtomicString(isolate, "foo"), subProperty); | 163 object->Set(v8AtomicString(isolate, "foo"), subProperty); |
163 | 164 |
164 ScriptValue scriptObject(scriptState, object); | 165 ScriptValue scriptObject(scriptState(), object); |
165 checkInjection(scriptState, IDBKey::createString("myNewKey"), scriptObject,
"foo.baz"); | 166 checkInjection(scriptState(), IDBKey::createString("myNewKey"), scriptObject
, "foo.baz"); |
166 checkInjection(scriptState, IDBKey::createNumber(789), scriptObject, "foo.ba
z"); | 167 checkInjection(scriptState(), IDBKey::createNumber(789), scriptObject, "foo.
baz"); |
167 checkInjection(scriptState, IDBKey::createDate(4567), scriptObject, "foo.baz
"); | 168 checkInjection(scriptState(), IDBKey::createDate(4567), scriptObject, "foo.b
az"); |
168 checkInjection(scriptState, IDBKey::createDate(4567), scriptObject, "bar"); | 169 checkInjection(scriptState(), IDBKey::createDate(4567), scriptObject, "bar")
; |
169 checkInjection(scriptState, IDBKey::createArray(IDBKey::KeyArray()), scriptO
bject, "foo.baz"); | 170 checkInjection(scriptState(), IDBKey::createArray(IDBKey::KeyArray()), scrip
tObject, "foo.baz"); |
170 checkInjection(scriptState, IDBKey::createArray(IDBKey::KeyArray()), scriptO
bject, "bar"); | 171 checkInjection(scriptState(), IDBKey::createArray(IDBKey::KeyArray()), scrip
tObject, "bar"); |
171 | 172 |
172 checkInjectionFails(scriptState, IDBKey::createString("zoo"), scriptObject,
"foo.bar.baz"); | 173 checkInjectionFails(scriptState(), IDBKey::createString("zoo"), scriptObject
, "foo.bar.baz"); |
173 checkInjection(scriptState, IDBKey::createString("zoo"), scriptObject, "foo.
xyz.foo"); | 174 checkInjection(scriptState(), IDBKey::createString("zoo"), scriptObject, "fo
o.xyz.foo"); |
174 } | 175 } |
175 | 176 |
176 } // namespace | 177 } // namespace |
OLD | NEW |