| 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" |
| 11 #include "chrome/browser/extensions/activity_log/dom_actions.h" | 11 #include "chrome/browser/extensions/activity_log/dom_actions.h" |
| 12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
| 13 #include "chrome/browser/extensions/test_extension_system.h" | 13 #include "chrome/browser/extensions/test_extension_system.h" |
| 14 #include "chrome/common/chrome_constants.h" | 14 #include "chrome/common/chrome_constants.h" |
| 15 #include "chrome/common/chrome_switches.h" | 15 #include "chrome/common/chrome_switches.h" |
| 16 #include "chrome/common/extensions/dom_action_types.h" | 16 #include "chrome/common/extensions/dom_action_types.h" |
| 17 #include "chrome/common/extensions/extension_builder.h" | 17 #include "chrome/common/extensions/extension_builder.h" |
| 18 #include "chrome/test/base/testing_profile.h" | 18 #include "chrome/test/base/testing_profile.h" |
| 19 #include "content/public/browser/browser_thread.h" | 19 #include "content/public/test/test_browser_thread_bundle.h" |
| 20 #include "content/public/test/test_browser_thread.h" | |
| 21 #include "sql/statement.h" | 20 #include "sql/statement.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" | 21 #include "testing/gtest/include/gtest/gtest.h" |
| 23 | 22 |
| 24 #if defined(OS_CHROMEOS) | 23 #if defined(OS_CHROMEOS) |
| 25 #include "chrome/browser/chromeos/login/user_manager.h" | 24 #include "chrome/browser/chromeos/login/user_manager.h" |
| 26 #include "chrome/browser/chromeos/settings/cros_settings.h" | 25 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 27 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 28 #endif | 27 #endif |
| 29 | 28 |
| 30 namespace { | 29 namespace { |
| 31 | 30 |
| 32 const char kExtensionId[] = "abc"; | 31 const char kExtensionId[] = "abc"; |
| 33 | 32 |
| 34 } // namespace | 33 } // namespace |
| 35 | 34 |
| 36 namespace extensions { | 35 namespace extensions { |
| 37 | 36 |
| 38 class ActivityLogTest : public testing::Test { | 37 class ActivityLogTest : public testing::Test { |
| 39 public: | 38 protected: |
| 40 ActivityLogTest() | 39 ActivityLogTest() |
| 41 : message_loop_(base::MessageLoop::TYPE_IO), | 40 : thread_bundle_(content::TestBrowserThreadBundle::IO_MAINLOOP) { |
| 42 ui_thread_(BrowserThread::UI, &message_loop_), | 41 #if defined OS_CHROMEOS |
| 43 db_thread_(BrowserThread::DB, &message_loop_), | 42 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 44 file_thread_(BrowserThread::FILE, &message_loop_), | 43 #endif |
| 45 io_thread_(BrowserThread::IO, &message_loop_) {} | |
| 46 | |
| 47 virtual void SetUp() OVERRIDE { | |
| 48 CommandLine command_line(CommandLine::NO_PROGRAM); | 44 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 49 profile_.reset(new TestingProfile()); | 45 profile_.reset(new TestingProfile()); |
| 50 CommandLine::ForCurrentProcess()->AppendSwitch( | 46 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 51 switches::kEnableExtensionActivityLogging); | 47 switches::kEnableExtensionActivityLogging); |
| 52 CommandLine::ForCurrentProcess()->AppendSwitch( | 48 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 53 switches::kEnableExtensionActivityLogTesting); | 49 switches::kEnableExtensionActivityLogTesting); |
| 54 ActivityLog::RecomputeLoggingIsEnabled(); | 50 ActivityLog::RecomputeLoggingIsEnabled(); |
| 55 extension_service_ = static_cast<TestExtensionSystem*>( | 51 extension_service_ = static_cast<TestExtensionSystem*>( |
| 56 ExtensionSystem::Get(profile_.get()))->CreateExtensionService( | 52 ExtensionSystem::Get(profile_.get()))->CreateExtensionService( |
| 57 &command_line, base::FilePath(), false); | 53 &command_line, base::FilePath(), false); |
| 58 } | 54 } |
| 59 | 55 |
| 60 virtual void TearDown() OVERRIDE { | 56 virtual ~ActivityLogTest() { |
| 57 #if defined OS_CHROMEOS |
| 58 test_user_manager_.reset(); |
| 59 #endif |
| 61 base::RunLoop().RunUntilIdle(); | 60 base::RunLoop().RunUntilIdle(); |
| 62 profile_.reset(NULL); | 61 profile_.reset(NULL); |
| 63 base::MessageLoop::current()->PostDelayedTask( | |
| 64 FROM_HERE, | |
| 65 base::MessageLoop::QuitClosure(), | |
| 66 base::TimeDelta::FromSeconds(4)); // Don't hang on failure. | |
| 67 base::RunLoop().RunUntilIdle(); | |
| 68 } | 62 } |
| 69 | 63 |
| 70 static void RetrieveActions_LogAndFetchActions( | 64 static void RetrieveActions_LogAndFetchActions( |
| 71 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 65 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 72 ASSERT_EQ(2, static_cast<int>(i->size())); | 66 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 73 } | 67 } |
| 74 | 68 |
| 75 static void Arguments_Missing( | 69 static void Arguments_Missing( |
| 76 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 77 scoped_refptr<Action> last = i->front(); | 71 scoped_refptr<Action> last = i->front(); |
| 78 std::string id(kExtensionId); | 72 std::string id(kExtensionId); |
| 79 std::string noargs = "ID: " + id + ", CATEGORY: " | 73 std::string noargs = "ID: " + id + ", CATEGORY: " |
| 80 "CALL, API: tabs.testMethod, ARGS: "; | 74 "CALL, API: tabs.testMethod, ARGS: "; |
| 81 ASSERT_EQ(noargs, last->PrintForDebug()); | 75 ASSERT_EQ(noargs, last->PrintForDebug()); |
| 82 } | 76 } |
| 83 | 77 |
| 84 static void Arguments_Present( | 78 static void Arguments_Present( |
| 85 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 79 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 86 scoped_refptr<Action> last = i->front(); | 80 scoped_refptr<Action> last = i->front(); |
| 87 std::string id(kExtensionId); | 81 std::string id(kExtensionId); |
| 88 std::string args = "ID: " + id + ", CATEGORY: " | 82 std::string args = "ID: " + id + ", CATEGORY: " |
| 89 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; | 83 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; |
| 90 ASSERT_EQ(args, last->PrintForDebug()); | 84 ASSERT_EQ(args, last->PrintForDebug()); |
| 91 } | 85 } |
| 92 | 86 |
| 93 protected: | 87 protected: |
| 94 scoped_ptr<TestingProfile> profile_; | 88 scoped_ptr<TestingProfile> profile_; |
| 95 ExtensionService* extension_service_; | 89 ExtensionService* extension_service_; |
| 96 | 90 |
| 97 private: | 91 content::TestBrowserThreadBundle thread_bundle_; |
| 98 base::MessageLoop message_loop_; | |
| 99 content::TestBrowserThread ui_thread_; | |
| 100 content::TestBrowserThread db_thread_; | |
| 101 content::TestBrowserThread file_thread_; | |
| 102 content::TestBrowserThread io_thread_; | |
| 103 | |
| 104 #if defined OS_CHROMEOS | 92 #if defined OS_CHROMEOS |
| 105 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 93 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 106 chromeos::ScopedTestCrosSettings test_cros_settings_; | 94 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 107 chromeos::ScopedTestUserManager test_user_manager_; | 95 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 108 #endif | 96 #endif |
| 109 }; | 97 }; |
| 110 | 98 |
| 111 TEST_F(ActivityLogTest, Enabled) { | 99 TEST_F(ActivityLogTest, Enabled) { |
| 112 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 100 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 113 } | 101 } |
| 114 | 102 |
| 115 TEST_F(ActivityLogTest, Construct) { | 103 TEST_F(ActivityLogTest, Construct) { |
| 116 scoped_refptr<const Extension> extension = | 104 scoped_refptr<const Extension> extension = |
| 117 ExtensionBuilder() | 105 ExtensionBuilder() |
| (...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 181 activity_log->LogAPIAction(kExtensionId, | 169 activity_log->LogAPIAction(kExtensionId, |
| 182 std::string("extension.connect"), | 170 std::string("extension.connect"), |
| 183 args.get(), | 171 args.get(), |
| 184 std::string()); | 172 std::string()); |
| 185 activity_log->GetActions( | 173 activity_log->GetActions( |
| 186 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); | 174 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); |
| 187 } | 175 } |
| 188 | 176 |
| 189 } // namespace extensions | 177 } // namespace extensions |
| 190 | 178 |
| OLD | NEW |