| 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 15 matching lines...) Expand all Loading... |
| 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 "extensions/common/test_util.h" |
| 34 #include "testing/gtest/include/gtest/gtest.h" | 34 #include "testing/gtest/include/gtest/gtest.h" |
| 35 | 35 |
| 36 #if defined(OS_CHROMEOS) | |
| 37 #include "chrome/browser/chromeos/login/users/scoped_test_user_manager.h" | |
| 38 #include "chrome/browser/chromeos/settings/cros_settings.h" | |
| 39 #include "chrome/browser/chromeos/settings/device_settings_service.h" | |
| 40 #endif | |
| 41 | |
| 42 namespace { | 36 namespace { |
| 43 | 37 |
| 44 const char kExtensionId[] = "abc"; | 38 const char kExtensionId[] = "abc"; |
| 45 | 39 |
| 46 const char* const kUrlApiCalls[] = { | 40 const char* const kUrlApiCalls[] = { |
| 47 "HTMLButtonElement.formAction", "HTMLEmbedElement.src", | 41 "HTMLButtonElement.formAction", "HTMLEmbedElement.src", |
| 48 "HTMLFormElement.action", "HTMLFrameElement.src", | 42 "HTMLFormElement.action", "HTMLFrameElement.src", |
| 49 "HTMLHtmlElement.manifest", "HTMLIFrameElement.src", | 43 "HTMLHtmlElement.manifest", "HTMLIFrameElement.src", |
| 50 "HTMLImageElement.longDesc", "HTMLImageElement.src", | 44 "HTMLImageElement.longDesc", "HTMLImageElement.src", |
| 51 "HTMLImageElement.lowsrc", "HTMLInputElement.formAction", | 45 "HTMLImageElement.lowsrc", "HTMLInputElement.formAction", |
| 52 "HTMLInputElement.src", "HTMLLinkElement.href", | 46 "HTMLInputElement.src", "HTMLLinkElement.href", |
| 53 "HTMLMediaElement.src", "HTMLMediaElement.currentSrc", | 47 "HTMLMediaElement.src", "HTMLMediaElement.currentSrc", |
| 54 "HTMLModElement.cite", "HTMLObjectElement.data", | 48 "HTMLModElement.cite", "HTMLObjectElement.data", |
| 55 "HTMLQuoteElement.cite", "HTMLScriptElement.src", | 49 "HTMLQuoteElement.cite", "HTMLScriptElement.src", |
| 56 "HTMLSourceElement.src", "HTMLTrackElement.src", | 50 "HTMLSourceElement.src", "HTMLTrackElement.src", |
| 57 "HTMLVideoElement.poster"}; | 51 "HTMLVideoElement.poster"}; |
| 58 | 52 |
| 59 } // namespace | 53 } // namespace |
| 60 | 54 |
| 61 namespace extensions { | 55 namespace extensions { |
| 62 | 56 |
| 63 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 57 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
| 64 protected: | 58 protected: |
| 65 virtual bool enable_activity_logging_switch() const { return true; } | 59 virtual bool enable_activity_logging_switch() const { return true; } |
| 66 void SetUp() override { | 60 void SetUp() override { |
| 67 ChromeRenderViewHostTestHarness::SetUp(); | 61 ChromeRenderViewHostTestHarness::SetUp(); |
| 68 #if defined OS_CHROMEOS | |
| 69 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); | |
| 70 #endif | |
| 71 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); | 62 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
| 72 if (enable_activity_logging_switch()) { | 63 if (enable_activity_logging_switch()) { |
| 73 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 64 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 74 switches::kEnableExtensionActivityLogging); | 65 switches::kEnableExtensionActivityLogging); |
| 75 } | 66 } |
| 76 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 67 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
| 77 switches::kEnableExtensionActivityLogTesting); | 68 switches::kEnableExtensionActivityLogTesting); |
| 78 extension_service_ = static_cast<TestExtensionSystem*>( | 69 extension_service_ = static_cast<TestExtensionSystem*>( |
| 79 ExtensionSystem::Get(profile()))->CreateExtensionService | 70 ExtensionSystem::Get(profile()))->CreateExtensionService |
| 80 (&command_line, base::FilePath(), false); | 71 (&command_line, base::FilePath(), false); |
| 81 base::RunLoop().RunUntilIdle(); | 72 base::RunLoop().RunUntilIdle(); |
| 82 } | 73 } |
| 83 | 74 |
| 84 void TearDown() override { | 75 void TearDown() override { |
| 85 #if defined OS_CHROMEOS | |
| 86 test_user_manager_.reset(); | |
| 87 #endif | |
| 88 base::RunLoop().RunUntilIdle(); | 76 base::RunLoop().RunUntilIdle(); |
| 89 ChromeRenderViewHostTestHarness::TearDown(); | 77 ChromeRenderViewHostTestHarness::TearDown(); |
| 90 } | 78 } |
| 91 | 79 |
| 92 static void RetrieveActions_LogAndFetchActions0( | 80 static void RetrieveActions_LogAndFetchActions0( |
| 93 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { | 81 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
| 94 ASSERT_EQ(0, static_cast<int>(i->size())); | 82 ASSERT_EQ(0, static_cast<int>(i->size())); |
| 95 } | 83 } |
| 96 | 84 |
| 97 static void RetrieveActions_LogAndFetchActions2( | 85 static void RetrieveActions_LogAndFetchActions2( |
| (...skipping 93 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 191 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); | 179 ASSERT_EQ("http://www.google.co.uk/", action->arg_url().spec()); |
| 192 other = action->other(); | 180 other = action->other(); |
| 193 ASSERT_TRUE(other); | 181 ASSERT_TRUE(other); |
| 194 ASSERT_TRUE( | 182 ASSERT_TRUE( |
| 195 other->GetInteger(activity_log_constants::kActionDomVerb, &dom_verb)); | 183 other->GetInteger(activity_log_constants::kActionDomVerb, &dom_verb)); |
| 196 ASSERT_EQ(DomActionType::SETTER, dom_verb); | 184 ASSERT_EQ(DomActionType::SETTER, dom_verb); |
| 197 } | 185 } |
| 198 } | 186 } |
| 199 | 187 |
| 200 ExtensionService* extension_service_; | 188 ExtensionService* extension_service_; |
| 201 | |
| 202 #if defined OS_CHROMEOS | |
| 203 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | |
| 204 chromeos::ScopedTestCrosSettings test_cros_settings_; | |
| 205 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | |
| 206 #endif | |
| 207 }; | 189 }; |
| 208 | 190 |
| 209 TEST_F(ActivityLogTest, Construct) { | 191 TEST_F(ActivityLogTest, Construct) { |
| 210 ASSERT_TRUE(GetDatabaseEnabled()); | 192 ASSERT_TRUE(GetDatabaseEnabled()); |
| 211 ASSERT_FALSE(GetWatchdogActive()); | 193 ASSERT_FALSE(GetWatchdogActive()); |
| 212 } | 194 } |
| 213 | 195 |
| 214 TEST_F(ActivityLogTest, LogAndFetchActions) { | 196 TEST_F(ActivityLogTest, LogAndFetchActions) { |
| 215 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 197 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
| 216 std::unique_ptr<base::ListValue> args(new base::ListValue()); | 198 std::unique_ptr<base::ListValue> args(new base::ListValue()); |
| (...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 447 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); | 429 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); |
| 448 // ... but not those of the watchdog app. | 430 // ... but not those of the watchdog app. |
| 449 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); | 431 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); |
| 450 extension_service_->DisableExtension(activity_log_extension->id(), | 432 extension_service_->DisableExtension(activity_log_extension->id(), |
| 451 Extension::DISABLE_USER_ACTION); | 433 Extension::DISABLE_USER_ACTION); |
| 452 // Disabling the watchdog app means that we're back to never logging anything. | 434 // Disabling the watchdog app means that we're back to never logging anything. |
| 453 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); | 435 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); |
| 454 } | 436 } |
| 455 | 437 |
| 456 } // namespace extensions | 438 } // namespace extensions |
| OLD | NEW |