Chromium Code Reviews| Index: chrome/browser/extensions/extension_user_script_loader_unittest.cc |
| diff --git a/chrome/browser/extensions/extension_user_script_loader_unittest.cc b/chrome/browser/extensions/extension_user_script_loader_unittest.cc |
| index 878eedd4475ba4795629e8e903abd7714c779485..c4ee2a57d843353e67443ab98da261fdd446b903 100644 |
| --- a/chrome/browser/extensions/extension_user_script_loader_unittest.cc |
| +++ b/chrome/browser/extensions/extension_user_script_loader_unittest.cc |
| @@ -14,19 +14,20 @@ |
| #include "base/files/scoped_temp_dir.h" |
| #include "base/location.h" |
| #include "base/memory/ptr_util.h" |
| +#include "base/message_loop/message_loop.h" |
| #include "base/run_loop.h" |
| #include "base/single_thread_task_runner.h" |
| #include "base/strings/string_util.h" |
| +#include "base/threading/thread_task_runner_handle.h" |
| #include "chrome/browser/chrome_notification_types.h" |
| #include "chrome/test/base/testing_profile.h" |
| #include "content/public/browser/notification_observer.h" |
| #include "content/public/browser/notification_registrar.h" |
| #include "content/public/browser/notification_service.h" |
| -#include "content/public/test/test_browser_thread.h" |
| +#include "content/public/test/test_browser_thread_bundle.h" |
| #include "extensions/common/host_id.h" |
| #include "testing/gtest/include/gtest/gtest.h" |
| -using content::BrowserThread; |
| using extensions::URLPatternSet; |
| namespace { |
| @@ -45,7 +46,10 @@ namespace extensions { |
| class ExtensionUserScriptLoaderTest : public testing::Test, |
| public content::NotificationObserver { |
| public: |
| - ExtensionUserScriptLoaderTest() : shared_memory_(NULL) {} |
| + ExtensionUserScriptLoaderTest() |
| + : scoped_task_environment_( |
| + base::test::ScopedTaskEnvironment::MainThreadType::UI), |
| + shared_memory_(NULL) {} |
| void SetUp() override { |
| ASSERT_TRUE(temp_dir_.CreateUniqueTempDir()); |
| @@ -54,18 +58,6 @@ class ExtensionUserScriptLoaderTest : public testing::Test, |
| registrar_.Add(this, |
| extensions::NOTIFICATION_USER_SCRIPTS_UPDATED, |
| content::NotificationService::AllSources()); |
| - |
| - // ExtensionUserScriptLoader posts tasks to the file thread so make the |
|
sky
2017/04/27 22:17:46
Is this the same with ScopedTaskEvironment?
fdoray
2017/05/01 17:44:59
I added a TestBrowserThreadBundle instead of a Sco
sky
2017/05/01 18:07:07
I'm not sure that is the same thing. Could you get
fdoray
2017/05/01 18:15:47
I'll do this part in a separate CL.
|
| - // current thread look like one. |
| - file_thread_.reset(new content::TestBrowserThread( |
| - BrowserThread::FILE, base::MessageLoop::current())); |
| - ui_thread_.reset(new content::TestBrowserThread( |
| - BrowserThread::UI, base::MessageLoop::current())); |
| - } |
| - |
| - void TearDown() override { |
| - file_thread_.reset(); |
| - ui_thread_.reset(); |
| } |
| void Observe(int type, |
| @@ -74,21 +66,20 @@ class ExtensionUserScriptLoaderTest : public testing::Test, |
| DCHECK(type == extensions::NOTIFICATION_USER_SCRIPTS_UPDATED); |
| shared_memory_ = content::Details<base::SharedMemory>(details).ptr(); |
| - if (base::MessageLoop::current() == &message_loop_) |
| + if (main_thread_task_runner_->RunsTasksOnCurrentThread()) |
| base::MessageLoop::current()->QuitWhenIdle(); |
| } |
| + content::TestBrowserThreadBundle test_browser_thread_bundle_; |
| + |
| + const scoped_refptr<base::SingleThreadTaskRunner> main_thread_task_runner_ = |
| + base::ThreadTaskRunnerHandle::Get(); |
| + |
| // Directory containing user scripts. |
| base::ScopedTempDir temp_dir_; |
| content::NotificationRegistrar registrar_; |
| - // MessageLoop used in tests. |
| - base::MessageLoopForUI message_loop_; |
| - |
| - std::unique_ptr<content::TestBrowserThread> file_thread_; |
| - std::unique_ptr<content::TestBrowserThread> ui_thread_; |
| - |
| // Updated to the script shared memory when we get notified. |
| base::SharedMemory* shared_memory_; |
| }; |