| 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/file_util.h" | 6 #include "base/file_util.h" |
| 7 #include "base/files/scoped_temp_dir.h" | 7 #include "base/files/scoped_temp_dir.h" |
| 8 #include "base/message_loop.h" | 8 #include "base/message_loop.h" |
| 9 #include "base/message_loop_proxy.h" | 9 #include "base/message_loop_proxy.h" |
| 10 #include "base/threading/sequenced_worker_pool.h" | 10 #include "base/threading/sequenced_worker_pool.h" |
| (...skipping 14 matching lines...) Expand all Loading... |
| 25 public: | 25 public: |
| 26 DomStorageAreaTest() | 26 DomStorageAreaTest() |
| 27 : kOrigin(GURL("http://dom_storage/")), | 27 : kOrigin(GURL("http://dom_storage/")), |
| 28 kKey(ASCIIToUTF16("key")), | 28 kKey(ASCIIToUTF16("key")), |
| 29 kValue(ASCIIToUTF16("value")), | 29 kValue(ASCIIToUTF16("value")), |
| 30 kKey2(ASCIIToUTF16("key2")), | 30 kKey2(ASCIIToUTF16("key2")), |
| 31 kValue2(ASCIIToUTF16("value2")) { | 31 kValue2(ASCIIToUTF16("value2")) { |
| 32 } | 32 } |
| 33 | 33 |
| 34 const GURL kOrigin; | 34 const GURL kOrigin; |
| 35 const string16 kKey; | 35 const base::string16 kKey; |
| 36 const string16 kValue; | 36 const base::string16 kValue; |
| 37 const string16 kKey2; | 37 const base::string16 kKey2; |
| 38 const string16 kValue2; | 38 const base::string16 kValue2; |
| 39 | 39 |
| 40 // Method used in the CommitTasks test case. | 40 // Method used in the CommitTasks test case. |
| 41 void InjectedCommitSequencingTask(DomStorageArea* area) { | 41 void InjectedCommitSequencingTask(DomStorageArea* area) { |
| 42 // At this point the OnCommitTimer has run. | 42 // At this point the OnCommitTimer has run. |
| 43 // Verify that it put a commit in flight. | 43 // Verify that it put a commit in flight. |
| 44 EXPECT_EQ(1, area->commit_batches_in_flight_); | 44 EXPECT_EQ(1, area->commit_batches_in_flight_); |
| 45 EXPECT_FALSE(area->commit_batch_.get()); | 45 EXPECT_FALSE(area->commit_batch_.get()); |
| 46 EXPECT_TRUE(area->HasUncommittedChanges()); | 46 EXPECT_TRUE(area->HasUncommittedChanges()); |
| 47 // Make additional change and verify that a new commit batch | 47 // Make additional change and verify that a new commit batch |
| 48 // is created for that change. | 48 // is created for that change. |
| 49 NullableString16 old_value; | 49 NullableString16 old_value; |
| 50 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); | 50 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_value)); |
| 51 EXPECT_TRUE(area->commit_batch_.get()); | 51 EXPECT_TRUE(area->commit_batch_.get()); |
| 52 EXPECT_EQ(1, area->commit_batches_in_flight_); | 52 EXPECT_EQ(1, area->commit_batches_in_flight_); |
| 53 EXPECT_TRUE(area->HasUncommittedChanges()); | 53 EXPECT_TRUE(area->HasUncommittedChanges()); |
| 54 } | 54 } |
| 55 | 55 |
| 56 // Class used in the CommitChangesAtShutdown test case. | 56 // Class used in the CommitChangesAtShutdown test case. |
| 57 class VerifyChangesCommittedDatabase : public DomStorageDatabase { | 57 class VerifyChangesCommittedDatabase : public DomStorageDatabase { |
| 58 public: | 58 public: |
| 59 VerifyChangesCommittedDatabase() {} | 59 VerifyChangesCommittedDatabase() {} |
| 60 virtual ~VerifyChangesCommittedDatabase() { | 60 virtual ~VerifyChangesCommittedDatabase() { |
| 61 const string16 kKey(ASCIIToUTF16("key")); | 61 const base::string16 kKey(ASCIIToUTF16("key")); |
| 62 const string16 kValue(ASCIIToUTF16("value")); | 62 const base::string16 kValue(ASCIIToUTF16("value")); |
| 63 ValuesMap values; | 63 ValuesMap values; |
| 64 ReadAllValues(&values); | 64 ReadAllValues(&values); |
| 65 EXPECT_EQ(1u, values.size()); | 65 EXPECT_EQ(1u, values.size()); |
| 66 EXPECT_EQ(kValue, values[kKey].string()); | 66 EXPECT_EQ(kValue, values[kKey].string()); |
| 67 } | 67 } |
| 68 }; | 68 }; |
| 69 | 69 |
| 70 private: | 70 private: |
| 71 MessageLoop message_loop_; | 71 MessageLoop message_loop_; |
| 72 }; | 72 }; |
| 73 | 73 |
| 74 TEST_F(DomStorageAreaTest, DomStorageAreaBasics) { | 74 TEST_F(DomStorageAreaTest, DomStorageAreaBasics) { |
| 75 scoped_refptr<DomStorageArea> area( | 75 scoped_refptr<DomStorageArea> area( |
| 76 new DomStorageArea(1, std::string(), kOrigin, NULL, NULL)); | 76 new DomStorageArea(1, std::string(), kOrigin, NULL, NULL)); |
| 77 string16 old_value; | 77 base::string16 old_value; |
| 78 NullableString16 old_nullable_value; | 78 NullableString16 old_nullable_value; |
| 79 scoped_refptr<DomStorageArea> copy; | 79 scoped_refptr<DomStorageArea> copy; |
| 80 | 80 |
| 81 // We don't focus on the underlying DomStorageMap functionality | 81 // We don't focus on the underlying DomStorageMap functionality |
| 82 // since that's covered by seperate unit tests. | 82 // since that's covered by seperate unit tests. |
| 83 EXPECT_EQ(kOrigin, area->origin()); | 83 EXPECT_EQ(kOrigin, area->origin()); |
| 84 EXPECT_EQ(1, area->namespace_id()); | 84 EXPECT_EQ(1, area->namespace_id()); |
| 85 EXPECT_EQ(0u, area->Length()); | 85 EXPECT_EQ(0u, area->Length()); |
| 86 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); | 86 EXPECT_TRUE(area->SetItem(kKey, kValue, &old_nullable_value)); |
| 87 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_nullable_value)); | 87 EXPECT_TRUE(area->SetItem(kKey2, kValue2, &old_nullable_value)); |
| (...skipping 375 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 463 EXPECT_EQ( | 463 EXPECT_EQ( |
| 464 base::FilePath().AppendASCII("-journal"), | 464 base::FilePath().AppendASCII("-journal"), |
| 465 DomStorageDatabase::GetJournalFilePath(base::FilePath())); | 465 DomStorageDatabase::GetJournalFilePath(base::FilePath())); |
| 466 EXPECT_EQ( | 466 EXPECT_EQ( |
| 467 base::FilePath().AppendASCII(".extensiononly-journal"), | 467 base::FilePath().AppendASCII(".extensiononly-journal"), |
| 468 DomStorageDatabase::GetJournalFilePath( | 468 DomStorageDatabase::GetJournalFilePath( |
| 469 base::FilePath().AppendASCII(".extensiononly"))); | 469 base::FilePath().AppendASCII(".extensiononly"))); |
| 470 } | 470 } |
| 471 | 471 |
| 472 } // namespace dom_storage | 472 } // namespace dom_storage |
| OLD | NEW |