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 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
(...skipping 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
46 public: | 46 public: |
47 ActivityDatabaseTestPolicy() {}; | 47 ActivityDatabaseTestPolicy() {}; |
48 | 48 |
49 static const char kTableName[]; | 49 static const char kTableName[]; |
50 static const char* kTableContentFields[]; | 50 static const char* kTableContentFields[]; |
51 static const char* kTableFieldTypes[]; | 51 static const char* kTableFieldTypes[]; |
52 | 52 |
53 virtual void Record(ActivityDatabase* db, scoped_refptr<Action> action); | 53 virtual void Record(ActivityDatabase* db, scoped_refptr<Action> action); |
54 | 54 |
55 protected: | 55 protected: |
56 virtual bool InitDatabase(sql::Connection* db) OVERRIDE; | 56 virtual bool InitDatabase(sql::Connection* db) override; |
57 virtual bool FlushDatabase(sql::Connection*) OVERRIDE; | 57 virtual bool FlushDatabase(sql::Connection*) override; |
58 virtual void OnDatabaseFailure() OVERRIDE {} | 58 virtual void OnDatabaseFailure() override {} |
59 virtual void OnDatabaseClose() OVERRIDE { delete this; } | 59 virtual void OnDatabaseClose() override { delete this; } |
60 | 60 |
61 std::vector<scoped_refptr<Action> > queue_; | 61 std::vector<scoped_refptr<Action> > queue_; |
62 }; | 62 }; |
63 | 63 |
64 const char ActivityDatabaseTestPolicy::kTableName[] = "actions"; | 64 const char ActivityDatabaseTestPolicy::kTableName[] = "actions"; |
65 const char* ActivityDatabaseTestPolicy::kTableContentFields[] = { | 65 const char* ActivityDatabaseTestPolicy::kTableContentFields[] = { |
66 "extension_id", "time", "action_type", "api_name"}; | 66 "extension_id", "time", "action_type", "api_name"}; |
67 const char* ActivityDatabaseTestPolicy::kTableFieldTypes[] = { | 67 const char* ActivityDatabaseTestPolicy::kTableFieldTypes[] = { |
68 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR"}; | 68 "LONGVARCHAR NOT NULL", "INTEGER", "INTEGER", "LONGVARCHAR"}; |
69 | 69 |
(...skipping 30 matching lines...) Expand all Loading... |
100 } | 100 } |
101 | 101 |
102 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, | 102 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, |
103 scoped_refptr<Action> action) { | 103 scoped_refptr<Action> action) { |
104 queue_.push_back(action); | 104 queue_.push_back(action); |
105 db->AdviseFlush(queue_.size()); | 105 db->AdviseFlush(queue_.size()); |
106 } | 106 } |
107 | 107 |
108 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { | 108 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { |
109 protected: | 109 protected: |
110 virtual void SetUp() OVERRIDE { | 110 virtual void SetUp() override { |
111 ChromeRenderViewHostTestHarness::SetUp(); | 111 ChromeRenderViewHostTestHarness::SetUp(); |
112 #if defined OS_CHROMEOS | 112 #if defined OS_CHROMEOS |
113 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 113 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
114 #endif | 114 #endif |
115 CommandLine command_line(CommandLine::NO_PROGRAM); | 115 CommandLine command_line(CommandLine::NO_PROGRAM); |
116 CommandLine::ForCurrentProcess()->AppendSwitch( | 116 CommandLine::ForCurrentProcess()->AppendSwitch( |
117 switches::kEnableExtensionActivityLogTesting); | 117 switches::kEnableExtensionActivityLogTesting); |
118 } | 118 } |
119 | 119 |
120 virtual void TearDown() OVERRIDE { | 120 virtual void TearDown() override { |
121 #if defined OS_CHROMEOS | 121 #if defined OS_CHROMEOS |
122 test_user_manager_.reset(); | 122 test_user_manager_.reset(); |
123 #endif | 123 #endif |
124 ChromeRenderViewHostTestHarness::TearDown(); | 124 ChromeRenderViewHostTestHarness::TearDown(); |
125 } | 125 } |
126 | 126 |
127 // Creates a test database and initializes the table schema. | 127 // Creates a test database and initializes the table schema. |
128 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { | 128 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { |
129 db_delegate_ = new ActivityDatabaseTestPolicy(); | 129 db_delegate_ = new ActivityDatabaseTestPolicy(); |
130 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); | 130 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); |
(...skipping 146 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
277 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); | 277 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); |
278 ActivityDatabase* activity_db = new ActivityDatabase(delegate); | 278 ActivityDatabase* activity_db = new ActivityDatabase(delegate); |
279 scoped_refptr<Action> action = new Action( | 279 scoped_refptr<Action> action = new Action( |
280 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); | 280 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); |
281 action->mutable_args()->AppendString("woof"); | 281 action->mutable_args()->AppendString("woof"); |
282 delegate->Record(activity_db, action); | 282 delegate->Record(activity_db, action); |
283 activity_db->Close(); | 283 activity_db->Close(); |
284 } | 284 } |
285 | 285 |
286 } // namespace extensions | 286 } // namespace extensions |
OLD | NEW |