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

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

Issue 11421192: Save extension activity log to a file. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: Another small fix Created 8 years 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
(Empty)
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
3 // found in the LICENSE file.
4
5 #include <string>
6 #include "base/file_path.h"
7 #include "base/file_util.h"
8 #include "base/files/scoped_temp_dir.h"
9 #include "chrome/browser/extensions/activity_database.h"
10 #include "chrome/browser/extensions/blocked_actions.h"
11 #include "chrome/browser/extensions/manager_actions.h"
12 #include "chrome/browser/extensions/url_actions.h"
13 #include "sql/statement.h"
14 #include "testing/gtest/include/gtest/gtest.h"
15
16 namespace extensions {
17
18 // Check that the database is initialized properly.
19 TEST(ActivityDatabaseTest, Init) {
20 base::ScopedTempDir temp_dir;
21 FilePath db_file;
22 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
23 db_file = temp_dir.path().AppendASCII("ActivityInit.db");
24 file_util::Delete(db_file, false);
25
26 ActivityDatabase* activity_db = new ActivityDatabase();
27 activity_db->AddRef();
28 ASSERT_EQ(sql::INIT_OK, activity_db->Init(db_file, NULL));
29 ASSERT_TRUE(activity_db->initialized());
30 activity_db->Release();
31
32 sql::Connection db;
33 ASSERT_TRUE(db.Open(db_file));
34 ASSERT_TRUE(db.DoesTableExist(UrlAction::kTableName));
35 ASSERT_TRUE(db.DoesTableExist(ManagerAction::kTableName));
36 ASSERT_TRUE(db.DoesTableExist(BlockedAction::kTableName));
37 db.Close();
38 }
39
40 // Check that actions are recorded in the db.
41 TEST(ActivityDatabaseTest, RecordAction) {
42 base::ScopedTempDir temp_dir;
43 FilePath db_file;
44 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
45 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
46 file_util::Delete(db_file, false);
47
48 ActivityDatabase* activity_db = new ActivityDatabase();
49 activity_db->AddRef();
50 ASSERT_EQ(sql::INIT_OK, activity_db->Init(db_file, NULL));
51 scoped_refptr<ManagerAction> action = new ManagerAction(
52 "punky",
53 ManagerAction::READ,
54 ManagerAction::BOOKMARK,
55 "brewster",
56 base::Time::Now());
57 activity_db->RecordManagerAction(action);
58 activity_db->Close();
59 activity_db->Release();
60
61 sql::Connection db;
62 ASSERT_TRUE(db.Open(db_file));
63
64 std::string sql_str = "SELECT * FROM " +
65 std::string(ManagerAction::kTableName);
66 sql::Statement statement(db.GetUniqueStatement(sql_str.c_str()));
67 ASSERT_TRUE(statement.Step());
68 ASSERT_EQ("punky", statement.ColumnString(0));
69 ASSERT_EQ("READ", statement.ColumnString(2));
70 ASSERT_EQ("BOOKMARK", statement.ColumnString(3));
71 ASSERT_EQ("brewster", statement.ColumnString(4));
72 }
73
74 // Check that nothing explodes if the DB isn't initialized.
75 TEST(ActivityDatabaseTest, InitFailure) {
76 base::ScopedTempDir temp_dir;
77 FilePath db_file;
78 ASSERT_TRUE(temp_dir.CreateUniqueTempDir());
79 db_file = temp_dir.path().AppendASCII("ActivityRecord.db");
80 file_util::Delete(db_file, false);
81
82 ActivityDatabase* activity_db = new ActivityDatabase();
83 activity_db->AddRef();
84 scoped_refptr<ManagerAction> action = new ManagerAction(
85 "punky",
86 ManagerAction::READ,
87 ManagerAction::BOOKMARK,
88 "brewster",
89 base::Time::Now());
90 activity_db->RecordManagerAction(action);
91 activity_db->Close();
92 activity_db->Release();
93 }
94
95 } // namespace
96
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698