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

Side by Side Diff: chrome/browser/extensions/activity_log/activity_database_unittest.cc

Issue 14774012: Replaced enum strings with ints in Activity Log database (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Added missing Singleton dep Created 7 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) 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/command_line.h" 6 #include "base/command_line.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/run_loop.h" 10 #include "base/run_loop.h"
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
124 124
125 sql::Connection db; 125 sql::Connection db;
126 ASSERT_TRUE(db.Open(db_file)); 126 ASSERT_TRUE(db.Open(db_file));
127 127
128 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName)); 128 ASSERT_TRUE(db.DoesTableExist(APIAction::kTableName));
129 std::string sql_str = "SELECT * FROM " + 129 std::string sql_str = "SELECT * FROM " +
130 std::string(APIAction::kTableName); 130 std::string(APIAction::kTableName);
131 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); 131 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
132 ASSERT_TRUE(statement.Step()); 132 ASSERT_TRUE(statement.Step());
133 ASSERT_EQ("punky", statement.ColumnString(0)); 133 ASSERT_EQ("punky", statement.ColumnString(0));
134 ASSERT_EQ("CALL", statement.ColumnString(2)); 134 ASSERT_EQ(0, statement.ColumnInt(2));
135 ASSERT_EQ("brewster", statement.ColumnString(3)); 135 ASSERT_EQ("brewster", statement.ColumnString(3));
136 ASSERT_EQ("woof", statement.ColumnString(4)); 136 ASSERT_EQ("woof", statement.ColumnString(4));
137 } 137 }
138 138
139 // Check that blocked actions are recorded in the db. 139 // Check that blocked actions are recorded in the db.
140 TEST_F(ActivityDatabaseTest, RecordBlockedAction) { 140 TEST_F(ActivityDatabaseTest, RecordBlockedAction) {
141 base::ScopedTempDir temp_dir; 141 base::ScopedTempDir temp_dir;
142 base::FilePath db_file; 142 base::FilePath db_file;
143 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 143 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
144 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 144 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
(...skipping 16 matching lines...) Expand all
161 ASSERT_TRUE(db.Open(db_file)); 161 ASSERT_TRUE(db.Open(db_file));
162 162
163 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName)); 163 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName));
164 std::string sql_str = "SELECT * FROM " + 164 std::string sql_str = "SELECT * FROM " +
165 std::string(BlockedAction::kTableName); 165 std::string(BlockedAction::kTableName);
166 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str())); 166 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
167 ASSERT_TRUE(statement.Step()); 167 ASSERT_TRUE(statement.Step());
168 ASSERT_EQ("punky", statement.ColumnString(0)); 168 ASSERT_EQ("punky", statement.ColumnString(0));
169 ASSERT_EQ("do.evilThings", statement.ColumnString(2)); 169 ASSERT_EQ("do.evilThings", statement.ColumnString(2));
170 ASSERT_EQ("1, 2", statement.ColumnString(3)); 170 ASSERT_EQ("1, 2", statement.ColumnString(3));
171 ASSERT_EQ("access denied", statement.ColumnString(4)); 171 ASSERT_EQ(1, statement.ColumnInt(4));
172 ASSERT_EQ("extra", statement.ColumnString(5)); 172 ASSERT_EQ("extra", statement.ColumnString(5));
173 } 173 }
174 174
175 // Check that we can read back recent actions in the db. 175 // Check that we can read back recent actions in the db.
176 TEST_F(ActivityDatabaseTest, GetTodaysActions) { 176 TEST_F(ActivityDatabaseTest, GetTodaysActions) {
177 base::ScopedTempDir temp_dir; 177 base::ScopedTempDir temp_dir;
178 base::FilePath db_file; 178 base::FilePath db_file;
179 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); 179 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
180 db_file = temp_dir.path().AppendASCII("ActivityRecord.db"); 180 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
181 file_util::Delete(db_file, false); 181 file_util::Delete(db_file, false);
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
215 "lets", 215 "lets",
216 "vamoose", 216 "vamoose",
217 "extra"); 217 "extra");
218 activity_db->RecordAction(api_action); 218 activity_db->RecordAction(api_action);
219 activity_db->RecordAction(dom_action); 219 activity_db->RecordAction(dom_action);
220 activity_db->RecordAction(extra_dom_action); 220 activity_db->RecordAction(extra_dom_action);
221 221
222 // Read them back 222 // Read them back
223 std::string api_print = "ID: punky, CATEGORY: CALL, " 223 std::string api_print = "ID: punky, CATEGORY: CALL, "
224 "API: brewster, ARGS: woof"; 224 "API: brewster, ARGS: woof";
225 std::string dom_print = "DOM API CALL: lets, ARGS: vamoose"; 225 std::string dom_print = "DOM API CALL: lets, ARGS: vamoose, VERB: MODIFIED";
226 scoped_ptr<std::vector<scoped_refptr<Action> > > actions = 226 scoped_ptr<std::vector<scoped_refptr<Action> > > actions =
227 activity_db->GetActions("punky", 0); 227 activity_db->GetActions("punky", 0);
228 ASSERT_EQ(2, static_cast<int>(actions->size())); 228 ASSERT_EQ(2, static_cast<int>(actions->size()));
229 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); 229 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug());
230 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); 230 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug());
231 231
232 activity_db->Close(); 232 activity_db->Close();
233 } 233 }
234 234
235 // Check that we can read back recent actions in the db. 235 // Check that we can read back recent actions in the db.
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 "vamoose", 286 "vamoose",
287 "extra"); 287 "extra");
288 activity_db->RecordAction(api_action); 288 activity_db->RecordAction(api_action);
289 activity_db->RecordAction(dom_action); 289 activity_db->RecordAction(dom_action);
290 activity_db->RecordAction(toonew_dom_action); 290 activity_db->RecordAction(toonew_dom_action);
291 activity_db->RecordAction(tooold_dom_action); 291 activity_db->RecordAction(tooold_dom_action);
292 292
293 // Read them back 293 // Read them back
294 std::string api_print = "ID: punky, CATEGORY: CALL, " 294 std::string api_print = "ID: punky, CATEGORY: CALL, "
295 "API: brewster, ARGS: woof"; 295 "API: brewster, ARGS: woof";
296 std::string dom_print = "DOM API CALL: lets, ARGS: vamoose"; 296 std::string dom_print = "DOM API CALL: lets, ARGS: vamoose, VERB: MODIFIED";
297 scoped_ptr<std::vector<scoped_refptr<Action> > > actions = 297 scoped_ptr<std::vector<scoped_refptr<Action> > > actions =
298 activity_db->GetActions("punky", 3); 298 activity_db->GetActions("punky", 3);
299 ASSERT_EQ(2, static_cast<int>(actions->size())); 299 ASSERT_EQ(2, static_cast<int>(actions->size()));
300 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug()); 300 ASSERT_EQ(dom_print, actions->at(0)->PrintForDebug());
301 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug()); 301 ASSERT_EQ(api_print, actions->at(1)->PrintForDebug());
302 302
303 activity_db->Close(); 303 activity_db->Close();
304 } 304 }
305 305
306 TEST_F(ActivityDatabaseTest, BatchModeOff) { 306 TEST_F(ActivityDatabaseTest, BatchModeOff) {
(...skipping 88 matching lines...) Expand 10 before | Expand all | Expand 10 after
395 APIAction::CALL, 395 APIAction::CALL,
396 "brewster", 396 "brewster",
397 "woooof", 397 "woooof",
398 "extra"); 398 "extra");
399 activity_db->RecordAction(action); 399 activity_db->RecordAction(action);
400 activity_db->Close(); 400 activity_db->Close();
401 } 401 }
402 402
403 } // namespace 403 } // namespace
404 404
OLDNEW
« no previous file with comments | « chrome/browser/extensions/activity_log/activity_actions.cc ('k') | chrome/browser/extensions/activity_log/api_actions.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698