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 16 matching lines...) Expand all Loading... |
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) | 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" | 37 #include "chrome/browser/chromeos/settings/cros_settings.h" |
39 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 38 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
40 #endif | 39 #endif |
41 | 40 |
42 namespace { | 41 namespace { |
43 | 42 |
44 const char kExtensionId[] = "abc"; | 43 const char kExtensionId[] = "abc"; |
45 | 44 |
46 const char* const kUrlApiCalls[] = { | 45 const char* const kUrlApiCalls[] = { |
47 "HTMLButtonElement.formAction", "HTMLEmbedElement.src", | 46 "HTMLButtonElement.formAction", "HTMLEmbedElement.src", |
(...skipping 10 matching lines...) Expand all Loading... |
58 | 57 |
59 } // namespace | 58 } // namespace |
60 | 59 |
61 namespace extensions { | 60 namespace extensions { |
62 | 61 |
63 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 62 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
64 protected: | 63 protected: |
65 virtual bool enable_activity_logging_switch() const { return true; } | 64 virtual bool enable_activity_logging_switch() const { return true; } |
66 void SetUp() override { | 65 void SetUp() override { |
67 ChromeRenderViewHostTestHarness::SetUp(); | 66 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); | 67 base::CommandLine command_line(base::CommandLine::NO_PROGRAM); |
72 if (enable_activity_logging_switch()) { | 68 if (enable_activity_logging_switch()) { |
73 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 69 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
74 switches::kEnableExtensionActivityLogging); | 70 switches::kEnableExtensionActivityLogging); |
75 } | 71 } |
76 base::CommandLine::ForCurrentProcess()->AppendSwitch( | 72 base::CommandLine::ForCurrentProcess()->AppendSwitch( |
77 switches::kEnableExtensionActivityLogTesting); | 73 switches::kEnableExtensionActivityLogTesting); |
78 extension_service_ = static_cast<TestExtensionSystem*>( | 74 extension_service_ = static_cast<TestExtensionSystem*>( |
79 ExtensionSystem::Get(profile()))->CreateExtensionService | 75 ExtensionSystem::Get(profile()))->CreateExtensionService |
80 (&command_line, base::FilePath(), false); | 76 (&command_line, base::FilePath(), false); |
81 base::RunLoop().RunUntilIdle(); | 77 base::RunLoop().RunUntilIdle(); |
82 } | 78 } |
83 | 79 |
84 void TearDown() override { | 80 void TearDown() override { |
85 #if defined OS_CHROMEOS | |
86 test_user_manager_.reset(); | |
87 #endif | |
88 base::RunLoop().RunUntilIdle(); | 81 base::RunLoop().RunUntilIdle(); |
89 ChromeRenderViewHostTestHarness::TearDown(); | 82 ChromeRenderViewHostTestHarness::TearDown(); |
90 } | 83 } |
91 | 84 |
92 static void RetrieveActions_LogAndFetchActions0( | 85 static void RetrieveActions_LogAndFetchActions0( |
93 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { | 86 std::unique_ptr<std::vector<scoped_refptr<Action>>> i) { |
94 ASSERT_EQ(0, static_cast<int>(i->size())); | 87 ASSERT_EQ(0, static_cast<int>(i->size())); |
95 } | 88 } |
96 | 89 |
97 static void RetrieveActions_LogAndFetchActions2( | 90 static void RetrieveActions_LogAndFetchActions2( |
(...skipping 97 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
195 other->GetInteger(activity_log_constants::kActionDomVerb, &dom_verb)); | 188 other->GetInteger(activity_log_constants::kActionDomVerb, &dom_verb)); |
196 ASSERT_EQ(DomActionType::SETTER, dom_verb); | 189 ASSERT_EQ(DomActionType::SETTER, dom_verb); |
197 } | 190 } |
198 } | 191 } |
199 | 192 |
200 ExtensionService* extension_service_; | 193 ExtensionService* extension_service_; |
201 | 194 |
202 #if defined OS_CHROMEOS | 195 #if defined OS_CHROMEOS |
203 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 196 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
204 chromeos::ScopedTestCrosSettings test_cros_settings_; | 197 chromeos::ScopedTestCrosSettings test_cros_settings_; |
205 std::unique_ptr<chromeos::ScopedTestUserManager> test_user_manager_; | |
206 #endif | 198 #endif |
207 }; | 199 }; |
208 | 200 |
209 TEST_F(ActivityLogTest, Construct) { | 201 TEST_F(ActivityLogTest, Construct) { |
210 ASSERT_TRUE(GetDatabaseEnabled()); | 202 ASSERT_TRUE(GetDatabaseEnabled()); |
211 ASSERT_FALSE(GetWatchdogActive()); | 203 ASSERT_FALSE(GetWatchdogActive()); |
212 } | 204 } |
213 | 205 |
214 TEST_F(ActivityLogTest, LogAndFetchActions) { | 206 TEST_F(ActivityLogTest, LogAndFetchActions) { |
215 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); | 207 ActivityLog* activity_log = ActivityLog::GetInstance(profile()); |
(...skipping 231 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); | 439 EXPECT_TRUE(activity_log->ShouldLog(empty_extension->id())); |
448 // ... but not those of the watchdog app. | 440 // ... but not those of the watchdog app. |
449 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); | 441 EXPECT_FALSE(activity_log->ShouldLog(activity_log_extension->id())); |
450 extension_service_->DisableExtension(activity_log_extension->id(), | 442 extension_service_->DisableExtension(activity_log_extension->id(), |
451 Extension::DISABLE_USER_ACTION); | 443 Extension::DISABLE_USER_ACTION); |
452 // Disabling the watchdog app means that we're back to never logging anything. | 444 // Disabling the watchdog app means that we're back to never logging anything. |
453 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); | 445 EXPECT_FALSE(activity_log->ShouldLog(empty_extension->id())); |
454 } | 446 } |
455 | 447 |
456 } // namespace extensions | 448 } // namespace extensions |
OLD | NEW |