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

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

Issue 264483002: This is the implementation of the primary and secondary blob journals for (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Export kAllBlobsKey Created 6 years, 7 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"
(...skipping 673 matching lines...) Expand 10 before | Expand all | Expand 10 after
684 EXPECT_EQ(encoded, v); 684 EXPECT_EQ(encoded, v);
685 685
686 StringPiece slice(encoded); 686 StringPiece slice(encoded);
687 IndexedDBKeyPath decoded; 687 IndexedDBKeyPath decoded;
688 EXPECT_TRUE(DecodeIDBKeyPath(&slice, &decoded)); 688 EXPECT_TRUE(DecodeIDBKeyPath(&slice, &decoded));
689 EXPECT_EQ(key_path, decoded); 689 EXPECT_EQ(key_path, decoded);
690 EXPECT_TRUE(slice.empty()); 690 EXPECT_TRUE(slice.empty());
691 } 691 }
692 } 692 }
693 693
694 TEST(IndexedDBLevelDBCodingTest, EncodeDecodeBlobJournal) {
695 std::vector<IndexedDBKeyPath> key_paths;
696 std::vector<std::string> encoded_paths;
697
698 std::vector<BlobJournalType> journals;
699
700 { // Empty journal
701 BlobJournalType journal;
702 journals.push_back(journal);
703 }
704
705 { // One item
706 BlobJournalType journal;
707 journal.push_back(std::make_pair(4, 7));
708 journals.push_back(journal);
709 }
710
711 { // kAllBlobsKey
712 BlobJournalType journal;
713 journal.push_back(std::make_pair(5, DatabaseMetaDataKey::kAllBlobsKey));
714 journals.push_back(journal);
715 }
716
717 { // A bunch of items
718 BlobJournalType journal;
719 journal.push_back(std::make_pair(4, 7));
720 journal.push_back(std::make_pair(5, 6));
721 journal.push_back(std::make_pair(4, 5));
722 journal.push_back(std::make_pair(4, 4));
723 journal.push_back(std::make_pair(1, 12));
724 journal.push_back(std::make_pair(4, 3));
725 journal.push_back(std::make_pair(15, 14));
726 journals.push_back(journal);
727 }
728
729 std::vector<BlobJournalType>::const_iterator journal_iter;
730 for (journal_iter = journals.begin(); journal_iter != journals.end();
731 ++journal_iter) {
732 std::string encoding;
733 EncodeBlobJournal(*journal_iter, &encoding);
734 StringPiece slice(encoding);
735 BlobJournalType journal_out;
736 EXPECT_TRUE(DecodeBlobJournal(&slice, &journal_out));
737 EXPECT_EQ(*journal_iter, journal_out);
738 }
739
740 journals.clear();
741
742 { // Illegal database id
743 BlobJournalType journal;
744 journal.push_back(std::make_pair(0, 3));
745 journals.push_back(journal);
746 }
747
748 { // Illegal blob id
749 BlobJournalType journal;
750 journal.push_back(std::make_pair(4, 0));
751 journals.push_back(journal);
752 }
753
754 for (journal_iter = journals.begin(); journal_iter != journals.end();
755 ++journal_iter) {
756 std::string encoding;
757 EncodeBlobJournal(*journal_iter, &encoding);
758 StringPiece slice(encoding);
759 BlobJournalType journal_out;
760 EXPECT_FALSE(DecodeBlobJournal(&slice, &journal_out));
761 }
762 }
763
694 TEST(IndexedDBLevelDBCodingTest, DecodeLegacyIDBKeyPath) { 764 TEST(IndexedDBLevelDBCodingTest, DecodeLegacyIDBKeyPath) {
695 // Legacy encoding of string key paths. 765 // Legacy encoding of string key paths.
696 std::vector<IndexedDBKeyPath> key_paths; 766 std::vector<IndexedDBKeyPath> key_paths;
697 std::vector<std::string> encoded_paths; 767 std::vector<std::string> encoded_paths;
698 768
699 { 769 {
700 key_paths.push_back(IndexedDBKeyPath(base::string16())); 770 key_paths.push_back(IndexedDBKeyPath(base::string16()));
701 encoded_paths.push_back(std::string()); 771 encoded_paths.push_back(std::string());
702 } 772 }
703 { 773 {
(...skipping 204 matching lines...) Expand 10 before | Expand all | Expand 10 after
908 std::string vB = WrappedEncodeVarInt(static_cast<int64>(n)); 978 std::string vB = WrappedEncodeVarInt(static_cast<int64>(n));
909 979
910 EXPECT_EQ(vA.size(), vB.size()); 980 EXPECT_EQ(vA.size(), vB.size());
911 EXPECT_EQ(*vA.begin(), *vB.begin()); 981 EXPECT_EQ(*vA.begin(), *vB.begin());
912 } 982 }
913 } 983 }
914 984
915 } // namespace 985 } // namespace
916 986
917 } // namespace content 987 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/indexed_db/indexed_db_leveldb_coding.cc ('k') | tools/metrics/histograms/histograms.xml » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698