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 |
11 * notice, this list of conditions and the following disclaimer in the | 11 * notice, this list of conditions and the following disclaimer in the |
12 * documentation and/or other materials provided with the distribution. | 12 * documentation and/or other materials provided with the distribution. |
13 * | 13 * |
14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY | 14 * THIS SOFTWARE IS PROVIDED BY APPLE AND ITS CONTRIBUTORS "AS IS" AND ANY |
15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED | 15 * EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE | 16 * WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE |
17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY | 17 * DISCLAIMED. IN NO EVENT SHALL APPLE OR ITS CONTRIBUTORS BE LIABLE FOR ANY |
18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES | 18 * DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES |
19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; | 19 * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; |
20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND | 20 * LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND |
21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT | 21 * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT |
22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF | 22 * (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF |
23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. | 23 * THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. |
24 */ | 24 */ |
25 | 25 |
26 #include "config.h" | 26 #include "config.h" |
| 27 #include "Document.h" |
| 28 #include "Frame.h" |
| 29 #include "FrameTestHelpers.h" |
27 #include "IDBBindingUtilities.h" | 30 #include "IDBBindingUtilities.h" |
28 #include "IDBKey.h" | 31 #include "IDBKey.h" |
29 #include "IDBKeyPath.h" | 32 #include "IDBKeyPath.h" |
| 33 #include "V8Binding.h" |
30 #include "V8PerIsolateData.h" | 34 #include "V8PerIsolateData.h" |
31 #include "V8Utilities.h" | 35 #include "V8Utilities.h" |
| 36 #include "WebFrame.h" |
| 37 #include "WebFrameImpl.h" |
| 38 #include "WebView.h" |
| 39 #include "WorldContextHandle.h" |
32 | 40 |
33 #include <gtest/gtest.h> | 41 #include <gtest/gtest.h> |
34 #include <wtf/Vector.h> | 42 #include <wtf/Vector.h> |
35 | 43 |
36 #if ENABLE(INDEXED_DATABASE) | 44 #if ENABLE(INDEXED_DATABASE) |
37 | 45 |
38 using namespace WebCore; | 46 using namespace WebCore; |
| 47 using namespace WebKit; |
39 | 48 |
40 namespace { | 49 namespace { |
41 | 50 |
42 PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(const ScriptValue& value,
const String& keyPath) | 51 PassRefPtr<IDBKey> checkKeyFromValueAndKeyPathInternal(const ScriptValue& value,
const String& keyPath) |
43 { | 52 { |
44 IDBKeyPath idbKeyPath(keyPath); | 53 IDBKeyPath idbKeyPath(keyPath); |
45 EXPECT_TRUE(idbKeyPath.isValid()); | 54 EXPECT_TRUE(idbKeyPath.isValid()); |
46 | 55 |
47 return createIDBKeyFromScriptValueAndKeyPath(value, idbKeyPath); | 56 return createIDBKeyFromScriptValueAndKeyPath(value, idbKeyPath); |
48 } | 57 } |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
83 } | 92 } |
84 | 93 |
85 void checkKeyPathNumberValue(const ScriptValue& value, const String& keyPath, in
t expected) | 94 void checkKeyPathNumberValue(const ScriptValue& value, const String& keyPath, in
t expected) |
86 { | 95 { |
87 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); | 96 RefPtr<IDBKey> idbKey = checkKeyFromValueAndKeyPathInternal(value, keyPath); |
88 ASSERT_TRUE(idbKey.get()); | 97 ASSERT_TRUE(idbKey.get()); |
89 ASSERT_EQ(IDBKey::NumberType, idbKey->type()); | 98 ASSERT_EQ(IDBKey::NumberType, idbKey->type()); |
90 ASSERT_TRUE(expected == idbKey->number()); | 99 ASSERT_TRUE(expected == idbKey->number()); |
91 } | 100 } |
92 | 101 |
| 102 static v8::Handle<v8::Context> context() |
| 103 { |
| 104 static WebView* webView; |
| 105 if (!webView) { |
| 106 webView = FrameTestHelpers::createWebViewAndLoad("about:blank"); |
| 107 webView->setFocus(true); |
| 108 } |
| 109 ScriptExecutionContext* context = static_cast<WebFrameImpl*>(webView->mainFr
ame())->frame()->document(); |
| 110 return toV8Context(context, WorldContextHandle(UseCurrentWorld)); |
| 111 } |
| 112 |
93 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) | 113 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyStringValue) |
94 { | 114 { |
95 v8::HandleScope handleScope; | 115 v8::HandleScope handleScope; |
96 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext
()); | 116 v8::Context::Scope scope(context()); |
97 | 117 |
98 v8::Local<v8::Object> object = v8::Object::New(); | 118 v8::Local<v8::Object> object = v8::Object::New(); |
99 object->Set(v8::String::New("foo"), v8::String::New("zoo")); | 119 object->Set(v8::String::New("foo"), v8::String::New("zoo")); |
100 | 120 |
101 ScriptValue scriptValue(object); | 121 ScriptValue scriptValue(object); |
102 | 122 |
103 checkKeyPathStringValue(scriptValue, "foo", "zoo"); | 123 checkKeyPathStringValue(scriptValue, "foo", "zoo"); |
104 checkKeyPathNullValue(scriptValue, "bar"); | 124 checkKeyPathNullValue(scriptValue, "bar"); |
105 } | 125 } |
106 | 126 |
107 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) | 127 TEST(IDBKeyFromValueAndKeyPathTest, TopLevelPropertyNumberValue) |
108 { | 128 { |
109 v8::HandleScope handleScope; | 129 v8::HandleScope handleScope; |
110 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext
()); | 130 v8::Context::Scope scope(context()); |
111 | 131 |
112 v8::Local<v8::Object> object = v8::Object::New(); | 132 v8::Local<v8::Object> object = v8::Object::New(); |
113 object->Set(v8::String::New("foo"), v8::Number::New(456)); | 133 object->Set(v8::String::New("foo"), v8::Number::New(456)); |
114 | 134 |
115 ScriptValue scriptValue(object); | 135 ScriptValue scriptValue(object); |
116 | 136 |
117 checkKeyPathNumberValue(scriptValue, "foo", 456); | 137 checkKeyPathNumberValue(scriptValue, "foo", 456); |
118 checkKeyPathNullValue(scriptValue, "bar"); | 138 checkKeyPathNullValue(scriptValue, "bar"); |
119 } | 139 } |
120 | 140 |
121 TEST(IDBKeyFromValueAndKeyPathTest, SubProperty) | 141 TEST(IDBKeyFromValueAndKeyPathTest, SubProperty) |
122 { | 142 { |
123 v8::HandleScope handleScope; | 143 v8::HandleScope handleScope; |
124 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext
()); | 144 v8::Context::Scope scope(context()); |
125 | 145 |
126 v8::Local<v8::Object> object = v8::Object::New(); | 146 v8::Local<v8::Object> object = v8::Object::New(); |
127 v8::Local<v8::Object> subProperty = v8::Object::New(); | 147 v8::Local<v8::Object> subProperty = v8::Object::New(); |
128 subProperty->Set(v8::String::New("bar"), v8::String::New("zee")); | 148 subProperty->Set(v8::String::New("bar"), v8::String::New("zee")); |
129 object->Set(v8::String::New("foo"), subProperty); | 149 object->Set(v8::String::New("foo"), subProperty); |
130 | 150 |
131 ScriptValue scriptValue(object); | 151 ScriptValue scriptValue(object); |
132 | 152 |
133 checkKeyPathStringValue(scriptValue, "foo.bar", "zee"); | 153 checkKeyPathStringValue(scriptValue, "foo.bar", "zee"); |
134 checkKeyPathNullValue(scriptValue, "bar"); | 154 checkKeyPathNullValue(scriptValue, "bar"); |
135 } | 155 } |
136 | 156 |
137 TEST(InjectIDBKeyTest, TopLevelPropertyStringValue) | 157 TEST(InjectIDBKeyTest, TopLevelPropertyStringValue) |
138 { | 158 { |
139 v8::HandleScope handleScope; | 159 v8::HandleScope handleScope; |
140 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext
()); | 160 v8::Context::Scope scope(context()); |
141 | 161 |
142 v8::Local<v8::Object> object = v8::Object::New(); | 162 v8::Local<v8::Object> object = v8::Object::New(); |
143 object->Set(v8::String::New("foo"), v8::String::New("zoo")); | 163 object->Set(v8::String::New("foo"), v8::String::New("zoo")); |
144 | 164 |
145 ScriptValue foozoo(object); | 165 ScriptValue foozoo(object); |
146 checkInjection(IDBKey::createString("myNewKey"), foozoo, "bar"); | 166 checkInjection(IDBKey::createString("myNewKey"), foozoo, "bar"); |
147 checkInjection(IDBKey::createNumber(1234), foozoo, "bar"); | 167 checkInjection(IDBKey::createNumber(1234), foozoo, "bar"); |
148 | 168 |
149 checkInjectionFails(IDBKey::createString("key"), foozoo, "foo.bar"); | 169 checkInjectionFails(IDBKey::createString("key"), foozoo, "foo.bar"); |
150 } | 170 } |
151 | 171 |
152 TEST(InjectIDBKeyTest, SubProperty) | 172 TEST(InjectIDBKeyTest, SubProperty) |
153 { | 173 { |
154 v8::HandleScope handleScope; | 174 v8::HandleScope handleScope; |
155 v8::Context::Scope scope(V8PerIsolateData::current()->ensureAuxiliaryContext
()); | 175 v8::Context::Scope scope(context()); |
156 | 176 |
157 v8::Local<v8::Object> object = v8::Object::New(); | 177 v8::Local<v8::Object> object = v8::Object::New(); |
158 v8::Local<v8::Object> subProperty = v8::Object::New(); | 178 v8::Local<v8::Object> subProperty = v8::Object::New(); |
159 subProperty->Set(v8::String::New("bar"), v8::String::New("zee")); | 179 subProperty->Set(v8::String::New("bar"), v8::String::New("zee")); |
160 object->Set(v8::String::New("foo"), subProperty); | 180 object->Set(v8::String::New("foo"), subProperty); |
161 | 181 |
162 ScriptValue scriptObject(object); | 182 ScriptValue scriptObject(object); |
163 checkInjection(IDBKey::createString("myNewKey"), scriptObject, "foo.baz"); | 183 checkInjection(IDBKey::createString("myNewKey"), scriptObject, "foo.baz"); |
164 checkInjection(IDBKey::createNumber(789), scriptObject, "foo.baz"); | 184 checkInjection(IDBKey::createNumber(789), scriptObject, "foo.baz"); |
165 checkInjection(IDBKey::createDate(4567), scriptObject, "foo.baz"); | 185 checkInjection(IDBKey::createDate(4567), scriptObject, "foo.baz"); |
166 checkInjection(IDBKey::createDate(4567), scriptObject, "bar"); | 186 checkInjection(IDBKey::createDate(4567), scriptObject, "bar"); |
167 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "foo.b
az"); | 187 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "foo.b
az"); |
168 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "bar")
; | 188 checkInjection(IDBKey::createArray(IDBKey::KeyArray()), scriptObject, "bar")
; |
169 | 189 |
170 checkInjectionFails(IDBKey::createString("zoo"), scriptObject, "foo.bar.baz"
); | 190 checkInjectionFails(IDBKey::createString("zoo"), scriptObject, "foo.bar.baz"
); |
171 checkInjection(IDBKey::createString("zoo"), scriptObject, "foo.xyz.foo"); | 191 checkInjection(IDBKey::createString("zoo"), scriptObject, "foo.xyz.foo"); |
172 } | 192 } |
173 | 193 |
174 } // namespace | 194 } // namespace |
175 | 195 |
176 #endif // ENABLE(INDEXED_DATABASE) | 196 #endif // ENABLE(INDEXED_DATABASE) |
OLD | NEW |