| 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/single_thread_task_runner.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" | 13 #include "base/thread_task_runner_handle.h" |
| 14 #include "base/threading/platform_thread.h" | 14 #include "base/threading/platform_thread.h" |
| 15 #include "components/scheduler/renderer/renderer_scheduler.h" | 15 #include "components/scheduler/renderer/lazy_scheduler_message_loop_delegate.h" |
| 16 #include "components/scheduler/renderer/renderer_scheduler_impl.h" |
| 16 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" | 17 #include "components/scheduler/renderer/webthread_impl_for_renderer_scheduler.h" |
| 17 #include "content/test/mock_webclipboard_impl.h" | 18 #include "content/test/mock_webclipboard_impl.h" |
| 18 #include "content/test/web_gesture_curve_mock.h" | 19 #include "content/test/web_gesture_curve_mock.h" |
| 19 #include "content/test/web_layer_tree_view_impl_for_testing.h" | 20 #include "content/test/web_layer_tree_view_impl_for_testing.h" |
| 20 #include "content/test/weburl_loader_mock_factory.h" | 21 #include "content/test/weburl_loader_mock_factory.h" |
| 21 #include "media/base/media.h" | 22 #include "media/base/media.h" |
| 22 #include "net/cookies/cookie_monster.h" | 23 #include "net/cookies/cookie_monster.h" |
| 23 #include "net/test/spawned_test_server/spawned_test_server.h" | 24 #include "net/test/spawned_test_server/spawned_test_server.h" |
| 24 #include "storage/browser/database/vfs_backend.h" | 25 #include "storage/browser/database/vfs_backend.h" |
| 25 #include "third_party/WebKit/public/platform/WebData.h" | 26 #include "third_party/WebKit/public/platform/WebData.h" |
| 26 #include "third_party/WebKit/public/platform/WebFileSystem.h" | 27 #include "third_party/WebKit/public/platform/WebFileSystem.h" |
| 27 #include "third_party/WebKit/public/platform/WebScheduler.h" | |
| 28 #include "third_party/WebKit/public/platform/WebStorageArea.h" | 28 #include "third_party/WebKit/public/platform/WebStorageArea.h" |
| 29 #include "third_party/WebKit/public/platform/WebStorageNamespace.h" | 29 #include "third_party/WebKit/public/platform/WebStorageNamespace.h" |
| 30 #include "third_party/WebKit/public/platform/WebString.h" | 30 #include "third_party/WebKit/public/platform/WebString.h" |
| 31 #include "third_party/WebKit/public/platform/WebURL.h" | 31 #include "third_party/WebKit/public/platform/WebURL.h" |
| 32 #include "third_party/WebKit/public/web/WebDatabase.h" | 32 #include "third_party/WebKit/public/web/WebDatabase.h" |
| 33 #include "third_party/WebKit/public/web/WebKit.h" | 33 #include "third_party/WebKit/public/web/WebKit.h" |
| 34 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 34 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
| 35 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" | 35 #include "third_party/WebKit/public/web/WebSecurityPolicy.h" |
| 36 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" | 36 #include "third_party/WebKit/public/web/WebStorageEventDispatcher.h" |
| 37 #include "v8/include/v8.h" | 37 #include "v8/include/v8.h" |
| (...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 70 } | 70 } |
| 71 | 71 |
| 72 protected: | 72 protected: |
| 73 ~DummyTaskRunner() override {} | 73 ~DummyTaskRunner() override {} |
| 74 | 74 |
| 75 base::PlatformThreadId thread_id_; | 75 base::PlatformThreadId thread_id_; |
| 76 | 76 |
| 77 DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner); | 77 DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner); |
| 78 }; | 78 }; |
| 79 | 79 |
| 80 class DummyWebThread : public blink::WebThread { | |
| 81 public: | |
| 82 DummyWebThread() | |
| 83 : thread_id_(base::PlatformThread::CurrentId()), | |
| 84 m_dummyScheduler(new blink::WebScheduler()) {} | |
| 85 | |
| 86 virtual void postTask(const blink::WebTraceLocation&, Task*) { NOTREACHED(); } | |
| 87 | |
| 88 virtual void postDelayedTask(const blink::WebTraceLocation&, | |
| 89 Task*, | |
| 90 long long delayMs) { | |
| 91 NOTREACHED(); | |
| 92 } | |
| 93 | |
| 94 virtual bool isCurrentThread() const { | |
| 95 return thread_id_ == base::PlatformThread::CurrentId(); | |
| 96 } | |
| 97 | |
| 98 virtual blink::WebScheduler* scheduler() const { | |
| 99 return m_dummyScheduler.get(); | |
| 100 } | |
| 101 | |
| 102 private: | |
| 103 base::PlatformThreadId thread_id_; | |
| 104 scoped_ptr<blink::WebScheduler> m_dummyScheduler; | |
| 105 | |
| 106 DISALLOW_COPY_AND_ASSIGN(DummyWebThread); | |
| 107 }; | |
| 108 | |
| 109 } // namespace | 80 } // namespace |
| 110 | 81 |
| 111 namespace content { | 82 namespace content { |
| 112 | 83 |
| 113 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { | 84 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
| 114 #if defined(OS_MACOSX) | 85 #if defined(OS_MACOSX) |
| 115 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 86 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 116 #endif | 87 #endif |
| 117 | 88 |
| 118 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 89 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
| 119 mock_clipboard_.reset(new MockWebClipboardImpl()); | 90 mock_clipboard_.reset(new MockWebClipboardImpl()); |
| 120 | 91 |
| 121 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 92 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 122 gin::V8Initializer::LoadV8Snapshot(); | 93 gin::V8Initializer::LoadV8Snapshot(); |
| 123 #endif | 94 #endif |
| 124 | 95 |
| 125 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner; | 96 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner; |
| 126 scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle; | 97 scoped_ptr<base::ThreadTaskRunnerHandle> dummy_task_runner_handle; |
| 127 if (base::MessageLoopProxy::current()) { | 98 if (!base::MessageLoopProxy::current()) { |
| 128 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | |
| 129 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( | |
| 130 renderer_scheduler_.get())); | |
| 131 } else { | |
| 132 // Dummy task runner is initialized here because the blink::initialize | 99 // Dummy task runner is initialized here because the blink::initialize |
| 133 // creates IsolateHolder which needs the current task runner handle. There | 100 // creates IsolateHolder which needs the current task runner handle. There |
| 134 // should be no task posted to this task runner. The message loop is not | 101 // should be no task posted to this task runner. The message loop is not |
| 135 // created before this initialization because some tests need specific kinds | 102 // created before this initialization because some tests need specific kinds |
| 136 // of message loops, and their types are not known upfront. Some tests also | 103 // of message loops, and their types are not known upfront. Some tests also |
| 137 // create their own thread bundles or message loops, and doing the same in | 104 // create their own thread bundles or message loops, and doing the same in |
| 138 // TestBlinkWebUnitTestSupport would introduce a conflict. | 105 // TestBlinkWebUnitTestSupport would introduce a conflict. |
| 139 dummy_task_runner = make_scoped_refptr(new DummyTaskRunner()); | 106 dummy_task_runner = make_scoped_refptr(new DummyTaskRunner()); |
| 140 dummy_task_runner_handle.reset( | 107 dummy_task_runner_handle.reset( |
| 141 new base::ThreadTaskRunnerHandle(dummy_task_runner)); | 108 new base::ThreadTaskRunnerHandle(dummy_task_runner)); |
| 142 web_thread_.reset(new DummyWebThread()); | |
| 143 } | 109 } |
| 110 renderer_scheduler_ = make_scoped_ptr(new scheduler::RendererSchedulerImpl( |
| 111 scheduler::LazySchedulerMessageLoopDelegate::Create())); |
| 112 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( |
| 113 renderer_scheduler_.get())); |
| 144 | 114 |
| 145 blink::initialize(this); | 115 blink::initialize(this); |
| 146 blink::setLayoutTestMode(true); | 116 blink::setLayoutTestMode(true); |
| 147 blink::WebSecurityPolicy::registerURLSchemeAsLocal( | 117 blink::WebSecurityPolicy::registerURLSchemeAsLocal( |
| 148 blink::WebString::fromUTF8("test-shell-resource")); | 118 blink::WebString::fromUTF8("test-shell-resource")); |
| 149 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 119 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
| 150 blink::WebString::fromUTF8("test-shell-resource")); | 120 blink::WebString::fromUTF8("test-shell-resource")); |
| 151 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 121 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
| 152 blink::WebString::fromUTF8("test-shell-resource")); | 122 blink::WebString::fromUTF8("test-shell-resource")); |
| 153 blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( | 123 blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( |
| (...skipping 250 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 404 DCHECK(base::MessageLoop::current()); | 374 DCHECK(base::MessageLoop::current()); |
| 405 DCHECK(!base::MessageLoop::current()->is_running()); | 375 DCHECK(!base::MessageLoop::current()->is_running()); |
| 406 base::MessageLoop::current()->Run(); | 376 base::MessageLoop::current()->Run(); |
| 407 } | 377 } |
| 408 | 378 |
| 409 void TestBlinkWebUnitTestSupport::exitRunLoop() { | 379 void TestBlinkWebUnitTestSupport::exitRunLoop() { |
| 410 base::MessageLoop::current()->Quit(); | 380 base::MessageLoop::current()->Quit(); |
| 411 } | 381 } |
| 412 | 382 |
| 413 } // namespace content | 383 } // namespace content |
| OLD | NEW |