Upstream version 7.36.149.0
[platform/framework/web/crosswalk.git] / src / content / test / content_test_launcher.cc
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
3 // found in the LICENSE file.
4
5 #include "content/public/test/test_launcher.h"
6
7 #include "base/base_paths.h"
8 #include "base/command_line.h"
9 #include "base/debug/stack_trace.h"
10 #include "base/logging.h"
11 #include "base/path_service.h"
12 #include "base/process/memory.h"
13 #include "base/sys_info.h"
14 #include "base/test/test_suite.h"
15 #include "base/test/test_timeouts.h"
16 #include "content/public/common/content_switches.h"
17 #include "content/public/test/content_test_suite_base.h"
18 #include "content/shell/app/shell_main_delegate.h"
19 #include "content/shell/common/shell_switches.h"
20 #include "testing/gtest/include/gtest/gtest.h"
21
22 #if defined(OS_ANDROID)
23 #include "base/message_loop/message_loop.h"
24 #include "content/app/mojo/mojo_init.h"
25 #include "content/common/url_schemes.h"
26 #include "content/public/common/content_paths.h"
27 #include "content/public/test/nested_message_pump_android.h"
28 #include "content/shell/browser/shell_content_browser_client.h"
29 #include "content/shell/common/shell_content_client.h"
30 #include "ui/base/ui_base_paths.h"
31 #endif
32
33 namespace content {
34
35 #if defined(OS_ANDROID)
36 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
37   return scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid());
38 };
39 #endif
40
41 class ContentBrowserTestSuite : public ContentTestSuiteBase {
42  public:
43   ContentBrowserTestSuite(int argc, char** argv)
44       : ContentTestSuiteBase(argc, argv) {
45   }
46   virtual ~ContentBrowserTestSuite() {
47   }
48
49  protected:
50   virtual void Initialize() OVERRIDE {
51
52 #if defined(OS_ANDROID)
53     // This needs to be done before base::TestSuite::Initialize() is called,
54     // as it also tries to set MessagePumpForUIFactory.
55     if (!base::MessageLoop::InitMessagePumpForUIFactory(
56             &CreateMessagePumpForUI))
57       VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
58
59     // For all other platforms, we call ContentMain for browser tests which goes
60     // through the normal browser initialization paths. For Android, we must set
61     // things up manually.
62     content_client_.reset(new ShellContentClient);
63     browser_content_client_.reset(new ShellContentBrowserClient());
64     SetContentClient(content_client_.get());
65     SetBrowserClientForTesting(browser_content_client_.get());
66
67     content::RegisterContentSchemes(false);
68     RegisterPathProvider();
69     ui::RegisterPathProvider();
70     RegisterInProcessThreads();
71
72     InitializeMojo();
73 #endif
74
75     ContentTestSuiteBase::Initialize();
76   }
77
78   virtual void Shutdown() OVERRIDE {
79     ContentTestSuiteBase::Shutdown();
80
81 #if defined(OS_ANDROID)
82     ShutdownMojo();
83 #endif
84   }
85
86 #if defined(OS_ANDROID)
87   scoped_ptr<ShellContentClient> content_client_;
88   scoped_ptr<ShellContentBrowserClient> browser_content_client_;
89 #endif
90
91   DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
92 };
93
94 class ContentTestLauncherDelegate : public TestLauncherDelegate {
95  public:
96   ContentTestLauncherDelegate() {}
97   virtual ~ContentTestLauncherDelegate() {}
98
99   virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
100     return ContentBrowserTestSuite(argc, argv).Run();
101   }
102
103   virtual bool AdjustChildProcessCommandLine(
104       CommandLine* command_line, const base::FilePath& temp_data_dir) OVERRIDE {
105     command_line->AppendSwitchPath(switches::kContentShellDataPath,
106                                    temp_data_dir);
107     command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
108     command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
109     return true;
110   }
111
112  protected:
113   virtual ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
114     return new ShellMainDelegate();
115   }
116
117  private:
118   DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
119 };
120
121 }  // namespace content
122
123 int main(int argc, char** argv) {
124   int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
125   content::ContentTestLauncherDelegate launcher_delegate;
126   return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
127 }