Skip to content

Commit

Permalink
Merge pull request #1825 from brave/status_bubble_view_brave_url
Browse files Browse the repository at this point in the history
Show brave url on status bubble
  • Loading branch information
simonhong authored Mar 12, 2019
2 parents 94401f9 + b418116 commit eba28d0
Show file tree
Hide file tree
Showing 7 changed files with 118 additions and 1 deletion.
2 changes: 2 additions & 0 deletions browser/ui/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,8 @@ source_set("ui") {
"views/brave_actions/brave_action_view.h",
"views/brave_actions/brave_actions_container.cc",
"views/brave_actions/brave_actions_container.h",
"views/brave_status_bubble_views.cc",
"views/brave_status_bubble_views.h",
"views/download/brave_download_item_view.cc",
"views/download/brave_download_item_view.h",
"views/frame/brave_browser_view.cc",
Expand Down
20 changes: 20 additions & 0 deletions browser/ui/views/brave_status_bubble_views.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/brave_status_bubble_views.h"

#include "content/public/common/url_constants.h"
#include "url/gurl.h"

void BraveStatusBubbleViews::SetURL(const GURL& url) {
GURL revised_url = url;
if (revised_url.SchemeIs(content::kChromeUIScheme)) {
GURL::Replacements replacements;
replacements.SetSchemeStr(content::kBraveUIScheme);
revised_url = revised_url.ReplaceComponents(replacements);
}

StatusBubbleViews::SetURL(revised_url);
}
23 changes: 23 additions & 0 deletions browser/ui/views/brave_status_bubble_views.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#ifndef BRAVE_BROWSER_UI_VIEWS_BRAVE_STATUS_BUBBLE_VIEWS_H_
#define BRAVE_BROWSER_UI_VIEWS_BRAVE_STATUS_BUBBLE_VIEWS_H_

#include "chrome/browser/ui/views/status_bubble_views.h"

class BraveStatusBubbleViews : public StatusBubbleViews {
public:
using StatusBubbleViews::StatusBubbleViews;
~BraveStatusBubbleViews() override = default;

// StatusBubbleViews overrides:
void SetURL(const GURL& url) override;

private:
DISALLOW_COPY_AND_ASSIGN(BraveStatusBubbleViews);
};

#endif // BRAVE_BROWSER_UI_VIEWS_BRAVE_STATUS_BUBBLE_VIEWS_H_
50 changes: 50 additions & 0 deletions browser/ui/views/brave_status_bubble_views_unittest.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "brave/browser/ui/views/brave_status_bubble_views.h"

#include "chrome/test/views/chrome_views_test_base.h"
#include "ui/views/widget/widget.h"

class BraveStatusBubbleViewsTest : public ChromeViewsTestBase {
protected:
// ChromeViewsTestBase overrides:
void SetUp() override {
ChromeViewsTestBase::SetUp();
CreateWidget();
}

void TearDown() override {
if (widget_ && !widget_->IsClosed())
widget_->Close();

ChromeViewsTestBase::TearDown();
}

views::Widget* widget() const {
return widget_;
}

private:
void CreateWidget() {
DCHECK(!widget_);
widget_ = new views::Widget;
views::Widget::InitParams params =
CreateParams(views::Widget::InitParams::TYPE_WINDOW_FRAMELESS);
widget_->Init(params);
}

views::Widget* widget_ = nullptr;
};

TEST_F(BraveStatusBubbleViewsTest, SetURLTest) {
BraveStatusBubbleViews bubble(widget()->GetContentsView());
bubble.SetURL(GURL("chrome://settings/"));
EXPECT_EQ(GURL("brave://settings/"), bubble.url_);

const GURL brave_url("https://www.brave.com/");
bubble.SetURL(brave_url);
EXPECT_EQ(brave_url, bubble.url_);
}
9 changes: 8 additions & 1 deletion chromium_src/chrome/browser/ui/views/frame/browser_view.cc
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
/* Copyright (c) 2019 The Brave Authors. All rights reserved.
* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at http://mozilla.org/MPL/2.0/. */

#include "chrome/browser/ui/views/toolbar/toolbar_view.h"
#include "brave/browser/ui/views/brave_status_bubble_views.h"
#include "brave/browser/ui/views/toolbar/brave_toolbar_view.h"

#define ToolbarView BraveToolbarView
#define StatusBubbleViews BraveStatusBubbleViews

#include "../../../../../../../chrome/browser/ui/views/frame/browser_view.cc"
#include "../../../../../../../chrome/browser/ui/views/frame/browser_view.cc" // NOLINT
14 changes: 14 additions & 0 deletions patches/chrome-browser-ui-views-status_bubble_views.h.patch
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
diff --git a/chrome/browser/ui/views/status_bubble_views.h b/chrome/browser/ui/views/status_bubble_views.h
index b2ad6e5d19f119f58df8deb7fa8a840a04681628..036d48dbdccc20eb300ba43bff0413e1ac281f99 100644
--- a/chrome/browser/ui/views/status_bubble_views.h
+++ b/chrome/browser/ui/views/status_bubble_views.h
@@ -70,6 +70,9 @@ class StatusBubbleViews : public StatusBubble {

private:
friend class StatusBubbleViewsTest;
+#if defined(BRAVE_CHROMIUM_BUILD)
+ FRIEND_TEST_ALL_PREFIXES(BraveStatusBubbleViewsTest, SetURLTest);
+#endif

class StatusView;
class StatusViewAnimation;
1 change: 1 addition & 0 deletions test/BUILD.gn
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ test("brave_unit_tests") {
"//brave/browser/brave_resources_util_unittest.cc",
"//brave/browser/brave_stats_updater_unittest.cc",
"//brave/browser/download/brave_download_item_model_unittest.cc",
"//brave/browser/ui/views/brave_status_bubble_views_unittest.cc",
"//brave/browser/tor/mock_tor_profile_service_impl.cc",
"//brave/browser/tor/mock_tor_profile_service_impl.h",
"//brave/browser/tor/mock_tor_profile_service_factory.cc",
Expand Down

0 comments on commit eba28d0

Please sign in to comment.