chromium/ui/aura/window_unittest.cc

// Copyright 2012 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "ui/aura/window.h"

#include <limits.h>

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/compiler_specific.h"
#include "base/memory/raw_ptr.h"
#include "base/strings/string_number_conversions.h"
#include "base/strings/string_util.h"
#include "base/strings/stringprintf.h"
#include "base/test/bind.h"
#include "build/build_config.h"
#include "cc/trees/layer_tree_frame_sink.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "ui/aura/client/capture_client.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/client/visibility_client.h"
#include "ui/aura/client/window_parenting_client.h"
#include "ui/aura/layout_manager.h"
#include "ui/aura/scoped_window_capture_request.h"
#include "ui/aura/scoped_window_event_targeting_blocker.h"
#include "ui/aura/test/aura_test_base.h"
#include "ui/aura/test/aura_test_utils.h"
#include "ui/aura/test/test_window_delegate.h"
#include "ui/aura/test/test_windows.h"
#include "ui/aura/test/window_test_api.h"
#include "ui/aura/window_delegate.h"
#include "ui/aura/window_event_dispatcher.h"
#include "ui/aura/window_observer.h"
#include "ui/aura/window_tracker.h"
#include "ui/aura/window_tree_host.h"
#include "ui/base/class_property.h"
#include "ui/base/hit_test.h"
#include "ui/compositor/compositor.h"
#include "ui/compositor/compositor_observer.h"
#include "ui/compositor/layer.h"
#include "ui/compositor/layer_animation_observer.h"
#include "ui/compositor/layer_animator.h"
#include "ui/compositor/scoped_animation_duration_scale_mode.h"
#include "ui/compositor/scoped_layer_animation_settings.h"
#include "ui/compositor/test/layer_animator_test_controller.h"
#include "ui/compositor/test/test_layers.h"
#include "ui/display/screen.h"
#include "ui/events/event.h"
#include "ui/events/event_utils.h"
#include "ui/events/gesture_detection/gesture_configuration.h"
#include "ui/events/keycodes/keyboard_codes.h"
#include "ui/events/test/event_generator.h"
#include "ui/gfx/canvas.h"
#include "ui/gfx/geometry/skia_conversions.h"
#include "ui/gfx/geometry/vector2d.h"
#include "ui/gfx/overlay_transform_utils.h"

DEFINE_UI_CLASS_PROPERTY_TYPE()

namespace {

enum class DeletionOrder {};

class DeletionTracker {};

// The helper class to wait for the animation completion and run callbacks.
class LayerTranslationAnimationNotifier : public ui::CompositorObserver {};

class DeletionTestProperty {};

DEFINE_OWNED_UI_CLASS_PROPERTY_KEY()

}  // namespace

DEFINE_UI_CLASS_PROPERTY_TYPE()

namespace aura {
namespace test {
namespace {

class WindowTest : public AuraTestBase {};

// Used for verifying destruction methods are invoked.
class DestroyTrackingDelegateImpl : public TestWindowDelegate {};

// Used to verify that when OnWindowDestroying is invoked the parent is also
// is in the process of being destroyed.
class ChildWindowDelegateImpl : public DestroyTrackingDelegateImpl {};

// Used to verify that a Window is removed from its parent when
// OnWindowDestroyed is called.
class DestroyOrphanDelegate : public TestWindowDelegate {};

// Used in verifying mouse capture.
class CaptureWindowDelegateImpl : public TestWindowDelegate {};

// Keeps track of the location of the gesture.
class GestureTrackPositionDelegate : public TestWindowDelegate {};

base::TimeTicks getTime() {}

class SelfEventHandlingWindowDelegate : public TestWindowDelegate {};

// The delegate deletes itself when the window is being destroyed.
class DestroyWindowDelegate : public TestWindowDelegate {};

void OffsetBounds(Window* window, int horizontal, int vertical) {}

TEST_F(WindowTest, GetChildById) {}

// Make sure that Window::Contains correctly handles children, grandchildren,
// and not containing NULL or parents.
TEST_F(WindowTest, Contains) {}

TEST_F(WindowTest, ContainsPointInRoot) {}

TEST_F(WindowTest, ContainsPoint) {}

TEST_F(WindowTest, MakeWindowCapturable) {}

TEST_F(WindowTest, DeletingCapturableWindows) {}

TEST_F(WindowTest, LayerReleasingAndSettingOfCapturableWindow) {}

TEST_F(WindowTest, RecreateLayerOfCapturableWindow) {}

TEST_F(WindowTest, ConvertPointToWindow) {}

TEST_F(WindowTest, MoveCursorTo) {}

TEST_F(WindowTest, ContainsMouse) {}

// Tests that the root window gets a valid LocalSurfaceId.
TEST_F(WindowTest, RootWindowHasValidLocalSurfaceId) {}

TEST_F(WindowTest, WindowEmbeddingClientHasValidLocalSurfaceId) {}

// Test Window::ConvertPointToWindow() with transform to root_window.
TEST_F(WindowTest, MoveCursorToWithTransformRootWindow) {}

// Tests Window::ConvertPointToWindow() with transform to non-root windows.
TEST_F(WindowTest, MoveCursorToWithTransformWindow) {}

// Test Window::ConvertPointToWindow() with complex transforms to both root and
// non-root windows.
// Test Window::ConvertPointToWindow() with transform to root_window.
TEST_F(WindowTest, MoveCursorToWithComplexTransform) {}

// Tests that we do not crash when a Window is destroyed by going out of
// scope (as opposed to being explicitly deleted by its WindowDelegate).
TEST_F(WindowTest, NoCrashOnWindowDelete) {}

TEST_F(WindowTest, GetEventHandlerForPoint) {}

TEST_F(WindowTest, GetEventHandlerForPointInCornerOfChildBounds) {}

TEST_F(WindowTest, GetEventHandlerForPointWithOverrideDescendingOrder) {}

TEST_F(WindowTest, GetToplevelWindow) {}

class AddedToRootWindowObserver : public WindowObserver {};

TEST_F(WindowTest, WindowAddedToRootWindowShouldNotifyChildAndNotParent) {}

// Various destruction assertions.
TEST_F(WindowTest, DestroyTest) {}

// Tests that a window is orphaned before OnWindowDestroyed is called.
TEST_F(WindowTest, OrphanedBeforeOnDestroyed) {}

// Make sure StackChildAtTop moves both the window and layer to the front.
TEST_F(WindowTest, StackChildAtTop) {}

// Make sure StackChildBelow works.
TEST_F(WindowTest, StackChildBelow) {}

// Various assertions for StackChildAbove.
TEST_F(WindowTest, StackChildAbove) {}

// Various capture assertions.
TEST_F(WindowTest, CaptureTests) {}

TEST_F(WindowTest, TouchCaptureCancelsOtherTouches) {}

TEST_F(WindowTest, TouchCaptureDoesntCancelCapturedTouches) {}

// Assertions around SetCapture() and touch/gestures.
TEST_F(WindowTest, TransferCaptureTouchEvents) {}

// Changes capture while capture is already ongoing.
TEST_F(WindowTest, ChangeCaptureWhileMouseDown) {}

// Verifies capture is reset when a window is destroyed.
TEST_F(WindowTest, ReleaseCaptureOnDestroy) {}

TEST_F(WindowTest, GetBoundsInRootWindow) {}

TEST_F(WindowTest, GetBoundsInRootWindowWithLayers) {}

TEST_F(WindowTest, GetBoundsInRootWindowWithLayersAndTranslations) {}

// TODO(tdanderson): Remove this class and use
//                   test::EventCountDelegate in its place.
class MouseEnterExitWindowDelegate : public TestWindowDelegate {};

// Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
// mouse transitions from window to window.
TEST_F(WindowTest, MouseEnterExit) {}

// Verifies that the WindowDelegate receives MouseExit from
// EventType::kMouseExited.
TEST_F(WindowTest, WindowTreeHostExit) {}

// Verifies that the WindowDelegate receives MouseExit and MouseEnter events for
// mouse transitions from window to window, even if the entered window sets
// and releases capture.
TEST_F(WindowTest, MouseEnterExitWithClick) {}

TEST_F(WindowTest, MouseEnterExitWhenDeleteWithCapture) {}

// Verifies that the correct enter / exits are sent if windows appear and are
// deleted under the current mouse position.
TEST_F(WindowTest, MouseEnterExitWithWindowAppearAndDelete) {}

// Verifies that enter / exits are sent if windows appear and are hidden
// under the current mouse position..
TEST_F(WindowTest, MouseEnterExitWithHide) {}

TEST_F(WindowTest, MouseEnterExitWithParentHide) {}

TEST_F(WindowTest, MouseEnterExitWithParentDelete) {}

// Creates a window with a delegate (w111) that can handle events at a lower
// z-index than a window without a delegate (w12). w12 is sized to fill the
// entire bounds of the container. This test verifies that
// GetEventHandlerForPoint() skips w12 even though its bounds contain the event,
// because it has no children that can handle the event and it has no delegate
// allowing it to handle the event itself.
TEST_F(WindowTest, GetEventHandlerForPoint_NoDelegate) {}

class VisibilityWindowDelegate : public TestWindowDelegate {};

// Verifies show/hide propagate correctly to children and the layer.
TEST_F(WindowTest, Visibility) {}

TEST_F(WindowTest, EventTargetingPolicy) {}

TEST_F(WindowTest, ScopedEventTargetingBlockerTest) {}

// Tests transformation on the root window.
TEST_F(WindowTest, Transform) {}

TEST_F(WindowTest, TransformGesture) {}

TEST_F(WindowTest, Property) {}

class DeletionTestLayoutManager : public LayoutManager {};

TEST_F(WindowTest, DeleteLayoutManagerBeforeOwnedProps) {}

TEST_F(WindowTest, SetBoundsInternalShouldCheckTargetBounds) {}

PropertyChangeInfo;

class WindowObserverTest : public WindowTest,
                           public WindowObserver {};

// Various assertions for WindowObserver.
TEST_F(WindowObserverTest, WindowObserver) {}

// Test if OnWindowVisibilityChanged is invoked with expected
// parameters.
TEST_F(WindowObserverTest, WindowVisibility) {}

// Test if OnWindowDestroyed is invoked as expected.
TEST_F(WindowObserverTest, WindowDestroyed) {}

TEST_F(WindowObserverTest, PropertyChanged) {}

// Verify that WindowObserver::OnWindowBoundsChanged() is notified when the
// bounds of a Window's Layer change without an animation.
TEST_F(WindowObserverTest, WindowBoundsChanged) {}

// Verify that WindowObserver::OnWindowBoundsChanged() is notified at every step
// of a bounds animation.
TEST_F(WindowObserverTest, WindowBoundsChangedAnimation) {}

// Verify that WindowObserver::OnWindowOpacitySet() is notified when the
// opacity of a Window's Layer changes without an animation.
TEST_F(WindowObserverTest, WindowOpacityChanged) {}

// Verify that WindowObserver::OnWindowOpacitySet() is notified at the
// beginning and at the end of a threaded opacity animation.
TEST_F(WindowObserverTest, WindowOpacityChangedAnimation) {}

// Verify that WindowObserver::OnWindowAlphaShapeSet() is notified when an alpha
// shape is set for a window.
TEST_F(WindowObserverTest, WindowAlphaShapeChanged) {}

// Verify that WindowObserver::OnWindow(TargetTransformChanging|Transformed)()
// are notified when SetTransform() is called and there is no animation.
TEST_F(WindowObserverTest, SetTransform) {}

// Verify that WindowObserver::OnWindowTransformed)() is notified at the
// beginning and at the end of a threaded transform animation. Verify that
// WindowObserver::OnWindowTargetTransformChanging() is notified when the
// threaded animation is started by SetTransform().
TEST_F(WindowObserverTest, SetTransformAnimation) {}

TEST_F(WindowObserverTest, OnWindowLayerRecreated) {}

TEST_F(WindowObserverTest, OnWindowLayerRecreatedWithOpacityAnimation) {}

TEST_F(WindowObserverTest, OnWindowLayerRecreatedWithTransformAnimation) {}

TEST_F(WindowTest, AcquireLayer) {}

// Make sure that properties which should persist from the old layer to the new
// layer actually do.
TEST_F(WindowTest, RecreateLayer) {}

// Verify that RecreateLayer() stacks the old layer above the newly creatd
// layer.
TEST_F(WindowTest, RecreateLayerZOrder) {}

// Ensure that acquiring a layer then recreating a layer does not crash
// and that RecreateLayer returns null.
TEST_F(WindowTest, AcquireThenRecreateLayer) {}

class TestVisibilityClient : public client::VisibilityClient {};

TEST_F(WindowTest, VisibilityClientIsVisible) {}

// Tests the mouse events seen by WindowDelegates in a Window hierarchy when
// changing the properties of a leaf Window.
TEST_F(WindowTest, MouseEventsOnLeafWindowChange) {}

// Tests the mouse events seen by WindowDelegates in a Window hierarchy when
// deleting a non-leaf Window.
TEST_F(WindowTest, MouseEventsOnNonLeafWindowDelete) {}

class RootWindowAttachmentObserver : public WindowObserver {};

TEST_F(WindowTest, RootWindowAttachment) {}

class BoundsChangedWindowObserver : public WindowObserver {};

TEST_F(WindowTest, RootWindowSetWhenReparenting) {}

TEST_F(WindowTest, OwnedByParentFalse) {}

// Used By DeleteWindowFromOnWindowDestroyed. Destroys a Window from
// OnWindowDestroyed().
class OwningWindowDelegate : public TestWindowDelegate {};

// Creates a window with two child windows. When the first child window is
// destroyed (WindowDelegate::OnWindowDestroyed) it deletes the second child.
// This synthesizes BrowserView and the status bubble. Both are children of the
// same parent and destroying BrowserView triggers it destroying the status
// bubble.
TEST_F(WindowTest, DeleteWindowFromOnWindowDestroyed) {}

// WindowObserver implementation that deletes a window in
// OnWindowVisibilityChanged().
class DeleteOnVisibilityChangedObserver : public WindowObserver {};

TEST_F(WindowTest, DeleteParentWindowFromOnWindowVisibiltyChanged) {}

// Used by DelegateNotifiedAsBoundsChange to verify OnBoundsChanged() is
// invoked.
class BoundsChangeDelegate : public TestWindowDelegate {};

// Verifies the delegate is notified when the actual bounds of the layer
// change.
TEST_F(WindowTest, DelegateNotifiedAsBoundsChange) {}

// Verifies the delegate is notified when the actual bounds of the layer
// change even when the window is not the layer's delegate
TEST_F(WindowTest, DelegateNotifiedAsBoundsChangeInHiddenLayer) {}

// Used by AddChildNotifications to track notification counts.
class AddChildNotificationsObserver : public WindowObserver {};

// Assertions around when root window notifications are sent.
TEST_F(WindowTest, AddChildNotifications) {}

// Tests that a delegate that destroys itself when the window is destroyed does
// not break.
TEST_F(WindowTest, DelegateDestroysSelfOnWindowDestroy) {}

class HierarchyObserver : public WindowObserver {};

// Tests hierarchy change notifications.
TEST_F(WindowTest, OnWindowHierarchyChange) {}

class TestLayerAnimationObserver : public ui::LayerAnimationObserver {};

TEST_F(WindowTest, WindowDestroyCompletesAnimations) {}

TEST_F(WindowTest, RootWindowUsesCompositorFrameSinkId) {}

TEST_F(WindowTest, LocalSurfaceIdChanges) {}

TEST_F(WindowTest, CreateLayerTreeFrameSink) {}

// This delegate moves its parent window to the specified one when the gesture
// ends.
class HandleGestureEndDelegate : public TestWindowDelegate {};

TEST_F(WindowTest, CleanupGestureStateChangesWindowHierarchy) {}

TEST_F(WindowTest, CleanupGestureStateDeleteOtherWindows) {}

class TestTouchWindowDelegate : public TestWindowDelegate {};

// Test for use-after-free in crbug.com/1297643.
TEST_F(WindowTest, DeleteWindowWhenCancellingTouch) {}

class WindowActualScreenBoundsTest
    : public WindowTest,
      public testing::WithParamInterface<
          /*is_target_transform_identical*/ bool> {};

INSTANTIATE_TEST_SUITE_P();

// Verifies that the function to get the window's screen bounds works as
// expected during layer animation.
TEST_P(WindowActualScreenBoundsTest, VerifyWindowActualBoundsDuringAnimation) {}

}  // namespace
}  // namespace test
}  // namespace aura