Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(6267)

Unified Diff: chrome/installer/automation_test/test_installer.py

Issue 20578004: Initial commit for the Automated Installer Testing Framework. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Add data. Created 7 years, 5 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
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..26e7f869f2afdc18844d73a69649223631ed2418
--- /dev/null
+++ b/chrome/installer/automation_test/test_installer.py
@@ -0,0 +1,111 @@
+# Copyright (c) 2012 The Chromium Authors. All rights reserved.
grt (UTC plus 2) 2013/07/30 03:31:38 the new-style notice is (note: no "(c)" and use th
sukolsak 2013/07/30 15:40:32 Should we put the notice in the data files? The da
gab 2013/07/30 20:44:14 Ya, I don't think we can, but it's pure data, not
+# 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 os
+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
grt (UTC plus 2) 2013/07/30 03:31:38 i don't have python readability, so take this with
+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
+ isinstance(value, dict))
+ current_property[key] = dict(
+ current_property[key].items() + value.items())
+
+
+# Parse a .prop file
+def ParseProperty(property_filename, dir):
grt (UTC plus 2) 2013/07/30 03:31:38 "dir" is the name of a built-in function. please u
+ property_file = open(os.path.join(dir, property_filename), "r")
grt (UTC plus 2) 2013/07/30 03:31:38 use the "with" statement when opening files here a
+ property = json.load(property_file)
+ property_file.close()
+ return property
+
+
+# Parse an array of .prop files
+def ParseProperties(property_filenames, dir):
+ current_property = {}
+ for property_filename in property_filenames:
+ new_property = ParseProperty(property_filename, dir)
+ 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()
+ dir = os.path.dirname(os.path.abspath(config_filename))
+
+ for state_name, state_property_filenames in config_data["states"]:
+ config.states[state_name] = ParseProperties(state_property_filenames, dir)
+ 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
+ verifier.Verify(config.states[state])
+
+
+def RunCommand(command):
+ print " * Run command: " + command + "\n"
+ subprocess.call(command, shell=True)
+
+
+def RunResetCommand():
+ print " * Reset\n"
+ # TODO(sukolsak): This might leave artifacts on the machine
+ subprocess.call("mini_installer.exe --chrome --uninstall"
grt (UTC plus 2) 2013/07/30 03:31:38 this isn't a true chrome uninstall command line, a
gab 2013/07/30 13:27:57 As I suggested on a previous patch set, I think we
+ + " & mini_installer.exe --chrome-frame --uninstall", shell=True)
+
+
+# Test the installer
+def Test(config):
+ for test in config.tests:
+ print "Testing [ " + " -> ".join(test) + " ]"
+
+ RunResetCommand()
+
+ current_state = test[0]
+ VerifyState(config, current_state)
+
+ for i in range(1, len(test), 2):
+ 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()

Powered by Google App Engine
This is Rietveld 408576698