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 "base/command_line.h" | 5 #include "base/command_line.h" |
6 #include "base/memory/scoped_ptr.h" | 6 #include "base/memory/scoped_ptr.h" |
7 #include "base/message_loop.h" | 7 #include "base/message_loop.h" |
8 #include "base/run_loop.h" | 8 #include "base/run_loop.h" |
9 #include "base/synchronization/waitable_event.h" | 9 #include "base/synchronization/waitable_event.h" |
10 #include "chrome/browser/extensions/activity_log/activity_log.h" | 10 #include "chrome/browser/extensions/activity_log/activity_log.h" |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
50 saved_cmdline_ = *CommandLine::ForCurrentProcess(); | 50 saved_cmdline_ = *CommandLine::ForCurrentProcess(); |
51 profile_.reset(new TestingProfile()); | 51 profile_.reset(new TestingProfile()); |
52 CommandLine::ForCurrentProcess()->AppendSwitch( | 52 CommandLine::ForCurrentProcess()->AppendSwitch( |
53 switches::kEnableExtensionActivityLogging); | 53 switches::kEnableExtensionActivityLogging); |
54 CommandLine::ForCurrentProcess()->AppendSwitch( | 54 CommandLine::ForCurrentProcess()->AppendSwitch( |
55 switches::kEnableExtensionActivityLogTesting); | 55 switches::kEnableExtensionActivityLogTesting); |
56 extension_service_ = static_cast<TestExtensionSystem*>( | 56 extension_service_ = static_cast<TestExtensionSystem*>( |
57 ExtensionSystem::Get(profile_.get()))->CreateExtensionService | 57 ExtensionSystem::Get(profile_.get()))->CreateExtensionService |
58 (&command_line, base::FilePath(), false); | 58 (&command_line, base::FilePath(), false); |
59 ActivityLog::RecomputeLoggingIsEnabled(false); | 59 ActivityLog::RecomputeLoggingIsEnabled(false); |
| 60 extension_service_ = static_cast<TestExtensionSystem*>( |
| 61 ExtensionSystem::Get(profile_.get()))->CreateExtensionService( |
| 62 &command_line, base::FilePath(), false); |
60 } | 63 } |
61 | 64 |
62 virtual ~ActivityLogTest() { | 65 virtual ~ActivityLogTest() { |
63 #if defined OS_CHROMEOS | 66 #if defined OS_CHROMEOS |
64 test_user_manager_.reset(); | 67 test_user_manager_.reset(); |
65 #endif | 68 #endif |
66 base::RunLoop().RunUntilIdle(); | 69 base::RunLoop().RunUntilIdle(); |
67 profile_.reset(NULL); | 70 profile_.reset(NULL); |
68 base::RunLoop().RunUntilIdle(); | 71 base::RunLoop().RunUntilIdle(); |
69 // Restore the original command line and undo the affects of SetUp(). | 72 // Restore the original command line and undo the affects of SetUp(). |
(...skipping 95 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
165 chromeos::ScopedTestCrosSettings test_cros_settings_; | 168 chromeos::ScopedTestCrosSettings test_cros_settings_; |
166 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 169 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
167 #endif | 170 #endif |
168 }; | 171 }; |
169 | 172 |
170 TEST_F(ActivityLogTest, Enabled) { | 173 TEST_F(ActivityLogTest, Enabled) { |
171 ASSERT_TRUE(ActivityLog::IsLogEnabledOnAnyProfile()); | 174 ASSERT_TRUE(ActivityLog::IsLogEnabledOnAnyProfile()); |
172 } | 175 } |
173 | 176 |
174 TEST_F(ActivityLogTest, Construct) { | 177 TEST_F(ActivityLogTest, Construct) { |
| 178 scoped_refptr<const Extension> extension = |
| 179 ExtensionBuilder() |
| 180 .SetManifest(DictionaryBuilder() |
| 181 .Set("name", "Test extension") |
| 182 .Set("version", "1.0.0") |
| 183 .Set("manifest_version", 2)) |
| 184 .Build(); |
| 185 extension_service_->AddExtension(extension); |
175 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 186 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
176 scoped_ptr<ListValue> args(new ListValue()); | 187 scoped_ptr<ListValue> args(new ListValue()); |
177 ASSERT_TRUE(activity_log->IsLogEnabled()); | 188 ASSERT_TRUE(activity_log->IsLogEnabled()); |
178 activity_log->LogAPIAction( | 189 activity_log->LogAPIAction( |
179 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 190 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
180 } | 191 } |
181 | 192 |
182 TEST_F(ActivityLogTest, LogAndFetchActions) { | 193 TEST_F(ActivityLogTest, LogAndFetchActions) { |
183 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 194 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
184 scoped_ptr<ListValue> args(new ListValue()); | 195 scoped_ptr<ListValue> args(new ListValue()); |
(...skipping 23 matching lines...) Expand all Loading... |
208 scoped_ptr<ListValue> args(new ListValue()); | 219 scoped_ptr<ListValue> args(new ListValue()); |
209 args->Set(0, new base::StringValue("hello")); | 220 args->Set(0, new base::StringValue("hello")); |
210 args->Set(1, new base::StringValue("world")); | 221 args->Set(1, new base::StringValue("world")); |
211 activity_log->LogAPIAction( | 222 activity_log->LogAPIAction( |
212 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 223 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
213 activity_log->GetActions( | 224 activity_log->GetActions( |
214 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); | 225 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); |
215 } | 226 } |
216 | 227 |
217 TEST_F(ActivityLogTest, LogWithArguments) { | 228 TEST_F(ActivityLogTest, LogWithArguments) { |
| 229 scoped_refptr<const Extension> extension = |
| 230 ExtensionBuilder() |
| 231 .SetManifest(DictionaryBuilder() |
| 232 .Set("name", "Test extension") |
| 233 .Set("version", "1.0.0") |
| 234 .Set("manifest_version", 2)) |
| 235 .Build(); |
| 236 extension_service_->AddExtension(extension); |
218 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 237 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
219 ASSERT_TRUE(activity_log->IsLogEnabled()); | 238 ASSERT_TRUE(activity_log->IsLogEnabled()); |
220 | 239 |
221 scoped_ptr<ListValue> args(new ListValue()); | 240 scoped_ptr<ListValue> args(new ListValue()); |
222 args->Set(0, new base::StringValue("hello")); | 241 args->Set(0, new base::StringValue("hello")); |
223 args->Set(1, new base::StringValue("world")); | 242 args->Set(1, new base::StringValue("world")); |
224 activity_log->LogAPIAction(kExtensionId, | 243 activity_log->LogAPIAction(kExtensionId, |
225 std::string("extension.connect"), | 244 std::string("extension.connect"), |
226 args.get(), | 245 args.get(), |
227 std::string()); | 246 std::string()); |
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
267 | 286 |
268 activity_log->GetActions( | 287 activity_log->GetActions( |
269 extension->id(), 0, base::Bind( | 288 extension->id(), 0, base::Bind( |
270 RenderViewActivityLogTest::Arguments_Prerender)); | 289 RenderViewActivityLogTest::Arguments_Prerender)); |
271 | 290 |
272 prerender_manager->CancelAllPrerenders(); | 291 prerender_manager->CancelAllPrerenders(); |
273 } | 292 } |
274 | 293 |
275 } // namespace extensions | 294 } // namespace extensions |
276 | 295 |
OLD | NEW |