Commit 35b4c2a5 authored by Mitsuru Oshima's avatar Mitsuru Oshima Committed by Commit Bot

autotest private API for application windows

1) getAppWindowInfo to retrieve the list of application windows
   with ids.
2) setAppWindowState to set the window state using the id.
3) closeAppWindow to close the window.

Bug: 1010671
Test: Covered by unit test except for close. It'll be covered in next CL.
Change-Id: Iaa71764a58663713ac5d745b550bfa7b46bb383b
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1857603
Commit-Queue: Mitsuru Oshima <oshima@chromium.org>
Reviewed-by: default avatarSteven Bennetts <stevenjb@chromium.org>
Cr-Commit-Position: refs/heads/master@{#706965}
parent 4fd0eb78
......@@ -50,6 +50,7 @@ component("ash") {
"public/cpp/arc_custom_tab.h",
"public/cpp/ash_prefs.h",
"public/cpp/assistant/assistant_settings.h",
"public/cpp/autotest_private_api_utils.h",
"public/cpp/docked_magnifier_controller.h",
"public/cpp/event_rewriter_controller.h",
"public/cpp/first_run_helper.h",
......@@ -216,6 +217,7 @@ component("ash") {
"autoclick/autoclick_ring_handler.h",
"autoclick/autoclick_scroll_position_handler.cc",
"autoclick/autoclick_scroll_position_handler.h",
"autotest_private_api_utils.cc",
"bluetooth_devices_observer.cc",
"bluetooth_devices_observer.h",
"cancel_mode.cc",
......
......@@ -76,6 +76,9 @@ void PrintWindowHierarchy(const aura::Window* active_window,
*out << indent_str;
*out << name << " (" << window << ")"
<< " type=" << window->type();
int window_id = window->id();
if (window_id != aura::Window::kInitialId)
*out << " id=" << window_id;
if (window->GetProperty(kWindowStateKey))
*out << " " << WindowState::Get(window)->GetStateType();
*out << ((window == active_window) ? " [active]" : "")
......
// Copyright 2019 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.
#include "ash/public/cpp/autotest_private_api_utils.h"
#include "ash/shell.h"
#include "ash/wm/mru_window_tracker.h"
#include "ash/wm/tablet_mode/scoped_skip_user_session_blocked_check.h"
namespace ash {
std::vector<aura::Window*> GetAppWindowList() {
ScopedSkipUserSessionBlockedCheck skip_session_blocked;
return Shell::Get()->mru_window_tracker()->BuildWindowForCycleWithPipList(
ash::kAllDesks);
}
} // namespace ash
// Copyright 2019 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.
#ifndef ASH_PUBLIC_CPP_AUTOTEST_PRIVATE_API_UTILS_H_
#define ASH_PUBLIC_CPP_AUTOTEST_PRIVATE_API_UTILS_H_
#include <vector>
#include "ash/ash_export.h"
namespace aura {
class Window;
}
// Utility functions for autotest private APIs and ShellTestAPI.
namespace ash {
// Get application windows, windows that are shown in overview grid.
ASH_EXPORT std::vector<aura::Window*> GetAppWindowList();
} // namespace ash
#endif // ASH_PUBLIC_CPP_AUTOTEST_PRIVATE_API_UTILS_H_
......@@ -33,6 +33,7 @@ enum class CrostiniResult;
namespace extensions {
class AssistantInteractionHelper;
class WindowStateChangeObserver;
class AutotestPrivateInitializeEventsFunction : public ExtensionFunction {
public:
......@@ -784,8 +785,6 @@ class AutotestPrivateSetArcAppWindowStateFunction : public ExtensionFunction {
AUTOTESTPRIVATE_SETARCAPPWINDOWSTATE)
private:
class WindowStateChangeObserver;
~AutotestPrivateSetArcAppWindowStateFunction() override;
ResponseAction Run() override;
......@@ -894,6 +893,42 @@ class AutotestPrivateWaitForDisplayRotationFunction
scoped_refptr<ExtensionFunction> self_;
};
class AutotestPrivateGetAppWindowListFunction : public ExtensionFunction {
public:
AutotestPrivateGetAppWindowListFunction();
DECLARE_EXTENSION_FUNCTION("autotestPrivate.getAppWindowList",
AUTOTESTPRIVATE_GETAPPWINDOWLIST)
private:
~AutotestPrivateGetAppWindowListFunction() override;
ResponseAction Run() override;
};
class AutotestPrivateSetAppWindowStateFunction : public ExtensionFunction {
public:
AutotestPrivateSetAppWindowStateFunction();
DECLARE_EXTENSION_FUNCTION("autotestPrivate.setAppWindowState",
AUTOTESTPRIVATE_SETAPPWINDOWSTATE)
private:
~AutotestPrivateSetAppWindowStateFunction() override;
ResponseAction Run() override;
void WindowStateChanged(ash::WindowStateType expected_type, bool success);
std::unique_ptr<WindowStateChangeObserver> window_state_observer_;
};
class AutotestPrivateCloseAppWindowFunction : public ExtensionFunction {
public:
DECLARE_EXTENSION_FUNCTION("autotestPrivate.closeAppWindow",
AUTOTESTPRIVATE_CLOSEAPPWINDOW)
private:
~AutotestPrivateCloseAppWindowFunction() override;
ResponseAction Run() override;
};
template <>
KeyedService*
BrowserContextKeyedAPIFactory<AutotestPrivateAPI>::BuildServiceInstanceFor(
......
......@@ -314,6 +314,39 @@ namespace autotestPrivate {
boolean hasNotification;
};
// A mapping of ash::AppType.
enum AppWindowType {
Browser,
ChromeApp,
ArcApp,
CrostiniApp,
SystemApp,
ExtensionApp
};
dictionary AppWindowInfo {
long id;
DOMString name;
AppWindowType windowType;
WindowStateType stateType;
Bounds bounds_in_root;
Bounds target_bounds;
DOMString displayId;
DOMString title;
boolean isAnimating;
boolean isVisible;
boolean targetVisibility;
boolean canFocus;
// WM Releated stats
boolean isActive;
boolean hasFocus;
boolean onActiveDesk;
boolean hasCapture;
DOMString? arcPackageName;
};
callback GetShelfItemsCallback = void (ShelfItem[] items);
callback GetShelfAutoHideBehaviorCallback = void (DOMString behavior);
......@@ -326,6 +359,8 @@ namespace autotestPrivate {
callback DOMStringCallback = void (DOMString data);
callback GetAppWindowListCallback = void (AppWindowInfo[] window_list);
interface Functions {
// Must be called to allow autotestPrivateAPI events to be fired.
static void initializeEvents();
......@@ -606,22 +641,25 @@ namespace autotestPrivate {
// Send WM event to change the ARC app window's window state.
// |packageName|: the package name of the ARC app window.
// |eventType|: WM event type to send to the ARC app window.
// |change|: WM event type to send to the ARC app window.
// |callback|: called when the window state is changed.
static void setArcAppWindowState(DOMString packageName,
WindowStateChangeDict change,
WindowStateCallback callback);
[deprecated="Use setAppWindowState"] static void setArcAppWindowState(
DOMString packageName,
WindowStateChangeDict change,
WindowStateCallback callback);
// Get ARC app window's window state.
// |packageName|: the package name of the ARC app window.
// |callback| is invoked with the window state.
static void getArcAppWindowState(DOMString packageName, WindowStateCallback callback);
static void getArcAppWindowState(DOMString packageName,
WindowStateCallback callback);
// Get various information on an ARC window.
// |packageName|: the package name of the ARC app window.
// |callback|: called when the operation has completed.
static void getArcAppWindowInfo(DOMString packageName,
GetArcAppWindowInfoCallback callback);
[deprecated="Use getAppWindowList"] static void getArcAppWindowInfo(
DOMString packageName,
GetArcAppWindowInfoCallback callback);
// Start ARC performance tracing for the active ARC app window.
// |callback|: Called when the operation has completed.
......@@ -640,6 +678,7 @@ namespace autotestPrivate {
// |callback|: called when the operation has completed.
static void setArcAppWindowFocus(DOMString packageName,
VoidCallback callback);
// Invokes the callback when the display rotation animation is finished, or
// invokes it immediately if it is not animating. The callback argument
// is true if the display's rotation is same as |rotation|, or false otherwise.
......@@ -649,6 +688,24 @@ namespace autotestPrivate {
static void waitForDisplayRotation(DOMString displayId,
RotationType rotation,
WaitForDisplayRotationCallback callback);
// Get information on nall application windows. Callback will be called
// with the list of |AppWindowInfo| dictionary.
// |callback|: called with window list.
static void getAppWindowList(GetAppWindowListCallback callback);
// Send WM event to change the app window's window state.
// |id|: the id of the window
// |change|: WM event type to send to the app window.
// |callback|: called when the window state is changed.
static void setAppWindowState(long id,
WindowStateChangeDict change,
WindowStateCallback callback);
// Closes an app window given by "id".
// |id|: the id of the window
// |callback|: called when the window state is requested to close.
static void closeAppWindow(long id, VoidCallback callback);
};
interface Events {
......
......@@ -497,7 +497,43 @@ var defaultTests = [
chrome.autotestPrivate.arcAppTracingStart(chrome.test.callbackFail(
'Failed to start custom tracing.'));
},
// This test verifies that test can get the window list and set
// window state.
function getWindowInfoAndSetState() {
chrome.autotestPrivate.getAppWindowList(function(list) {
var found = false;
for (i = 0; i < list.length; i++) {
var window = list[i];
if (window.name != 'BrowserFrame') {
continue;
}
found = true;
// Sanity check
chrome.test.assertEq('BrowserFrame', window.name);
chrome.test.assertTrue(window.title.includes('New Tab') > 0);
chrome.test.assertEq('Browser', window.windowType);
chrome.test.assertTrue(window.isVisible);
chrome.test.assertTrue(window.targetVisibility);
chrome.test.assertFalse(window.isAnimating);
chrome.test.assertTrue(window.canFocus);
chrome.test.assertTrue(window.hasFocus);
chrome.test.assertTrue(window.isActive);
chrome.test.assertFalse(window.hasCapture);
var change = new Object();
change.eventType = 'WMEventMaximize';
chrome.autotestPrivate.setAppWindowState(
window.id,
change,
function(state) {
chrome.test.assertEq(state, 'Maximized');
chrome.test.assertNoLastError();
chrome.test.succeed();
});
}
chrome.test.assertTrue(found);
});
},
// KEEP |lockScreen()| TESTS AT THE BOTTOM OF THE defaultTests AS IT WILL
// CHANGE THE SESSION STATE TO LOCKED STATE.
function lockScreen() {
......@@ -510,12 +546,12 @@ var defaultTests = [
var arcEnabledTests = [
// This test verifies that getArcState returns provisioned True in case ARC
// provisioning is done.
function arcProvisioned() {chrome.autotestPrivate.getArcState(
function(state) {
chrome.test.assertTrue(state.provisioned);
chrome.test.assertNoLastError();
chrome.test.succeed();
});
function arcProvisioned() {
chrome.autotestPrivate.getArcState(function(state) {
chrome.test.assertTrue(state.provisioned);
chrome.test.assertNoLastError();
chrome.test.succeed();
});
},
// This test verifies that ARC Terms of Service are not needed in case ARC is
// provisioned and Terms of Service are accepted.
......
......@@ -1454,6 +1454,9 @@ enum HistogramValue {
AUTOTESTPRIVATE_WAITFORDISPLAYROTATION = 1391,
AUTOTESTPRIVATE_ARCAPPTRACINGSTART = 1392,
AUTOTESTPRIVATE_ARCAPPTRACINGSTOPANDANALYZE = 1393,
AUTOTESTPRIVATE_GETAPPWINDOWLIST = 1394,
AUTOTESTPRIVATE_SETAPPWINDOWSTATE = 1395,
AUTOTESTPRIVATE_CLOSEAPPWINDOW = 1396,
// Last entry: Add new entries above, then run:
// python tools/metrics/histograms/update_extension_histograms.py
ENUM_BOUNDARY
......
......@@ -20899,6 +20899,9 @@ Called by update_net_error_codes.py.-->
<int value="1391" label="AUTOTESTPRIVATE_WAITFORDISPLAYROTATION"/>
<int value="1392" label="AUTOTESTPRIVATE_ARCAPPTRACINGSTART"/>
<int value="1393" label="AUTOTESTPRIVATE_ARCAPPTRACINGSTOPANDANALYZE"/>
<int value="1394" label="AUTOTESTPRIVATE_GETAPPWINDOWLIST"/>
<int value="1395" label="AUTOTESTPRIVATE_SETAPPWINDOWSTATE"/>
<int value="1396" label="AUTOTESTPRIVATE_CLOSEAPPWINDOW"/>
</enum>
<enum name="ExtensionIconState">
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