Index: chrome/installer/automation_test/test_installer.py |
diff --git a/chrome/installer/automation_test/test_installer.py b/chrome/installer/automation_test/test_installer.py |
new file mode 100644 |
index 0000000000000000000000000000000000000000..2409c0d094de8cd3469069059e93541351616ab8 |
--- /dev/null |
+++ b/chrome/installer/automation_test/test_installer.py |
@@ -0,0 +1,97 @@ |
+# Copyright (c) 2012 The Chromium Authors. All rights reserved. |
gab
2013/07/26 20:39:48
2013
|
+# Use of this source code is governed by a BSD-style license that can be |
+# found in the LICENSE file. |
+ |
+import argparse |
+import json |
+import subprocess |
+import verifier |
+ |
+class Config: |
+ def __init__(self): |
+ self.states = {} |
+ self.actions = {} |
+ self.tests = [] |
+ |
+# Merge the new Property object into the current Property object |
+def MergeProperties(current_property, new_property): |
+ for key, value in new_property.iteritems(): |
+ if key not in current_property: |
+ current_property[key] = value |
+ else: |
+ assert(isinstance(current_property[key], dict) and \ |
robertshield
2013/07/26 19:32:23
\ not needed here
|
+ isinstance(value, dict)) |
+ current_property[key] = \ |
+ dict(current_property[key].items() + value.items()) |
robertshield
2013/07/26 19:32:23
hanging indents (that continue a statement) are us
gab
2013/07/26 20:39:48
This is the overriding merge I like but Robert doe
|
+ |
+# Parse a .prop file |
+def ParseProperty(property_filename): |
+ property_file = open(property_filename, "r") |
+ property = json.load(property_file) |
+ property_file.close() |
+ return property |
+ |
robertshield
2013/07/26 19:32:23
I believe it is two blank lines between top-level
gab
2013/07/26 20:39:48
We should get someone with python readability to t
|
+# Parse an array of .prop files |
+def ParseProperties(property_filenames): |
+ current_property = {} |
+ for property_filename in property_filenames: |
+ new_property = ParseProperty(property_filename) |
+ MergeProperties(current_property, new_property) |
+ return current_property |
+ |
+# Parse a .config file |
+def ParseConfig(config_filename): |
+ config = Config() |
+ |
+ config_file = open(config_filename, "r") |
+ config_data = json.load(config_file) |
+ config_file.close() |
+ |
+ for state_name, state_property_filenames in config_data["states"]: |
+ config.states[state_name] = ParseProperties(state_property_filenames) |
+ for action_name, action_command in config_data["actions"]: |
+ config.actions[action_name] = action_command |
+ config.tests = config_data["tests"] |
+ return config |
+ |
+# Verify that the current machine states match the given machine states |
+def VerifyState(config, state): |
+ print " * Current state: " + state |
gab
2013/07/26 20:39:48
What's the idea behind spaces + *? I guess it make
|
+ verifier.Verify(config.states[state]) |
+ |
+def RunCommand(command): |
+ print " * Run command: " + command + "\n" |
+ subprocess.call(command, shell=True) |
+ |
+def RunResetCommand(): |
+ print " * Reset\n" |
+ subprocess.call("mini_installer.exe --chrome --uninstall" |
gab
2013/07/26 20:39:48
I don't actually think that works... I don't think
|
+ + " & mini_installer.exe --chrome-frame --uninstall", shell=True) # FIXME |
robertshield
2013/07/26 19:32:23
indent 2 more
|
+ |
+# Test the installer |
+def Test(config): |
+ for test in config.tests: |
+ print "Testing [ " + " -> ".join(test) + " ]" |
gab
2013/07/26 20:39:48
What does this print exactly? The format appears w
sukolsak
2013/07/30 15:40:32
It joins the strings in the array with " -> ". So,
|
+ |
+ RunResetCommand() |
+ |
+ current_state = test[0] |
+ VerifyState(config, current_state) |
+ |
+ for i in range(1, len(test), 2): |
gab
2013/07/26 20:39:48
Perhaps assert that len(tests) is odd before runni
|
+ action = test[i] |
+ RunCommand(config.actions[action]) |
+ |
+ current_state = test[i + 1] |
+ VerifyState(config, current_state) |
+ |
+def main(): |
+ parser = argparse.ArgumentParser(description="Test the installer.") |
+ parser.add_argument("config_filename", help="the config file") |
+ args = parser.parse_args() |
+ |
+ config = ParseConfig(args.config_filename) |
+ Test(config) |
+ |
+if __name__ == "__main__": |
+ main() |