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

Side by Side Diff: chrome/browser/webdata/token_service_table_unittest.cc

Issue 12543034: Move creation of the various WebDatabaseTable types out of WebDatabase. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix Windows release builds (COMDAT folding combined static functions being used for keys. Created 7 years, 9 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
« no previous file with comments | « chrome/browser/webdata/token_service_table.cc ('k') | chrome/browser/webdata/web_apps_table.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #include "base/file_util.h" 5 #include "base/file_util.h"
6 #include "base/files/scoped_temp_dir.h" 6 #include "base/files/scoped_temp_dir.h"
7 #include "base/path_service.h" 7 #include "base/path_service.h"
8 #include "base/strings/string_number_conversions.h" 8 #include "base/strings/string_number_conversions.h"
9 #include "base/time.h" 9 #include "base/time.h"
10 #include "chrome/browser/webdata/token_service_table.h" 10 #include "chrome/browser/webdata/token_service_table.h"
11 #include "chrome/browser/webdata/web_database.h" 11 #include "chrome/browser/webdata/web_database.h"
12 #include "chrome/common/chrome_paths.h" 12 #include "chrome/common/chrome_paths.h"
13 #include "testing/gtest/include/gtest/gtest.h" 13 #include "testing/gtest/include/gtest/gtest.h"
14 14
15 using base::Time; 15 using base::Time;
16 16
17 class TokenServiceTableTest : public testing::Test { 17 class TokenServiceTableTest : public testing::Test {
18 public: 18 public:
19 TokenServiceTableTest() {} 19 TokenServiceTableTest() {}
20 virtual ~TokenServiceTableTest() {} 20 virtual ~TokenServiceTableTest() {}
21 21
22 protected: 22 protected:
23 virtual void SetUp() { 23 virtual void SetUp() {
24 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 24 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
25 file_ = temp_dir_.path().AppendASCII("TestWebDatabase"); 25 file_ = temp_dir_.path().AppendASCII("TestWebDatabase");
26
27 table_.reset(new TokenServiceTable);
28 db_.reset(new WebDatabase);
29 db_->AddTable(table_.get());
30 ASSERT_EQ(sql::INIT_OK, db_->Init(file_, std::string()));
26 } 31 }
27 32
28 base::FilePath file_; 33 base::FilePath file_;
29 base::ScopedTempDir temp_dir_; 34 base::ScopedTempDir temp_dir_;
30 35 scoped_ptr<TokenServiceTable> table_;
36 scoped_ptr<WebDatabase> db_;
31 private: 37 private:
32 DISALLOW_COPY_AND_ASSIGN(TokenServiceTableTest); 38 DISALLOW_COPY_AND_ASSIGN(TokenServiceTableTest);
33 }; 39 };
34 40
35 TEST_F(TokenServiceTableTest, TokenServiceGetAllRemoveAll) { 41 TEST_F(TokenServiceTableTest, TokenServiceGetAllRemoveAll) {
36 WebDatabase db;
37 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
38
39 std::map<std::string, std::string> out_map; 42 std::map<std::string, std::string> out_map;
40 std::string service; 43 std::string service;
41 std::string service2; 44 std::string service2;
42 service = "testservice"; 45 service = "testservice";
43 service2 = "othertestservice"; 46 service2 = "othertestservice";
44 47
45 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 48 EXPECT_TRUE(table_->GetAllTokens(&out_map));
46 EXPECT_TRUE(out_map.empty()); 49 EXPECT_TRUE(out_map.empty());
47 50
48 // Check that get all tokens works 51 // Check that get all tokens works
49 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service, 52 EXPECT_TRUE(table_->SetTokenForService(service, "pepperoni"));
50 "pepperoni")); 53 EXPECT_TRUE(table_->SetTokenForService(service2, "steak"));
51 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service2, "steak")); 54 EXPECT_TRUE(table_->GetAllTokens(&out_map));
52 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map));
53 EXPECT_EQ(out_map.find(service)->second, "pepperoni"); 55 EXPECT_EQ(out_map.find(service)->second, "pepperoni");
54 EXPECT_EQ(out_map.find(service2)->second, "steak"); 56 EXPECT_EQ(out_map.find(service2)->second, "steak");
55 out_map.clear(); 57 out_map.clear();
56 58
57 // Purge 59 // Purge
58 EXPECT_TRUE(db.GetTokenServiceTable()->RemoveAllTokens()); 60 EXPECT_TRUE(table_->RemoveAllTokens());
59 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 61 EXPECT_TRUE(table_->GetAllTokens(&out_map));
60 EXPECT_TRUE(out_map.empty()); 62 EXPECT_TRUE(out_map.empty());
61 63
62 // Check that you can still add it back in 64 // Check that you can still add it back in
63 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service, "cheese")); 65 EXPECT_TRUE(table_->SetTokenForService(service, "cheese"));
64 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 66 EXPECT_TRUE(table_->GetAllTokens(&out_map));
65 EXPECT_EQ(out_map.find(service)->second, "cheese"); 67 EXPECT_EQ(out_map.find(service)->second, "cheese");
66 } 68 }
67 69
68 TEST_F(TokenServiceTableTest, TokenServiceGetSet) { 70 TEST_F(TokenServiceTableTest, TokenServiceGetSet) {
69 WebDatabase db;
70 ASSERT_EQ(sql::INIT_OK, db.Init(file_, std::string()));
71
72 std::map<std::string, std::string> out_map; 71 std::map<std::string, std::string> out_map;
73 std::string service; 72 std::string service;
74 service = "testservice"; 73 service = "testservice";
75 74
76 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 75 EXPECT_TRUE(table_->GetAllTokens(&out_map));
77 EXPECT_TRUE(out_map.empty()); 76 EXPECT_TRUE(out_map.empty());
78 77
79 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service, 78 EXPECT_TRUE(table_->SetTokenForService(service, "pepperoni"));
80 "pepperoni")); 79 EXPECT_TRUE(table_->GetAllTokens(&out_map));
81 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map));
82 EXPECT_EQ(out_map.find(service)->second, "pepperoni"); 80 EXPECT_EQ(out_map.find(service)->second, "pepperoni");
83 out_map.clear(); 81 out_map.clear();
84 82
85 // try blanking it - won't remove it from the db though! 83 // try blanking it - won't remove it from the db though!
86 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service, "")); 84 EXPECT_TRUE(table_->SetTokenForService(service, ""));
87 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 85 EXPECT_TRUE(table_->GetAllTokens(&out_map));
88 EXPECT_EQ(out_map.find(service)->second, ""); 86 EXPECT_EQ(out_map.find(service)->second, "");
89 out_map.clear(); 87 out_map.clear();
90 88
91 // try mutating it 89 // try mutating it
92 EXPECT_TRUE(db.GetTokenServiceTable()->SetTokenForService(service, "ham")); 90 EXPECT_TRUE(table_->SetTokenForService(service, "ham"));
93 EXPECT_TRUE(db.GetTokenServiceTable()->GetAllTokens(&out_map)); 91 EXPECT_TRUE(table_->GetAllTokens(&out_map));
94 EXPECT_EQ(out_map.find(service)->second, "ham"); 92 EXPECT_EQ(out_map.find(service)->second, "ham");
95 } 93 }
OLDNEW
« no previous file with comments | « chrome/browser/webdata/token_service_table.cc ('k') | chrome/browser/webdata/web_apps_table.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698