Commit c8ce93c1 authored by Dominic Battre's avatar Dominic Battre Committed by Commit Bot

Create a screenshot if ShowAndFocusNativeWindow() fails

If ShowAndFocusNativeWindow() fails, the always_on_top_window_killer_win
does not capture a screenshot because the test fails with a CHECK
instead of a timeout. This CL just makes sure that a screenshot is
captured every time ShowAndFocusNativeWindow() fails.

Bug: 711256
Change-Id: Ica8a4ff7493ca0de36a17e147c9c2806c275f30c
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1559173
Commit-Queue: Colin Blundell <blundell@chromium.org>
Reviewed-by: default avatarColin Blundell <blundell@chromium.org>
Reviewed-by: default avatarGreg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649060}
parent bcefaaa8
......@@ -40,10 +40,6 @@ constexpr char kWindowFoundPostTest[] =
"out. This may have been caused by this test or a previous test and may "
"cause flakes;";
// A command line switch to specify the output directory into which snapshots
// are to be saved in case an always-on-top window is found.
constexpr char kSnapshotOutputDir[] = "snapshot-output-dir";
// A window enumerator that searches for always-on-top windows. A snapshot of
// the screen is saved if any unexpected on-top windows are found.
class WindowEnumerator {
......
......@@ -6,11 +6,13 @@
#include <Psapi.h>
#include "base/command_line.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/stl_util.h"
#include "base/time/time.h"
#include "chrome/test/base/interactive_test_utils_aura.h"
#include "chrome/test/base/save_desktop_snapshot_win.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/test/ui_controls.h"
#include "ui/base/win/foreground_helper.h"
......@@ -67,6 +69,18 @@ bool ShowAndFocusNativeWindow(gfx::NativeWindow window) {
LOG(ERROR) << "ShowAndFocusNativeWindow failed. foreground window: "
<< foreground_window << ", title: " << window_title << ", path: "
<< path_str;
const base::FilePath output_dir =
base::CommandLine::ForCurrentProcess()->GetSwitchValuePath(
kSnapshotOutputDir);
if (!output_dir.empty()) {
base::FilePath snapshot_file = SaveDesktopSnapshot(output_dir);
if (!snapshot_file.empty()) {
LOG(ERROR) << "Screenshot saved to file: \"" << snapshot_file.value()
<< "\"";
}
}
return false;
}
......
......@@ -74,6 +74,8 @@ SkBitmap CaptureScreen() {
} // namespace
const char kSnapshotOutputDir[] = "snapshot-output-dir";
base::FilePath SaveDesktopSnapshot(const base::FilePath& output_dir) {
// Create the output file.
base::Time::Exploded exploded;
......
......@@ -7,6 +7,10 @@
#include "base/files/file_path.h"
// A command line switch to specify the output directory into which snapshots
// are to be saved; e.g., in case an always-on-top window is found.
extern const char kSnapshotOutputDir[];
// Saves a snapshot of the desktop to a file in |output_dir|, returning the path
// to the file if created. An empty path is returned if no new snapshot is
// created.
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment