blob: 2ee3ded92d73154dd39c7e128b85d5f300f5acab [file] [log] [blame]
// Copyright 2020 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// This file contains utility functions for lacros_chrome_browsertests.
#ifndef CHROME_BROWSER_LACROS_BROWSER_TEST_UTIL_H_
#define CHROME_BROWSER_LACROS_BROWSER_TEST_UTIL_H_
#include <stdint.h>
#include <string>
#include "base/location.h"
#include "chromeos/crosapi/mojom/test_controller.mojom.h"
namespace aura {
class Window;
} // namespace aura
namespace browser_test_util {
// Waits for an element to be created.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool WaitForElementCreation(const std::string& element_name);
// Some crosapi methods rely on the assumption that ash/exo are aware of the
// existence of a Lacros Window. Wayland is an async protocol that uses a
// different communication channel than crosapi. This method provides a
// synchronization mechanism for window creation and destruction.
//
// Waits for the Window to be created. |id| comes from |GetWindowId|.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool WaitForWindowCreation(const std::string& id);
// Waits for the window to be destroyed. |id| comes from |GetWindowId|.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool WaitForWindowDestruction(const std::string& id);
// Waits for the shelf item to either be created or destroyed, matching
// |exists|.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool WaitForShelfItem(const std::string& id, bool exists);
// Waits for the app to be closed, running or active, matching |state|,
// a bitmask of |crosapi::mojom::ShelfItemState| values.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool WaitForShelfItemState(
const std::string& id,
uint32_t state,
const base::Location& location = base::Location::Current());
// This function relies on |window| already being available in ash. It prompts
// ash to send the Wayland events associated with a mouse click to the |window|.
// It waits for the events to be seen by Aura.
//
// This function is necessary to prime the Wayland serial_id. The serial_id is
// generated by the Wayland server and sent to Wayland client along-side user
// events. This serial_id is a required input to Wayland clipboard APIs.
//
// |window| must be a root window.
// Returns false if Ash is unavailable or lacks the required TestController
// functionality.
[[nodiscard]] bool SendAndWaitForMouseClick(aura::Window* window);
} // namespace browser_test_util
#endif // CHROME_BROWSER_LACROS_BROWSER_TEST_UTIL_H_