Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(369)

Side by Side Diff: content/test/test_blink_web_unit_test_support.cc

Issue 1130433002: Adding task runner/ message loop to tests that use IsolateHolder. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Fixing mac build. Created 5 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « no previous file | gin/converter_unittest.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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 "content/test/test_blink_web_unit_test_support.h" 5 #include "content/test/test_blink_web_unit_test_support.h"
6 6
7 #include "base/files/file_path.h" 7 #include "base/files/file_path.h"
8 #include "base/files/file_util.h" 8 #include "base/files/file_util.h"
9 #include "base/files/scoped_temp_dir.h" 9 #include "base/files/scoped_temp_dir.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "base/single_thread_task_runner.h"
11 #include "base/strings/utf_string_conversions.h" 12 #include "base/strings/utf_string_conversions.h"
13 #include "base/thread_task_runner_handle.h"
14 #include "base/threading/platform_thread.h"
12 #include "components/scheduler/renderer/renderer_scheduler.h" 15 #include "components/scheduler/renderer/renderer_scheduler.h"
13 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" 16 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h"
14 #include "content/test/mock_webclipboard_impl.h" 17 #include "content/test/mock_webclipboard_impl.h"
15 #include "content/test/web_gesture_curve_mock.h" 18 #include "content/test/web_gesture_curve_mock.h"
16 #include "content/test/web_layer_tree_view_impl_for_testing.h" 19 #include "content/test/web_layer_tree_view_impl_for_testing.h"
17 #include "content/test/weburl_loader_mock_factory.h" 20 #include "content/test/weburl_loader_mock_factory.h"
18 #include "media/base/media.h" 21 #include "media/base/media.h"
19 #include "net/cookies/cookie_monster.h" 22 #include "net/cookies/cookie_monster.h"
20 #include "net/test/spawned_test_server/spawned_test_server.h" 23 #include "net/test/spawned_test_server/spawned_test_server.h"
21 #include "storage/browser/database/vfs_backend.h" 24 #include "storage/browser/database/vfs_backend.h"
(...skipping 12 matching lines...) Expand all
34 37
35 #if defined(OS_MACOSX) 38 #if defined(OS_MACOSX)
36 #include "base/mac/foundation_util.h" 39 #include "base/mac/foundation_util.h"
37 #include "base/mac/scoped_nsautorelease_pool.h" 40 #include "base/mac/scoped_nsautorelease_pool.h"
38 #endif 41 #endif
39 42
40 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 43 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
41 #include "gin/v8_initializer.h" 44 #include "gin/v8_initializer.h"
42 #endif 45 #endif
43 46
47 namespace {
48
49 class DummyTaskRunner : public base::SingleThreadTaskRunner {
50 public:
51 DummyTaskRunner() : thread_id_(base::PlatformThread::CurrentId()) {}
52
53 bool PostDelayedTask(const tracked_objects::Location& from_here,
54 const base::Closure& task,
55 base::TimeDelta delay) override {
56 NOTREACHED();
57 return false;
58 }
59
60 bool PostNonNestableDelayedTask(const tracked_objects::Location& from_here,
61 const base::Closure& task,
62 base::TimeDelta delay) override {
63 NOTREACHED();
64 return false;
65 }
66
67 bool RunsTasksOnCurrentThread() const override {
68 return thread_id_ == base::PlatformThread::CurrentId();
69 }
70
71 protected:
72 ~DummyTaskRunner() override {}
73
74 base::PlatformThreadId thread_id_;
75
76 DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner);
77 };
78
79 } // namespace
80
44 namespace content { 81 namespace content {
45 82
46 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { 83 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() {
47 #if defined(OS_MACOSX) 84 #if defined(OS_MACOSX)
48 base::mac::ScopedNSAutoreleasePool autorelease_pool; 85 base::mac::ScopedNSAutoreleasePool autorelease_pool;
49 #endif 86 #endif
50 87
51 url_loader_factory_.reset(new WebURLLoaderMockFactory()); 88 url_loader_factory_.reset(new WebURLLoaderMockFactory());
52 mock_clipboard_.reset(new MockWebClipboardImpl()); 89 mock_clipboard_.reset(new MockWebClipboardImpl());
53 90
54 #ifdef V8_USE_EXTERNAL_STARTUP_DATA 91 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
55 gin::V8Initializer::LoadV8Snapshot(); 92 gin::V8Initializer::LoadV8Snapshot();
56 #endif 93 #endif
57 94
95 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner;
96 scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle;
58 if (base::MessageLoopProxy::current()) { 97 if (base::MessageLoopProxy::current()) {
59 renderer_scheduler_ = scheduler::RendererScheduler::Create(); 98 renderer_scheduler_ = scheduler::RendererScheduler::Create();
60 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( 99 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler(
61 renderer_scheduler_.get())); 100 renderer_scheduler_.get()));
101 } else {
102 // Dummy task runner is initialized here because the blink::initialize
103 // creates IsolateHolder which needs the current task runner handle. There
104 // should be no task posted to this task runner. The message loop is not
105 // created before this initialization because some tests need specific kinds
106 // of message loops, and their types are not known upfront. Some tests also
107 // create their own thread bundles or message loops, and doing the same in
108 // TestBlinkWebUnitTestSupport would introduce a conflict.
109 dummy_task_runner = make_scoped_refptr(new DummyTaskRunner());
110 dummy_task_runner_handle.reset(
111 new base::ThreadTaskRunnerHandle(dummy_task_runner));
62 } 112 }
63 113
64 blink::initialize(this); 114 blink::initialize(this);
65 blink::setLayoutTestMode(true); 115 blink::setLayoutTestMode(true);
66 blink::WebSecurityPolicy::registerURLSchemeAsLocal( 116 blink::WebSecurityPolicy::registerURLSchemeAsLocal(
67 blink::WebString::fromUTF8("test-shell-resource")); 117 blink::WebString::fromUTF8("test-shell-resource"));
68 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( 118 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess(
69 blink::WebString::fromUTF8("test-shell-resource")); 119 blink::WebString::fromUTF8("test-shell-resource"));
70 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( 120 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated(
71 blink::WebString::fromUTF8("test-shell-resource")); 121 blink::WebString::fromUTF8("test-shell-resource"));
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after
323 DCHECK(base::MessageLoop::current()); 373 DCHECK(base::MessageLoop::current());
324 DCHECK(!base::MessageLoop::current()->is_running()); 374 DCHECK(!base::MessageLoop::current()->is_running());
325 base::MessageLoop::current()->Run(); 375 base::MessageLoop::current()->Run();
326 } 376 }
327 377
328 void TestBlinkWebUnitTestSupport::exitRunLoop() { 378 void TestBlinkWebUnitTestSupport::exitRunLoop() {
329 base::MessageLoop::current()->Quit(); 379 base::MessageLoop::current()->Quit();
330 } 380 }
331 381
332 } // namespace content 382 } // namespace content
OLDNEW
« no previous file with comments | « no previous file | gin/converter_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698