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

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

Issue 16870007: Switch database/file_identifier to std::string, remove createFromDatabaseIdentifier calls (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2013 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 "content/browser/indexed_db/indexed_db_backing_store.h" 5 #include "content/browser/indexed_db/indexed_db_backing_store.h"
6 6
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h" 8 #include "base/files/scoped_temp_dir.h"
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "base/strings/string16.h" 10 #include "base/strings/string16.h"
11 #include "base/strings/utf_string_conversions.h" 11 #include "base/strings/utf_string_conversions.h"
12 #include "content/browser/indexed_db/indexed_db_factory.h" 12 #include "content/browser/indexed_db/indexed_db_factory.h"
13 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h" 13 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
14 #include "googleurl/src/gurl.h"
14 #include "testing/gtest/include/gtest/gtest.h" 15 #include "testing/gtest/include/gtest/gtest.h"
15 #include "third_party/WebKit/public/web/WebSecurityOrigin.h" 16 #include "webkit/common/database/database_identifier.h"
16 17
17 using WebKit::WebSecurityOrigin;
18 using WebKit::WebIDBKey; 18 using WebKit::WebIDBKey;
19 19
20 namespace content { 20 namespace content {
21 21
22 namespace { 22 namespace {
23 23
24 class IndexedDBBackingStoreTest : public testing::Test { 24 class IndexedDBBackingStoreTest : public testing::Test {
25 public: 25 public:
26 IndexedDBBackingStoreTest() {} 26 IndexedDBBackingStoreTest() {}
27 virtual void SetUp() { 27 virtual void SetUp() {
28 string16 file_identifier; 28 std::string file_identifier;
29 backing_store_ = IndexedDBBackingStore::OpenInMemory(file_identifier); 29 backing_store_ = IndexedDBBackingStore::OpenInMemory(file_identifier);
30 30
31 // useful keys and values during tests 31 // useful keys and values during tests
32 const char raw_value1[] = "value1"; 32 const char raw_value1[] = "value1";
33 33
34 const char raw_value2[] = "value2"; 34 const char raw_value2[] = "value2";
35 const char raw_value3[] = "value3"; 35 const char raw_value3[] = "value3";
36 m_value1.insert( 36 m_value1.insert(
37 m_value1.end(), &raw_value1[0], &raw_value1[0] + sizeof(raw_value1)); 37 m_value1.end(), &raw_value1[0], &raw_value1[0] + sizeof(raw_value1));
38 m_value2.insert( 38 m_value2.insert(
(...skipping 287 matching lines...) Expand 10 before | Expand all | Expand 10 after
326 } 326 }
327 } 327 }
328 328
329 class MockIDBFactory : public IndexedDBFactory { 329 class MockIDBFactory : public IndexedDBFactory {
330 public: 330 public:
331 static scoped_refptr<MockIDBFactory> Create() { 331 static scoped_refptr<MockIDBFactory> Create() {
332 return make_scoped_refptr(new MockIDBFactory()); 332 return make_scoped_refptr(new MockIDBFactory());
333 } 333 }
334 334
335 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore( 335 scoped_refptr<IndexedDBBackingStore> TestOpenBackingStore(
336 const WebSecurityOrigin& origin, 336 const GURL& origin,
337 const base::FilePath& data_directory) { 337 const base::FilePath& data_directory) {
338 return OpenBackingStore(origin.databaseIdentifier(), data_directory); 338 return OpenBackingStore(
339 webkit_database::GetIdentifierFromOrigin(origin), data_directory);
339 } 340 }
340 341
341 private: 342 private:
342 virtual ~MockIDBFactory() {} 343 virtual ~MockIDBFactory() {}
343 }; 344 };
344 345
345 TEST(IndexedDBFactoryTest, BackingStoreLifetime) { 346 TEST(IndexedDBFactoryTest, BackingStoreLifetime) {
346 WebSecurityOrigin origin1 = 347 GURL origin1("http://localhost:81");
347 WebSecurityOrigin::createFromString("http://localhost:81"); 348 GURL origin2("http://localhost:82");
348 WebSecurityOrigin origin2 =
349 WebSecurityOrigin::createFromString("http://localhost:82");
350 349
351 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create(); 350 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create();
352 351
353 base::ScopedTempDir temp_directory; 352 base::ScopedTempDir temp_directory;
354 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 353 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
355 scoped_refptr<IndexedDBBackingStore> disk_store1 = 354 scoped_refptr<IndexedDBBackingStore> disk_store1 =
356 factory->TestOpenBackingStore(origin1, temp_directory.path()); 355 factory->TestOpenBackingStore(origin1, temp_directory.path());
357 EXPECT_TRUE(disk_store1->HasOneRef()); 356 EXPECT_TRUE(disk_store1->HasOneRef());
358 357
359 scoped_refptr<IndexedDBBackingStore> disk_store2 = 358 scoped_refptr<IndexedDBBackingStore> disk_store2 =
360 factory->TestOpenBackingStore(origin1, temp_directory.path()); 359 factory->TestOpenBackingStore(origin1, temp_directory.path());
361 EXPECT_EQ(disk_store1.get(), disk_store2.get()); 360 EXPECT_EQ(disk_store1.get(), disk_store2.get());
362 EXPECT_FALSE(disk_store2->HasOneRef()); 361 EXPECT_FALSE(disk_store2->HasOneRef());
363 362
364 scoped_refptr<IndexedDBBackingStore> disk_store3 = 363 scoped_refptr<IndexedDBBackingStore> disk_store3 =
365 factory->TestOpenBackingStore(origin2, temp_directory.path()); 364 factory->TestOpenBackingStore(origin2, temp_directory.path());
366 EXPECT_TRUE(disk_store3->HasOneRef()); 365 EXPECT_TRUE(disk_store3->HasOneRef());
367 EXPECT_FALSE(disk_store1->HasOneRef()); 366 EXPECT_FALSE(disk_store1->HasOneRef());
368 367
369 disk_store2 = NULL; 368 disk_store2 = NULL;
370 EXPECT_TRUE(disk_store1->HasOneRef()); 369 EXPECT_TRUE(disk_store1->HasOneRef());
371 } 370 }
372 371
373 TEST(IndexedDBFactoryTest, MemoryBackingStoreLifetime) { 372 TEST(IndexedDBFactoryTest, MemoryBackingStoreLifetime) {
374 WebSecurityOrigin origin1 = 373 GURL origin1("http://localhost:81");
375 WebSecurityOrigin::createFromString("http://localhost:81"); 374 GURL origin2("http://localhost:82");
376 WebSecurityOrigin origin2 =
377 WebSecurityOrigin::createFromString("http://localhost:82");
378 375
379 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create(); 376 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create();
380 scoped_refptr<IndexedDBBackingStore> mem_store1 = 377 scoped_refptr<IndexedDBBackingStore> mem_store1 =
381 factory->TestOpenBackingStore(origin1, base::FilePath()); 378 factory->TestOpenBackingStore(origin1, base::FilePath());
382 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and factory 379 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1 and factory
383 380
384 scoped_refptr<IndexedDBBackingStore> mem_store2 = 381 scoped_refptr<IndexedDBBackingStore> mem_store2 =
385 factory->TestOpenBackingStore(origin1, base::FilePath()); 382 factory->TestOpenBackingStore(origin1, base::FilePath());
386 EXPECT_EQ(mem_store1.get(), mem_store2.get()); 383 EXPECT_EQ(mem_store1.get(), mem_store2.get());
387 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1, 2 and factory 384 EXPECT_FALSE(mem_store1->HasOneRef()); // mem_store1, 2 and factory
(...skipping 17 matching lines...) Expand all
405 { 402 {
406 base::ScopedTempDir temp_directory; 403 base::ScopedTempDir temp_directory;
407 ASSERT_TRUE(temp_directory.CreateUniqueTempDir()); 404 ASSERT_TRUE(temp_directory.CreateUniqueTempDir());
408 const base::FilePath base_path = temp_directory.path(); 405 const base::FilePath base_path = temp_directory.path();
409 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create(); 406 scoped_refptr<MockIDBFactory> factory = MockIDBFactory::Create();
410 407
411 int limit = file_util::GetMaximumPathComponentLength(base_path); 408 int limit = file_util::GetMaximumPathComponentLength(base_path);
412 EXPECT_GT(limit, 0); 409 EXPECT_GT(limit, 0);
413 410
414 std::string origin(limit + 1, 'x'); 411 std::string origin(limit + 1, 'x');
415 WebSecurityOrigin too_long_origin = 412 GURL too_long_origin("http://" + origin + ":81/");
416 WebSecurityOrigin::createFromString(WebKit::WebString::fromUTF8(
417 std::string("http://" + origin + ":81/").c_str()));
418 scoped_refptr<IndexedDBBackingStore> diskStore1 = 413 scoped_refptr<IndexedDBBackingStore> diskStore1 =
419 factory->TestOpenBackingStore(too_long_origin, base_path); 414 factory->TestOpenBackingStore(too_long_origin, base_path);
420 EXPECT_FALSE(diskStore1.get()); 415 EXPECT_FALSE(diskStore1.get());
421 416
422 WebSecurityOrigin ok_origin = 417 GURL ok_origin("http://someorigin.com:82/");
423 WebSecurityOrigin::createFromString("http://someorigin.com:82/");
424 scoped_refptr<IndexedDBBackingStore> diskStore2 = 418 scoped_refptr<IndexedDBBackingStore> diskStore2 =
425 factory->TestOpenBackingStore(ok_origin, base_path); 419 factory->TestOpenBackingStore(ok_origin, base_path);
426 EXPECT_TRUE(diskStore2.get()); 420 EXPECT_TRUE(diskStore2.get());
427 } 421 }
428 422
429 } // namespace 423 } // namespace
430 424
431 } // namespace content 425 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698