Update To 11.40.268.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/i18n/icu_util.h"
11 #include "base/logging.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 "media/base/media_switches.h"
21 #include "testing/gtest/include/gtest/gtest.h"
22
23 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
24 #include "gin/public/isolate_holder.h"
25 #endif
26
27 #if defined(OS_ANDROID)
28 #include "base/message_loop/message_loop.h"
29 #include "content/app/mojo/mojo_init.h"
30 #include "content/common/url_schemes.h"
31 #include "content/public/common/content_paths.h"
32 #include "content/public/test/nested_message_pump_android.h"
33 #include "content/shell/browser/shell_content_browser_client.h"
34 #include "content/shell/common/shell_content_client.h"
35 #include "ui/base/ui_base_paths.h"
36 #endif
37
38 namespace content {
39
40 #if defined(OS_ANDROID)
41 scoped_ptr<base::MessagePump> CreateMessagePumpForUI() {
42   return scoped_ptr<base::MessagePump>(new NestedMessagePumpAndroid());
43 };
44 #endif
45
46 class ContentBrowserTestSuite : public ContentTestSuiteBase {
47  public:
48   ContentBrowserTestSuite(int argc, char** argv)
49       : ContentTestSuiteBase(argc, argv) {
50   }
51   ~ContentBrowserTestSuite() override {}
52
53  protected:
54   void Initialize() override {
55 #if defined(OS_ANDROID)
56     base::i18n::AllowMultipleInitializeCallsForTesting();
57     base::i18n::InitializeICU();
58
59 #ifdef V8_USE_EXTERNAL_STARTUP_DATA
60     gin::IsolateHolder::LoadV8Snapshot();
61 #endif
62
63     // This needs to be done before base::TestSuite::Initialize() is called,
64     // as it also tries to set MessagePumpForUIFactory.
65     if (!base::MessageLoop::InitMessagePumpForUIFactory(
66             &CreateMessagePumpForUI))
67       VLOG(0) << "MessagePumpForUIFactory already set, unable to override.";
68
69     // For all other platforms, we call ContentMain for browser tests which goes
70     // through the normal browser initialization paths. For Android, we must set
71     // things up manually.
72     content_client_.reset(new ShellContentClient);
73     browser_content_client_.reset(new ShellContentBrowserClient());
74     SetContentClient(content_client_.get());
75     SetBrowserClientForTesting(browser_content_client_.get());
76
77     content::RegisterContentSchemes(false);
78     RegisterPathProvider();
79     ui::RegisterPathProvider();
80     RegisterInProcessThreads();
81
82     InitializeMojo();
83 #endif
84
85     ContentTestSuiteBase::Initialize();
86   }
87
88 #if defined(OS_ANDROID)
89   scoped_ptr<ShellContentClient> content_client_;
90   scoped_ptr<ShellContentBrowserClient> browser_content_client_;
91 #endif
92
93   DISALLOW_COPY_AND_ASSIGN(ContentBrowserTestSuite);
94 };
95
96 class ContentTestLauncherDelegate : public TestLauncherDelegate {
97  public:
98   ContentTestLauncherDelegate() {}
99   ~ContentTestLauncherDelegate() override {}
100
101   int RunTestSuite(int argc, char** argv) override {
102     return ContentBrowserTestSuite(argc, argv).Run();
103   }
104
105   bool AdjustChildProcessCommandLine(
106       CommandLine* command_line,
107       const base::FilePath& temp_data_dir) override {
108     command_line->AppendSwitchPath(switches::kContentShellDataPath,
109                                    temp_data_dir);
110     command_line->AppendSwitch(switches::kUseFakeDeviceForMediaStream);
111     command_line->AppendSwitch(switches::kUseFakeUIForMediaStream);
112     return true;
113   }
114
115  protected:
116   ContentMainDelegate* CreateContentMainDelegate() override {
117     return new ShellMainDelegate();
118   }
119
120  private:
121   DISALLOW_COPY_AND_ASSIGN(ContentTestLauncherDelegate);
122 };
123
124 }  // namespace content
125
126 int main(int argc, char** argv) {
127   int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
128   content::ContentTestLauncherDelegate launcher_delegate;
129   return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
130 }