1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66
|
// Copyright 2015 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef COMPONENTS_ZOOM_TEST_ZOOM_TEST_UTILS_H_
#define COMPONENTS_ZOOM_TEST_ZOOM_TEST_UTILS_H_
#include "base/functional/callback_forward.h"
#include "base/memory/raw_ptr.h"
#include "base/scoped_observation.h"
#include "components/zoom/zoom_controller.h"
#include "components/zoom/zoom_observer.h"
namespace content {
class MessageLoopRunner;
}
namespace zoom {
bool operator==(const ZoomController::ZoomChangedEventData& lhs,
const ZoomController::ZoomChangedEventData& rhs);
class ZoomChangedWatcher : public zoom::ZoomObserver {
public:
using ZoomEventPred = base::RepeatingCallback<bool(
const ZoomController::ZoomChangedEventData&)>;
// Used to wait until we see a zoom changed event that satisfies the
// given |predicate|.
ZoomChangedWatcher(ZoomController* zoom_controller, ZoomEventPred predicate);
ZoomChangedWatcher(content::WebContents* web_contents,
ZoomEventPred predicate);
// Used to wait until we see a zoom changed event equal to the given
// |expected_event_data|.
ZoomChangedWatcher(
ZoomController* zoom_controller,
const ZoomController::ZoomChangedEventData& expected_event_data);
ZoomChangedWatcher(
content::WebContents* web_contents,
const ZoomController::ZoomChangedEventData& expected_event_data);
ZoomChangedWatcher(const ZoomChangedWatcher&) = delete;
ZoomChangedWatcher& operator=(const ZoomChangedWatcher&) = delete;
~ZoomChangedWatcher() override;
void Wait();
// zoom::ZoomObserver:
void OnZoomControllerDestroyed(
zoom::ZoomController* zoom_controller) override;
void OnZoomChanged(
const ZoomController::ZoomChangedEventData& event_data) override;
private:
raw_ptr<ZoomController> zoom_controller_;
ZoomEventPred predicate_;
scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
bool change_received_ = false;
base::ScopedObservation<zoom::ZoomController, zoom::ZoomObserver>
zoom_observation_{this};
};
} // namespace zoom
#endif // COMPONENTS_ZOOM_TEST_ZOOM_TEST_UTILS_H_
|