[SyncFS] Build indexes from FileTracker entries on disk.
[chromium-blink-merge.git] / content / test / webkit_support.cc
bloba3e48edd92ccef80ae475fd56ae83df2d7c19a42
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
3 // found in the LICENSE file.
5 #include "content/test/webkit_support.h"
7 #include <string>
9 #include "base/command_line.h"
10 #include "base/message_loop/message_loop.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string_tokenizer.h"
13 #include "content/public/common/content_switches.h"
14 #include "content/public/common/user_agent.h"
15 #include "content/test/test_webkit_platform_support.h"
16 #include "third_party/WebKit/public/web/WebCache.h"
17 #include "third_party/WebKit/public/web/WebKit.h"
18 #include "third_party/WebKit/public/web/WebRuntimeFeatures.h"
19 #include "url/url_util.h"
21 #if defined(OS_WIN)
22 #include "ui/gfx/win/dpi.h"
23 #endif
25 #if defined(OS_ANDROID)
26 #include "base/android/jni_android.h"
27 #include "net/android/network_library.h"
28 #endif
30 #if defined(OS_MACOSX)
31 #include "base/test/mock_chrome_application_mac.h"
32 #endif
34 namespace content {
36 namespace {
38 void EnableBlinkPlatformLogChannels(const std::string& channels) {
39 if (channels.empty())
40 return;
41 base::StringTokenizer t(channels, ", ");
42 while (t.GetNext())
43 blink::enableLogChannel(t.token().c_str());
46 void ParseBlinkCommandLineArgumentsForUnitTests() {
47 const CommandLine& command_line = *CommandLine::ForCurrentProcess();
48 EnableBlinkPlatformLogChannels(
49 command_line.GetSwitchValueASCII(switches::kBlinkPlatformLogChannels));
52 class TestEnvironment {
53 public:
54 #if defined(OS_ANDROID)
55 // Android UI message loop goes through Java, so don't use it in tests.
56 typedef base::MessageLoop MessageLoopType;
57 #else
58 typedef base::MessageLoopForUI MessageLoopType;
59 #endif
61 TestEnvironment() {
62 main_message_loop_.reset(new MessageLoopType);
64 // TestWebKitPlatformSupport must be instantiated after MessageLoopType.
65 webkit_platform_support_.reset(new TestWebKitPlatformSupport);
68 ~TestEnvironment() {
71 TestWebKitPlatformSupport* webkit_platform_support() const {
72 return webkit_platform_support_.get();
75 private:
76 scoped_ptr<MessageLoopType> main_message_loop_;
77 scoped_ptr<TestWebKitPlatformSupport> webkit_platform_support_;
80 TestEnvironment* test_environment;
82 } // namespace
84 void SetUpTestEnvironmentForUnitTests() {
85 ParseBlinkCommandLineArgumentsForUnitTests();
87 blink::WebRuntimeFeatures::enableExperimentalFeatures(true);
88 blink::WebRuntimeFeatures::enableTestOnlyFeatures(true);
90 #if defined(OS_ANDROID)
91 JNIEnv* env = base::android::AttachCurrentThread();
92 net::android::RegisterNetworkLibrary(env);
93 #endif
95 #if defined(OS_MACOSX)
96 mock_cr_app::RegisterMockCrApp();
97 #endif
99 #if defined(OS_WIN)
100 gfx::InitDeviceScaleFactor(1.0f);
101 #endif
103 // Explicitly initialize the GURL library before spawning any threads.
104 // Otherwise crash may happend when different threads try to create a GURL
105 // at same time.
106 url::Initialize();
107 test_environment = new TestEnvironment;
110 void TearDownTestEnvironment() {
111 // Flush any remaining messages before we kill ourselves.
112 // http://code.google.com/p/chromium/issues/detail?id=9500
113 base::RunLoop().RunUntilIdle();
115 if (RunningOnValgrind())
116 blink::WebCache::clear();
117 delete test_environment;
118 test_environment = NULL;
121 } // namespace content