| 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/synchronization/waitable_event.h" | 7 #include "base/synchronization/waitable_event.h" |
| 8 #include "chrome/browser/extensions/activity_log/activity_log.h" | 8 #include "chrome/browser/extensions/activity_log/activity_log.h" |
| 9 #include "chrome/browser/extensions/activity_log/dom_actions.h" | 9 #include "chrome/browser/extensions/activity_log/dom_actions.h" |
| 10 #include "chrome/browser/extensions/extension_service.h" | 10 #include "chrome/browser/extensions/extension_service.h" |
| 11 #include "chrome/browser/extensions/test_extension_system.h" | 11 #include "chrome/browser/extensions/test_extension_system.h" |
| 12 #include "chrome/common/chrome_constants.h" | 12 #include "chrome/common/chrome_constants.h" |
| 13 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
| 14 #include "chrome/common/extensions/dom_action_types.h" | 14 #include "chrome/common/extensions/dom_action_types.h" |
| 15 #include "chrome/common/extensions/extension_builder.h" | 15 #include "chrome/common/extensions/extension_builder.h" |
| 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" | 16 #include "chrome/test/base/chrome_render_view_host_test_harness.h" |
| 17 #include "chrome/test/base/testing_profile.h" | 17 #include "chrome/test/base/testing_profile.h" |
| 18 #include "content/public/browser/browser_thread.h" | 18 #include "content/public/browser/browser_thread.h" |
| 19 #include "content/public/test/test_browser_thread.h" | |
| 20 #include "sql/statement.h" | 19 #include "sql/statement.h" |
| 21 #include "testing/gtest/include/gtest/gtest.h" | 20 #include "testing/gtest/include/gtest/gtest.h" |
| 22 | 21 |
| 23 #if defined(OS_CHROMEOS) | 22 #if defined(OS_CHROMEOS) |
| 24 #include "chrome/browser/chromeos/login/user_manager.h" | 23 #include "chrome/browser/chromeos/login/user_manager.h" |
| 25 #include "chrome/browser/chromeos/settings/cros_settings.h" | 24 #include "chrome/browser/chromeos/settings/cros_settings.h" |
| 26 #include "chrome/browser/chromeos/settings/device_settings_service.h" | 25 #include "chrome/browser/chromeos/settings/device_settings_service.h" |
| 27 #endif | 26 #endif |
| 28 | 27 |
| 29 namespace extensions { | 28 namespace extensions { |
| 30 | 29 |
| 31 class ActivityLogTest : public ChromeRenderViewHostTestHarness { | 30 class ActivityLogTest : public ChromeRenderViewHostTestHarness { |
| 32 public: | 31 public: |
| 33 ActivityLogTest() | |
| 34 : ui_thread_(BrowserThread::UI, base::MessageLoop::current()), | |
| 35 db_thread_(BrowserThread::DB, base::MessageLoop::current()), | |
| 36 file_thread_(BrowserThread::FILE, base::MessageLoop::current()) {} | |
| 37 | |
| 38 virtual void SetUp() OVERRIDE { | 32 virtual void SetUp() OVERRIDE { |
| 39 ChromeRenderViewHostTestHarness::SetUp(); | 33 ChromeRenderViewHostTestHarness::SetUp(); |
| 34 #if defined OS_CHROMEOS |
| 35 test_user_manager_.reset(new chromeos::ScopedTestUserManager()); |
| 36 #endif |
| 40 CommandLine command_line(CommandLine::NO_PROGRAM); | 37 CommandLine command_line(CommandLine::NO_PROGRAM); |
| 41 profile_ = | 38 profile_ = |
| 42 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); | 39 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); |
| 43 extension_service_ = static_cast<TestExtensionSystem*>( | 40 extension_service_ = static_cast<TestExtensionSystem*>( |
| 44 ExtensionSystem::Get(profile_))->CreateExtensionService( | 41 ExtensionSystem::Get(profile_))->CreateExtensionService( |
| 45 &command_line, base::FilePath(), false); | 42 &command_line, base::FilePath(), false); |
| 46 CommandLine::ForCurrentProcess()->AppendSwitch( | 43 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 47 switches::kEnableExtensionActivityLogging); | 44 switches::kEnableExtensionActivityLogging); |
| 48 CommandLine::ForCurrentProcess()->AppendSwitch( | 45 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 49 switches::kEnableExtensionActivityLogTesting); | 46 switches::kEnableExtensionActivityLogTesting); |
| 50 ActivityLog::RecomputeLoggingIsEnabled(); | 47 ActivityLog::RecomputeLoggingIsEnabled(); |
| 51 } | 48 } |
| 52 | 49 |
| 53 virtual ~ActivityLogTest() { | 50 virtual void TearDown() OVERRIDE { |
| 54 base::MessageLoop::current()->PostTask(FROM_HERE, | 51 #if defined OS_CHROMEOS |
| 55 base::MessageLoop::QuitClosure()); | 52 test_user_manager_.reset(); |
| 56 base::MessageLoop::current()->Run(); | 53 #endif |
| 54 ChromeRenderViewHostTestHarness::TearDown(); |
| 57 } | 55 } |
| 58 | 56 |
| 59 static void RetrieveActions_LogAndFetchActions( | 57 static void RetrieveActions_LogAndFetchActions( |
| 60 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 58 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 61 ASSERT_EQ(2, static_cast<int>(i->size())); | 59 ASSERT_EQ(2, static_cast<int>(i->size())); |
| 62 } | 60 } |
| 63 | 61 |
| 64 static void Arguments_Missing( | 62 static void Arguments_Missing( |
| 65 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 63 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 66 scoped_refptr<Action> last = i->front(); | 64 scoped_refptr<Action> last = i->front(); |
| 67 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " | 65 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " |
| 68 "CALL, API: tabs.testMethod, ARGS: "; | 66 "CALL, API: tabs.testMethod, ARGS: "; |
| 69 ASSERT_EQ(noargs, last->PrintForDebug()); | 67 ASSERT_EQ(noargs, last->PrintForDebug()); |
| 70 } | 68 } |
| 71 | 69 |
| 72 static void Arguments_Present( | 70 static void Arguments_Present( |
| 73 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { | 71 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { |
| 74 scoped_refptr<Action> last = i->front(); | 72 scoped_refptr<Action> last = i->front(); |
| 75 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " | 73 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " |
| 76 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; | 74 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; |
| 77 ASSERT_EQ(args, last->PrintForDebug()); | 75 ASSERT_EQ(args, last->PrintForDebug()); |
| 78 } | 76 } |
| 79 | 77 |
| 80 protected: | 78 protected: |
| 81 ExtensionService* extension_service_; | 79 ExtensionService* extension_service_; |
| 82 Profile* profile_; | 80 Profile* profile_; |
| 83 | 81 |
| 84 private: | |
| 85 content::TestBrowserThread ui_thread_; | |
| 86 content::TestBrowserThread db_thread_; | |
| 87 content::TestBrowserThread file_thread_; | |
| 88 | |
| 89 #if defined OS_CHROMEOS | 82 #if defined OS_CHROMEOS |
| 90 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; | 83 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; |
| 91 chromeos::ScopedTestCrosSettings test_cros_settings_; | 84 chromeos::ScopedTestCrosSettings test_cros_settings_; |
| 92 chromeos::ScopedTestUserManager test_user_manager_; | 85 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_; |
| 93 #endif | 86 #endif |
| 94 }; | 87 }; |
| 95 | 88 |
| 96 TEST_F(ActivityLogTest, Enabled) { | 89 TEST_F(ActivityLogTest, Enabled) { |
| 97 ASSERT_TRUE(ActivityLog::IsLogEnabled()); | 90 ASSERT_TRUE(ActivityLog::IsLogEnabled()); |
| 98 } | 91 } |
| 99 | 92 |
| 100 TEST_F(ActivityLogTest, Construct) { | 93 TEST_F(ActivityLogTest, Construct) { |
| 101 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); | 94 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); |
| 102 scoped_refptr<const Extension> extension = | 95 scoped_refptr<const Extension> extension = |
| (...skipping 77 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 180 args->Set(0, new base::StringValue("hello")); | 173 args->Set(0, new base::StringValue("hello")); |
| 181 args->Set(1, new base::StringValue("world")); | 174 args->Set(1, new base::StringValue("world")); |
| 182 activity_log->LogAPIAction( | 175 activity_log->LogAPIAction( |
| 183 extension, std::string("extension.connect"), args.get(), std::string()); | 176 extension, std::string("extension.connect"), args.get(), std::string()); |
| 184 activity_log->GetActions( | 177 activity_log->GetActions( |
| 185 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present)); | 178 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present)); |
| 186 } | 179 } |
| 187 | 180 |
| 188 } // namespace extensions | 181 } // namespace extensions |
| 189 | 182 |
| OLD | NEW |