| OLD | NEW |
| (Empty) | |
| 1 # Copyright 2017 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 import chrome_helper |
| 6 import visitor |
| 7 |
| 8 class ProcessVisitor(visitor.Visitor): |
| 9 """ Visitor for Processes entry in property. |
| 10 """ |
| 11 def _VisitEntry(self, entry_name, entry_value): |
| 12 """ Check whether a process is running or not. |
| 13 |
| 14 Args: |
| 15 'entry_name' - A string represents the path to the process being |
| 16 verified. |
| 17 'entry_value' - A dictionary with the following key and value: |
| 18 'running': a boolean indicating whether the process |
| 19 should be running. |
| 20 """ |
| 21 running_process_paths = [path for (_, path) in |
| 22 chrome_helper.GetProcessIDAndPathPairs()] |
| 23 process_path = self._variable_expander.Expand(entry_name) |
| 24 is_running = process_path in running_process_paths |
| 25 self._HandleProcess(is_running, entry_value['running'], process_path) |
| 26 |
| 27 def _HandleProcess(self, is_running, should_process_run, process_path): |
| 28 """ Abstract function to check process. |
| 29 |
| 30 Args: |
| 31 is_running: A boolean represents whether the process is running. |
| 32 should_process_run: A boolean represents whether the process should |
| 33 keep running. |
| 34 process_path: A string represents the path to the process. |
| 35 """ |
| 36 raise NotImplementedError() |
| 37 |
| 38 class ProcessVerifier(ProcessVisitor): |
| 39 """Verifies that the running processes match the expectation dictionaries.""" |
| 40 def _HandleProcess(self, is_running, should_process_run, process_path): |
| 41 """ Overridden ProcessVisitor._HandleProcess to verify a process state. |
| 42 """ |
| 43 error_message = "" |
| 44 if is_running: |
| 45 error_message = 'Process %s is running' % process_path |
| 46 else: |
| 47 error_message = 'Process %s is not running' % process_path |
| 48 assert should_process_run == is_running, error_message |
| OLD | NEW |