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/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/files/file_path.h" | 8 #include "base/files/file_path.h" |
9 #include "base/files/file_util.h" | 9 #include "base/files/file_util.h" |
10 #include "base/files/scoped_temp_dir.h" | 10 #include "base/files/scoped_temp_dir.h" |
11 #include "base/path_service.h" | 11 #include "base/path_service.h" |
12 #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 "content/child/webthread_impl.h" | |
13 #include "content/public/common/content_switches.h" | 15 #include "content/public/common/content_switches.h" |
14 #include "content/renderer/scheduler/renderer_scheduler.h" | 16 #include "content/renderer/scheduler/renderer_scheduler.h" |
15 #include "content/renderer/scheduler/web_scheduler_impl.h" | 17 #include "content/renderer/scheduler/web_scheduler_impl.h" |
16 #include "content/test/mock_webclipboard_impl.h" | 18 #include "content/test/mock_webclipboard_impl.h" |
17 #include "content/test/web_gesture_curve_mock.h" | 19 #include "content/test/web_gesture_curve_mock.h" |
18 #include "content/test/web_layer_tree_view_impl_for_testing.h" | 20 #include "content/test/web_layer_tree_view_impl_for_testing.h" |
19 #include "content/test/weburl_loader_mock_factory.h" | 21 #include "content/test/weburl_loader_mock_factory.h" |
20 #include "media/base/media.h" | 22 #include "media/base/media.h" |
21 #include "net/cookies/cookie_monster.h" | 23 #include "net/cookies/cookie_monster.h" |
22 #include "net/test/spawned_test_server/spawned_test_server.h" | 24 #include "net/test/spawned_test_server/spawned_test_server.h" |
(...skipping 15 matching lines...) Expand all Loading... | |
38 #include "base/mac/foundation_util.h" | 40 #include "base/mac/foundation_util.h" |
39 #include "base/mac/scoped_nsautorelease_pool.h" | 41 #include "base/mac/scoped_nsautorelease_pool.h" |
40 #endif | 42 #endif |
41 | 43 |
42 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 44 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
43 #include "gin/public/isolate_holder.h" | 45 #include "gin/public/isolate_holder.h" |
44 #endif | 46 #endif |
45 | 47 |
46 namespace content { | 48 namespace content { |
47 | 49 |
50 namespace { | |
51 | |
52 class WebThreadImplForTest : public WebThreadBase { | |
53 public: | |
54 WebThreadImplForTest() | |
55 : owning_thread_task_runner_(base::ThreadTaskRunnerHandle::Get()), | |
56 thread_id_(base::PlatformThread::CurrentId()) { | |
57 } | |
58 | |
59 ~WebThreadImplForTest() override { | |
60 } | |
61 | |
62 // blink::WebThread: | |
63 blink::PlatformThreadId threadId() const override { | |
64 return thread_id_; | |
65 } | |
66 | |
67 // WebThreadBase: | |
68 base::MessageLoop* MessageLoop() const override { | |
69 DCHECK(isCurrentThread()); | |
70 return base::MessageLoop::current(); | |
71 } | |
72 | |
73 private: | |
74 base::SingleThreadTaskRunner* TaskRunner() const override { | |
75 return owning_thread_task_runner_.get(); | |
76 } | |
77 | |
78 scoped_refptr<base::SingleThreadTaskRunner> owning_thread_task_runner_; | |
79 blink::PlatformThreadId thread_id_; | |
80 }; | |
81 | |
82 } // namespace | |
83 | |
48 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { | 84 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
49 #if defined(OS_MACOSX) | 85 #if defined(OS_MACOSX) |
50 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 86 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
51 #endif | 87 #endif |
52 | 88 |
53 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 89 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
54 mock_clipboard_.reset(new MockWebClipboardImpl()); | 90 mock_clipboard_.reset(new MockWebClipboardImpl()); |
55 | 91 |
56 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 92 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
57 gin::IsolateHolder::LoadV8Snapshot(); | 93 gin::IsolateHolder::LoadV8Snapshot(); |
58 #endif | 94 #endif |
59 | 95 |
60 if (base::MessageLoopProxy::current()) { | 96 if (base::MessageLoopProxy::current()) { |
61 renderer_scheduler_ = RendererScheduler::Create(); | 97 renderer_scheduler_ = RendererScheduler::Create(); |
62 web_scheduler_.reset(new WebSchedulerImpl(renderer_scheduler_.get())); | 98 web_scheduler_.reset(new WebSchedulerImpl(renderer_scheduler_.get())); |
99 web_thread_.reset(new WebThreadImplForTest()); | |
Sami
2015/02/27 17:23:08
Since we're using the real scheduler, it seems lik
sadrul
2015/03/01 10:21:38
Sounds right. Done.
| |
63 } | 100 } |
64 | 101 |
65 blink::initialize(this); | 102 blink::initialize(this); |
66 blink::setLayoutTestMode(true); | 103 blink::setLayoutTestMode(true); |
67 blink::WebSecurityPolicy::registerURLSchemeAsLocal( | 104 blink::WebSecurityPolicy::registerURLSchemeAsLocal( |
68 blink::WebString::fromUTF8("test-shell-resource")); | 105 blink::WebString::fromUTF8("test-shell-resource")); |
69 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 106 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
70 blink::WebString::fromUTF8("test-shell-resource")); | 107 blink::WebString::fromUTF8("test-shell-resource")); |
71 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 108 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
72 blink::WebString::fromUTF8("test-shell-resource")); | 109 blink::WebString::fromUTF8("test-shell-resource")); |
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
312 bool TestBlinkWebUnitTestSupport::getBlobItems( | 349 bool TestBlinkWebUnitTestSupport::getBlobItems( |
313 const blink::WebString& uuid, | 350 const blink::WebString& uuid, |
314 blink::WebVector<blink::WebBlobData::Item*>* items) { | 351 blink::WebVector<blink::WebBlobData::Item*>* items) { |
315 return blob_registry_.GetBlobItems(uuid, items); | 352 return blob_registry_.GetBlobItems(uuid, items); |
316 } | 353 } |
317 | 354 |
318 blink::WebScheduler* TestBlinkWebUnitTestSupport::scheduler() { | 355 blink::WebScheduler* TestBlinkWebUnitTestSupport::scheduler() { |
319 return web_scheduler_.get(); | 356 return web_scheduler_.get(); |
320 } | 357 } |
321 | 358 |
359 blink::WebThread* TestBlinkWebUnitTestSupport::currentThread() { | |
360 if (web_thread_ && web_thread_->isCurrentThread()) | |
361 return web_thread_.get(); | |
362 return BlinkPlatformImpl::currentThread(); | |
363 } | |
364 | |
322 } // namespace content | 365 } // namespace content |
OLD | NEW |