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 <string> | 5 #include <string> |
6 #include "base/file_path.h" | 6 #include "base/file_path.h" |
7 #include "base/file_util.h" | 7 #include "base/file_util.h" |
8 #include "base/files/scoped_temp_dir.h" | 8 #include "base/files/scoped_temp_dir.h" |
9 #include "chrome/browser/extensions/activity_database.h" | 9 #include "chrome/browser/extensions/activity_database.h" |
10 #include "chrome/browser/extensions/api_actions.h" | 10 #include "chrome/browser/extensions/api_actions.h" |
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
45 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); | 45 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); |
46 file_util::Delete(db_file, false); | 46 file_util::Delete(db_file, false); |
47 | 47 |
48 ActivityDatabase* activity_db = new ActivityDatabase(); | 48 ActivityDatabase* activity_db = new ActivityDatabase(); |
49 activity_db->AddRef(); | 49 activity_db->AddRef(); |
50 activity_db->Init(db_file); | 50 activity_db->Init(db_file); |
51 ASSERT_TRUE(activity_db->initialized()); | 51 ASSERT_TRUE(activity_db->initialized()); |
52 scoped_refptr<APIAction> action = new APIAction( | 52 scoped_refptr<APIAction> action = new APIAction( |
53 "punky", | 53 "punky", |
54 base::Time::Now(), | 54 base::Time::Now(), |
| 55 APIAction::CALL, |
55 APIAction::READ, | 56 APIAction::READ, |
56 APIAction::BOOKMARK, | 57 APIAction::BOOKMARK, |
57 "brewster", | 58 "brewster", |
58 ""); | 59 ""); |
59 activity_db->RecordAction(action); | 60 activity_db->RecordAction(action); |
60 activity_db->Close(); | 61 activity_db->Close(); |
61 activity_db->Release(); | 62 activity_db->Release(); |
62 | 63 |
63 sql::Connection db; | 64 sql::Connection db; |
64 ASSERT_TRUE(db.Open(db_file)); | 65 ASSERT_TRUE(db.Open(db_file)); |
65 | 66 |
66 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); | 67 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); |
67 std::string sql_str = "SELECT * FROM " + | 68 std::string sql_str = "SELECT * FROM " + |
68 std::string(APIAction::kTableName); | 69 std::string(APIAction::kTableName); |
69 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); | 70 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); |
70 ASSERT_TRUE(statement.Step()); | 71 ASSERT_TRUE(statement.Step()); |
71 ASSERT_EQ("punky", statement.ColumnString(0)); | 72 ASSERT_EQ("punky", statement.ColumnString(0)); |
72 ASSERT_EQ("READ", statement.ColumnString(2)); | 73 ASSERT_EQ("CALL", statement.ColumnString(2)); |
73 ASSERT_EQ("BOOKMARK", statement.ColumnString(3)); | 74 ASSERT_EQ("READ", statement.ColumnString(3)); |
74 ASSERT_EQ("brewster", statement.ColumnString(4)); | 75 ASSERT_EQ("BOOKMARK", statement.ColumnString(4)); |
| 76 ASSERT_EQ("brewster", statement.ColumnString(5)); |
75 } | 77 } |
76 | 78 |
77 // Check that nothing explodes if the DB isn't initialized. | 79 // Check that nothing explodes if the DB isn't initialized. |
78 TEST(ActivityDatabaseTest, InitFailure) { | 80 TEST(ActivityDatabaseTest, InitFailure) { |
79 base::ScopedTempDir temp_dir; | 81 base::ScopedTempDir temp_dir; |
80 FilePath db_file; | 82 FilePath db_file; |
81 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 83 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
82 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); | 84 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); |
83 file_util::Delete(db_file, false); | 85 file_util::Delete(db_file, false); |
84 | 86 |
85 ActivityDatabase* activity_db = new ActivityDatabase(); | 87 ActivityDatabase* activity_db = new ActivityDatabase(); |
86 activity_db->AddRef(); | 88 activity_db->AddRef(); |
87 scoped_refptr<APIAction> action = new APIAction( | 89 scoped_refptr<APIAction> action = new APIAction( |
88 "punky", | 90 "punky", |
89 base::Time::Now(), | 91 base::Time::Now(), |
| 92 APIAction::CALL, |
90 APIAction::READ, | 93 APIAction::READ, |
91 APIAction::BOOKMARK, | 94 APIAction::BOOKMARK, |
92 "brewster", | 95 "brewster", |
93 ""); | 96 ""); |
94 activity_db->RecordAction(action); | 97 activity_db->RecordAction(action); |
95 activity_db->Close(); | 98 activity_db->Close(); |
96 activity_db->Release(); | 99 activity_db->Release(); |
97 } | 100 } |
98 | 101 |
99 } // namespace | 102 } // namespace |
100 | 103 |
OLD | NEW |