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

Unified Diff: chrome/test/mini_installer/window_verifier.py

Issue 23060002: Implement the window verifier in the Automated Installer Testing Framework. (Closed) Base URL: http://git.chromium.org/chromium/src.git@master
Patch Set: Created 7 years, 4 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/test/mini_installer/window_verifier.py
diff --git a/chrome/test/mini_installer/window_verifier.py b/chrome/test/mini_installer/window_verifier.py
new file mode 100644
index 0000000000000000000000000000000000000000..fd5a37086ec3163ed4669afcb6540be031b44bb0
--- /dev/null
+++ b/chrome/test/mini_installer/window_verifier.py
@@ -0,0 +1,48 @@
+# Copyright 2013 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 ctypes
+
+
+def VerifyWindows(windows):
+ """Verifies the current windows according to the expectation dictionaries.
+
+ Args:
+ windows: A dictionary whose keys are titles of windows and values are
+ expectation dictionaries. An expectation dictionary is a dictionary with
+ the following key and value:
+ 'exists' a boolean indicating whether the window should exist.
+ """
+ titles = WindowTitles()
+ for window_title, expectation in windows.iteritems():
+ if window_title in titles:
+ assert expectation['exists'], "Window '%s' exists" % window_title
gab 2013/08/13 17:49:27 Isn't there a way to test both cases in 1 line, so
+ else:
+ assert not expectation['exists'], \
+ "Window '%s' does not exist" % window_title
+
+
+def WindowTitles():
+ """Retutn the titles of all top-level windows."""
+ titles = []
+ # Create a callback function to pass to the EnumWindows function.
+ # The callback receives the handle to each top-level window.
+ def EnumerateWindowCallback(hwnd, _):
+ # If the window is visible, add its title to |titles|.
+ if ctypes.windll.user32.IsWindowVisible(hwnd):
+ length = ctypes.windll.user32.GetWindowTextLengthW(hwnd)
+ buffer = ctypes.create_unicode_buffer(length + 1)
+ ctypes.windll.user32.GetWindowTextW(hwnd, buffer, length + 1)
+ titles.append(buffer.value)
+ # Return True to continue enumerating windows.
+ return True
+ # Create a function prototype for the callback, which takes two pointers and
+ # returns a boolean.
+ callback_prototype = ctypes.WINFUNCTYPE(ctypes.c_bool,
+ ctypes.POINTER(ctypes.c_int),
+ ctypes.POINTER(ctypes.c_int))
+ callback = callback_prototype(EnumerateWindowCallback)
+ # Enumerate all top-level windows.
+ ctypes.windll.user32.EnumWindows(callback, 0)
+ return titles

Powered by Google App Engine
This is Rietveld 408576698