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

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: merged ToT Created 7 years, 6 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/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_),
43 db_thread_(BrowserThread::DB, &message_loop_),
44 file_thread_(BrowserThread::FILE, &message_loop_),
45 io_thread_(BrowserThread::IO, &message_loop_),
46 saved_cmdline_(CommandLine::NO_PROGRAM) { 41 saved_cmdline_(CommandLine::NO_PROGRAM) {
47 } 42 #if defined OS_CHROMEOS
48 43 test_user_manager_.reset(new chromeos::ScopedTestUserManager());
49 virtual void SetUp() OVERRIDE { 44 #endif
50 CommandLine command_line(CommandLine::NO_PROGRAM); 45 CommandLine command_line(CommandLine::NO_PROGRAM);
51 saved_cmdline_ = *CommandLine::ForCurrentProcess(); 46 saved_cmdline_ = *CommandLine::ForCurrentProcess();
52 profile_.reset(new TestingProfile()); 47 profile_.reset(new TestingProfile());
53 CommandLine::ForCurrentProcess()->AppendSwitch( 48 CommandLine::ForCurrentProcess()->AppendSwitch(
54 switches::kEnableExtensionActivityLogging); 49 switches::kEnableExtensionActivityLogging);
55 CommandLine::ForCurrentProcess()->AppendSwitch( 50 CommandLine::ForCurrentProcess()->AppendSwitch(
56 switches::kEnableExtensionActivityLogTesting); 51 switches::kEnableExtensionActivityLogTesting);
57 ActivityLog::RecomputeLoggingIsEnabled(); 52 ActivityLog::RecomputeLoggingIsEnabled();
58 extension_service_ = static_cast<TestExtensionSystem*>( 53 extension_service_ = static_cast<TestExtensionSystem*>(
59 ExtensionSystem::Get(profile_.get()))->CreateExtensionService( 54 ExtensionSystem::Get(profile_.get()))->CreateExtensionService(
60 &command_line, base::FilePath(), false); 55 &command_line, base::FilePath(), false);
61 } 56 }
62 57
63 virtual void TearDown() OVERRIDE { 58 virtual ~ActivityLogTest() {
59 #if defined OS_CHROMEOS
60 test_user_manager_.reset();
61 #endif
64 base::RunLoop().RunUntilIdle(); 62 base::RunLoop().RunUntilIdle();
65 profile_.reset(NULL); 63 profile_.reset(NULL);
66 base::MessageLoop::current()->PostDelayedTask(
67 FROM_HERE,
68 base::MessageLoop::QuitClosure(),
69 base::TimeDelta::FromSeconds(4)); // Don't hang on failure.
70 base::RunLoop().RunUntilIdle();
71
72 // Restore the original command line and undo the affects of SetUp(). 64 // Restore the original command line and undo the affects of SetUp().
73 *CommandLine::ForCurrentProcess() = saved_cmdline_; 65 *CommandLine::ForCurrentProcess() = saved_cmdline_;
74 ActivityLog::RecomputeLoggingIsEnabled(); 66 ActivityLog::RecomputeLoggingIsEnabled();
75 } 67 }
76 68
77 static void RetrieveActions_LogAndFetchActions( 69 static void RetrieveActions_LogAndFetchActions(
78 scoped_ptr<std::vector<scoped_refptr<Action> > > i) { 70 scoped_ptr<std::vector<scoped_refptr<Action> > > i) {
79 ASSERT_EQ(2, static_cast<int>(i->size())); 71 ASSERT_EQ(2, static_cast<int>(i->size()));
80 } 72 }
81 73
(...skipping 12 matching lines...) Expand all
94 std::string id(kExtensionId); 86 std::string id(kExtensionId);
95 std::string args = "ID: " + id + ", CATEGORY: " 87 std::string args = "ID: " + id + ", CATEGORY: "
96 "CALL, API: extension.connect, ARGS: \"hello\", \"world\""; 88 "CALL, API: extension.connect, ARGS: \"hello\", \"world\"";
97 ASSERT_EQ(args, last->PrintForDebug()); 89 ASSERT_EQ(args, last->PrintForDebug());
98 } 90 }
99 91
100 protected: 92 protected:
101 scoped_ptr<TestingProfile> profile_; 93 scoped_ptr<TestingProfile> profile_;
102 ExtensionService* extension_service_; 94 ExtensionService* extension_service_;
103 95
104 private: 96 content::TestBrowserThreadBundle thread_bundle_;
105 base::MessageLoop message_loop_;
106 content::TestBrowserThread ui_thread_;
107 content::TestBrowserThread db_thread_;
108 content::TestBrowserThread file_thread_;
109 content::TestBrowserThread io_thread_;
110 97
111 // Used to preserve a copy of the original command line. 98 // Used to preserve a copy of the original command line.
112 // The test framework will do this itself as well. However, by then, 99 // The test framework will do this itself as well. However, by then,
113 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in 100 // it is too late to call ActivityLog::RecomputeLoggingIsEnabled() in
114 // TearDown(). 101 // TearDown().
115 CommandLine saved_cmdline_; 102 CommandLine saved_cmdline_;
116 103
117 #if defined OS_CHROMEOS 104 #if defined OS_CHROMEOS
118 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_; 105 chromeos::ScopedTestDeviceSettingsService test_device_settings_service_;
119 chromeos::ScopedTestCrosSettings test_cros_settings_; 106 chromeos::ScopedTestCrosSettings test_cros_settings_;
120 chromeos::ScopedTestUserManager test_user_manager_; 107 scoped_ptr<chromeos::ScopedTestUserManager> test_user_manager_;
121 #endif 108 #endif
122 }; 109 };
123 110
124 TEST_F(ActivityLogTest, Enabled) { 111 TEST_F(ActivityLogTest, Enabled) {
125 ASSERT_TRUE(ActivityLog::IsLogEnabled()); 112 ASSERT_TRUE(ActivityLog::IsLogEnabled());
126 } 113 }
127 114
128 TEST_F(ActivityLogTest, Construct) { 115 TEST_F(ActivityLogTest, Construct) {
129 scoped_refptr<const Extension> extension = 116 scoped_refptr<const Extension> extension =
130 ExtensionBuilder() 117 ExtensionBuilder()
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after
194 activity_log->LogAPIAction(kExtensionId, 181 activity_log->LogAPIAction(kExtensionId,
195 std::string("extension.connect"), 182 std::string("extension.connect"),
196 args.get(), 183 args.get(),
197 std::string()); 184 std::string());
198 activity_log->GetActions( 185 activity_log->GetActions(
199 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present)); 186 kExtensionId, 0, base::Bind(ActivityLogTest::Arguments_Present));
200 } 187 }
201 188
202 } // namespace extensions 189 } // namespace extensions
203 190
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698