OLD | NEW |
---|---|
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 Loading... | |
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 // Always returns true to avoid triggering DCHECKs. | |
Sami
2015/05/05 17:12:30
This comment isn't accurate anymore.
| |
68 bool RunsTasksOnCurrentThread() const override { | |
69 return thread_id_ == base::PlatformThread::CurrentId(); | |
70 } | |
71 | |
72 protected: | |
73 ~DummyTaskRunner() override {} | |
74 | |
75 base::PlatformThreadId thread_id_; | |
76 | |
77 DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner); | |
78 }; | |
79 | |
80 } // namespace | |
81 | |
44 namespace content { | 82 namespace content { |
45 | 83 |
46 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { | 84 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
47 #if defined(OS_MACOSX) | 85 #if defined(OS_MACOSX) |
48 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 86 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
49 #endif | 87 #endif |
50 | 88 |
51 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 89 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
52 mock_clipboard_.reset(new MockWebClipboardImpl()); | 90 mock_clipboard_.reset(new MockWebClipboardImpl()); |
53 | 91 |
54 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 92 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
55 gin::V8Initializer::LoadV8Snapshot(); | 93 gin::V8Initializer::LoadV8Snapshot(); |
56 #endif | 94 #endif |
57 | 95 |
96 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner; | |
97 scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle; | |
58 if (base::MessageLoopProxy::current()) { | 98 if (base::MessageLoopProxy::current()) { |
59 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 99 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
60 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( | 100 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( |
61 renderer_scheduler_.get())); | 101 renderer_scheduler_.get())); |
102 } else { | |
103 // Dummy task runner is initialized here because the blink::initialize | |
104 // creates IsolateHolder which needs the current task runner handle. There | |
105 // should be no task posted to this task runner. The message loop is not | |
106 // created before this initialization because some tests need specific kinds | |
107 // of message loops, and their types are not known upfront. Some tests also | |
108 // create their own thread bundles or message loops, and doing the same in | |
109 // TestBlinkWebUnitTestSupport would introduce a conflict. | |
110 dummy_task_runner = make_scoped_refptr(new DummyTaskRunner()); | |
111 dummy_task_runner_handle.reset( | |
112 new base::ThreadTaskRunnerHandle(dummy_task_runner)); | |
62 } | 113 } |
63 | 114 |
64 blink::initialize(this); | 115 blink::initialize(this); |
65 blink::setLayoutTestMode(true); | 116 blink::setLayoutTestMode(true); |
66 blink::WebSecurityPolicy::registerURLSchemeAsLocal( | 117 blink::WebSecurityPolicy::registerURLSchemeAsLocal( |
67 blink::WebString::fromUTF8("test-shell-resource")); | 118 blink::WebString::fromUTF8("test-shell-resource")); |
68 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 119 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
69 blink::WebString::fromUTF8("test-shell-resource")); | 120 blink::WebString::fromUTF8("test-shell-resource")); |
70 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 121 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
71 blink::WebString::fromUTF8("test-shell-resource")); | 122 blink::WebString::fromUTF8("test-shell-resource")); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
323 DCHECK(base::MessageLoop::current()); | 374 DCHECK(base::MessageLoop::current()); |
324 DCHECK(!base::MessageLoop::current()->is_running()); | 375 DCHECK(!base::MessageLoop::current()->is_running()); |
325 base::MessageLoop::current()->Run(); | 376 base::MessageLoop::current()->Run(); |
326 } | 377 } |
327 | 378 |
328 void TestBlinkWebUnitTestSupport::exitRunLoop() { | 379 void TestBlinkWebUnitTestSupport::exitRunLoop() { |
329 base::MessageLoop::current()->Quit(); | 380 base::MessageLoop::current()->Quit(); |
330 } | 381 } |
331 | 382 |
332 } // namespace content | 383 } // namespace content |
OLD | NEW |