| 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 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 43 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 43 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 44 #endif | 44 #endif |
| 45 CommandLine command_line(CommandLine::NO_PROGRAM); | 45 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 46 saved_cmdline_ = *CommandLine::ForCurrentProcess(); | 46 saved_cmdline_ = *CommandLine::ForCurrentProcess(); |
| 47 profile_.reset(new TestingProfile()); | 47 profile_.reset(new TestingProfile()); |
| 48 CommandLine::ForCurrentProcess()->AppendSwitch( | 48 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 49 switches::kEnableExtensionActivityLogging); | 49 switches::kEnableExtensionActivityLogging); |
| 50 CommandLine::ForCurrentProcess()->AppendSwitch( | 50 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 51 switches::kEnableExtensionActivityLogTesting); | 51 switches::kEnableExtensionActivityLogTesting); |
| 52 ActivityLog::RecomputeLoggingIsEnabled(); | 52 ActivityLog::RecomputeLoggingIsEnabled(); |
| 53 extension_service_ = static_cast<TestExtensionSystem*>( | |
| 54 ExtensionSystem::Get(profile_.get()))->CreateExtensionService( | |
| 55 &command_line, base::FilePath(), false); | |
| 56 } | 53 } |
| 57 | 54 |
| 58 virtual ~ActivityLogTest() { | 55 virtual ~ActivityLogTest() { |
| 59 #if defined OS_CHROMEOS | 56 #if defined OS_CHROMEOS |
| 60 test_user_manager_.reset(); | 57 test_user_manager_.reset(); |
| 61 #endif | 58 #endif |
| 62 base::RunLoop().RunUntilIdle(); | 59 base::RunLoop().RunUntilIdle(); |
| 63 profile_.reset(NULL); | 60 profile_.reset(NULL); |
| 64 // Restore the original command line and undo the affects of SetUp(). | 61 // Restore the original command line and undo the affects of SetUp(). |
| 65 *CommandLine::ForCurrentProcess() = saved_cmdline_; | 62 *CommandLine::ForCurrentProcess() = saved_cmdline_; |
| (...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 106 chromeos::ScopedTestCrosSettings test_cros_settings_; | 103 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 107 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 104 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 108 #endif | 105 #endif |
| 109 }; | 106 }; |
| 110 | 107 |
| 111 TEST_F(ActivityLogTest, Enabled) { | 108 TEST_F(ActivityLogTest, Enabled) { |
| 112 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 109 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 113 } | 110 } |
| 114 | 111 |
| 115 TEST_F(ActivityLogTest, Construct) { | 112 TEST_F(ActivityLogTest, Construct) { |
| 116 scoped_refptr<const Extension> extension = | |
| 117 ExtensionBuilder() | |
| 118 .SetManifest(DictionaryBuilder() | |
| 119 .Set("name", "Test extension") | |
| 120 .Set("version", "1.0.0") | |
| 121 .Set("manifest_version", 2)) | |
| 122 .Build(); | |
| 123 extension_service_->AddExtension(extension); | |
| 124 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 113 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
| 125 scoped_ptr<ListValue> args(new ListValue()); | 114 scoped_ptr<ListValue> args(new ListValue()); |
| 126 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 115 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 127 activity_log->LogAPIAction( | 116 activity_log->LogAPIAction( |
| 128 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 117 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
| 129 } | 118 } |
| 130 | 119 |
| 131 TEST_F(ActivityLogTest, LogAndFetchActions) { | 120 TEST_F(ActivityLogTest, LogAndFetchActions) { |
| 132 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 121 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
| 133 scoped_ptr<ListValue> args(new ListValue()); | 122 scoped_ptr<ListValue> args(new ListValue()); |
| (...skipping 23 matching lines...) Expand all Loading... |
| 157 scoped_ptr<ListValue> args(new ListValue()); | 146 scoped_ptr<ListValue> args(new ListValue()); |
| 158 args->Set(0, new base::StringValue("hello")); | 147 args->Set(0, new base::StringValue("hello")); |
| 159 args->Set(1, new base::StringValue("world")); | 148 args->Set(1, new base::StringValue("world")); |
| 160 activity_log->LogAPIAction( | 149 activity_log->LogAPIAction( |
| 161 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 150 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
| 162 activity_log->GetActions( | 151 activity_log->GetActions( |
| 163 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); | 152 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); |
| 164 } | 153 } |
| 165 | 154 |
| 166 TEST_F(ActivityLogTest, LogWithArguments) { | 155 TEST_F(ActivityLogTest, LogWithArguments) { |
| 167 scoped_refptr<const Extension> extension = | |
| 168 ExtensionBuilder() | |
| 169 .SetManifest(DictionaryBuilder() | |
| 170 .Set("name", "Test extension") | |
| 171 .Set("version", "1.0.0") | |
| 172 .Set("manifest_version", 2)) | |
| 173 .Build(); | |
| 174 extension_service_->AddExtension(extension); | |
| 175 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 156 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
| 176 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 157 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 177 | 158 |
| 178 scoped_ptr<ListValue> args(new ListValue()); | 159 scoped_ptr<ListValue> args(new ListValue()); |
| 179 args->Set(0, new base::StringValue("hello")); | 160 args->Set(0, new base::StringValue("hello")); |
| 180 args->Set(1, new base::StringValue("world")); | 161 args->Set(1, new base::StringValue("world")); |
| 181 activity_log->LogAPIAction(kExtensionId, | 162 activity_log->LogAPIAction(kExtensionId, |
| 182 std::string("extension.connect"), | 163 std::string("extension.connect"), |
| 183 args.get(), | 164 args.get(), |
| 184 std::string()); | 165 std::string()); |
| 185 activity_log->GetActions( | 166 activity_log->GetActions( |
| 186 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); | 167 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); |
| 187 } | 168 } |
| 188 | 169 |
| 189 } // namespace extensions | 170 } // namespace extensions |
| 190 | 171 |
| OLD | NEW |