• Elly Fong-Jones's avatar
    views: add AnyWidgetObserver · 5bc5c1e7
    Elly Fong-Jones authored
    A common problem when writing integration tests for Views UI is that
    the involved UI is hidden behind an interface which hides the Widget,
    since it is usually an implementation detail. Specifically, it is
    common to have a function like so:
    
      static void MyDialog::Show(...);
    
    which internally creates a Widget, initializes it, shows it, etc, and
    invokes some callbacks or notifies some controller when the Widget is
    done. However, this makes it difficult for tests that expect to touch
    that UI to actually get ahold of it, which leads to various hacky
    approaches, like adding globals to track the last Widget created by
    MyDialog and similar. However, even this hack is considerably ugly
    when the UI is instead shown via something like:
    
      MyController::WaitUntilReadyAndThenShow(...);
    
    because the test can rarely tell when the UI is actually being
    displayed, which results in ad-hoc things like spinning the RunLoop a
    set number of times.
    
    To achieve that, this change:
    1) Adds a class AnyWidgetObserver, which can be used to observe events
       that happen on any Widget instance without needing to specifically
       register for that Widget instance;
    2) Adds a class AnyWidgetObserverSingleton, which is what the
       AnyWidgetObservers actually register as observers of;
    3) Has Widget notify AnyWidgetObserverSingleton of various interesting
       events;
    4) Adds some tests for AnyWidgetObserver.
    
    Bug: None
    Change-Id: I36c9b3c59bcae3bbe889731720e797339e5675d2
    Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2110812Reviewed-by: default avatarDana Fried <dfried@chromium.org>
    Reviewed-by: default avatarRobert Liao <robliao@chromium.org>
    Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
    Cr-Commit-Position: refs/heads/master@{#753332}
    5bc5c1e7
any_widget_observer_singleton.h 1.4 KB