| 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 35 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 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_NEW_USER_SCRIPTS); |
| 55 | 55 |
| 56 shared_memory_ = Details<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. |
| 65 FilePath script_dir_; | 65 FilePath script_dir_; |
| 66 | 66 |
| 67 // Updated to the script shared memory when we get notified. | 67 // Updated to the script shared memory when we get notified. |
| 68 SharedMemory* shared_memory_; | 68 base::SharedMemory* shared_memory_; |
| 69 }; | 69 }; |
| 70 | 70 |
| 71 // Test that we *don't* get spurious notifications. | 71 // Test that we *don't* get spurious notifications. |
| 72 TEST_F(GreasemonkeyMasterTest, NoScripts) { | 72 TEST_F(GreasemonkeyMasterTest, NoScripts) { |
| 73 // Set shared_memory_ to something non-NULL, so we can check it became NULL. | 73 // Set shared_memory_ to something non-NULL, so we can check it became NULL. |
| 74 shared_memory_ = reinterpret_cast<SharedMemory*>(1); | 74 shared_memory_ = reinterpret_cast<base::SharedMemory*>(1); |
| 75 | 75 |
| 76 scoped_refptr<GreasemonkeyMaster> master( | 76 scoped_refptr<GreasemonkeyMaster> master( |
| 77 new GreasemonkeyMaster(MessageLoop::current(), script_dir_)); | 77 new GreasemonkeyMaster(MessageLoop::current(), script_dir_)); |
| 78 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); | 78 message_loop_.PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 79 message_loop_.Run(); | 79 message_loop_.Run(); |
| 80 | 80 |
| 81 // There were no scripts in the script dir, so we shouldn't have gotten | 81 // There were no scripts in the script dir, so we shouldn't have gotten |
| 82 // a notification. | 82 // a notification. |
| 83 ASSERT_EQ(NULL, shared_memory_); | 83 ASSERT_EQ(NULL, shared_memory_); |
| 84 } | 84 } |
| (...skipping 24 matching lines...) Expand all 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 |