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 <stddef.h> | 5 #include <stddef.h> |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
(...skipping 14 matching lines...) Expand all Loading... |
25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 25 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
26 #include "chrome/test/base/testing_profile.h" | 26 #include "chrome/test/base/testing_profile.h" |
27 #include "content/public/browser/web_contents.h" | 27 #include "content/public/browser/web_contents.h" |
28 #include "content/public/test/test_browser_thread.h" | 28 #include "content/public/test/test_browser_thread.h" |
29 #include "extensions/common/dom_action_types.h" | 29 #include "extensions/common/dom_action_types.h" |
30 #include "sql/statement.h" | 30 #include "sql/statement.h" |
31 #include "testing/gtest/include/gtest/gtest.h" | 31 #include "testing/gtest/include/gtest/gtest.h" |
32 | 32 |
33 #if defined(OS_CHROMEOS) | 33 #if defined(OS_CHROMEOS) |
34 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" | 34 #include "chrome/browser/chromeos/login/users/mock_user_manager.h" |
35 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | |
36 #include "chrome/browser/chromeos/settings/cros_settings.h" | 35 #include "chrome/browser/chromeos/settings/cros_settings.h" |
37 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 36 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
38 #include "chromeos/chromeos_switches.h" | 37 #include "chromeos/chromeos_switches.h" |
39 #endif | 38 #endif |
40 | 39 |
41 using content::BrowserThread; | 40 using content::BrowserThread; |
42 | 41 |
43 namespace constants = activity_log_constants; | 42 namespace constants = activity_log_constants; |
44 | 43 |
45 namespace extensions { | 44 namespace extensions { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
106 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, | 105 void ActivityDatabaseTestPolicy::Record(ActivityDatabase* db, |
107 scoped_refptr<Action> action) { | 106 scoped_refptr<Action> action) { |
108 queue_.push_back(action); | 107 queue_.push_back(action); |
109 db->AdviseFlush(queue_.size()); | 108 db->AdviseFlush(queue_.size()); |
110 } | 109 } |
111 | 110 |
112 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { | 111 class ActivityDatabaseTest : public ChromeRenderViewHostTestHarness { |
113 protected: | 112 protected: |
114 void SetUp() override { | 113 void SetUp() override { |
115 ChromeRenderViewHostTestHarness::SetUp(); | 114 ChromeRenderViewHostTestHarness::SetUp(); |
116 #if defined OS_CHROMEOS | |
117 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | |
118 #endif | |
119 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 115 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
120 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 116 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
121 switches::kEnableExtensionActivityLogTesting); | 117 switches::kEnableExtensionActivityLogTesting); |
122 } | 118 } |
123 | 119 |
124 void TearDown() override { | 120 void TearDown() override { |
125 #if defined OS_CHROMEOS | |
126 test_user_manager_.reset(); | |
127 #endif | |
128 ChromeRenderViewHostTestHarness::TearDown(); | 121 ChromeRenderViewHostTestHarness::TearDown(); |
129 } | 122 } |
130 | 123 |
131 // Creates a test database and initializes the table schema. | 124 // Creates a test database and initializes the table schema. |
132 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { | 125 ActivityDatabase* OpenDatabase(const base::FilePath& db_file) { |
133 db_delegate_ = new ActivityDatabaseTestPolicy(); | 126 db_delegate_ = new ActivityDatabaseTestPolicy(); |
134 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); | 127 ActivityDatabase* activity_db = new ActivityDatabase(db_delegate_); |
135 activity_db->Init(db_file); | 128 activity_db->Init(db_file); |
136 CHECK(activity_db->is_db_valid()); | 129 CHECK(activity_db->is_db_valid()); |
137 return activity_db; | 130 return activity_db; |
(...skipping 21 matching lines...) Expand all Loading... |
159 statement.BindString(0, api_name_pattern); | 152 statement.BindString(0, api_name_pattern); |
160 if (!statement.Step()) | 153 if (!statement.Step()) |
161 return -1; | 154 return -1; |
162 return statement.ColumnInt(0); | 155 return statement.ColumnInt(0); |
163 } | 156 } |
164 | 157 |
165 private: | 158 private: |
166 #if defined OS_CHROMEOS | 159 #if defined OS_CHROMEOS |
167 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 160 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
168 chromeos::ScopedTestCrosSettings test_cros_settings_; | 161 chromeos::ScopedTestCrosSettings test_cros_settings_; |
169 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | |
170 #endif | 162 #endif |
171 | 163 |
172 ActivityDatabaseTestPolicy* db_delegate_; | 164 ActivityDatabaseTestPolicy* db_delegate_; |
173 }; | 165 }; |
174 | 166 |
175 // Check that the database is initialized properly. | 167 // Check that the database is initialized properly. |
176 TEST_F(ActivityDatabaseTest, Init) { | 168 TEST_F(ActivityDatabaseTest, Init) { |
177 base::ScopedTempDir temp_dir; | 169 base::ScopedTempDir temp_dir; |
178 base::FilePath db_file; | 170 base::FilePath db_file; |
179 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); | 171 ASSERT_TRUE(temp_dir.CreateUniqueTempDir()); |
(...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
281 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); | 273 ActivityDatabaseTestPolicy* delegate = new ActivityDatabaseTestPolicy(); |
282 ActivityDatabase* activity_db = new ActivityDatabase(delegate); | 274 ActivityDatabase* activity_db = new ActivityDatabase(delegate); |
283 scoped_refptr<Action> action = new Action( | 275 scoped_refptr<Action> action = new Action( |
284 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); | 276 "punky", base::Time::Now(), Action::ACTION_API_CALL, "brewster"); |
285 action->mutable_args()->AppendString("woof"); | 277 action->mutable_args()->AppendString("woof"); |
286 delegate->Record(activity_db, action); | 278 delegate->Record(activity_db, action); |
287 activity_db->Close(); | 279 activity_db->Close(); |
288 } | 280 } |
289 | 281 |
290 } // namespace extensions | 282 } // namespace extensions |
OLD | NEW |