| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "base/bind.h" | 5 #include "base/bind.h" |
| 6 #include "base/utf_string_conversions.h" | 6 #include "base/utf_string_conversions.h" |
| 7 #include "chrome/test/base/in_process_browser_test.h" | 7 #include "chrome/test/base/in_process_browser_test.h" |
| 8 #include "chrome/test/base/ui_test_utils.h" | 8 #include "chrome/test/base/ui_test_utils.h" |
| 9 #include "content/browser/utility_process_host_impl.h" | 9 #include "content/browser/utility_process_host_impl.h" |
| 10 #include "content/public/browser/utility_process_host_client.h" | 10 #include "content/public/browser/utility_process_host_client.h" |
| 11 #include "content/common/indexed_db/indexed_db_key.h" | 11 #include "content/common/indexed_db/indexed_db_key.h" |
| 12 #include "content/common/indexed_db/indexed_db_key_path.h" | 12 #include "content/common/indexed_db/indexed_db_key_path.h" |
| 13 #include "content/common/utility_messages.h" | 13 #include "content/common/utility_messages.h" |
| 14 #include "content/common/webkitplatformsupport_impl.h" | 14 #include "content/common/webkitplatformsupport_impl.h" |
| 15 #include "content/public/common/serialized_script_value.h" | 15 #include "content/public/common/serialized_script_value.h" |
| 16 #include "googleurl/src/gurl.h" | 16 #include "googleurl/src/gurl.h" |
| 17 #include "testing/gtest/include/gtest/gtest.h" | 17 #include "testing/gtest/include/gtest/gtest.h" |
| 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" | 18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" |
| 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" | 19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize
dScriptValue.h" |
| 20 #include "webkit/glue/idb_bindings.h" | 20 #include "webkit/glue/idb_bindings.h" |
| 21 #include "webkit/glue/web_io_operators.h" | 21 #include "webkit/glue/web_io_operators.h" |
| 22 | 22 |
| 23 using content::BrowserThread; | 23 using content::BrowserThread; |
| 24 using content::IndexedDBKey; |
| 25 using content::IndexedDBKeyPath; |
| 24 using content::UtilityProcessHost; | 26 using content::UtilityProcessHost; |
| 25 using content::UtilityProcessHostClient; | 27 using content::UtilityProcessHostClient; |
| 28 using content::SerializedScriptValue; |
| 26 using WebKit::WebSerializedScriptValue; | 29 using WebKit::WebSerializedScriptValue; |
| 27 using WebKit::WebIDBKeyPath; | 30 using WebKit::WebIDBKeyPath; |
| 28 | 31 |
| 29 // Enables calling WebKit::shutdown no matter where a "return" happens. | 32 // Enables calling WebKit::shutdown no matter where a "return" happens. |
| 30 class ScopedShutdownWebKit { | 33 class ScopedShutdownWebKit { |
| 31 public: | 34 public: |
| 32 ScopedShutdownWebKit() { | 35 ScopedShutdownWebKit() { |
| 33 } | 36 } |
| 34 | 37 |
| 35 ~ScopedShutdownWebKit() { | 38 ~ScopedShutdownWebKit() { |
| (...skipping 12 matching lines...) Expand all Loading... |
| 48 | 51 |
| 49 // {foo: "zoo"} | 52 // {foo: "zoo"} |
| 50 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; | 53 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; |
| 51 std::vector<WebSerializedScriptValue> serialized_values; | 54 std::vector<WebSerializedScriptValue> serialized_values; |
| 52 serialized_values.push_back( | 55 serialized_values.push_back( |
| 53 WebSerializedScriptValue::fromString(string16(data_foo_zoo, | 56 WebSerializedScriptValue::fromString(string16(data_foo_zoo, |
| 54 arraysize(data_foo_zoo)))); | 57 arraysize(data_foo_zoo)))); |
| 55 | 58 |
| 56 // {foo: null} | 59 // {foo: null} |
| 57 char16 data_foo_null[] = {0x0353, 0x6f66, 0x306f, 0x017b}; | 60 char16 data_foo_null[] = {0x0353, 0x6f66, 0x306f, 0x017b}; |
| 58 serialized_values.push_back(content::SerializedScriptValue( | 61 serialized_values.push_back(SerializedScriptValue( |
| 59 false, false, string16(data_foo_null, arraysize(data_foo_null)))); | 62 false, false, string16(data_foo_null, arraysize(data_foo_null)))); |
| 60 | 63 |
| 61 // {} | 64 // {} |
| 62 char16 data_object[] = {0x017b}; | 65 char16 data_object[] = {0x017b}; |
| 63 serialized_values.push_back(content::SerializedScriptValue( | 66 serialized_values.push_back(SerializedScriptValue( |
| 64 false, false, string16(data_object, arraysize(data_object)))); | 67 false, false, string16(data_object, arraysize(data_object)))); |
| 65 | 68 |
| 66 // null | 69 // null |
| 67 serialized_values.push_back( | 70 serialized_values.push_back( |
| 68 WebSerializedScriptValue::fromString(string16())); | 71 WebSerializedScriptValue::fromString(string16())); |
| 69 | 72 |
| 70 std::vector<WebKit::WebIDBKey> values; | 73 std::vector<WebKit::WebIDBKey> values; |
| 71 content::IndexedDBKeyPath key_path; | 74 IndexedDBKeyPath key_path; |
| 72 | 75 |
| 73 key_path.SetString(UTF8ToUTF16("foo")); | 76 key_path.SetString(UTF8ToUTF16("foo")); |
| 74 webkit_glue::IDBKeysFromValuesAndKeyPath( | 77 webkit_glue::IDBKeysFromValuesAndKeyPath( |
| 75 serialized_values, key_path, &values); | 78 serialized_values, key_path, &values); |
| 76 | 79 |
| 77 ASSERT_EQ(size_t(4), values.size()); | 80 ASSERT_EQ(size_t(4), values.size()); |
| 78 ASSERT_EQ(WebKit::WebIDBKey::StringType, values[0].type()); | 81 ASSERT_EQ(WebKit::WebIDBKey::StringType, values[0].type()); |
| 79 ASSERT_EQ(UTF8ToUTF16("zoo"), values[0].string()); | 82 ASSERT_EQ(UTF8ToUTF16("zoo"), values[0].string()); |
| 80 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[1].type()); | 83 ASSERT_EQ(WebKit::WebIDBKey::InvalidType, values[1].type()); |
| 81 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type()); | 84 ASSERT_EQ(WebKit::WebIDBKey::NullType, values[2].type()); |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 } | 138 } |
| 136 | 139 |
| 137 void SetExpectedKeys(int expected_id, | 140 void SetExpectedKeys(int expected_id, |
| 138 const std::vector<IndexedDBKey>& expected_keys, | 141 const std::vector<IndexedDBKey>& expected_keys, |
| 139 bool failed) { | 142 bool failed) { |
| 140 expected_id_ = expected_id; | 143 expected_id_ = expected_id; |
| 141 expected_keys_ = expected_keys; | 144 expected_keys_ = expected_keys; |
| 142 value_for_key_path_failed_ = failed; | 145 value_for_key_path_failed_ = failed; |
| 143 } | 146 } |
| 144 | 147 |
| 145 void SetExpectedValue(const content::SerializedScriptValue& expected_value) { | 148 void SetExpectedValue(const SerializedScriptValue& expected_value) { |
| 146 expected_value_ = expected_value; | 149 expected_value_ = expected_value; |
| 147 } | 150 } |
| 148 | 151 |
| 149 void CheckValuesForKeyPath( | 152 void CheckValuesForKeyPath( |
| 150 int id, | 153 int id, |
| 151 const std::vector<content::SerializedScriptValue>& serialized_values, | 154 const std::vector<SerializedScriptValue>& serialized_values, |
| 152 const content::IndexedDBKeyPath& key_path) { | 155 const IndexedDBKeyPath& key_path) { |
| 153 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 156 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 154 BrowserThread::PostTask( | 157 BrowserThread::PostTask( |
| 155 BrowserThread::IO, FROM_HERE, | 158 BrowserThread::IO, FROM_HERE, |
| 156 base::Bind(&IDBKeyPathHelper::CheckValuesForKeyPath, this, id, | 159 base::Bind(&IDBKeyPathHelper::CheckValuesForKeyPath, this, id, |
| 157 serialized_values, key_path)); | 160 serialized_values, key_path)); |
| 158 return; | 161 return; |
| 159 } | 162 } |
| 160 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 163 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 161 bool ret = utility_process_host_->Send( | 164 bool ret = utility_process_host_->Send( |
| 162 new UtilityMsg_IDBKeysFromValuesAndKeyPath( | 165 new UtilityMsg_IDBKeysFromValuesAndKeyPath( |
| 163 id, serialized_values, key_path)); | 166 id, serialized_values, key_path)); |
| 164 ASSERT_TRUE(ret); | 167 ASSERT_TRUE(ret); |
| 165 } | 168 } |
| 166 | 169 |
| 167 void CheckInjectValue(const IndexedDBKey& key, | 170 void CheckInjectValue(const IndexedDBKey& key, |
| 168 const content::SerializedScriptValue& value, | 171 const SerializedScriptValue& value, |
| 169 const content::IndexedDBKeyPath& key_path) { | 172 const IndexedDBKeyPath& key_path) { |
| 170 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { | 173 if (!BrowserThread::CurrentlyOn(BrowserThread::IO)) { |
| 171 BrowserThread::PostTask( | 174 BrowserThread::PostTask( |
| 172 BrowserThread::IO, FROM_HERE, | 175 BrowserThread::IO, FROM_HERE, |
| 173 base::Bind(&IDBKeyPathHelper::CheckInjectValue, this, key, value, | 176 base::Bind(&IDBKeyPathHelper::CheckInjectValue, this, key, value, |
| 174 key_path)); | 177 key_path)); |
| 175 return; | 178 return; |
| 176 } | 179 } |
| 177 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); | 180 DCHECK(BrowserThread::CurrentlyOn(BrowserThread::IO)); |
| 178 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( | 181 bool ret = utility_process_host_->Send(new UtilityMsg_InjectIDBKey( |
| 179 key, value, key_path)); | 182 key, value, key_path)); |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 212 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 215 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 213 MessageLoop::QuitClosure()); | 216 MessageLoop::QuitClosure()); |
| 214 } | 217 } |
| 215 | 218 |
| 216 void OnIDBKeysFromValuesAndKeyPathFailed(int id) { | 219 void OnIDBKeysFromValuesAndKeyPathFailed(int id) { |
| 217 EXPECT_TRUE(value_for_key_path_failed_); | 220 EXPECT_TRUE(value_for_key_path_failed_); |
| 218 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 221 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 219 MessageLoop::QuitClosure()); | 222 MessageLoop::QuitClosure()); |
| 220 } | 223 } |
| 221 | 224 |
| 222 void OnInjectIDBKeyFinished(const content::SerializedScriptValue& new_value) { | 225 void OnInjectIDBKeyFinished(const SerializedScriptValue& new_value) { |
| 223 EXPECT_EQ(expected_value_.data(), new_value.data()); | 226 EXPECT_EQ(expected_value_.data(), new_value.data()); |
| 224 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, | 227 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, |
| 225 MessageLoop::QuitClosure()); | 228 MessageLoop::QuitClosure()); |
| 226 } | 229 } |
| 227 | 230 |
| 228 | 231 |
| 229 private: | 232 private: |
| 230 virtual ~IDBKeyPathHelper() {} | 233 virtual ~IDBKeyPathHelper() {} |
| 231 | 234 |
| 232 int expected_id_; | 235 int expected_id_; |
| 233 std::vector<IndexedDBKey> expected_keys_; | 236 std::vector<IndexedDBKey> expected_keys_; |
| 234 base::WeakPtr<UtilityProcessHost> utility_process_host_; | 237 base::WeakPtr<UtilityProcessHost> utility_process_host_; |
| 235 bool value_for_key_path_failed_; | 238 bool value_for_key_path_failed_; |
| 236 content::SerializedScriptValue expected_value_; | 239 SerializedScriptValue expected_value_; |
| 237 }; | 240 }; |
| 238 | 241 |
| 239 // This test fixture runs in the UI thread. However, most of the work done by | 242 // This test fixture runs in the UI thread. However, most of the work done by |
| 240 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO | 243 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO |
| 241 // thread. This fixture delegates to IDBKeyPathHelper and blocks via | 244 // thread. This fixture delegates to IDBKeyPathHelper and blocks via |
| 242 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit | 245 // "ui_test_utils::RunMessageLoop()", until IDBKeyPathHelper posts a quit |
| 243 // message the MessageLoop. | 246 // message the MessageLoop. |
| 244 class ScopedIDBKeyPathHelper { | 247 class ScopedIDBKeyPathHelper { |
| 245 public: | 248 public: |
| 246 ScopedIDBKeyPathHelper() { | 249 ScopedIDBKeyPathHelper() { |
| 247 key_path_helper_ = new IDBKeyPathHelper(); | 250 key_path_helper_ = new IDBKeyPathHelper(); |
| 248 key_path_helper_->CreateUtilityProcess(); | 251 key_path_helper_->CreateUtilityProcess(); |
| 249 ui_test_utils::RunMessageLoop(); | 252 ui_test_utils::RunMessageLoop(); |
| 250 } | 253 } |
| 251 | 254 |
| 252 ~ScopedIDBKeyPathHelper() { | 255 ~ScopedIDBKeyPathHelper() { |
| 253 key_path_helper_->DestroyUtilityProcess(); | 256 key_path_helper_->DestroyUtilityProcess(); |
| 254 ui_test_utils::RunMessageLoop(); | 257 ui_test_utils::RunMessageLoop(); |
| 255 } | 258 } |
| 256 | 259 |
| 257 void SetExpectedKeys(int id, const std::vector<IndexedDBKey>& expected_keys, | 260 void SetExpectedKeys(int id, |
| 258 bool failed) { | 261 const std::vector<IndexedDBKey>& expected_keys, |
| 262 bool failed) { |
| 259 key_path_helper_->SetExpectedKeys(id, expected_keys, failed); | 263 key_path_helper_->SetExpectedKeys(id, expected_keys, failed); |
| 260 } | 264 } |
| 261 | 265 |
| 262 void SetExpectedValue(const content::SerializedScriptValue& expected_value) { | 266 void SetExpectedValue(const SerializedScriptValue& expected_value) { |
| 263 key_path_helper_->SetExpectedValue(expected_value); | 267 key_path_helper_->SetExpectedValue(expected_value); |
| 264 } | 268 } |
| 265 | 269 |
| 266 void CheckValuesForKeyPath( | 270 void CheckValuesForKeyPath( |
| 267 int id, | 271 int id, |
| 268 const std::vector<content::SerializedScriptValue>& | 272 const std::vector<SerializedScriptValue>& |
| 269 serialized_script_values, | 273 serialized_script_values, |
| 270 const content::IndexedDBKeyPath& key_path) { | 274 const IndexedDBKeyPath& key_path) { |
| 271 key_path_helper_->CheckValuesForKeyPath(id, serialized_script_values, | 275 key_path_helper_->CheckValuesForKeyPath(id, serialized_script_values, |
| 272 key_path); | 276 key_path); |
| 273 ui_test_utils::RunMessageLoop(); | 277 ui_test_utils::RunMessageLoop(); |
| 274 } | 278 } |
| 275 | 279 |
| 276 void CheckInjectValue(const IndexedDBKey& key, | 280 void CheckInjectValue(const IndexedDBKey& key, |
| 277 const content::SerializedScriptValue& value, | 281 const SerializedScriptValue& value, |
| 278 const content::IndexedDBKeyPath& key_path) { | 282 const IndexedDBKeyPath& key_path) { |
| 279 key_path_helper_->CheckInjectValue(key, value, key_path); | 283 key_path_helper_->CheckInjectValue(key, value, key_path); |
| 280 ui_test_utils::RunMessageLoop(); | 284 ui_test_utils::RunMessageLoop(); |
| 281 } | 285 } |
| 282 | 286 |
| 283 private: | 287 private: |
| 284 scoped_refptr<IDBKeyPathHelper> key_path_helper_; | 288 scoped_refptr<IDBKeyPathHelper> key_path_helper_; |
| 285 }; | 289 }; |
| 286 | 290 |
| 287 // Cases: | 291 // Cases: |
| 288 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathExtract) { | 292 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathExtract) { |
| 289 ScopedIDBKeyPathHelper scoped_helper; | 293 ScopedIDBKeyPathHelper scoped_helper; |
| 290 const int kId = 7; | 294 const int kId = 7; |
| 291 std::vector<IndexedDBKey> expected_keys; | 295 std::vector<IndexedDBKey> expected_keys; |
| 292 std::vector<content::SerializedScriptValue> serialized_values; | 296 std::vector<SerializedScriptValue> serialized_values; |
| 293 | 297 |
| 294 IndexedDBKey string_zoo_key; | 298 IndexedDBKey string_zoo_key; |
| 295 string_zoo_key.SetString(UTF8ToUTF16("zoo")); | 299 string_zoo_key.SetString(UTF8ToUTF16("zoo")); |
| 296 IndexedDBKey null_key; | 300 IndexedDBKey null_key; |
| 297 null_key.SetNull(); | 301 null_key.SetNull(); |
| 298 IndexedDBKey invalid_key; | 302 IndexedDBKey invalid_key; |
| 299 invalid_key.SetInvalid(); | 303 invalid_key.SetInvalid(); |
| 300 | 304 |
| 301 // keypath: "foo", value: {foo: "zoo"}, expected: "zoo" | 305 // keypath: "foo", value: {foo: "zoo"}, expected: "zoo" |
| 302 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; | 306 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; |
| 303 serialized_values.push_back(content::SerializedScriptValue( | 307 serialized_values.push_back(SerializedScriptValue( |
| 304 false, false, string16(data_foo_zoo, arraysize(data_foo_zoo)))); | 308 false, false, string16(data_foo_zoo, arraysize(data_foo_zoo)))); |
| 305 expected_keys.push_back(string_zoo_key); | 309 expected_keys.push_back(string_zoo_key); |
| 306 | 310 |
| 307 // keypath: "foo", value: {foo: null}, expected: invalid | 311 // keypath: "foo", value: {foo: null}, expected: invalid |
| 308 char16 data_foo_null[] = {0x0353, 0x6f66, 0x306f, 0x017b}; | 312 char16 data_foo_null[] = {0x0353, 0x6f66, 0x306f, 0x017b}; |
| 309 serialized_values.push_back(content::SerializedScriptValue( | 313 serialized_values.push_back(SerializedScriptValue( |
| 310 false, false, string16(data_foo_null, arraysize(data_foo_null)))); | 314 false, false, string16(data_foo_null, arraysize(data_foo_null)))); |
| 311 expected_keys.push_back(invalid_key); | 315 expected_keys.push_back(invalid_key); |
| 312 | 316 |
| 313 // keypath: "foo", value: {}, expected: null | 317 // keypath: "foo", value: {}, expected: null |
| 314 char16 data_object[] = {0x017b}; | 318 char16 data_object[] = {0x017b}; |
| 315 serialized_values.push_back(content::SerializedScriptValue( | 319 serialized_values.push_back(SerializedScriptValue( |
| 316 false, false, string16(data_object, arraysize(data_object)))); | 320 false, false, string16(data_object, arraysize(data_object)))); |
| 317 expected_keys.push_back(null_key); | 321 expected_keys.push_back(null_key); |
| 318 | 322 |
| 319 // keypath: "foo", value: null, expected: null | 323 // keypath: "foo", value: null, expected: null |
| 320 serialized_values.push_back( | 324 serialized_values.push_back( |
| 321 content::SerializedScriptValue(true, false, string16())); | 325 SerializedScriptValue(true, false, string16())); |
| 322 expected_keys.push_back(null_key); | 326 expected_keys.push_back(null_key); |
| 323 | 327 |
| 324 scoped_helper.SetExpectedKeys(kId, expected_keys, false); | 328 scoped_helper.SetExpectedKeys(kId, expected_keys, false); |
| 325 | 329 |
| 326 content::IndexedDBKeyPath key_path; | 330 IndexedDBKeyPath key_path; |
| 327 key_path.SetString(UTF8ToUTF16("foo")); | 331 key_path.SetString(UTF8ToUTF16("foo")); |
| 328 scoped_helper.CheckValuesForKeyPath( | 332 scoped_helper.CheckValuesForKeyPath( |
| 329 kId, serialized_values, key_path); | 333 kId, serialized_values, key_path); |
| 330 } | 334 } |
| 331 | 335 |
| 332 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathPropertyNotAvailable) { | 336 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathPropertyNotAvailable) { |
| 333 ScopedIDBKeyPathHelper scoped_helper; | 337 ScopedIDBKeyPathHelper scoped_helper; |
| 334 const int kId = 7; | 338 const int kId = 7; |
| 335 std::vector<IndexedDBKey> expected_keys; | 339 std::vector<IndexedDBKey> expected_keys; |
| 336 IndexedDBKey null_value; | 340 IndexedDBKey null_value; |
| 337 null_value.SetNull(); | 341 null_value.SetNull(); |
| 338 expected_keys.push_back(null_value); | 342 expected_keys.push_back(null_value); |
| 339 expected_keys.push_back(null_value); | 343 expected_keys.push_back(null_value); |
| 340 | 344 |
| 341 scoped_helper.SetExpectedKeys(kId, expected_keys, false); | 345 scoped_helper.SetExpectedKeys(kId, expected_keys, false); |
| 342 | 346 |
| 343 std::vector<content::SerializedScriptValue> serialized_values; | 347 std::vector<SerializedScriptValue> serialized_values; |
| 344 // {foo: "zoo", bar: null} | 348 // {foo: "zoo", bar: null} |
| 345 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162, | 349 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162, |
| 346 0x3072, 0x027b}; | 350 0x3072, 0x027b}; |
| 347 serialized_values.push_back(content::SerializedScriptValue( | 351 serialized_values.push_back(SerializedScriptValue( |
| 348 false, false, string16(data, arraysize(data)))); | 352 false, false, string16(data, arraysize(data)))); |
| 349 | 353 |
| 350 // null | 354 // null |
| 351 serialized_values.push_back( | 355 serialized_values.push_back( |
| 352 content::SerializedScriptValue(true, false, string16())); | 356 SerializedScriptValue(true, false, string16())); |
| 353 | 357 |
| 354 content::IndexedDBKeyPath key_path; | 358 IndexedDBKeyPath key_path; |
| 355 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable")); | 359 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable")); |
| 356 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path); | 360 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path); |
| 357 } | 361 } |
| 358 | 362 |
| 359 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathMultipleCalls) { | 363 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathMultipleCalls) { |
| 360 ScopedIDBKeyPathHelper scoped_helper; | 364 ScopedIDBKeyPathHelper scoped_helper; |
| 361 const int kId = 7; | 365 const int kId = 7; |
| 362 std::vector<IndexedDBKey> expected_keys; | 366 std::vector<IndexedDBKey> expected_keys; |
| 363 | 367 |
| 364 IndexedDBKey null_value; | 368 IndexedDBKey null_value; |
| 365 null_value.SetNull(); | 369 null_value.SetNull(); |
| 366 expected_keys.push_back(null_value); | 370 expected_keys.push_back(null_value); |
| 367 expected_keys.push_back(null_value); | 371 expected_keys.push_back(null_value); |
| 368 scoped_helper.SetExpectedKeys(kId, expected_keys, false); | 372 scoped_helper.SetExpectedKeys(kId, expected_keys, false); |
| 369 | 373 |
| 370 std::vector<content::SerializedScriptValue> serialized_values; | 374 std::vector<SerializedScriptValue> serialized_values; |
| 371 | 375 |
| 372 // {foo: "zoo", bar: null} | 376 // {foo: "zoo", bar: null} |
| 373 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162, | 377 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162, |
| 374 0x3072, 0x027b}; | 378 0x3072, 0x027b}; |
| 375 serialized_values.push_back(content::SerializedScriptValue( | 379 serialized_values.push_back(SerializedScriptValue( |
| 376 false, false, string16(data, arraysize(data)))); | 380 false, false, string16(data, arraysize(data)))); |
| 377 | 381 |
| 378 // null | 382 // null |
| 379 serialized_values.push_back( | 383 serialized_values.push_back( |
| 380 content::SerializedScriptValue(true, false, string16())); | 384 SerializedScriptValue(true, false, string16())); |
| 381 | 385 |
| 382 content::IndexedDBKeyPath key_path; | 386 IndexedDBKeyPath key_path; |
| 383 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable")); | 387 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable")); |
| 384 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path); | 388 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path); |
| 385 | 389 |
| 386 // Call again with the Utility process in batch mode and with valid keys. | 390 // Call again with the Utility process in batch mode and with valid keys. |
| 387 expected_keys.clear(); | 391 expected_keys.clear(); |
| 388 IndexedDBKey value; | 392 IndexedDBKey value; |
| 389 value.SetString(UTF8ToUTF16("zoo")); | 393 value.SetString(UTF8ToUTF16("zoo")); |
| 390 expected_keys.push_back(value); | 394 expected_keys.push_back(value); |
| 391 expected_keys.push_back(null_value); | 395 expected_keys.push_back(null_value); |
| 392 scoped_helper.SetExpectedKeys(kId + 1, expected_keys, false); | 396 scoped_helper.SetExpectedKeys(kId + 1, expected_keys, false); |
| 393 key_path.SetString(UTF8ToUTF16("foo")); | 397 key_path.SetString(UTF8ToUTF16("foo")); |
| 394 scoped_helper.CheckValuesForKeyPath(kId + 1, serialized_values, key_path); | 398 scoped_helper.CheckValuesForKeyPath(kId + 1, serialized_values, key_path); |
| 395 } | 399 } |
| 396 | 400 |
| 397 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, InjectIDBKey) { | 401 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, InjectIDBKey) { |
| 398 // {foo: 'zoo'} | 402 // {foo: 'zoo'} |
| 399 const char16 initial_data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; | 403 const char16 initial_data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; |
| 400 content::SerializedScriptValue value( | 404 SerializedScriptValue value( |
| 401 false, false, string16(initial_data, arraysize(initial_data))); | 405 false, false, string16(initial_data, arraysize(initial_data))); |
| 402 IndexedDBKey key; | 406 IndexedDBKey key; |
| 403 key.SetString(UTF8ToUTF16("myNewKey")); | 407 key.SetString(UTF8ToUTF16("myNewKey")); |
| 404 | 408 |
| 405 ScopedIDBKeyPathHelper scoped_helper; | 409 ScopedIDBKeyPathHelper scoped_helper; |
| 406 | 410 |
| 407 // {foo: 'zoo', bar: 'myNewKey'} | 411 // {foo: 'zoo', bar: 'myNewKey'} |
| 408 const char16 expected_data[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603, | 412 const char16 expected_data[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603, |
| 409 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, | 413 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, |
| 410 0x5301, 0x6203, 0x7261, 0x013f, 0x0853, | 414 0x5301, 0x6203, 0x7261, 0x013f, 0x0853, |
| 411 0x796d, 0x654e, 0x4b77, 0x7965, 0x027b}; | 415 0x796d, 0x654e, 0x4b77, 0x7965, 0x027b}; |
| 412 content::SerializedScriptValue expected_value( | 416 SerializedScriptValue expected_value( |
| 413 false, false, string16(expected_data, arraysize(expected_data))); | 417 false, false, string16(expected_data, arraysize(expected_data))); |
| 414 scoped_helper.SetExpectedValue(expected_value); | 418 scoped_helper.SetExpectedValue(expected_value); |
| 415 content::IndexedDBKeyPath key_path; | 419 IndexedDBKeyPath key_path; |
| 416 key_path.SetString(UTF8ToUTF16("bar")); | 420 key_path.SetString(UTF8ToUTF16("bar")); |
| 417 scoped_helper.CheckInjectValue(key, value, key_path); | 421 scoped_helper.CheckInjectValue(key, value, key_path); |
| 418 | 422 |
| 419 // Should fail - can't apply properties to string value of key foo | 423 // Should fail - can't apply properties to string value of key foo |
| 420 const content::SerializedScriptValue failure_value; | 424 const SerializedScriptValue failure_value; |
| 421 scoped_helper.SetExpectedValue(failure_value); | 425 scoped_helper.SetExpectedValue(failure_value); |
| 422 key_path.SetString(UTF8ToUTF16("foo.bad.path")); | 426 key_path.SetString(UTF8ToUTF16("foo.bad.path")); |
| 423 scoped_helper.CheckInjectValue(key, value, key_path); | 427 scoped_helper.CheckInjectValue(key, value, key_path); |
| 424 | 428 |
| 425 // {foo: 'zoo', bar: {baz: 'myNewKey'}} | 429 // {foo: 'zoo', bar: {baz: 'myNewKey'}} |
| 426 const char16 expected_data2[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603, | 430 const char16 expected_data2[] = {0x01ff, 0x003f, 0x3f6f, 0x5301, 0x6603, |
| 427 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, | 431 0x6f6f, 0x013f, 0x0353, 0x6f7a, 0x3f6f, |
| 428 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, | 432 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, |
| 429 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, | 433 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, |
| 430 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, | 434 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, |
| 431 0x027b}; | 435 0x027b}; |
| 432 content::SerializedScriptValue expected_value2( | 436 SerializedScriptValue expected_value2( |
| 433 false, false, string16(expected_data2, arraysize(expected_data2))); | 437 false, false, string16(expected_data2, arraysize(expected_data2))); |
| 434 scoped_helper.SetExpectedValue(expected_value2); | 438 scoped_helper.SetExpectedValue(expected_value2); |
| 435 key_path.SetString(UTF8ToUTF16("bar.baz")); | 439 key_path.SetString(UTF8ToUTF16("bar.baz")); |
| 436 scoped_helper.CheckInjectValue(key, value, key_path); | 440 scoped_helper.CheckInjectValue(key, value, key_path); |
| 437 } | 441 } |
| OLD | NEW |