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

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

Issue 14113053: chrome: Use base::MessageLoop. (Part 3) (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase again 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 "chrome/browser/extensions/user_script_master.h" 5 #include "chrome/browser/extensions/user_script_master.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/file_util.h" 9 #include "base/file_util.h"
10 #include "base/files/file_path.h" 10 #include "base/files/file_path.h"
(...skipping 22 matching lines...) Expand all
33 33
34 namespace extensions { 34 namespace extensions {
35 35
36 // Test bringing up a master on a specific directory, putting a script 36 // Test bringing up a master on a specific directory, putting a script
37 // in there, etc. 37 // in there, etc.
38 38
39 class UserScriptMasterTest : public testing::Test, 39 class UserScriptMasterTest : public testing::Test,
40 public content::NotificationObserver { 40 public content::NotificationObserver {
41 public: 41 public:
42 UserScriptMasterTest() 42 UserScriptMasterTest()
43 : message_loop_(MessageLoop::TYPE_UI), 43 : message_loop_(base::MessageLoop::TYPE_UI),
44 shared_memory_(NULL) { 44 shared_memory_(NULL) {
45 } 45 }
46 46
47 virtual void SetUp() { 47 virtual void SetUp() {
48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); 48 ASSERT_TRUE(temp_dir_.CreateUniqueTempDir());
49 49
50 // Register for all user script notifications. 50 // Register for all user script notifications.
51 registrar_.Add(this, chrome::NOTIFICATION_USER_SCRIPTS_UPDATED, 51 registrar_.Add(this, chrome::NOTIFICATION_USER_SCRIPTS_UPDATED,
52 content::NotificationService::AllSources()); 52 content::NotificationService::AllSources());
53 53
54 // UserScriptMaster posts tasks to the file thread so make the current 54 // UserScriptMaster posts tasks to the file thread so make the current
55 // thread look like one. 55 // thread look like one.
56 file_thread_.reset(new content::TestBrowserThread( 56 file_thread_.reset(new content::TestBrowserThread(
57 BrowserThread::FILE, MessageLoop::current())); 57 BrowserThread::FILE, base::MessageLoop::current()));
58 ui_thread_.reset(new content::TestBrowserThread( 58 ui_thread_.reset(new content::TestBrowserThread(
59 BrowserThread::UI, MessageLoop::current())); 59 BrowserThread::UI, base::MessageLoop::current()));
60 } 60 }
61 61
62 virtual void TearDown() { 62 virtual void TearDown() {
63 file_thread_.reset(); 63 file_thread_.reset();
64 ui_thread_.reset(); 64 ui_thread_.reset();
65 } 65 }
66 66
67 virtual void Observe(int type, 67 virtual void Observe(int type,
68 const content::NotificationSource& source, 68 const content::NotificationSource& source,
69 const content::NotificationDetails& details) OVERRIDE { 69 const content::NotificationDetails& details) OVERRIDE {
70 DCHECK(type == chrome::NOTIFICATION_USER_SCRIPTS_UPDATED); 70 DCHECK(type == chrome::NOTIFICATION_USER_SCRIPTS_UPDATED);
71 71
72 shared_memory_ = content::Details<base::SharedMemory>(details).ptr(); 72 shared_memory_ = content::Details<base::SharedMemory>(details).ptr();
73 if (MessageLoop::current() == &message_loop_) 73 if (base::MessageLoop::current() == &message_loop_)
74 MessageLoop::current()->Quit(); 74 base::MessageLoop::current()->Quit();
75 } 75 }
76 76
77 // Directory containing user scripts. 77 // Directory containing user scripts.
78 base::ScopedTempDir temp_dir_; 78 base::ScopedTempDir temp_dir_;
79 79
80 content::NotificationRegistrar registrar_; 80 content::NotificationRegistrar registrar_;
81 81
82 // MessageLoop used in tests. 82 // MessageLoop used in tests.
83 MessageLoop message_loop_; 83 base::MessageLoop message_loop_;
84 84
85 scoped_ptr<content::TestBrowserThread> file_thread_; 85 scoped_ptr<content::TestBrowserThread> file_thread_;
86 scoped_ptr<content::TestBrowserThread> ui_thread_; 86 scoped_ptr<content::TestBrowserThread> ui_thread_;
87 87
88 // Updated to the script shared memory when we get notified. 88 // Updated to the script shared memory when we get notified.
89 base::SharedMemory* shared_memory_; 89 base::SharedMemory* shared_memory_;
90 }; 90 };
91 91
92 // Test that we get notified even when there are no scripts. 92 // Test that we get notified even when there are no scripts.
93 TEST_F(UserScriptMasterTest, NoScripts) { 93 TEST_F(UserScriptMasterTest, NoScripts) {
94 TestingProfile profile; 94 TestingProfile profile;
95 scoped_refptr<UserScriptMaster> master(new UserScriptMaster(&profile)); 95 scoped_refptr<UserScriptMaster> master(new UserScriptMaster(&profile));
96 master->StartLoad(); 96 master->StartLoad();
97 message_loop_.PostTask(FROM_HERE, MessageLoop::QuitClosure()); 97 message_loop_.PostTask(FROM_HERE, base::MessageLoop::QuitClosure());
98 message_loop_.Run(); 98 message_loop_.Run();
99 99
100 ASSERT_TRUE(shared_memory_ != NULL); 100 ASSERT_TRUE(shared_memory_ != NULL);
101 } 101 }
102 102
103 TEST_F(UserScriptMasterTest, Parse1) { 103 TEST_F(UserScriptMasterTest, Parse1) {
104 const std::string text( 104 const std::string text(
105 "// This is my awesome script\n" 105 "// This is my awesome script\n"
106 "// It does stuff.\n" 106 "// It does stuff.\n"
107 "// ==UserScript== trailing garbage\n" 107 "// ==UserScript== trailing garbage\n"
(...skipping 162 matching lines...) Expand 10 before | Expand all | Expand 10 after
270 UserScriptMaster::ScriptReloader* script_reloader = 270 UserScriptMaster::ScriptReloader* script_reloader =
271 new UserScriptMaster::ScriptReloader(NULL); 271 new UserScriptMaster::ScriptReloader(NULL);
272 script_reloader->AddRef(); 272 script_reloader->AddRef();
273 script_reloader->LoadUserScripts(&user_scripts); 273 script_reloader->LoadUserScripts(&user_scripts);
274 script_reloader->Release(); 274 script_reloader->Release();
275 275
276 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); 276 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string());
277 } 277 }
278 278
279 } // namespace extensions 279 } // namespace extensions
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698