Chromium Code Reviews| 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/message_loop/message_loop.h" | |
|
Sami
2015/05/05 13:55:54
Do you need this for anything?
ssid
2015/05/05 16:00:06
Done.
| |
| 10 #include "base/path_service.h" | 11 #include "base/path_service.h" |
| 12 #include "base/single_thread_task_runner.h" | |
| 11 #include "base/strings/utf_string_conversions.h" | 13 #include "base/strings/utf_string_conversions.h" |
| 14 #include "base/thread_task_runner_handle.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() {} | |
| 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 13:55:54
Could you make this do the right thing instead? So
ssid
2015/05/05 16:00:06
Done.
| |
| 68 bool RunsTasksOnCurrentThread() const override { return true; } | |
| 69 | |
| 70 protected: | |
| 71 ~DummyTaskRunner() override {} | |
| 72 | |
| 73 DISALLOW_COPY_AND_ASSIGN(DummyTaskRunner); | |
| 74 }; | |
| 75 | |
| 76 } // namespace | |
| 77 | |
| 44 namespace content { | 78 namespace content { |
| 45 | 79 |
| 46 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { | 80 TestBlinkWebUnitTestSupport::TestBlinkWebUnitTestSupport() { |
| 47 #if defined(OS_MACOSX) | 81 #if defined(OS_MACOSX) |
| 48 base::mac::ScopedNSAutoreleasePool autorelease_pool; | 82 base::mac::ScopedNSAutoreleasePool autorelease_pool; |
| 49 #endif | 83 #endif |
| 50 | 84 |
| 51 url_loader_factory_.reset(new WebURLLoaderMockFactory()); | 85 url_loader_factory_.reset(new WebURLLoaderMockFactory()); |
| 52 mock_clipboard_.reset(new MockWebClipboardImpl()); | 86 mock_clipboard_.reset(new MockWebClipboardImpl()); |
| 53 | 87 |
| 54 #ifdef V8_USE_EXTERNAL_STARTUP_DATA | 88 #ifdef V8_USE_EXTERNAL_STARTUP_DATA |
| 55 gin::V8Initializer::LoadV8Snapshot(); | 89 gin::V8Initializer::LoadV8Snapshot(); |
| 56 #endif | 90 #endif |
| 57 | 91 |
| 92 scoped_refptr<base::SingleThreadTaskRunner> dummy_task_runner; | |
| 93 scoped_ptr<base::ThreadTaskRunnerHandle> handle; | |
|
Sami
2015/05/05 13:55:54
nit: |handle| is a little too nonspecific for a va
ssid
2015/05/05 16:00:06
Done.
| |
| 58 if (base::MessageLoopProxy::current()) { | 94 if (base::MessageLoopProxy::current()) { |
| 59 renderer_scheduler_ = scheduler::RendererScheduler::Create(); | 95 renderer_scheduler_ = scheduler::RendererScheduler::Create(); |
| 60 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( | 96 web_thread_.reset(new scheduler::WebThreadImplForRendererScheduler( |
| 61 renderer_scheduler_.get())); | 97 renderer_scheduler_.get())); |
| 98 } else { | |
| 99 // Dummy task runner is initialized here because the blink::initialize | |
| 100 // creates IsolateHolder which needs the current task runner handle. There | |
| 101 // should be no task posted to this handle. The message loop is not created | |
| 102 // before this initialization because tests need different kinds of message | |
| 103 // loop which is not known upfront and each test suite that uses thread | |
|
Sami
2015/05/05 13:55:54
nit: "posted to this handle" => "posted to this ta
ssid
2015/05/05 16:00:06
Done.
| |
| 104 // bundle or message loop initializes its own. | |
| 105 dummy_task_runner = make_scoped_refptr(new DummyTaskRunner()); | |
| 106 handle.reset(new base::ThreadTaskRunnerHandle(dummy_task_runner)); | |
| 62 } | 107 } |
| 63 | 108 |
| 64 blink::initialize(this); | 109 blink::initialize(this); |
| 110 | |
| 111 if (dummy_task_runner.get()) { | |
|
Sami
2015/05/05 13:55:54
There's no need to reset the task explicitly is th
Primiano Tucci (use gerrit)
2015/05/05 14:26:51
Nit: just if (dummy_task_runner), scoped_refptr is
Sami
2015/05/05 14:35:46
I meant the destructors of both variables would au
ssid
2015/05/05 16:00:06
Done.
| |
| 112 // The dummy task runner is destroyed after the initialization is done. | |
| 113 handle.reset(); | |
| 114 dummy_task_runner = nullptr; | |
| 115 } | |
| 116 | |
| 65 blink::setLayoutTestMode(true); | 117 blink::setLayoutTestMode(true); |
| 66 blink::WebSecurityPolicy::registerURLSchemeAsLocal( | 118 blink::WebSecurityPolicy::registerURLSchemeAsLocal( |
| 67 blink::WebString::fromUTF8("test-shell-resource")); | 119 blink::WebString::fromUTF8("test-shell-resource")); |
| 68 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( | 120 blink::WebSecurityPolicy::registerURLSchemeAsNoAccess( |
| 69 blink::WebString::fromUTF8("test-shell-resource")); | 121 blink::WebString::fromUTF8("test-shell-resource")); |
| 70 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( | 122 blink::WebSecurityPolicy::registerURLSchemeAsDisplayIsolated( |
| 71 blink::WebString::fromUTF8("test-shell-resource")); | 123 blink::WebString::fromUTF8("test-shell-resource")); |
| 72 blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( | 124 blink::WebSecurityPolicy::registerURLSchemeAsEmptyDocument( |
| 73 blink::WebString::fromUTF8("test-shell-resource")); | 125 blink::WebString::fromUTF8("test-shell-resource")); |
| 74 blink::WebRuntimeFeatures::enableApplicationCache(true); | 126 blink::WebRuntimeFeatures::enableApplicationCache(true); |
| (...skipping 248 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 323 DCHECK(base::MessageLoop::current()); | 375 DCHECK(base::MessageLoop::current()); |
| 324 DCHECK(!base::MessageLoop::current()->is_running()); | 376 DCHECK(!base::MessageLoop::current()->is_running()); |
| 325 base::MessageLoop::current()->Run(); | 377 base::MessageLoop::current()->Run(); |
| 326 } | 378 } |
| 327 | 379 |
| 328 void TestBlinkWebUnitTestSupport::exitRunLoop() { | 380 void TestBlinkWebUnitTestSupport::exitRunLoop() { |
| 329 base::MessageLoop::current()->Quit(); | 381 base::MessageLoop::current()->Quit(); |
| 330 } | 382 } |
| 331 | 383 |
| 332 } // namespace content | 384 } // namespace content |
| OLD | NEW |