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" | |
12 #include "base/strings/utf_string_conversions.h" | 11 #include "base/strings/utf_string_conversions.h" |
13 #include "base/thread_task_runner_handle.h" | |
14 #include "base/threading/platform_thread.h" | |
15 #include "components/scheduler/renderer/renderer_scheduler.h" | 12 #include "components/scheduler/renderer/renderer_scheduler.h" |
16 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" | 13 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
17 #include "content/test/mock_webclipboard_impl.h" | 14 #include "content/test/mock_webclipboard_impl.h" |
18 #include "content/test/web_gesture_curve_mock.h" | 15 #include "content/test/web_gesture_curve_mock.h" |
19 #include "content/test/web_layer_tree_view_impl_for_testing.h" | 16 #include "content/test/web_layer_tree_view_impl_for_testing.h" |
20 #include "content/test/weburl_loader_mock_factory.h" | 17 #include "content/test/weburl_loader_mock_factory.h" |
21 #include "media/base/media.h" | 18 #include "media/base/media.h" |
22 #include "net/cookies/cookie_monster.h" | 19 #include "net/cookies/cookie_monster.h" |
23 #include "net/test/spawned_test_server/spawned_test_server.h" | 20 #include "net/test/spawned_test_server/spawned_test_server.h" |
24 #include "storage/browser/database/vfs_backend.h" | 21 #include "storage/browser/database/vfs_backend.h" |
(...skipping 12 matching lines...) Expand all Loading... |
37 | 34 |
38 #if defined(OS_MACOSX) | 35 #if defined(OS_MACOSX) |
39 #include "base/mac/foundation_util.h" | 36 #include "base/mac/foundation_util.h" |
40 #include "base/mac/scoped_nsautorelease_pool.h" | 37 #include "base/mac/scoped_nsautorelease_pool.h" |
41 #endif | 38 #endif |
42 | 39 |
43 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 40 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
44 #include "gin/v8_initializer.h" | 41 #include "gin/v8_initializer.h" |
45 #endif | 42 #endif |
46 | 43 |
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 | |
81 namespace content { | 44 namespace content { |
82 | 45 |
83 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { | 46 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
84 #if defined(OS_MACOSX) | 47 #if defined(OS_MACOSX) |
85 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 48 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
86 #endif | 49 #endif |
87 | 50 |
88 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 51 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
89 mock_clipboard_.reset(new MockWebClipboardImpl()); | 52 mock_clipboard_.reset(new MockWebClipboardImpl()); |
90 | 53 |
91 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 54 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
92 gin::V8Initializer::LoadV8Snapshot(); | 55 gin::V8Initializer::LoadV8Snapshot(); |
93 #endif | 56 #endif |
94 | 57 |
95 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner; | |
96 scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle; | |
97 if (base::MessageLoopProxy::current()) { | 58 if (base::MessageLoopProxy::current()) { |
98 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 59 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
99 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( | 60 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( |
100 renderer_scheduler_.get())); | 61 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)); | |
112 } | 62 } |
113 | 63 |
114 blink::initialize(this); | 64 blink::initialize(this); |
115 blink::setLayoutTestMode(true); | 65 blink::setLayoutTestMode(true); |
116 blink::WebSecurityPolicy::registerURLSchemeAsLocal( | 66 blink::WebSecurityPolicy::registerURLSchemeAsLocal( |
117 blink::WebString::fromUTF8("test-shell-resource")); | 67 blink::WebString::fromUTF8("test-shell-resource")); |
118 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 68 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
119 blink::WebString::fromUTF8("test-shell-resource")); | 69 blink::WebString::fromUTF8("test-shell-resource")); |
120 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 70 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
121 blink::WebString::fromUTF8("test-shell-resource")); | 71 blink::WebString::fromUTF8("test-shell-resource")); |
(...skipping 251 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
373 DCHECK(base::MessageLoop::current()); | 323 DCHECK(base::MessageLoop::current()); |
374 DCHECK(!base::MessageLoop::current()->is_running()); | 324 DCHECK(!base::MessageLoop::current()->is_running()); |
375 base::MessageLoop::current()->Run(); | 325 base::MessageLoop::current()->Run(); |
376 } | 326 } |
377 | 327 |
378 void TestBlinkWebUnitTestSupport::exitRunLoop() { | 328 void TestBlinkWebUnitTestSupport::exitRunLoop() { |
379 base::MessageLoop::current()->Quit(); | 329 base::MessageLoop::current()->Quit(); |
380 } | 330 } |
381 | 331 |
382 } // namespace content | 332 } // namespace content |
OLD | NEW |