summaryrefslogtreecommitdiffstats
path: root/chromecast/browser/test/chromecast_browser_test_runner.cc
blob: 4ffc3b3458996e099abdef5ae0dcfb4138e5fe8f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "base/command_line.h"
#include "base/macros.h"
#include "base/sys_info.h"
#include "chromecast/app/cast_main_delegate.h"
#include "chromecast/base/chromecast_switches.h"
#include "content/public/common/content_switches.h"
#include "content/public/test/content_test_suite_base.h"
#include "content/public/test/test_launcher.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace chromecast {
namespace shell {

namespace {

// Duplicate switch to avoid dependency on chromecast/internal.
const char kSwitchesAVSettingsUnixSocketPath[] = "av-settings-unix-socket-path";

const char kAvSettingsUnixSocketPath[] = "/tmp/avsettings";
const char kTestTypeBrowser[] = "browser";

class BrowserTestSuite : public content::ContentTestSuiteBase {
 public:
  BrowserTestSuite(int argc, char** argv)
      : content::ContentTestSuiteBase(argc, argv) {
  }
  ~BrowserTestSuite() override {
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(BrowserTestSuite);
};

class ChromecastTestLauncherDelegate : public content::TestLauncherDelegate {
 public:
  ChromecastTestLauncherDelegate() {}
  ~ChromecastTestLauncherDelegate() override {}

  int RunTestSuite(int argc, char** argv) override {
    return BrowserTestSuite(argc, argv).Run();
  }

  bool AdjustChildProcessCommandLine(
      base::CommandLine* command_line,
      const base::FilePath& temp_data_dir) override {
    // TODO(gunsch): handle temp_data_dir
    command_line->AppendSwitch(switches::kNoWifi);
    command_line->AppendSwitchASCII(switches::kTestType, kTestTypeBrowser);
    command_line->AppendSwitchASCII(kSwitchesAVSettingsUnixSocketPath,
                                    kAvSettingsUnixSocketPath);
    return true;
  }

 protected:
  content::ContentMainDelegate* CreateContentMainDelegate() override {
    return new CastMainDelegate();
  }

 private:
  DISALLOW_COPY_AND_ASSIGN(ChromecastTestLauncherDelegate);
};

}  // namespace

}  // namespace shell
}  // namespace chromecast

int main(int argc, char** argv) {
  int default_jobs = std::max(1, base::SysInfo::NumberOfProcessors() / 2);
  chromecast::shell::ChromecastTestLauncherDelegate launcher_delegate;
  return LaunchTests(&launcher_delegate, default_jobs, argc, argv);
}