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

Side by Side Diff: chrome/browser/extensions/user_script_listener_unittest.cc

Issue 345023: Get rid of MessageLoop* caching in extensions code. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 1 month 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) 2009 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2009 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 <algorithm> 5 #include <algorithm>
6 #include <vector> 6 #include <vector>
7 7
8 #include "base/message_loop.h" 8 #include "base/message_loop.h"
9 #include "base/thread.h" 9 #include "base/thread.h"
10 #include "chrome/browser/chrome_thread.h" 10 #include "chrome/browser/chrome_thread.h"
(...skipping 13 matching lines...) Expand all
24 // A simple test URLRequestJob. We don't care what it does, only that whether it 24 // A simple test URLRequestJob. We don't care what it does, only that whether it
25 // starts and finishes. 25 // starts and finishes.
26 class SimpleTestJob : public URLRequestTestJob { 26 class SimpleTestJob : public URLRequestTestJob {
27 public: 27 public:
28 explicit SimpleTestJob(URLRequest* request) 28 explicit SimpleTestJob(URLRequest* request)
29 : URLRequestTestJob(request, test_headers(), test_data_1(), true) {} 29 : URLRequestTestJob(request, test_headers(), test_data_1(), true) {}
30 }; 30 };
31 31
32 class MockUserScriptMaster : public UserScriptMaster { 32 class MockUserScriptMaster : public UserScriptMaster {
33 public: 33 public:
34 explicit MockUserScriptMaster(MessageLoop* worker, const FilePath& script_dir) 34 explicit MockUserScriptMaster(const FilePath& script_dir)
35 : UserScriptMaster(worker, script_dir) {} 35 : UserScriptMaster(script_dir) {}
36 36
37 virtual void StartScan() { 37 virtual void StartScan() {
38 // Do nothing. We want to manually control when scans occur. 38 // Do nothing. We want to manually control when scans occur.
39 } 39 }
40 void TestStartScan() { 40 void TestStartScan() {
41 UserScriptMaster::StartScan(); 41 UserScriptMaster::StartScan();
42 } 42 }
43 }; 43 };
44 44
45 class MockIOThread : public ChromeThread { 45 class MockIOThread : public ChromeThread {
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
177 177
178 // Note: these variables are accessed on both threads, but since we only 178 // Note: these variables are accessed on both threads, but since we only
179 // one thread executes at a time, they are safe. 179 // one thread executes at a time, they are safe.
180 std::vector<int> started_requests_; 180 std::vector<int> started_requests_;
181 std::vector<int> completed_requests_; 181 std::vector<int> completed_requests_;
182 }; 182 };
183 183
184 class UserScriptListenerTest : public testing::Test { 184 class UserScriptListenerTest : public testing::Test {
185 public: 185 public:
186 virtual void SetUp() { 186 virtual void SetUp() {
187 ui_thread_.reset(new ChromeThread(ChromeThread::UI, &loop_));
188 file_thread_.reset(new ChromeThread(ChromeThread::FILE, &loop_));
187 io_thread_.reset(new MockIOThread()); 189 io_thread_.reset(new MockIOThread());
188 base::Thread::Options options(MessageLoop::TYPE_IO, 0); 190 base::Thread::Options options(MessageLoop::TYPE_IO, 0);
189 io_thread_->StartWithOptions(options); 191 io_thread_->StartWithOptions(options);
190 DCHECK(io_thread_->message_loop()); 192 DCHECK(io_thread_->message_loop());
191 DCHECK(io_thread_->IsRunning()); 193 DCHECK(io_thread_->IsRunning());
192 194
193 FilePath install_dir = profile_.GetPath() 195 FilePath install_dir = profile_.GetPath()
194 .AppendASCII(ExtensionsService::kInstallDirectoryName); 196 .AppendASCII(ExtensionsService::kInstallDirectoryName);
195 197
196 resource_tester_ = 198 resource_tester_ =
197 new ResourceDispatcherHostTester(io_thread_->message_loop()); 199 new ResourceDispatcherHostTester(io_thread_->message_loop());
198 200
199 master_ = new MockUserScriptMaster(&loop_, install_dir); 201 master_ = new MockUserScriptMaster(install_dir);
200 202
201 service_ = new ExtensionsService(&profile_, 203 service_ = new ExtensionsService(&profile_,
202 CommandLine::ForCurrentProcess(), 204 CommandLine::ForCurrentProcess(),
203 profile_.GetPrefs(), 205 profile_.GetPrefs(),
204 install_dir, 206 install_dir,
205 &loop_,
206 &loop_,
207 false); 207 false);
208 service_->set_extensions_enabled(true); 208 service_->set_extensions_enabled(true);
209 service_->set_show_extensions_prompts(false); 209 service_->set_show_extensions_prompts(false);
210 service_->ClearProvidersForTesting(); 210 service_->ClearProvidersForTesting();
211 service_->Init(); 211 service_->Init();
212 } 212 }
213 213
214 virtual void TearDown() { 214 virtual void TearDown() {
215 io_thread_.reset(); 215 io_thread_.reset();
216 file_thread_.reset();
217 ui_thread_.reset();
216 resource_tester_ = NULL; 218 resource_tester_ = NULL;
217 } 219 }
218 220
219 protected: 221 protected:
220 TestingProfile profile_; 222 TestingProfile profile_;
221 MessageLoopForUI loop_; 223 MessageLoopForUI loop_;
224 scoped_ptr<ChromeThread> ui_thread_;
225 scoped_ptr<ChromeThread> file_thread_;
222 scoped_ptr<MockIOThread> io_thread_; 226 scoped_ptr<MockIOThread> io_thread_;
223 scoped_refptr<ResourceDispatcherHostTester> resource_tester_; 227 scoped_refptr<ResourceDispatcherHostTester> resource_tester_;
224 scoped_refptr<MockUserScriptMaster> master_; 228 scoped_refptr<MockUserScriptMaster> master_;
225 scoped_refptr<ExtensionsService> service_; 229 scoped_refptr<ExtensionsService> service_;
226 }; 230 };
227 231
228 // Loads a single extension and ensures that requests to URLs with content 232 // Loads a single extension and ensures that requests to URLs with content
229 // scripts are delayed. 233 // scripts are delayed.
230 TEST_F(UserScriptListenerTest, SingleExtension) { 234 TEST_F(UserScriptListenerTest, SingleExtension) {
231 FilePath extensions_path; 235 FilePath extensions_path;
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after
300 304
301 // Make the same requests, and they should complete instantly. 305 // Make the same requests, and they should complete instantly.
302 resource_tester_->MakeTestRequest(2, GURL("http://google.com/")); 306 resource_tester_->MakeTestRequest(2, GURL("http://google.com/"));
303 resource_tester_->MakeTestRequest(3, GURL("http://yahoo.com/")); 307 resource_tester_->MakeTestRequest(3, GURL("http://yahoo.com/"));
304 308
305 EXPECT_TRUE(resource_tester_->IsRequestStarted(2)); 309 EXPECT_TRUE(resource_tester_->IsRequestStarted(2));
306 EXPECT_TRUE(resource_tester_->IsRequestComplete(2)); 310 EXPECT_TRUE(resource_tester_->IsRequestComplete(2));
307 EXPECT_TRUE(resource_tester_->IsRequestStarted(3)); 311 EXPECT_TRUE(resource_tester_->IsRequestStarted(3));
308 EXPECT_TRUE(resource_tester_->IsRequestComplete(3)); 312 EXPECT_TRUE(resource_tester_->IsRequestComplete(3));
309 } 313 }
OLDNEW
« no previous file with comments | « chrome/browser/extensions/user_script_listener.cc ('k') | chrome/browser/extensions/user_script_master.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698