| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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 <base/test/test_suite.h> | 5 #include "base/message_loop.h" |
| 6 #include "base/rand_util.h" |
| 7 #include "base/threading/thread_local_storage.h" |
| 8 #include "base/test/test_suite.h" |
| 9 #include "third_party/WebKit/Source/Platform/chromium/public/Platform.h" |
| 10 #include "webkit/compositor_bindings/web_compositor_support_impl.h" |
| 11 #include "webkit/glue/webthread_impl.h" |
| 6 #include <gmock/gmock.h> | 12 #include <gmock/gmock.h> |
| 7 | 13 |
| 8 #if defined(USE_LIBCC_FOR_COMPOSITOR) | 14 #include "base/debug/trace_event_impl.h" |
| 9 #include <webkit/support/webkit_support.h> | 15 |
| 10 #endif | 16 using webkit_glue::WebThreadImplForMessageLoop; |
| 17 |
| 18 class TestPlatform : public WebKit::Platform { |
| 19 public: |
| 20 virtual WebKit::WebCompositorSupport* compositorSupport() { |
| 21 return &compositor_support_; |
| 22 } |
| 23 |
| 24 virtual void cryptographicallyRandomValues( |
| 25 unsigned char* buffer, size_t length) { |
| 26 base::RandBytes(buffer, length); |
| 27 } |
| 28 |
| 29 virtual WebKit::WebThread* createThread(const char* name) { |
| 30 return new webkit_glue::WebThreadImpl(name); |
| 31 } |
| 32 |
| 33 virtual WebKit::WebThread* currentThread() { |
| 34 webkit_glue::WebThreadImplForMessageLoop* thread = |
| 35 static_cast<WebThreadImplForMessageLoop*>(current_thread_slot_.Get()); |
| 36 if (thread) |
| 37 return (thread); |
| 38 |
| 39 scoped_refptr<base::MessageLoopProxy> message_loop = |
| 40 base::MessageLoopProxy::current(); |
| 41 if (!message_loop) |
| 42 return NULL; |
| 43 |
| 44 thread = new WebThreadImplForMessageLoop(message_loop); |
| 45 current_thread_slot_.Set(thread); |
| 46 return thread; |
| 47 } |
| 48 |
| 49 virtual double currentTime() { |
| 50 return base::Time::Now().ToDoubleT(); |
| 51 } |
| 52 |
| 53 virtual double monotonicallyIncreasingTime() { |
| 54 return base::TimeTicks::Now().ToInternalValue() / |
| 55 static_cast<double>(base::Time::kMicrosecondsPerSecond); |
| 56 } |
| 57 |
| 58 private: |
| 59 base::ThreadLocalStorage::Slot current_thread_slot_; |
| 60 webkit::WebCompositorSupportImpl compositor_support_; |
| 61 }; |
| 11 | 62 |
| 12 int main(int argc, char** argv) { | 63 int main(int argc, char** argv) { |
| 13 ::testing::InitGoogleMock(&argc, argv); | 64 ::testing::InitGoogleMock(&argc, argv); |
| 14 TestSuite testSuite(argc, argv); | 65 TestSuite testSuite(argc, argv); |
| 15 #if defined(USE_LIBCC_FOR_COMPOSITOR) | 66 TestPlatform platform; |
| 16 webkit_support::SetUpTestEnvironmentForUnitTests(); | 67 MessageLoop message_loop; |
| 17 #endif | 68 WebKit::Platform::initialize(&platform); |
| 18 int result = testSuite.Run(); | 69 int result = testSuite.Run(); |
| 19 #if defined(USE_LIBCC_FOR_COMPOSITOR) | 70 WebKit::Platform::shutdown(); |
| 20 webkit_support::TearDownTestEnvironment(); | |
| 21 #endif | |
| 22 | 71 |
| 23 return result; | 72 return result; |
| 24 } | 73 } |
| 25 | 74 |
| OLD | NEW |