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 // TODO(felt): Reinstate this when I'm done testing this issue! |
66 ActivityLog::RecomputeLoggingIsEnabled(); | 63 //*CommandLine::ForCurrentProcess() = saved_cmdline_; |
| 64 //ActivityLog::RecomputeLoggingIsEnabled(); |
67 } | 65 } |
68 | 66 |
69 static void RetrieveActions_LogAndFetchActions( | 67 static void RetrieveActions_LogAndFetchActions( |
70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 68 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
71 ASSERT_EQ(2, static_cast<int>(i->size())); | 69 ASSERT_EQ(2, static_cast<int>(i->size())); |
72 } | 70 } |
73 | 71 |
74 static void Arguments_Missing( | 72 static void Arguments_Missing( |
75 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 73 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
76 scoped_refptr<Action> last = i->front(); | 74 scoped_refptr<Action> last = i->front(); |
(...skipping 29 matching lines...) Expand all Loading... |
106 chromeos::ScopedTestCrosSettings test_cros_settings_; | 104 chromeos::ScopedTestCrosSettings test_cros_settings_; |
107 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | 105 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
108 #endif | 106 #endif |
109 }; | 107 }; |
110 | 108 |
111 TEST_F(ActivityLogTest, Enabled) { | 109 TEST_F(ActivityLogTest, Enabled) { |
112 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 110 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
113 } | 111 } |
114 | 112 |
115 TEST_F(ActivityLogTest, Construct) { | 113 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()); | 114 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
125 scoped_ptr<ListValue> args(new ListValue()); | 115 scoped_ptr<ListValue> args(new ListValue()); |
126 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 116 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
127 activity_log->LogAPIAction( | 117 activity_log->LogAPIAction( |
128 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 118 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
129 } | 119 } |
130 | 120 |
131 TEST_F(ActivityLogTest, LogAndFetchActions) { | 121 TEST_F(ActivityLogTest, LogAndFetchActions) { |
132 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); | 122 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
133 scoped_ptr<ListValue> args(new ListValue()); | 123 scoped_ptr<ListValue> args(new ListValue()); |
(...skipping 23 matching lines...) Expand all Loading... |
157 scoped_ptr<ListValue> args(new ListValue()); | 147 scoped_ptr<ListValue> args(new ListValue()); |
158 args->Set(0, new base::StringValue("hello")); | 148 args->Set(0, new base::StringValue("hello")); |
159 args->Set(1, new base::StringValue("world")); | 149 args->Set(1, new base::StringValue("world")); |
160 activity_log->LogAPIAction( | 150 activity_log->LogAPIAction( |
161 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); | 151 kExtensionId, std::string("tabs.testMethod"), args.get(), std::string()); |
162 activity_log->GetActions( | 152 activity_log->GetActions( |
163 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); | 153 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Missing)); |
164 } | 154 } |
165 | 155 |
166 TEST_F(ActivityLogTest, LogWithArguments) { | 156 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()); | 157 ActivityLog* activity_log = ActivityLog::GetInstance(profile_.get()); |
176 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 158 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
177 | 159 |
178 scoped_ptr<ListValue> args(new ListValue()); | 160 scoped_ptr<ListValue> args(new ListValue()); |
179 args->Set(0, new base::StringValue("hello")); | 161 args->Set(0, new base::StringValue("hello")); |
180 args->Set(1, new base::StringValue("world")); | 162 args->Set(1, new base::StringValue("world")); |
181 activity_log->LogAPIAction(kExtensionId, | 163 activity_log->LogAPIAction(kExtensionId, |
182 std::string("extension.connect"), | 164 std::string("extension.connect"), |
183 args.get(), | 165 args.get(), |
184 std::string()); | 166 std::string()); |
185 activity_log->GetActions( | 167 activity_log->GetActions( |
186 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); | 168 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); |
187 } | 169 } |
188 | 170 |
189 } // namespace extensions | 171 } // namespace extensions |
190 | 172 |
OLD | NEW |