OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/blink_test_environment.h" | 5 #include "content/test/blink_test_environment.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/message_loop/message_loop.h" | 10 #include "base/message_loop/message_loop.h" |
11 #include "base/run_loop.h" | 11 #include "base/run_loop.h" |
12 #include "base/strings/string_tokenizer.h" | 12 #include "base/strings/string_tokenizer.h" |
13 #include "base/test/test_discardable_memory_allocator.h" | 13 #include "base/test/test_discardable_memory_allocator.h" |
14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" | 14 #include "base/third_party/dynamic_annotations/dynamic_annotations.h" |
15 #include "build/build_config.h" | 15 #include "build/build_config.h" |
16 #include "content/public/common/content_switches.h" | 16 #include "content/public/common/content_switches.h" |
17 #include "content/public/common/user_agent.h" | 17 #include "content/public/common/user_agent.h" |
18 #include "content/public/test/test_content_client_initializer.h" | 18 #include "content/public/test/test_content_client_initializer.h" |
19 #include "content/test/test_blink_web_unit_test_support.h" | 19 #include "content/test/test_blink_web_unit_test_support.h" |
20 #include "third_party/WebKit/public/web/WebCache.h" | 20 #include "third_party/WebKit/public/web/WebCache.h" |
21 #include "third_party/WebKit/public/web/WebKit.h" | 21 #include "third_party/WebKit/public/web/WebKit.h" |
22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" | 22 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h" |
23 #include "url/url_util.h" | 23 #include "url/url_util.h" |
24 | 24 |
25 #if defined(OS_WIN) | 25 #if defined(OS_WIN) |
26 #include "ui/display/win/dpi.h" | 26 #include "ui/display/win/dpi.h" |
27 #endif | 27 #endif |
28 | 28 |
29 #if defined(OS_ANDROID) | |
30 #include "base/android/jni_android.h" | |
31 #include "net/android/network_library.h" | |
32 #endif | |
33 | |
34 #if defined(OS_MACOSX) | 29 #if defined(OS_MACOSX) |
35 #include "base/test/mock_chrome_application_mac.h" | 30 #include "base/test/mock_chrome_application_mac.h" |
36 #endif | 31 #endif |
37 | 32 |
38 namespace content { | 33 namespace content { |
39 | 34 |
40 namespace { | 35 namespace { |
41 | 36 |
42 void EnableBlinkPlatformLogChannels(const std::string& channels) { | 37 void EnableBlinkPlatformLogChannels(const std::string& channels) { |
43 if (channels.empty()) | 38 if (channels.empty()) |
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
91 TestEnvironment* test_environment; | 86 TestEnvironment* test_environment; |
92 | 87 |
93 } // namespace | 88 } // namespace |
94 | 89 |
95 void SetUpBlinkTestEnvironment() { | 90 void SetUpBlinkTestEnvironment() { |
96 ParseBlinkCommandLineArgumentsForUnitTests(); | 91 ParseBlinkCommandLineArgumentsForUnitTests(); |
97 | 92 |
98 blink::WebRuntimeFeatures::enableExperimentalFeatures(true); | 93 blink::WebRuntimeFeatures::enableExperimentalFeatures(true); |
99 blink::WebRuntimeFeatures::enableTestOnlyFeatures(true); | 94 blink::WebRuntimeFeatures::enableTestOnlyFeatures(true); |
100 | 95 |
101 #if defined(OS_ANDROID) | |
102 JNIEnv* env = base::android::AttachCurrentThread(); | |
103 net::android::RegisterNetworkLibrary(env); | |
104 #endif | |
105 | |
106 #if defined(OS_MACOSX) | 96 #if defined(OS_MACOSX) |
107 mock_cr_app::RegisterMockCrApp(); | 97 mock_cr_app::RegisterMockCrApp(); |
108 #endif | 98 #endif |
109 | 99 |
110 #if defined(OS_WIN) | 100 #if defined(OS_WIN) |
111 display::win::SetDefaultDeviceScaleFactor(1.0f); | 101 display::win::SetDefaultDeviceScaleFactor(1.0f); |
112 #endif | 102 #endif |
113 | 103 |
114 // Explicitly initialize the GURL library before spawning any threads. | 104 // Explicitly initialize the GURL library before spawning any threads. |
115 // Otherwise crash may happend when different threads try to create a GURL | 105 // Otherwise crash may happend when different threads try to create a GURL |
116 // at same time. | 106 // at same time. |
117 url::Initialize(); | 107 url::Initialize(); |
118 test_environment = new TestEnvironment; | 108 test_environment = new TestEnvironment; |
119 } | 109 } |
120 | 110 |
121 void TearDownBlinkTestEnvironment() { | 111 void TearDownBlinkTestEnvironment() { |
122 // Flush any remaining messages before we kill ourselves. | 112 // Flush any remaining messages before we kill ourselves. |
123 // http://code.google.com/p/chromium/issues/detail?id=9500 | 113 // http://code.google.com/p/chromium/issues/detail?id=9500 |
124 base::RunLoop().RunUntilIdle(); | 114 base::RunLoop().RunUntilIdle(); |
125 | 115 |
126 if (RunningOnValgrind()) | 116 if (RunningOnValgrind()) |
127 blink::WebCache::clear(); | 117 blink::WebCache::clear(); |
128 delete test_environment; | 118 delete test_environment; |
129 test_environment = NULL; | 119 test_environment = NULL; |
130 } | 120 } |
131 | 121 |
132 } // namespace content | 122 } // namespace content |
OLD | NEW |