OLD | NEW |
1 // Copyright (c) 2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2008 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/greasemonkey_master.h" | 5 #include "chrome/browser/greasemonkey_master.h" |
6 | 6 |
7 #include <fstream> | 7 #include <fstream> |
8 | 8 |
9 #include "base/file_path.h" | 9 #include "base/file_path.h" |
10 #include "base/file_util.h" | 10 #include "base/file_util.h" |
(...skipping 16 matching lines...) Expand all Loading... |
27 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_str)); | 27 ASSERT_TRUE(PathService::Get(base::DIR_TEMP, &path_str)); |
28 script_dir_ = FilePath(path_str).Append( | 28 script_dir_ = FilePath(path_str).Append( |
29 FILE_PATH_LITERAL("GreasemonkeyTest")); | 29 FILE_PATH_LITERAL("GreasemonkeyTest")); |
30 | 30 |
31 // Create a fresh, empty copy of this directory. | 31 // Create a fresh, empty copy of this directory. |
32 file_util::Delete(script_dir_.value(), true); | 32 file_util::Delete(script_dir_.value(), true); |
33 file_util::CreateDirectory(script_dir_.value()); | 33 file_util::CreateDirectory(script_dir_.value()); |
34 | 34 |
35 // Register for all user script notifications. | 35 // Register for all user script notifications. |
36 NotificationService::current()->AddObserver(this, | 36 NotificationService::current()->AddObserver(this, |
37 NOTIFY_NEW_USER_SCRIPTS, | 37 NOTIFY_GREASEMONKEY_SCRIPTS_LOADED, |
38 NotificationService::AllSources()); | 38 NotificationService::AllSources()); |
39 } | 39 } |
40 | 40 |
41 virtual void TearDown() { | 41 virtual void TearDown() { |
42 NotificationService::current()->RemoveObserver(this, | 42 NotificationService::current()->RemoveObserver(this, |
43 NOTIFY_NEW_USER_SCRIPTS, | 43 NOTIFY_GREASEMONKEY_SCRIPTS_LOADED, |
44 NotificationService::AllSources()); | 44 NotificationService::AllSources()); |
45 | 45 |
46 // Clean up test directory. | 46 // Clean up test directory. |
47 ASSERT_TRUE(file_util::Delete(script_dir_.value(), true)); | 47 ASSERT_TRUE(file_util::Delete(script_dir_.value(), true)); |
48 ASSERT_FALSE(file_util::PathExists(script_dir_.value())); | 48 ASSERT_FALSE(file_util::PathExists(script_dir_.value())); |
49 } | 49 } |
50 | 50 |
51 virtual void Observe(NotificationType type, | 51 virtual void Observe(NotificationType type, |
52 const NotificationSource& source, | 52 const NotificationSource& source, |
53 const NotificationDetails& details) { | 53 const NotificationDetails& details) { |
54 DCHECK(type == NOTIFY_NEW_USER_SCRIPTS); | 54 DCHECK(type == NOTIFY_GREASEMONKEY_SCRIPTS_LOADED); |
55 | 55 |
56 shared_memory_ = Details<base::SharedMemory>(details).ptr(); | 56 shared_memory_ = Details<base::SharedMemory>(details).ptr(); |
57 if (MessageLoop::current() == &message_loop_) | 57 if (MessageLoop::current() == &message_loop_) |
58 MessageLoop::current()->Quit(); | 58 MessageLoop::current()->Quit(); |
59 } | 59 } |
60 | 60 |
61 // MessageLoop used in tests. | 61 // MessageLoop used in tests. |
62 MessageLoop message_loop_; | 62 MessageLoop message_loop_; |
63 | 63 |
64 // Directory containing user scripts. | 64 // Directory containing user scripts. |
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
109 file.close(); | 109 file.close(); |
110 | 110 |
111 scoped_refptr<GreasemonkeyMaster> master( | 111 scoped_refptr<GreasemonkeyMaster> master( |
112 new GreasemonkeyMaster(MessageLoop::current(), script_dir_)); | 112 new GreasemonkeyMaster(MessageLoop::current(), script_dir_)); |
113 | 113 |
114 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); | 114 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); |
115 message_loop_.Run(); | 115 message_loop_.Run(); |
116 | 116 |
117 ASSERT_TRUE(shared_memory_ != NULL); | 117 ASSERT_TRUE(shared_memory_ != NULL); |
118 } | 118 } |
OLD | NEW |