| 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/message_loop.h" | 7 #include "base/message_loop/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 45 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 56 } | 56 } |
| 57 | 57 |
| 58 virtual void TearDown() OVERRIDE { | 58 virtual void TearDown() OVERRIDE { |
| 59 #if defined OS_CHROMEOS | 59 #if defined OS_CHROMEOS |
| 60 test_user_manager_.reset(); | 60 test_user_manager_.reset(); |
| 61 #endif | 61 #endif |
| 62 base::RunLoop().RunUntilIdle(); | 62 base::RunLoop().RunUntilIdle(); |
| 63 ChromeRenderViewHostTestHarness::TearDown(); | 63 ChromeRenderViewHostTestHarness::TearDown(); |
| 64 } | 64 } |
| 65 | 65 |
| 66 static void RetrieveActions_LogAndFetchActions( | 66 static void RetrieveActions_LogAndFetchActions0( |
| 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 68 ASSERT_EQ(0, static_cast<int>(i->size())); |
| 69 } |
| 70 |
| 71 static void RetrieveActions_LogAndFetchActions2( |
| 67 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 72 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 68 ASSERT_EQ(2, static_cast<int>(i->size())); | 73 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 69 } | 74 } |
| 70 | 75 |
| 71 void SetPolicy(bool log_arguments) { | 76 void SetPolicy(bool log_arguments) { |
| 72 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 77 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 73 if (log_arguments) | 78 if (log_arguments) |
| 74 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); | 79 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_FULLSTREAM); |
| 75 else | 80 else |
| 76 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_COUNTS); | 81 activity_log->SetDefaultPolicy(ActivityLogPolicy::POLICY_COUNTS); |
| (...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 135 action->set_page_url(GURL("http://www.google.com")); | 140 action->set_page_url(GURL("http://www.google.com")); |
| 136 activity_log->LogAction(action); | 141 activity_log->LogAction(action); |
| 137 | 142 |
| 138 activity_log->GetFilteredActions( | 143 activity_log->GetFilteredActions( |
| 139 kExtensionId, | 144 kExtensionId, |
| 140 Action::ACTION_ANY, | 145 Action::ACTION_ANY, |
| 141 "", | 146 "", |
| 142 "", | 147 "", |
| 143 "", | 148 "", |
| 144 0, | 149 0, |
| 145 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions)); | 150 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions2)); |
| 146 } | 151 } |
| 147 | 152 |
| 148 TEST_F(ActivityLogTest, LogPrerender) { | 153 TEST_F(ActivityLogTest, LogPrerender) { |
| 149 scoped_refptr<const Extension> extension = | 154 scoped_refptr<const Extension> extension = |
| 150 ExtensionBuilder() | 155 ExtensionBuilder() |
| 151 .SetManifest(DictionaryBuilder() | 156 .SetManifest(DictionaryBuilder() |
| 152 .Set("name", "Test extension") | 157 .Set("name", "Test extension") |
| 153 .Set("version", "1.0.0") | 158 .Set("version", "1.0.0") |
| 154 .Set("manifest_version", 2)) | 159 .Set("manifest_version", 2)) |
| 155 .Build(); | 160 .Build(); |
| (...skipping 30 matching lines...) Expand all Loading... |
| 186 Action::ACTION_ANY, | 191 Action::ACTION_ANY, |
| 187 "", | 192 "", |
| 188 "", | 193 "", |
| 189 "", | 194 "", |
| 190 0, | 195 0, |
| 191 base::Bind(ActivityLogTest::Arguments_Prerender)); | 196 base::Bind(ActivityLogTest::Arguments_Prerender)); |
| 192 | 197 |
| 193 prerender_manager->CancelAllPrerenders(); | 198 prerender_manager->CancelAllPrerenders(); |
| 194 } | 199 } |
| 195 | 200 |
| 201 TEST_F(ActivityLogTest, UninstalledExtension) { |
| 202 scoped_refptr<const Extension> extension = |
| 203 ExtensionBuilder() |
| 204 .SetManifest(DictionaryBuilder() |
| 205 .Set("name", "Test extension") |
| 206 .Set("version", "1.0.0") |
| 207 .Set("manifest_version", 2)) |
| 208 .Build(); |
| 209 |
| 210 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 211 scoped_ptr<base::ListValue> args(new base::ListValue()); |
| 212 ASSERT_TRUE(GetDatabaseEnabled()); |
| 213 |
| 214 // Write some API calls |
| 215 scoped_refptr<Action> action = new Action(extension->id(), |
| 216 base::Time::Now(), |
| 217 Action::ACTION_API_CALL, |
| 218 "tabs.testMethod"); |
| 219 activity_log->LogAction(action); |
| 220 action = new Action(extension->id(), |
| 221 base::Time::Now(), |
| 222 Action::ACTION_DOM_ACCESS, |
| 223 "document.write"); |
| 224 action->set_page_url(GURL("http://www.google.com")); |
| 225 |
| 226 activity_log->OnExtensionUninstalled(extension); |
| 227 |
| 228 activity_log->GetFilteredActions( |
| 229 extension->id(), |
| 230 Action::ACTION_ANY, |
| 231 "", |
| 232 "", |
| 233 "", |
| 234 0, |
| 235 base::Bind(ActivityLogTest::RetrieveActions_LogAndFetchActions0)); |
| 236 } |
| 237 |
| 196 } // namespace extensions | 238 } // namespace extensions |
| OLD | NEW |