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

Side by Side Diff: webkit/browser/dom_storage/session_storage_database_unittest.cc

Issue 16415016: Move nullable_string16.h to the string subdirectory. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: moar 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) 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 5
6 #include "webkit/browser/dom_storage/session_storage_database.h" 6 #include "webkit/browser/dom_storage/session_storage_database.h"
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
64 64
65 // Test data. 65 // Test data.
66 const GURL kOrigin1; 66 const GURL kOrigin1;
67 const GURL kOrigin2; 67 const GURL kOrigin2;
68 const std::string kNamespace1; 68 const std::string kNamespace1;
69 const std::string kNamespace2; 69 const std::string kNamespace2;
70 const std::string kNamespaceClone; 70 const std::string kNamespaceClone;
71 const base::string16 kKey1; 71 const base::string16 kKey1;
72 const base::string16 kKey2; 72 const base::string16 kKey2;
73 const base::string16 kKey3; 73 const base::string16 kKey3;
74 const NullableString16 kValue1; 74 const base::NullableString16 kValue1;
75 const NullableString16 kValue2; 75 const base::NullableString16 kValue2;
76 const NullableString16 kValue3; 76 const base::NullableString16 kValue3;
77 const NullableString16 kValue4; 77 const base::NullableString16 kValue4;
78 const NullableString16 kValueNull; 78 const base::NullableString16 kValueNull;
79 79
80 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabaseTest); 80 DISALLOW_COPY_AND_ASSIGN(SessionStorageDatabaseTest);
81 }; 81 };
82 82
83 SessionStorageDatabaseTest::SessionStorageDatabaseTest() 83 SessionStorageDatabaseTest::SessionStorageDatabaseTest()
84 : kOrigin1("http://www.origin1.com"), 84 : kOrigin1("http://www.origin1.com"),
85 kOrigin2("http://www.origin2.com"), 85 kOrigin2("http://www.origin2.com"),
86 kNamespace1("namespace1"), 86 kNamespace1("namespace1"),
87 kNamespace2("namespace2"), 87 kNamespace2("namespace2"),
88 kNamespaceClone("wascloned"), 88 kNamespaceClone("wascloned"),
89 kKey1(ASCIIToUTF16("key1")), 89 kKey1(ASCIIToUTF16("key1")),
90 kKey2(ASCIIToUTF16("key2")), 90 kKey2(ASCIIToUTF16("key2")),
91 kKey3(ASCIIToUTF16("key3")), 91 kKey3(ASCIIToUTF16("key3")),
92 kValue1(NullableString16(ASCIIToUTF16("value1"), false)), 92 kValue1(base::NullableString16(ASCIIToUTF16("value1"), false)),
93 kValue2(NullableString16(ASCIIToUTF16("value2"), false)), 93 kValue2(base::NullableString16(ASCIIToUTF16("value2"), false)),
94 kValue3(NullableString16(ASCIIToUTF16("value3"), false)), 94 kValue3(base::NullableString16(ASCIIToUTF16("value3"), false)),
95 kValue4(NullableString16(ASCIIToUTF16("value4"), false)), 95 kValue4(base::NullableString16(ASCIIToUTF16("value4"), false)),
96 kValueNull(NullableString16(true)) { } 96 kValueNull(base::NullableString16(true)) { }
97 97
98 SessionStorageDatabaseTest::~SessionStorageDatabaseTest() { } 98 SessionStorageDatabaseTest::~SessionStorageDatabaseTest() { }
99 99
100 void SessionStorageDatabaseTest::SetUp() { 100 void SessionStorageDatabaseTest::SetUp() {
101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 101 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
102 ResetDatabase(); 102 ResetDatabase();
103 } 103 }
104 104
105 void SessionStorageDatabaseTest::ResetDatabase() { 105 void SessionStorageDatabaseTest::ResetDatabase() {
106 db_ = new SessionStorageDatabase(temp_dir_.path()); 106 db_ = new SessionStorageDatabase(temp_dir_.path());
(...skipping 216 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 CompareValuesMaps(values, reference); 323 CompareValuesMaps(values, reference);
324 } 324 }
325 325
326 void SessionStorageDatabaseTest::CompareValuesMaps( 326 void SessionStorageDatabaseTest::CompareValuesMaps(
327 const ValuesMap& map1, 327 const ValuesMap& map1,
328 const ValuesMap& map2) const { 328 const ValuesMap& map2) const {
329 ASSERT_EQ(map2.size(), map1.size()); 329 ASSERT_EQ(map2.size(), map1.size());
330 for (ValuesMap::const_iterator it = map1.begin(); it != map1.end(); ++it) { 330 for (ValuesMap::const_iterator it = map1.begin(); it != map1.end(); ++it) {
331 base::string16 key = it->first; 331 base::string16 key = it->first;
332 ASSERT_TRUE(map2.find(key) != map2.end()); 332 ASSERT_TRUE(map2.find(key) != map2.end());
333 NullableString16 val1 = it->second; 333 base::NullableString16 val1 = it->second;
334 NullableString16 val2 = map2.find(key)->second; 334 base::NullableString16 val2 = map2.find(key)->second;
335 EXPECT_EQ(val2.is_null(), val1.is_null()); 335 EXPECT_EQ(val2.is_null(), val1.is_null());
336 EXPECT_EQ(val2.string(), val1.string()); 336 EXPECT_EQ(val2.string(), val1.string());
337 } 337 }
338 } 338 }
339 339
340 void SessionStorageDatabaseTest::CheckNamespaceIds( 340 void SessionStorageDatabaseTest::CheckNamespaceIds(
341 const std::set<std::string>& expected_namespace_ids) const { 341 const std::set<std::string>& expected_namespace_ids) const {
342 std::map<std::string, std::vector<GURL> > namespaces_and_origins; 342 std::map<std::string, std::vector<GURL> > namespaces_and_origins;
343 EXPECT_TRUE(db_->ReadNamespacesAndOrigins(&namespaces_and_origins)); 343 EXPECT_TRUE(db_->ReadNamespacesAndOrigins(&namespaces_and_origins));
344 EXPECT_EQ(expected_namespace_ids.size(), namespaces_and_origins.size()); 344 EXPECT_EQ(expected_namespace_ids.size(), namespaces_and_origins.size());
(...skipping 348 matching lines...) Expand 10 before | Expand all | Expand 10 after
693 CheckAreaData(kNamespaceClone, kOrigin1, data1); 693 CheckAreaData(kNamespaceClone, kOrigin1, data1);
694 CheckAreaData(kNamespaceClone, kOrigin2, data2); 694 CheckAreaData(kNamespaceClone, kOrigin2, data2);
695 } 695 }
696 696
697 TEST_F(SessionStorageDatabaseTest, WriteRawBytes) { 697 TEST_F(SessionStorageDatabaseTest, WriteRawBytes) {
698 // Write data which is not valid utf8 and contains null bytes. 698 // Write data which is not valid utf8 and contains null bytes.
699 unsigned char raw_data[10] = {255, 0, 0, 0, 1, 2, 3, 4, 5, 0}; 699 unsigned char raw_data[10] = {255, 0, 0, 0, 1, 2, 3, 4, 5, 0};
700 ValuesMap changes; 700 ValuesMap changes;
701 base::string16 string_with_raw_data; 701 base::string16 string_with_raw_data;
702 string_with_raw_data.assign(reinterpret_cast<char16*>(raw_data), 5); 702 string_with_raw_data.assign(reinterpret_cast<char16*>(raw_data), 5);
703 changes[kKey1] = NullableString16(string_with_raw_data, false); 703 changes[kKey1] = base::NullableString16(string_with_raw_data, false);
704 EXPECT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin1, false, changes)); 704 EXPECT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin1, false, changes));
705 CheckDatabaseConsistency(); 705 CheckDatabaseConsistency();
706 ValuesMap values; 706 ValuesMap values;
707 db_->ReadAreaValues(kNamespace1, kOrigin1, &values); 707 db_->ReadAreaValues(kNamespace1, kOrigin1, &values);
708 const unsigned char* data = 708 const unsigned char* data =
709 reinterpret_cast<const unsigned char*>(values[kKey1].string().data()); 709 reinterpret_cast<const unsigned char*>(values[kKey1].string().data());
710 for (int i = 0; i < 10; ++i) 710 for (int i = 0; i < 10; ++i)
711 EXPECT_EQ(raw_data[i], data[i]); 711 EXPECT_EQ(raw_data[i], data[i]);
712 } 712 }
713 713
(...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after
789 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data2)); 789 ASSERT_TRUE(db_->CommitAreaChanges(kNamespace1, kOrigin2, false, data2));
790 790
791 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin1)); 791 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin1));
792 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2)); 792 EXPECT_TRUE(db_->DeleteArea(kNamespace1, kOrigin2));
793 // Check that also the namespace start key was deleted. 793 // Check that also the namespace start key was deleted.
794 CheckDatabaseConsistency(); 794 CheckDatabaseConsistency();
795 } 795 }
796 796
797 797
798 } // namespace dom_storage 798 } // namespace dom_storage
OLDNEW
« no previous file with comments | « webkit/browser/dom_storage/session_storage_database.cc ('k') | webkit/common/dom_storage/dom_storage_map.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698