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

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

Issue 19442002: Convert to new WebIDBTypes enums and accessors (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: fix content/common/DEPS Created 7 years, 5 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_leveldb_coding.h" 5 #include "content/browser/indexed_db/indexed_db_leveldb_coding.h"
6 6
7 #include <limits> 7 #include <limits>
8 #include <vector> 8 #include <vector>
9 9
10 #include "base/basictypes.h" 10 #include "base/basictypes.h"
11 #include "base/strings/string16.h" 11 #include "base/strings/string16.h"
12 #include "base/strings/string_piece.h" 12 #include "base/strings/string_piece.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "content/common/indexed_db/indexed_db_key.h" 14 #include "content/common/indexed_db/indexed_db_key.h"
15 #include "content/common/indexed_db/indexed_db_key_path.h" 15 #include "content/common/indexed_db/indexed_db_key_path.h"
16 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
17 17
18 using base::StringPiece; 18 using base::StringPiece;
19 using WebKit::WebIDBKey; 19 using WebKit::WebIDBKeyTypeDate;
20 using WebKit::WebIDBKeyPath; 20 using WebKit::WebIDBKeyTypeNumber;
21 21
22 namespace content { 22 namespace content {
23 23
24 namespace { 24 namespace {
25 25
26 static IndexedDBKey CreateArrayIDBKey() { 26 static IndexedDBKey CreateArrayIDBKey() {
27 return IndexedDBKey(IndexedDBKey::KeyArray()); 27 return IndexedDBKey(IndexedDBKey::KeyArray());
28 } 28 }
29 29
30 static IndexedDBKey CreateArrayIDBKey(const IndexedDBKey& key1) { 30 static IndexedDBKey CreateArrayIDBKey(const IndexedDBKey& key1) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
119 119
120 TEST(IndexedDBLevelDBCodingTest, MaxIDBKey) { 120 TEST(IndexedDBLevelDBCodingTest, MaxIDBKey) {
121 std::string max_key = MaxIDBKey(); 121 std::string max_key = MaxIDBKey();
122 122
123 std::string min_key = MinIDBKey(); 123 std::string min_key = MinIDBKey();
124 std::string array_key; 124 std::string array_key;
125 EncodeIDBKey(IndexedDBKey(IndexedDBKey::KeyArray()), &array_key); 125 EncodeIDBKey(IndexedDBKey(IndexedDBKey::KeyArray()), &array_key);
126 std::string string_key; 126 std::string string_key;
127 EncodeIDBKey(IndexedDBKey(ASCIIToUTF16("Hello world")), &string_key); 127 EncodeIDBKey(IndexedDBKey(ASCIIToUTF16("Hello world")), &string_key);
128 std::string number_key; 128 std::string number_key;
129 EncodeIDBKey(IndexedDBKey(3.14, WebIDBKey::NumberType), &number_key); 129 EncodeIDBKey(IndexedDBKey(3.14, WebIDBKeyTypeNumber), &number_key);
130 std::string date_key; 130 std::string date_key;
131 EncodeIDBKey(IndexedDBKey(1000000, WebIDBKey::DateType), &date_key); 131 EncodeIDBKey(IndexedDBKey(1000000, WebIDBKeyTypeDate), &date_key);
132 132
133 EXPECT_GT(CompareKeys(max_key, min_key), 0); 133 EXPECT_GT(CompareKeys(max_key, min_key), 0);
134 EXPECT_GT(CompareKeys(max_key, array_key), 0); 134 EXPECT_GT(CompareKeys(max_key, array_key), 0);
135 EXPECT_GT(CompareKeys(max_key, string_key), 0); 135 EXPECT_GT(CompareKeys(max_key, string_key), 0);
136 EXPECT_GT(CompareKeys(max_key, number_key), 0); 136 EXPECT_GT(CompareKeys(max_key, number_key), 0);
137 EXPECT_GT(CompareKeys(max_key, date_key), 0); 137 EXPECT_GT(CompareKeys(max_key, date_key), 0);
138 } 138 }
139 139
140 TEST(IndexedDBLevelDBCodingTest, MinIDBKey) { 140 TEST(IndexedDBLevelDBCodingTest, MinIDBKey) {
141 std::string min_key = MinIDBKey(); 141 std::string min_key = MinIDBKey();
142 142
143 std::string max_key = MaxIDBKey(); 143 std::string max_key = MaxIDBKey();
144 std::string array_key; 144 std::string array_key;
145 EncodeIDBKey(IndexedDBKey(IndexedDBKey::KeyArray()), &array_key); 145 EncodeIDBKey(IndexedDBKey(IndexedDBKey::KeyArray()), &array_key);
146 std::string string_key; 146 std::string string_key;
147 EncodeIDBKey(IndexedDBKey(ASCIIToUTF16("Hello world")), &string_key); 147 EncodeIDBKey(IndexedDBKey(ASCIIToUTF16("Hello world")), &string_key);
148 std::string number_key; 148 std::string number_key;
149 EncodeIDBKey(IndexedDBKey(3.14, WebIDBKey::NumberType), &number_key); 149 EncodeIDBKey(IndexedDBKey(3.14, WebIDBKeyTypeNumber), &number_key);
150 std::string date_key; 150 std::string date_key;
151 EncodeIDBKey(IndexedDBKey(1000000, WebIDBKey::DateType), &date_key); 151 EncodeIDBKey(IndexedDBKey(1000000, WebIDBKeyTypeDate), &date_key);
152 152
153 EXPECT_LT(CompareKeys(min_key, max_key), 0); 153 EXPECT_LT(CompareKeys(min_key, max_key), 0);
154 EXPECT_LT(CompareKeys(min_key, array_key), 0); 154 EXPECT_LT(CompareKeys(min_key, array_key), 0);
155 EXPECT_LT(CompareKeys(min_key, string_key), 0); 155 EXPECT_LT(CompareKeys(min_key, string_key), 0);
156 EXPECT_LT(CompareKeys(min_key, number_key), 0); 156 EXPECT_LT(CompareKeys(min_key, number_key), 0);
157 EXPECT_LT(CompareKeys(min_key, date_key), 0); 157 EXPECT_LT(CompareKeys(min_key, date_key), 0);
158 } 158 }
159 159
160 static std::string WrappedEncodeInt(int64 value) { 160 static std::string WrappedEncodeInt(int64 value) {
161 std::string buffer; 161 std::string buffer;
(...skipping 352 matching lines...) Expand 10 before | Expand all | Expand 10 after
514 } 514 }
515 } 515 }
516 516
517 TEST(IndexedDBLevelDBCodingTest, EncodeDecodeIDBKey) { 517 TEST(IndexedDBLevelDBCodingTest, EncodeDecodeIDBKey) {
518 IndexedDBKey expected_key; 518 IndexedDBKey expected_key;
519 scoped_ptr<IndexedDBKey> decoded_key; 519 scoped_ptr<IndexedDBKey> decoded_key;
520 std::string v; 520 std::string v;
521 StringPiece slice; 521 StringPiece slice;
522 522
523 std::vector<IndexedDBKey> test_cases; 523 std::vector<IndexedDBKey> test_cases;
524 test_cases.push_back(IndexedDBKey(1234, WebIDBKey::NumberType)); 524 test_cases.push_back(IndexedDBKey(1234, WebIDBKeyTypeNumber));
525 test_cases.push_back(IndexedDBKey(7890, WebIDBKey::DateType)); 525 test_cases.push_back(IndexedDBKey(7890, WebIDBKeyTypeDate));
526 test_cases.push_back(IndexedDBKey(ASCIIToUTF16("Hello World!"))); 526 test_cases.push_back(IndexedDBKey(ASCIIToUTF16("Hello World!")));
527 test_cases.push_back(IndexedDBKey(IndexedDBKey::KeyArray())); 527 test_cases.push_back(IndexedDBKey(IndexedDBKey::KeyArray()));
528 528
529 IndexedDBKey::KeyArray array; 529 IndexedDBKey::KeyArray array;
530 array.push_back(IndexedDBKey(1234, WebIDBKey::NumberType)); 530 array.push_back(IndexedDBKey(1234, WebIDBKeyTypeNumber));
531 array.push_back(IndexedDBKey(7890, WebIDBKey::DateType)); 531 array.push_back(IndexedDBKey(7890, WebIDBKeyTypeDate));
532 array.push_back(IndexedDBKey(ASCIIToUTF16("Hello World!"))); 532 array.push_back(IndexedDBKey(ASCIIToUTF16("Hello World!")));
533 array.push_back(IndexedDBKey(IndexedDBKey::KeyArray())); 533 array.push_back(IndexedDBKey(IndexedDBKey::KeyArray()));
534 test_cases.push_back(IndexedDBKey(array)); 534 test_cases.push_back(IndexedDBKey(array));
535 535
536 for (size_t i = 0; i < test_cases.size(); ++i) { 536 for (size_t i = 0; i < test_cases.size(); ++i) {
537 expected_key = test_cases[i]; 537 expected_key = test_cases[i];
538 v.clear(); 538 v.clear();
539 EncodeIDBKey(expected_key, &v); 539 EncodeIDBKey(expected_key, &v);
540 slice = StringPiece(&*v.begin(), v.size()); 540 slice = StringPiece(&*v.begin(), v.size());
541 EXPECT_TRUE(DecodeIDBKey(&slice, &decoded_key)); 541 EXPECT_TRUE(DecodeIDBKey(&slice, &decoded_key));
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after
663 IndexedDBKeyPath decoded; 663 IndexedDBKeyPath decoded;
664 EXPECT_TRUE(DecodeIDBKeyPath(&slice, &decoded)); 664 EXPECT_TRUE(DecodeIDBKeyPath(&slice, &decoded));
665 EXPECT_EQ(key_path, decoded); 665 EXPECT_EQ(key_path, decoded);
666 EXPECT_TRUE(slice.empty()); 666 EXPECT_TRUE(slice.empty());
667 } 667 }
668 } 668 }
669 669
670 TEST(IndexedDBLevelDBCodingTest, ExtractAndCompareIDBKeys) { 670 TEST(IndexedDBLevelDBCodingTest, ExtractAndCompareIDBKeys) {
671 std::vector<IndexedDBKey> keys; 671 std::vector<IndexedDBKey> keys;
672 672
673 keys.push_back(IndexedDBKey(-10, WebIDBKey::NumberType)); 673 keys.push_back(IndexedDBKey(-10, WebIDBKeyTypeNumber));
674 keys.push_back(IndexedDBKey(0, WebIDBKey::NumberType)); 674 keys.push_back(IndexedDBKey(0, WebIDBKeyTypeNumber));
675 keys.push_back(IndexedDBKey(3.14, WebIDBKey::NumberType)); 675 keys.push_back(IndexedDBKey(3.14, WebIDBKeyTypeNumber));
676 676
677 keys.push_back(IndexedDBKey(0, WebIDBKey::DateType)); 677 keys.push_back(IndexedDBKey(0, WebIDBKeyTypeDate));
678 keys.push_back(IndexedDBKey(100, WebIDBKey::DateType)); 678 keys.push_back(IndexedDBKey(100, WebIDBKeyTypeDate));
679 keys.push_back(IndexedDBKey(100000, WebIDBKey::DateType)); 679 keys.push_back(IndexedDBKey(100000, WebIDBKeyTypeDate));
680 680
681 keys.push_back(IndexedDBKey(ASCIIToUTF16(""))); 681 keys.push_back(IndexedDBKey(ASCIIToUTF16("")));
682 keys.push_back(IndexedDBKey(ASCIIToUTF16("a"))); 682 keys.push_back(IndexedDBKey(ASCIIToUTF16("a")));
683 keys.push_back(IndexedDBKey(ASCIIToUTF16("b"))); 683 keys.push_back(IndexedDBKey(ASCIIToUTF16("b")));
684 keys.push_back(IndexedDBKey(ASCIIToUTF16("baaa"))); 684 keys.push_back(IndexedDBKey(ASCIIToUTF16("baaa")));
685 keys.push_back(IndexedDBKey(ASCIIToUTF16("baab"))); 685 keys.push_back(IndexedDBKey(ASCIIToUTF16("baab")));
686 keys.push_back(IndexedDBKey(ASCIIToUTF16("c"))); 686 keys.push_back(IndexedDBKey(ASCIIToUTF16("c")));
687 687
688 keys.push_back(CreateArrayIDBKey()); 688 keys.push_back(CreateArrayIDBKey());
689 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKey::NumberType))); 689 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKeyTypeNumber)));
690 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKey::NumberType), 690 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKeyTypeNumber),
691 IndexedDBKey(3.14, WebIDBKey::NumberType))); 691 IndexedDBKey(3.14, WebIDBKeyTypeNumber)));
692 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKey::DateType))); 692 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKeyTypeDate)));
693 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKey::DateType), 693 keys.push_back(CreateArrayIDBKey(IndexedDBKey(0, WebIDBKeyTypeDate),
694 IndexedDBKey(0, WebIDBKey::DateType))); 694 IndexedDBKey(0, WebIDBKeyTypeDate)));
695 keys.push_back(CreateArrayIDBKey(IndexedDBKey(ASCIIToUTF16("")))); 695 keys.push_back(CreateArrayIDBKey(IndexedDBKey(ASCIIToUTF16(""))));
696 keys.push_back(CreateArrayIDBKey(IndexedDBKey(ASCIIToUTF16("")), 696 keys.push_back(CreateArrayIDBKey(IndexedDBKey(ASCIIToUTF16("")),
697 IndexedDBKey(ASCIIToUTF16("a")))); 697 IndexedDBKey(ASCIIToUTF16("a"))));
698 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey())); 698 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey()));
699 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey(), CreateArrayIDBKey())); 699 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey(), CreateArrayIDBKey()));
700 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey(CreateArrayIDBKey()))); 700 keys.push_back(CreateArrayIDBKey(CreateArrayIDBKey(CreateArrayIDBKey())));
701 keys.push_back(CreateArrayIDBKey( 701 keys.push_back(CreateArrayIDBKey(
702 CreateArrayIDBKey(CreateArrayIDBKey(CreateArrayIDBKey())))); 702 CreateArrayIDBKey(CreateArrayIDBKey(CreateArrayIDBKey()))));
703 703
704 for (size_t i = 0; i < keys.size() - 1; ++i) { 704 for (size_t i = 0; i < keys.size() - 1; ++i) {
(...skipping 134 matching lines...) Expand 10 before | Expand all | Expand 10 after
839 std::string vB = WrappedEncodeVarInt(static_cast<int64>(n)); 839 std::string vB = WrappedEncodeVarInt(static_cast<int64>(n));
840 840
841 EXPECT_EQ(vA.size(), vB.size()); 841 EXPECT_EQ(vA.size(), vB.size());
842 EXPECT_EQ(*vA.begin(), *vB.begin()); 842 EXPECT_EQ(*vA.begin(), *vB.begin());
843 } 843 }
844 } 844 }
845 845
846 } // namespace 846 } // namespace
847 847
848 } // namespace content 848 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_leveldb_coding.cc ('k') | content/child/indexed_db/indexed_db_dispatcher_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698