| OLD | NEW |
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "extensions/browser/extension_user_script_loader.h" | 5 #include "extensions/browser/extension_user_script_loader.h" |
| 6 | 6 |
| 7 #include <set> | 7 #include <set> |
| 8 #include <string> | 8 #include <string> |
| 9 | 9 |
| 10 #include "base/files/file_path.h" | 10 #include "base/files/file_path.h" |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 64 ui_thread_.reset(); | 64 ui_thread_.reset(); |
| 65 } | 65 } |
| 66 | 66 |
| 67 void Observe(int type, | 67 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 == extensions::NOTIFICATION_USER_SCRIPTS_UPDATED); | 70 DCHECK(type == extensions::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 (base::MessageLoop::current() == &message_loop_) | 73 if (base::MessageLoop::current() == &message_loop_) |
| 74 base::MessageLoop::current()->Quit(); | 74 base::MessageLoop::current()->QuitWhenIdle(); |
| 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 base::MessageLoopForUI message_loop_; | 83 base::MessageLoopForUI 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(ExtensionUserScriptLoaderTest, NoScripts) { | 93 TEST_F(ExtensionUserScriptLoaderTest, NoScripts) { |
| 94 TestingProfile profile; | 94 TestingProfile profile; |
| 95 ExtensionUserScriptLoader loader( | 95 ExtensionUserScriptLoader loader( |
| 96 &profile, | 96 &profile, |
| 97 HostID(), | 97 HostID(), |
| 98 true /* listen_for_extension_system_loaded */); | 98 true /* listen_for_extension_system_loaded */); |
| 99 loader.StartLoad(); | 99 loader.StartLoad(); |
| 100 message_loop_.task_runner()->PostTask(FROM_HERE, | 100 message_loop_.task_runner()->PostTask( |
| 101 base::MessageLoop::QuitClosure()); | 101 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); |
| 102 message_loop_.Run(); | 102 message_loop_.Run(); |
| 103 | 103 |
| 104 ASSERT_TRUE(shared_memory_ != NULL); | 104 ASSERT_TRUE(shared_memory_ != NULL); |
| 105 } | 105 } |
| 106 | 106 |
| 107 TEST_F(ExtensionUserScriptLoaderTest, Parse1) { | 107 TEST_F(ExtensionUserScriptLoaderTest, Parse1) { |
| 108 const std::string text( | 108 const std::string text( |
| 109 "// This is my awesome script\n" | 109 "// This is my awesome script\n" |
| 110 "// It does stuff.\n" | 110 "// It does stuff.\n" |
| 111 "// ==UserScript== trailing garbage\n" | 111 "// ==UserScript== trailing garbage\n" |
| (...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 269 ExtensionUserScriptLoader loader( | 269 ExtensionUserScriptLoader loader( |
| 270 &profile, | 270 &profile, |
| 271 HostID(), | 271 HostID(), |
| 272 true /* listen_for_extension_system_loaded */); | 272 true /* listen_for_extension_system_loaded */); |
| 273 loader.LoadScriptsForTest(&user_scripts); | 273 loader.LoadScriptsForTest(&user_scripts); |
| 274 | 274 |
| 275 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); | 275 EXPECT_EQ(content, user_scripts[0].js_scripts()[0].GetContent().as_string()); |
| 276 } | 276 } |
| 277 | 277 |
| 278 } // namespace extensions | 278 } // namespace extensions |
| OLD | NEW |