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 "chrome/browser/extensions/activity_log/activity_log.h" | 5 #include "chrome/browser/extensions/activity_log/activity_log.h" |
6 | 6 |
7 #include <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <memory> | 9 #include <memory> |
10 | 10 |
(...skipping 12 matching lines...) Expand all Loading... |
23 #include "chrome/common/chrome_constants.h" | 23 #include "chrome/common/chrome_constants.h" |
24 #include "chrome/common/chrome_switches.h" | 24 #include "chrome/common/chrome_switches.h" |
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_bundle.h" | 28 #include "content/public/test/test_browser_thread_bundle.h" |
29 #include "extensions/browser/extension_registry.h" | 29 #include "extensions/browser/extension_registry.h" |
30 #include "extensions/browser/uninstall_reason.h" | 30 #include "extensions/browser/uninstall_reason.h" |
31 #include "extensions/common/dom_action_types.h" | 31 #include "extensions/common/dom_action_types.h" |
32 #include "extensions/common/extension_builder.h" | 32 #include "extensions/common/extension_builder.h" |
| 33 #include "extensions/common/test_util.h" |
33 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
34 | 35 |
35 #if defined(OS_CHROMEOS) | 36 #if defined(OS_CHROMEOS) |
36 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | 37 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" |
37 #include "chrome/browser/chromeos/settings/cros_settings.h" | 38 #include "chrome/browser/chromeos/settings/cros_settings.h" |
38 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 39 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
39 #endif | 40 #endif |
40 | 41 |
41 namespace { | 42 namespace { |
42 | 43 |
(...skipping 11 matching lines...) Expand all Loading... |
54 "HTMLQuoteElement.cite", "HTMLScriptElement.src", | 55 "HTMLQuoteElement.cite", "HTMLScriptElement.src", |
55 "HTMLSourceElement.src", "HTMLTrackElement.src", | 56 "HTMLSourceElement.src", "HTMLTrackElement.src", |
56 "HTMLVideoElement.poster"}; | 57 "HTMLVideoElement.poster"}; |
57 | 58 |
58 } // namespace | 59 } // namespace |
59 | 60 |
60 namespace extensions { | 61 namespace extensions { |
61 | 62 |
62 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 63 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
63 protected: | 64 protected: |
| 65 virtual bool enable_activity_logging_switch() const { return true; } |
64 void SetUp() override { | 66 void SetUp() override { |
65 ChromeRenderViewHostTestHarness::SetUp(); | 67 ChromeRenderViewHostTestHarness::SetUp(); |
66 #if defined OS_CHROMEOS | 68 #if defined OS_CHROMEOS |
67 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | 69 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
68 #endif | 70 #endif |
69 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 71 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
70 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 72 if (enable_activity_logging_switch()) { |
71 switches::kEnableExtensionActivityLogging); | 73 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 74 switches::kEnableExtensionActivityLogging); |
| 75 } |
72 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 76 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
73 switches::kEnableExtensionActivityLogTesting); | 77 switches::kEnableExtensionActivityLogTesting); |
74 extension_service_ = static_cast<TestExtensionSystem*>( | 78 extension_service_ = static_cast<TestExtensionSystem*>( |
75 ExtensionSystem::Get(profile()))->CreateExtensionService | 79 ExtensionSystem::Get(profile()))->CreateExtensionService |
76 (&command_line, base::FilePath(), false); | 80 (&command_line, base::FilePath(), false); |
77 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
78 } | 82 } |
79 | 83 |
80 void TearDown() override { | 84 void TearDown() override { |
81 #if defined OS_CHROMEOS | 85 #if defined OS_CHROMEOS |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
239 scoped_refptr<const Extension> extension = | 243 scoped_refptr<const Extension> extension = |
240 ExtensionBuilder() | 244 ExtensionBuilder() |
241 .SetManifest(DictionaryBuilder() | 245 .SetManifest(DictionaryBuilder() |
242 .Set("name", "Test extension") | 246 .Set("name", "Test extension") |
243 .Set("version", "1.0.0") | 247 .Set("version", "1.0.0") |
244 .Set("manifest_version", 2) | 248 .Set("manifest_version", 2) |
245 .Build()) | 249 .Build()) |
246 .Build(); | 250 .Build(); |
247 extension_service_->AddExtension(extension.get()); | 251 extension_service_->AddExtension(extension.get()); |
248 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 252 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 253 EXPECT_TRUE(activity_log->ShouldLog(extension->id())); |
249 ASSERT_TRUE(GetDatabaseEnabled()); | 254 ASSERT_TRUE(GetDatabaseEnabled()); |
250 GURL url("http://www.google.com"); | 255 GURL url("http://www.google.com"); |
251 | 256 |
252 prerender::PrerenderManager* prerender_manager = | 257 prerender::PrerenderManager* prerender_manager = |
253 prerender::PrerenderManagerFactory::GetForProfile( | 258 prerender::PrerenderManagerFactory::GetForProfile( |
254 Profile::FromBrowserContext(profile())); | 259 Profile::FromBrowserContext(profile())); |
255 | 260 |
256 const gfx::Size kSize(640, 480); | 261 const gfx::Size kSize(640, 480); |
257 std::unique_ptr<prerender::PrerenderHandle> prerender_handle( | 262 std::unique_ptr<prerender::PrerenderHandle> prerender_handle( |
258 prerender_manager->AddPrerenderFromOmnibox( | 263 prerender_manager->AddPrerenderFromOmnibox( |
(...skipping 26 matching lines...) Expand all Loading... |
285 } | 290 } |
286 | 291 |
287 TEST_F(ActivityLogTest, ArgUrlExtraction) { | 292 TEST_F(ActivityLogTest, ArgUrlExtraction) { |
288 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 293 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
289 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 294 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
290 | 295 |
291 base::Time now = base::Time::Now(); | 296 base::Time now = base::Time::Now(); |
292 | 297 |
293 // Submit a DOM API call which should have its URL extracted into the arg_url | 298 // Submit a DOM API call which should have its URL extracted into the arg_url |
294 // field. | 299 // field. |
| 300 EXPECT_TRUE(activity_log->ShouldLog(kExtensionId)); |
295 scoped_refptr<Action> action = new Action(kExtensionId, | 301 scoped_refptr<Action> action = new Action(kExtensionId, |
296 now, | 302 now, |
297 Action::ACTION_DOM_ACCESS, | 303 Action::ACTION_DOM_ACCESS, |
298 "XMLHttpRequest.open"); | 304 "XMLHttpRequest.open"); |
299 action->set_page_url(GURL("http://www.google.com/")); | 305 action->set_page_url(GURL("http://www.google.com/")); |
300 action->mutable_args()->AppendString("POST"); | 306 action->mutable_args()->AppendString("POST"); |
301 action->mutable_args()->AppendString("http://api.google.com/"); | 307 action->mutable_args()->AppendString("http://api.google.com/"); |
302 action->mutable_other()->SetInteger(activity_log_constants::kActionDomVerb, | 308 action->mutable_other()->SetInteger(activity_log_constants::kActionDomVerb, |
303 DomActionType::METHOD); | 309 DomActionType::METHOD); |
304 activity_log->LogAction(action); | 310 activity_log->LogAction(action); |
(...skipping 104 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
409 activity_log->GetFilteredActions( | 415 activity_log->GetFilteredActions( |
410 kExtensionId, | 416 kExtensionId, |
411 Action::ACTION_ANY, | 417 Action::ACTION_ANY, |
412 "", | 418 "", |
413 "", | 419 "", |
414 "", | 420 "", |
415 -1, | 421 -1, |
416 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlApiCalls)); | 422 base::Bind(ActivityLogTest::RetrieveActions_ArgUrlApiCalls)); |
417 } | 423 } |
418 | 424 |
| 425 class ActivityLogTestWithoutSwitch : public ActivityLogTest { |
| 426 public: |
| 427 ActivityLogTestWithoutSwitch() {} |
| 428 ~ActivityLogTestWithoutSwitch() override {} |
| 429 bool enable_activity_logging_switch() const override { return false; } |
| 430 }; |
| 431 |
| 432 TEST_F(ActivityLogTestWithoutSwitch, TestShouldLog) { |
| 433 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 434 scoped_refptr<const Extension> empty_extension = |
| 435 test_util::CreateEmptyExtension(); |
| 436 extension_service_->AddExtension(empty_extension.get()); |
| 437 // Since the command line switch for logging isn't enabled and there's no |
| 438 // watchdog app active, the activity log shouldn't log anything. |
| 439 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); |
| 440 const char kWhitelistedExtensionId[] = "eplckmlabaanikjjcgnigddmagoglhmp"; |
| 441 scoped_refptr<const Extension> activity_log_extension = |
| 442 test_util::CreateEmptyExtension(kWhitelistedExtensionId); |
| 443 extension_service_->AddExtension(activity_log_extension.get()); |
| 444 // Loading a watchdog app means the activity log should log other extension |
| 445 // activities... |
| 446 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); |
| 447 // ... but not those of the watchdog app. |
| 448 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); |
| 449 extension_service_->DisableExtension(activity_log_extension->id(), |
| 450 Extension::DISABLE_USER_ACTION); |
| 451 // Disabling the watchdog app means that we're back to never logging anything. |
| 452 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); |
| 453 } |
| 454 |
419 } // namespace extensions | 455 } // namespace extensions |
OLD | NEW |