Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(226)

Side by Side Diff: chrome/browser/extensions/activity_log/activity_log_unittest.cc

Issue 14197014: Add TestBrowserThreadBundle into RenderViewHostTestHarness. Kill some unnecessary real threads. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: address jyasskin's comments\ Created 7 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
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/extension_service.h" 9 #include "chrome/browser/extensions/extension_service.h"
10 #include "chrome/browser/extensions/test_extension_system.h" 10 #include "chrome/browser/extensions/test_extension_system.h"
11 #include "chrome/common/chrome_constants.h" 11 #include "chrome/common/chrome_constants.h"
12 #include "chrome/common/chrome_switches.h" 12 #include "chrome/common/chrome_switches.h"
13 #include "chrome/common/extensions/extension_builder.h" 13 #include "chrome/common/extensions/extension_builder.h"
14 #include "chrome/test/base/chrome_render_view_host_test_harness.h" 14 #include "chrome/test/base/chrome_render_view_host_test_harness.h"
15 #include "chrome/test/base/testing_profile.h" 15 #include "chrome/test/base/testing_profile.h"
16 #include "content/public/browser/browser_thread.h" 16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/test/test_browser_thread.h"
18 #include "sql/statement.h" 17 #include "sql/statement.h"
19 #include "testing/gtest/include/gtest/gtest.h" 18 #include "testing/gtest/include/gtest/gtest.h"
20 19
21 #if defined(OS_CHROMEOS) 20 #if defined(OS_CHROMEOS)
22 #include "chrome/browser/chromeos/login/user_manager.h" 21 #include "chrome/browser/chromeos/login/user_manager.h"
23 #include "chrome/browser/chromeos/settings/cros_settings.h" 22 #include "chrome/browser/chromeos/settings/cros_settings.h"
24 #include "chrome/browser/chromeos/settings/device_settings_service.h" 23 #include "chrome/browser/chromeos/settings/device_settings_service.h"
25 #endif 24 #endif
26 25
27 namespace extensions { 26 namespace extensions {
28 27
29 class ActivityLogTest : public ChromeRenderViewHostTestHarness { 28 class ActivityLogTest : public ChromeRenderViewHostTestHarness {
30 public: 29 public:
31 ActivityLogTest()
32 : ui_thread_(BrowserThread::UI, MessageLoop::current()),
33 db_thread_(BrowserThread::DB, MessageLoop::current()),
34 file_thread_(BrowserThread::FILE, MessageLoop::current()) {}
35
36 virtual void SetUp() OVERRIDE { 30 virtual void SetUp() OVERRIDE {
37 ChromeRenderViewHostTestHarness::SetUp(); 31 ChromeRenderViewHostTestHarness::SetUp();
32 #if defined OS_CHROMEOS
33 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
34 #endif
38 CommandLine command_line(CommandLine::NO_PROGRAM); 35 CommandLine command_line(CommandLine::NO_PROGRAM);
39 profile_ = 36 profile_ =
40 Profile::FromBrowserContext(web_contents()->GetBrowserContext()); 37 Profile::FromBrowserContext(web_contents()->GetBrowserContext());
41 extension_service_ = static_cast<TestExtensionSystem*>( 38 extension_service_ = static_cast<TestExtensionSystem*>(
42 ExtensionSystem::Get(profile_))->CreateExtensionService( 39 ExtensionSystem::Get(profile_))->CreateExtensionService(
43 &command_line, base::FilePath(), false); 40 &command_line, base::FilePath(), false);
44 CommandLine::ForCurrentProcess()->AppendSwitch( 41 CommandLine::ForCurrentProcess()->AppendSwitch(
45 switches::kEnableExtensionActivityUI); 42 switches::kEnableExtensionActivityUI);
46 CommandLine::ForCurrentProcess()->AppendSwitch( 43 CommandLine::ForCurrentProcess()->AppendSwitch(
47 switches::kEnableExtensionActivityLogTesting); 44 switches::kEnableExtensionActivityLogTesting);
48 ActivityLog::RecomputeLoggingIsEnabled(); 45 ActivityLog::RecomputeLoggingIsEnabled();
49 } 46 }
50 47
51 virtual ~ActivityLogTest() { 48 virtual void TearDown() OVERRIDE {
52 MessageLoop::current()->PostTask(FROM_HERE, MessageLoop::QuitClosure()); 49 #if defined OS_CHROMEOS
53 MessageLoop::current()->Run(); 50 test_user_manager_.reset();
51 #endif
52 ChromeRenderViewHostTestHarness::TearDown();
54 } 53 }
55 54
56 static void RetrieveActions_LogAndFetchActions( 55 static void RetrieveActions_LogAndFetchActions(
57 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 56 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
58 ASSERT_EQ(2, static_cast<int>(i->size())); 57 ASSERT_EQ(2, static_cast<int>(i->size()));
59 } 58 }
60 59
61 static void Arguments_Missing( 60 static void Arguments_Missing(
62 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 61 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
63 scoped_refptr<Action> last = i->front(); 62 scoped_refptr<Action> last = i->front();
64 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " 63 std::string noargs = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
65 "CALL, API: tabs.testMethod, ARGS: "; 64 "CALL, API: tabs.testMethod, ARGS: ";
66 ASSERT_EQ(noargs, last->PrintForDebug()); 65 ASSERT_EQ(noargs, last->PrintForDebug());
67 } 66 }
68 67
69 static void Arguments_Present( 68 static void Arguments_Present(
70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 69 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
71 scoped_refptr<Action> last = i->front(); 70 scoped_refptr<Action> last = i->front();
72 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: " 71 std::string args = "ID: odlameecjipmbmbejkplpemijjgpljce, CATEGORY: "
73 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; 72 "CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
74 ASSERT_EQ(args, last->PrintForDebug()); 73 ASSERT_EQ(args, last->PrintForDebug());
75 } 74 }
76 75
77 protected: 76 protected:
78 ExtensionService* extension_service_; 77 ExtensionService* extension_service_;
79 Profile* profile_; 78 Profile* profile_;
80 79
81 private:
82 content::TestBrowserThread ui_thread_;
83 content::TestBrowserThread db_thread_;
84 content::TestBrowserThread file_thread_;
85
86 #if defined OS_CHROMEOS 80 #if defined OS_CHROMEOS
87 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 81 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
88 chromeos::ScopedTestCrosSettings test_cros_settings_; 82 chromeos::ScopedTestCrosSettings test_cros_settings_;
89 chromeos::ScopedTestUserManager test_user_manager_; 83 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
90 #endif 84 #endif
91 }; 85 };
92 86
93 TEST_F(ActivityLogTest, Enabled) { 87 TEST_F(ActivityLogTest, Enabled) {
94 ASSERT_TRUE(ActivityLog::IsLogEnabled()); 88 ASSERT_TRUE(ActivityLog::IsLogEnabled());
95 } 89 }
96 90
97 TEST_F(ActivityLogTest, Construct) { 91 TEST_F(ActivityLogTest, Construct) {
98 ActivityLog* activity_log = ActivityLog::GetInstance(profile_); 92 ActivityLog* activity_log = ActivityLog::GetInstance(profile_);
99 scoped_refptr<const Extension> extension = 93 scoped_refptr<const Extension> extension =
(...skipping 76 matching lines...) Expand 10 before | Expand all | Expand 10 after
176 args->Set(0, new base::StringValue("hello")); 170 args->Set(0, new base::StringValue("hello"));
177 args->Set(1, new base::StringValue("world")); 171 args->Set(1, new base::StringValue("world"));
178 activity_log->LogAPIAction( 172 activity_log->LogAPIAction(
179 extension, std::string("extension.connect"), args.get(), std::string()); 173 extension, std::string("extension.connect"), args.get(), std::string());
180 activity_log->GetActions( 174 activity_log->GetActions(
181 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present)); 175 extension->id(), 0, base::Bind(ActivityLogTest::Arguments_Present));
182 } 176 }
183 177
184 } // namespace extensions 178 } // namespace extensions
185 179
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698