| Index: chrome/test/mini_installer/process_visitor.py
|
| diff --git a/chrome/test/mini_installer/process_visitor.py b/chrome/test/mini_installer/process_visitor.py
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..8fa1e345b10b9d8c672bdad20bcd81691ecf30af
|
| --- /dev/null
|
| +++ b/chrome/test/mini_installer/process_visitor.py
|
| @@ -0,0 +1,48 @@
|
| +# Copyright 2017 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.
|
| +
|
| +import chrome_helper
|
| +import visitor
|
| +
|
| +class ProcessVisitor(visitor.Visitor):
|
| + """ Visitor for Processes entry in property.
|
| + """
|
| + def _VisitEntry(self, entry_name, entry_value):
|
| + """ Check whether a process is running or not.
|
| +
|
| + Args:
|
| + 'entry_name' - A string represents the path to the process being
|
| + verified.
|
| + 'entry_value' - A dictionary with the following key and value:
|
| + 'running': a boolean indicating whether the process
|
| + should be running.
|
| + """
|
| + running_process_paths = [path for (_, path) in
|
| + chrome_helper.GetProcessIDAndPathPairs()]
|
| + process_path = self._variable_expander.Expand(entry_name)
|
| + is_running = process_path in running_process_paths
|
| + self._HandleProcess(is_running, entry_value['running'], process_path)
|
| +
|
| + def _HandleProcess(self, is_running, should_process_run, process_path):
|
| + """ Abstract function to check process.
|
| +
|
| + Args:
|
| + is_running: A boolean represents whether the process is running.
|
| + should_process_run: A boolean represents whether the process should
|
| + keep running.
|
| + process_path: A string represents the path to the process.
|
| + """
|
| + raise NotImplementedError()
|
| +
|
| +class ProcessVerifier(ProcessVisitor):
|
| + """Verifies that the running processes match the expectation dictionaries."""
|
| + def _HandleProcess(self, is_running, should_process_run, process_path):
|
| + """ Overridden ProcessVisitor._HandleProcess to verify a process state.
|
| + """
|
| + error_message = ""
|
| + if is_running:
|
| + error_message = 'Process %s is running' % process_path
|
| + else:
|
| + error_message = 'Process %s is not running' % process_path
|
| + assert should_process_run == is_running, error_message
|
|
|