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 <stddef.h> | 7 #include <stddef.h> |
8 | 8 |
9 #include <set> | 9 #include <set> |
10 #include <string> | 10 #include <string> |
11 | 11 |
12 #include "base/files/file_path.h" | 12 #include "base/files/file_path.h" |
13 #include "base/files/file_util.h" | 13 #include "base/files/file_util.h" |
14 #include "base/files/scoped_temp_dir.h" | 14 #include "base/files/scoped_temp_dir.h" |
15 #include "base/location.h" | 15 #include "base/location.h" |
16 #include "base/memory/ptr_util.h" | 16 #include "base/memory/ptr_util.h" |
| 17 #include "base/run_loop.h" |
17 #include "base/single_thread_task_runner.h" | 18 #include "base/single_thread_task_runner.h" |
18 #include "base/strings/string_util.h" | 19 #include "base/strings/string_util.h" |
19 #include "chrome/browser/chrome_notification_types.h" | 20 #include "chrome/browser/chrome_notification_types.h" |
20 #include "chrome/test/base/testing_profile.h" | 21 #include "chrome/test/base/testing_profile.h" |
21 #include "content/public/browser/notification_observer.h" | 22 #include "content/public/browser/notification_observer.h" |
22 #include "content/public/browser/notification_registrar.h" | 23 #include "content/public/browser/notification_registrar.h" |
23 #include "content/public/browser/notification_service.h" | 24 #include "content/public/browser/notification_service.h" |
24 #include "content/public/test/test_browser_thread.h" | 25 #include "content/public/test/test_browser_thread.h" |
25 #include "extensions/common/host_id.h" | 26 #include "extensions/common/host_id.h" |
26 #include "testing/gtest/include/gtest/gtest.h" | 27 #include "testing/gtest/include/gtest/gtest.h" |
(...skipping 66 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
93 }; | 94 }; |
94 | 95 |
95 // Test that we get notified even when there are no scripts. | 96 // Test that we get notified even when there are no scripts. |
96 TEST_F(ExtensionUserScriptLoaderTest, NoScripts) { | 97 TEST_F(ExtensionUserScriptLoaderTest, NoScripts) { |
97 TestingProfile profile; | 98 TestingProfile profile; |
98 ExtensionUserScriptLoader loader( | 99 ExtensionUserScriptLoader loader( |
99 &profile, | 100 &profile, |
100 HostID(), | 101 HostID(), |
101 true /* listen_for_extension_system_loaded */); | 102 true /* listen_for_extension_system_loaded */); |
102 loader.StartLoad(); | 103 loader.StartLoad(); |
103 message_loop_.task_runner()->PostTask( | 104 base::RunLoop().RunUntilIdle(); |
104 FROM_HERE, base::MessageLoop::QuitWhenIdleClosure()); | |
105 message_loop_.Run(); | |
106 | 105 |
107 ASSERT_TRUE(shared_memory_ != NULL); | 106 ASSERT_TRUE(shared_memory_ != NULL); |
108 } | 107 } |
109 | 108 |
110 TEST_F(ExtensionUserScriptLoaderTest, Parse1) { | 109 TEST_F(ExtensionUserScriptLoaderTest, Parse1) { |
111 const std::string text( | 110 const std::string text( |
112 "// This is my awesome script\n" | 111 "// This is my awesome script\n" |
113 "// It does stuff.\n" | 112 "// It does stuff.\n" |
114 "// ==UserScript== trailing garbage\n" | 113 "// ==UserScript== trailing garbage\n" |
115 "// @name foobar script\n" | 114 "// @name foobar script\n" |
(...skipping 157 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
273 &profile, | 272 &profile, |
274 HostID(), | 273 HostID(), |
275 true /* listen_for_extension_system_loaded */); | 274 true /* listen_for_extension_system_loaded */); |
276 loader.LoadScriptsForTest(&user_scripts); | 275 loader.LoadScriptsForTest(&user_scripts); |
277 | 276 |
278 EXPECT_EQ(content, | 277 EXPECT_EQ(content, |
279 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); | 278 user_scripts[0]->js_scripts()[0]->GetContent().as_string()); |
280 } | 279 } |
281 | 280 |
282 } // namespace extensions | 281 } // namespace extensions |
OLD | NEW |