Skip to content

Commit

Permalink
Fixed upstream browser test failure
Browse files Browse the repository at this point in the history
fixed ExtensionSidePanelBrowserTest.WindowCloseCalledWhenLoading.
This test assumes reading list's content doesn't becomes available
immediately right after calling SidePanelCoordinator::Show(reading_list).
  • Loading branch information
simonhong committed Sep 18, 2023
1 parent 5e2fa93 commit c385a05
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 6 deletions.
37 changes: 32 additions & 5 deletions browser/ui/views/side_panel/brave_read_later_side_panel_view.cc
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,8 @@
#include "brave/grit/brave_generated_resources.h"
#include "brave/grit/brave_theme_resources.h"
#include "chrome/browser/ui/views/side_panel/read_later_side_panel_web_view.h"
#include "chrome/browser/ui/views/side_panel/side_panel_content_proxy.h"
#include "chrome/browser/ui/views/side_panel/side_panel_util.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/font_list.h"
Expand Down Expand Up @@ -78,11 +80,36 @@ BraveReadLaterSidePanelView::BraveReadLaterSidePanelView(
AddChildView(std::make_unique<ReadLaterSidePanelHeaderView>());
AddChildView(std::make_unique<views::Separator>())
->SetColorId(kColorSidebarPanelHeaderSeparator);
AddChildView(std::make_unique<ReadLaterSidePanelWebView>(browser, close_cb))
->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred,
views::MaximumFlexSizeRule::kUnbounded));
auto* web_view = AddChildView(
std::make_unique<ReadLaterSidePanelWebView>(browser, close_cb));
web_view->SetProperty(
views::kFlexBehaviorKey,
views::FlexSpecification(views::MinimumFlexSizeRule::kPreferred,
views::MaximumFlexSizeRule::kUnbounded));

// Originally SidePanelEntry's Content was ReadLaterSidePanelWebView
// and it's availability is set to true when SidePanelWebUIView::ShowUI()
// and then proxy's availability callback is executed.
// However, we use parent view(BraveReadLaterSidePanelView) to have
// panel specific header view and this class becomes SidePanelEntry's Content.
// To make this content available when SidePanelWebUIVew::ShowUI() is called,
// this observes WebView's visibility because it's set as visible when
// ShowUI() is called.
// NOTE: If we use our own reading list page and it has loading spinner, maybe
// we can set `true` here.
SidePanelUtil::GetSidePanelContentProxy(this)->SetAvailable(false);
observation_.Observe(web_view);
}

void BraveReadLaterSidePanelView::OnViewVisibilityChanged(
views::View* observed_view,
views::View* starting_view) {
// Once it becomes available, stop observing becuase its availablity is
// not changed from now on.
if (observed_view->GetVisible()) {
SidePanelUtil::GetSidePanelContentProxy(this)->SetAvailable(true);
observation_.Reset();
}
}

BraveReadLaterSidePanelView::~BraveReadLaterSidePanelView() = default;
11 changes: 10 additions & 1 deletion browser/ui/views/side_panel/brave_read_later_side_panel_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -7,19 +7,28 @@
#define BRAVE_BROWSER_UI_VIEWS_SIDE_PANEL_BRAVE_READ_LATER_SIDE_PANEL_VIEW_H_

#include "base/functional/callback_forward.h"
#include "base/scoped_observation.h"
#include "ui/views/view.h"
#include "ui/views/view_observer.h"

class Browser;

// Gives reading list specific header view with web view.
class BraveReadLaterSidePanelView : public views::View {
class BraveReadLaterSidePanelView : public views::View,
public views::ViewObserver {
public:
BraveReadLaterSidePanelView(Browser* browser,
base::RepeatingClosure close_cb);
~BraveReadLaterSidePanelView() override;
BraveReadLaterSidePanelView(const BraveReadLaterSidePanelView&) = delete;
BraveReadLaterSidePanelView& operator=(const BraveReadLaterSidePanelView&) =
delete;

private:
void OnViewVisibilityChanged(views::View* observed_view,
views::View* starting_view) override;

base::ScopedObservation<views::View, views::ViewObserver> observation_{this};
};

#endif // BRAVE_BROWSER_UI_VIEWS_SIDE_PANEL_BRAVE_READ_LATER_SIDE_PANEL_VIEW_H_

0 comments on commit c385a05

Please sign in to comment.