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