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

Side by Side Diff: content/browser/indexed_db/idbbindingutilities_browsertest.cc

Issue 10821037: Move a number of other tests from browser_tests to content_browsertests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: a little cleaner Created 8 years, 4 months 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 | Annotate | Revision Log
OLDNEW
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/message_loop.h"
6 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
7 #include "chrome/test/base/in_process_browser_test.h"
8 #include "chrome/test/base/ui_test_utils.h"
9 #include "content/browser/utility_process_host_impl.h" 8 #include "content/browser/utility_process_host_impl.h"
10 #include "content/public/browser/utility_process_host_client.h" 9 #include "content/public/browser/utility_process_host_client.h"
11 #include "content/common/indexed_db/indexed_db_key.h" 10 #include "content/common/indexed_db/indexed_db_key.h"
12 #include "content/common/indexed_db/indexed_db_key_path.h" 11 #include "content/common/indexed_db/indexed_db_key_path.h"
13 #include "content/common/utility_messages.h" 12 #include "content/common/utility_messages.h"
14 #include "content/common/webkitplatformsupport_impl.h" 13 #include "content/common/webkitplatformsupport_impl.h"
15 #include "content/public/common/serialized_script_value.h" 14 #include "content/public/common/serialized_script_value.h"
15 #include "content/public/test/test_utils.h"
16 #include "content/test/content_browser_test.h"
16 #include "googleurl/src/gurl.h" 17 #include "googleurl/src/gurl.h"
17 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
18 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 19 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
19 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h" 20 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSerialize dScriptValue.h"
20 #include "webkit/glue/idb_bindings.h" 21 #include "webkit/glue/idb_bindings.h"
21 #include "webkit/glue/web_io_operators.h" 22 #include "webkit/glue/web_io_operators.h"
22 23
23 using content::BrowserThread;
24 using content::IndexedDBKey;
25 using content::IndexedDBKeyPath;
26 using content::UtilityProcessHost;
27 using content::UtilityProcessHostClient;
28 using content::SerializedScriptValue;
29 using WebKit::WebSerializedScriptValue; 24 using WebKit::WebSerializedScriptValue;
30 using WebKit::WebIDBKeyPath; 25 using WebKit::WebIDBKeyPath;
31 26
27 namespace content {
28
32 // Enables calling WebKit::shutdown no matter where a "return" happens. 29 // Enables calling WebKit::shutdown no matter where a "return" happens.
33 class ScopedShutdownWebKit { 30 class ScopedShutdownWebKit {
34 public: 31 public:
35 ScopedShutdownWebKit() { 32 ScopedShutdownWebKit() {
36 } 33 }
37 34
38 ~ScopedShutdownWebKit() { 35 ~ScopedShutdownWebKit() {
39 WebKit::shutdown(); 36 WebKit::shutdown();
40 } 37 }
41 38
42 private: 39 private:
43 DISALLOW_COPY_AND_ASSIGN(ScopedShutdownWebKit); 40 DISALLOW_COPY_AND_ASSIGN(ScopedShutdownWebKit);
44 }; 41 };
45 42
46 // Sanity test, check the function call directly outside the sandbox. 43 // Sanity test, check the function call directly outside the sandbox.
47 TEST(IDBKeyPathWithoutSandbox, Value) { 44 TEST(IDBKeyPathWithoutSandbox, Value) {
48 content::WebKitPlatformSupportImpl webkit_platform_support; 45 WebKitPlatformSupportImpl webkit_platform_support;
49 WebKit::initialize(&webkit_platform_support); 46 WebKit::initialize(&webkit_platform_support);
50 ScopedShutdownWebKit shutdown_webkit; 47 ScopedShutdownWebKit shutdown_webkit;
51 48
52 // {foo: "zoo"} 49 // {foo: "zoo"}
53 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; 50 char16 data_foo_zoo[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
54 std::vector<WebSerializedScriptValue> serialized_values; 51 std::vector<WebSerializedScriptValue> serialized_values;
55 serialized_values.push_back( 52 serialized_values.push_back(
56 WebSerializedScriptValue::fromString(string16(data_foo_zoo, 53 WebSerializedScriptValue::fromString(string16(data_foo_zoo,
57 arraysize(data_foo_zoo)))); 54 arraysize(data_foo_zoo))));
58 55
(...skipping 176 matching lines...) Expand 10 before | Expand all | Expand 10 after
235 int expected_id_; 232 int expected_id_;
236 std::vector<IndexedDBKey> expected_keys_; 233 std::vector<IndexedDBKey> expected_keys_;
237 base::WeakPtr<UtilityProcessHost> utility_process_host_; 234 base::WeakPtr<UtilityProcessHost> utility_process_host_;
238 bool value_for_key_path_failed_; 235 bool value_for_key_path_failed_;
239 SerializedScriptValue expected_value_; 236 SerializedScriptValue expected_value_;
240 }; 237 };
241 238
242 // This test fixture runs in the UI thread. However, most of the work done by 239 // This test fixture runs in the UI thread. However, most of the work done by
243 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO 240 // UtilityProcessHost (and wrapped by IDBKeyPathHelper above) happens on the IO
244 // thread. This fixture delegates to IDBKeyPathHelper and blocks via 241 // thread. This fixture delegates to IDBKeyPathHelper and blocks via
245 // "content::RunMessageLoop()", until IDBKeyPathHelper posts a quit 242 // "RunMessageLoop()", until IDBKeyPathHelper posts a quit
246 // message the MessageLoop. 243 // message the MessageLoop.
247 class ScopedIDBKeyPathHelper { 244 class ScopedIDBKeyPathHelper {
248 public: 245 public:
249 ScopedIDBKeyPathHelper() { 246 ScopedIDBKeyPathHelper() {
250 key_path_helper_ = new IDBKeyPathHelper(); 247 key_path_helper_ = new IDBKeyPathHelper();
251 key_path_helper_->CreateUtilityProcess(); 248 key_path_helper_->CreateUtilityProcess();
252 content::RunMessageLoop(); 249 RunMessageLoop();
253 } 250 }
254 251
255 ~ScopedIDBKeyPathHelper() { 252 ~ScopedIDBKeyPathHelper() {
256 key_path_helper_->DestroyUtilityProcess(); 253 key_path_helper_->DestroyUtilityProcess();
257 content::RunMessageLoop(); 254 RunMessageLoop();
258 } 255 }
259 256
260 void SetExpectedKeys(int id, 257 void SetExpectedKeys(int id,
261 const std::vector<IndexedDBKey>& expected_keys, 258 const std::vector<IndexedDBKey>& expected_keys,
262 bool failed) { 259 bool failed) {
263 key_path_helper_->SetExpectedKeys(id, expected_keys, failed); 260 key_path_helper_->SetExpectedKeys(id, expected_keys, failed);
264 } 261 }
265 262
266 void SetExpectedValue(const SerializedScriptValue& expected_value) { 263 void SetExpectedValue(const SerializedScriptValue& expected_value) {
267 key_path_helper_->SetExpectedValue(expected_value); 264 key_path_helper_->SetExpectedValue(expected_value);
268 } 265 }
269 266
270 void CheckValuesForKeyPath( 267 void CheckValuesForKeyPath(
271 int id, 268 int id,
272 const std::vector<SerializedScriptValue>& 269 const std::vector<SerializedScriptValue>&
273 serialized_script_values, 270 serialized_script_values,
274 const IndexedDBKeyPath& key_path) { 271 const IndexedDBKeyPath& key_path) {
275 key_path_helper_->CheckValuesForKeyPath(id, serialized_script_values, 272 key_path_helper_->CheckValuesForKeyPath(id, serialized_script_values,
276 key_path); 273 key_path);
277 content::RunMessageLoop(); 274 RunMessageLoop();
278 } 275 }
279 276
280 void CheckInjectValue(const IndexedDBKey& key, 277 void CheckInjectValue(const IndexedDBKey& key,
281 const SerializedScriptValue& value, 278 const SerializedScriptValue& value,
282 const IndexedDBKeyPath& key_path) { 279 const IndexedDBKeyPath& key_path) {
283 key_path_helper_->CheckInjectValue(key, value, key_path); 280 key_path_helper_->CheckInjectValue(key, value, key_path);
284 content::RunMessageLoop(); 281 RunMessageLoop();
285 } 282 }
286 283
287 private: 284 private:
288 scoped_refptr<IDBKeyPathHelper> key_path_helper_; 285 scoped_refptr<IDBKeyPathHelper> key_path_helper_;
289 }; 286 };
290 287
291 // Cases: 288 // Cases:
292 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathExtract) { 289 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, IDBKeyPathExtract) {
293 ScopedIDBKeyPathHelper scoped_helper; 290 ScopedIDBKeyPathHelper scoped_helper;
294 const int kId = 7; 291 const int kId = 7;
295 std::vector<IndexedDBKey> expected_keys; 292 std::vector<IndexedDBKey> expected_keys;
296 std::vector<SerializedScriptValue> serialized_values; 293 std::vector<SerializedScriptValue> serialized_values;
297 294
298 IndexedDBKey string_zoo_key; 295 IndexedDBKey string_zoo_key;
299 string_zoo_key.SetString(UTF8ToUTF16("zoo")); 296 string_zoo_key.SetString(UTF8ToUTF16("zoo"));
300 IndexedDBKey null_key; 297 IndexedDBKey null_key;
301 null_key.SetNull(); 298 null_key.SetNull();
302 IndexedDBKey invalid_key; 299 IndexedDBKey invalid_key;
(...skipping 23 matching lines...) Expand all
326 expected_keys.push_back(null_key); 323 expected_keys.push_back(null_key);
327 324
328 scoped_helper.SetExpectedKeys(kId, expected_keys, false); 325 scoped_helper.SetExpectedKeys(kId, expected_keys, false);
329 326
330 IndexedDBKeyPath key_path; 327 IndexedDBKeyPath key_path;
331 key_path.SetString(UTF8ToUTF16("foo")); 328 key_path.SetString(UTF8ToUTF16("foo"));
332 scoped_helper.CheckValuesForKeyPath( 329 scoped_helper.CheckValuesForKeyPath(
333 kId, serialized_values, key_path); 330 kId, serialized_values, key_path);
334 } 331 }
335 332
336 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathPropertyNotAvailable) { 333 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, IDBKeyPathPropertyNotAvailable) {
337 ScopedIDBKeyPathHelper scoped_helper; 334 ScopedIDBKeyPathHelper scoped_helper;
338 const int kId = 7; 335 const int kId = 7;
339 std::vector<IndexedDBKey> expected_keys; 336 std::vector<IndexedDBKey> expected_keys;
340 IndexedDBKey null_value; 337 IndexedDBKey null_value;
341 null_value.SetNull(); 338 null_value.SetNull();
342 expected_keys.push_back(null_value); 339 expected_keys.push_back(null_value);
343 expected_keys.push_back(null_value); 340 expected_keys.push_back(null_value);
344 341
345 scoped_helper.SetExpectedKeys(kId, expected_keys, false); 342 scoped_helper.SetExpectedKeys(kId, expected_keys, false);
346 343
347 std::vector<SerializedScriptValue> serialized_values; 344 std::vector<SerializedScriptValue> serialized_values;
348 // {foo: "zoo", bar: null} 345 // {foo: "zoo", bar: null}
349 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162, 346 char16 data[] = {0x0353, 0x6f66, 0x536f, 0x7a03, 0x6f6f, 0x0353, 0x6162,
350 0x3072, 0x027b}; 347 0x3072, 0x027b};
351 serialized_values.push_back(SerializedScriptValue( 348 serialized_values.push_back(SerializedScriptValue(
352 false, false, string16(data, arraysize(data)))); 349 false, false, string16(data, arraysize(data))));
353 350
354 // null 351 // null
355 serialized_values.push_back( 352 serialized_values.push_back(
356 SerializedScriptValue(true, false, string16())); 353 SerializedScriptValue(true, false, string16()));
357 354
358 IndexedDBKeyPath key_path; 355 IndexedDBKeyPath key_path;
359 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable")); 356 key_path.SetString(UTF8ToUTF16("PropertyNotAvailable"));
360 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path); 357 scoped_helper.CheckValuesForKeyPath(kId, serialized_values, key_path);
361 } 358 }
362 359
363 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, IDBKeyPathMultipleCalls) { 360 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, IDBKeyPathMultipleCalls) {
364 ScopedIDBKeyPathHelper scoped_helper; 361 ScopedIDBKeyPathHelper scoped_helper;
365 const int kId = 7; 362 const int kId = 7;
366 std::vector<IndexedDBKey> expected_keys; 363 std::vector<IndexedDBKey> expected_keys;
367 364
368 IndexedDBKey null_value; 365 IndexedDBKey null_value;
369 null_value.SetNull(); 366 null_value.SetNull();
370 expected_keys.push_back(null_value); 367 expected_keys.push_back(null_value);
371 expected_keys.push_back(null_value); 368 expected_keys.push_back(null_value);
372 scoped_helper.SetExpectedKeys(kId, expected_keys, false); 369 scoped_helper.SetExpectedKeys(kId, expected_keys, false);
373 370
(...skipping 17 matching lines...) Expand all
391 expected_keys.clear(); 388 expected_keys.clear();
392 IndexedDBKey value; 389 IndexedDBKey value;
393 value.SetString(UTF8ToUTF16("zoo")); 390 value.SetString(UTF8ToUTF16("zoo"));
394 expected_keys.push_back(value); 391 expected_keys.push_back(value);
395 expected_keys.push_back(null_value); 392 expected_keys.push_back(null_value);
396 scoped_helper.SetExpectedKeys(kId + 1, expected_keys, false); 393 scoped_helper.SetExpectedKeys(kId + 1, expected_keys, false);
397 key_path.SetString(UTF8ToUTF16("foo")); 394 key_path.SetString(UTF8ToUTF16("foo"));
398 scoped_helper.CheckValuesForKeyPath(kId + 1, serialized_values, key_path); 395 scoped_helper.CheckValuesForKeyPath(kId + 1, serialized_values, key_path);
399 } 396 }
400 397
401 IN_PROC_BROWSER_TEST_F(InProcessBrowserTest, InjectIDBKey) { 398 IN_PROC_BROWSER_TEST_F(ContentBrowserTest, InjectIDBKey) {
402 // {foo: 'zoo'} 399 // {foo: 'zoo'}
403 const char16 initial_data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b}; 400 const char16 initial_data[] = {0x0353,0x6f66,0x536f,0x7a03,0x6f6f,0x017b};
404 SerializedScriptValue value( 401 SerializedScriptValue value(
405 false, false, string16(initial_data, arraysize(initial_data))); 402 false, false, string16(initial_data, arraysize(initial_data)));
406 IndexedDBKey key; 403 IndexedDBKey key;
407 key.SetString(UTF8ToUTF16("myNewKey")); 404 key.SetString(UTF8ToUTF16("myNewKey"));
408 405
409 ScopedIDBKeyPathHelper scoped_helper; 406 ScopedIDBKeyPathHelper scoped_helper;
410 407
411 // {foo: 'zoo', bar: 'myNewKey'} 408 // {foo: 'zoo', bar: 'myNewKey'}
(...skipping 20 matching lines...) Expand all
432 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f, 429 0x5301, 0x6203, 0x7261, 0x013f, 0x3f6f,
433 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853, 430 0x5302, 0x6203, 0x7a61, 0x023f, 0x0853,
434 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b, 431 0x796d, 0x654e, 0x4b77, 0x7965, 0x017b,
435 0x027b}; 432 0x027b};
436 SerializedScriptValue expected_value2( 433 SerializedScriptValue expected_value2(
437 false, false, string16(expected_data2, arraysize(expected_data2))); 434 false, false, string16(expected_data2, arraysize(expected_data2)));
438 scoped_helper.SetExpectedValue(expected_value2); 435 scoped_helper.SetExpectedValue(expected_value2);
439 key_path.SetString(UTF8ToUTF16("bar.baz")); 436 key_path.SetString(UTF8ToUTF16("bar.baz"));
440 scoped_helper.CheckInjectValue(key, value, key_path); 437 scoped_helper.CheckInjectValue(key, value, key_path);
441 } 438 }
439
440 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/in_process_webkit/indexed_db_browsertest.cc ('k') | content/browser/plugin_data_remover_impl_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698