summaryrefslogtreecommitdiffstats
path: root/chrome/test/mini_installer_test/mini_installer_test_util.h
blob: 8312dad879863c9c6a3edbc631bf626982965c20 (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
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) 2009 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.
//
// This file declares utility functions for mini installer tests.
// The reason for putting these functions in different class is to separate out
// the critical logic from utility methods.

#ifndef CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_
#define CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_

#include <windows.h>
#include <vector>

#include "base/basictypes.h"

// This structure holds the name and creation time
// details of all the chrome nightly builds.
class FileInfo {
 public:
  FileInfo() {}
  FileInfo(const std::wstring& in_name, int in_creation_time) {
    name_.assign(in_name);
    creation_time_ = in_creation_time;
  }
  // This is a predicate to sort file information.
  bool IsNewer(const FileInfo& creation_time_begin,
               const FileInfo& creation_time_end);

  std::wstring name_;
  int creation_time_;
};
typedef std::vector<FileInfo> FileInfoList;

// This class maintains all the utility methods that are needed by mini
// installer test class.
class MiniInstallerTestUtil {
 public:
  // This method will change the current directory to one level up and
  // return the new current path.
  static bool ChangeCurrentDirectory(std::wstring *current_path);

  // Closes specified process.
  static void CloseProcesses(const std::wstring& executable_name);

  // Close Window whose name is 'window_name', by sending Windows message
  // 'message' to it.
  static bool CloseWindow(const wchar_t* window_name, UINT message);

  // This method will get the latest installer based on the passed 'pattern' and
  // 'channel_type' arguments. The 'pattern' argument decides if the requested
  // installer is full or differential. The 'channel_type' parameter decides if
  // the build is stable/dev/beta.
  static bool GetInstaller(const wchar_t* pattern, std::wstring *name,
                           const wchar_t* channel_type);

  // This method will create a command line to run apply tag.
  static bool GetCommandForTagging(std::wstring *return_command);

  // Returns the directory containing exe_name.
  static std::wstring GetFilePath(const wchar_t* exe_name);

  // This method will get the list of all folders or files based on the passed
  // 'path' and 'pattern' argument. The 'pattern' argument decides if the
  // requested file is a full or a differential installer.
  static bool GetLatestFile(const wchar_t* path, const wchar_t* pattern,
                            FileInfoList *file_name);

  // This method will get the previous build number
  static void GetPreviousBuildNumber(const std::wstring& path,
      std::wstring *build_number, const wchar_t* channel_type);

  // This method will get the previous full installer based on 'diff_file'
  // and 'channel_type' arguments. The 'channel_type'
  // parameter decides if the build is stable/dev/beta. The 'diff_file'
  // parameter will hold the latest diff installer name.
  static bool GetPreviousFullInstaller(const std::wstring& diff_file,
      std::wstring *previous, const wchar_t* channel_type);

  // This method will return standalone installer file name.
  static bool GetStandaloneInstallerFileName(FileInfoList *file_name);

  // This method will get the version number from the filename.
  static bool GetStandaloneVersion(std::wstring* version);

  // This method will send enter key to window in the foreground.
  static void SendEnterKeyToWindow();

  // Verifies if the given process starts running.
  static void VerifyProcessLaunch(const wchar_t* process_name,
                                  bool expected_status);

  // Verifies if the given process stops running.
  static bool VerifyProcessClose(const wchar_t* process_name);

 private:
  DISALLOW_EVIL_CONSTRUCTORS(MiniInstallerTestUtil);
};

#endif  // CHROME_TEST_MINI_INSTALLER_TEST_MINI_INSTALLER_TEST_UTIL_H_