Upstream version 5.34.104.0
[platform/framework/web/crosswalk.git] / src / xwalk / test / base / xwalk_test_launcher.cc
1 // Copyright (c) 2013 Intel Corporation. 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 "base/command_line.h"
6 #include "base/file_util.h"
7 #include "base/files/file_path.h"
8 #include "base/logging.h"
9 #include "base/memory/linked_ptr.h"
10 #include "base/process/launch.h"
11 #include "base/run_loop.h"
12 #include "base/strings/string_util.h"
13 #include "base/sys_info.h"
14 #include "base/test/test_file_util.h"
15 #include "content/public/app/content_main.h"
16 #include "content/public/browser/browser_thread.h"
17 #include "content/public/common/content_switches.h"
18 #include "content/public/test/test_launcher.h"
19 #include "xwalk/runtime/app/xwalk_main_delegate.h"
20 #include "xwalk/test/base/xwalk_test_suite.h"
21
22 class XWalkTestLauncherDelegate : public content::TestLauncherDelegate {
23  public:
24   XWalkTestLauncherDelegate() {}
25   virtual ~XWalkTestLauncherDelegate() {}
26
27   virtual int RunTestSuite(int argc, char** argv) OVERRIDE {
28     return XWalkTestSuite(argc, argv).Run();
29   }
30
31   virtual bool AdjustChildProcessCommandLine(
32       CommandLine* command_line, const base::FilePath& temp_data_dir) OVERRIDE {
33     CommandLine new_command_line(command_line->GetProgram());
34     CommandLine::SwitchMap switches = command_line->GetSwitches();
35
36     for (CommandLine::SwitchMap::const_iterator iter = switches.begin();
37          iter != switches.end(); ++iter) {
38       new_command_line.AppendSwitchNative((*iter).first, (*iter).second);
39     }
40
41     // Expose the garbage collector interface, so we can test the object
42     // lifecycle tracker interface.
43     new_command_line.AppendSwitchASCII(
44         switches::kJavaScriptFlags, "--expose-gc");
45
46     *command_line = new_command_line;
47     return true;
48   }
49
50  protected:
51   virtual content::ContentMainDelegate* CreateContentMainDelegate() OVERRIDE {
52 #if defined(OS_WIN) || defined (OS_LINUX)
53     return new xwalk::XWalkMainDelegate();
54 #else
55     // This delegate is only guaranteed to link on linux and windows, so just
56     // bail out if we are on any other platform.
57     NOTREACHED();
58     return NULL;
59 #endif
60   }
61
62  private:
63   DISALLOW_COPY_AND_ASSIGN(XWalkTestLauncherDelegate);
64 };
65
66 int main(int argc, char** argv) {
67   int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
68   XWalkTestLauncherDelegate launcher_delegate;
69   return content::LaunchTests(&launcher_delegate, default_jobs, argc, argv);
70 }