Skip to content

Commit

Permalink
Added one more test for the case without selection
Browse files Browse the repository at this point in the history
  • Loading branch information
spylogsster committed Jan 18, 2023
1 parent b1d9eac commit f54c3c4
Show file tree
Hide file tree
Showing 7 changed files with 36 additions and 32 deletions.
1 change: 0 additions & 1 deletion browser/brave_app_controller_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/grit/generated_resources.h"

@implementation BraveAppController

Expand Down
34 changes: 31 additions & 3 deletions browser/brave_app_controller_mac_browsertest.mm
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,6 @@
* License, v. 2.0. If a copy of the MPL was not distributed with this file,
* You can obtain one at https://mozilla.org/MPL/2.0/. */

#include "base/memory/raw_ptr.h"

#import <Cocoa/Cocoa.h>
#import <Foundation/Foundation.h>
#import <objc/runtime.h>
Expand Down Expand Up @@ -44,7 +42,8 @@
BraveBrowserView::GetBrowserViewForBrowser(browser()));
OmniboxView* omnibox_view = browser_view->GetLocationBar()->GetOmniboxView();
omnibox_view->SelectAll(false);
EXPECT_TRUE(browser_view->HasSelectedURL());
EXPECT_TRUE(omnibox_view->IsSelectAll());
EXPECT_TRUE(BraveBrowserWindow::From(browser()->window())->HasSelectedURL());

BraveAppController* ac = base::mac::ObjCCastStrict<BraveAppController>(
[[NSApplication sharedApplication] delegate]);
Expand Down Expand Up @@ -85,4 +84,33 @@
EXPECT_TRUE([clean_link_menu_item isHidden]);
}

IN_PROC_BROWSER_TEST_F(BraveAppControllerBrowserTest,
CopyLinkItemNotVisibleWithoutSelection) {
ASSERT_TRUE(embedded_test_server()->Start());
GURL url = embedded_test_server()->GetURL(kTestingPage);
ASSERT_TRUE(ui_test_utils::NavigateToURL(browser(), url));
EXPECT_EQ(1u, chrome::GetTotalBrowserCount());

BraveBrowserView* browser_view = static_cast<BraveBrowserView*>(
BraveBrowserView::GetBrowserViewForBrowser(browser()));
OmniboxView* omnibox_view = browser_view->GetLocationBar()->GetOmniboxView();
EXPECT_FALSE(omnibox_view->IsSelectAll());
EXPECT_FALSE(BraveBrowserWindow::From(browser()->window())->HasSelectedURL());

BraveAppController* ac = base::mac::ObjCCastStrict<BraveAppController>(
[[NSApplication sharedApplication] delegate]);
ASSERT_TRUE(ac);
base::scoped_nsobject<NSMenu> edit_submenu(
[[[NSApp mainMenu] itemWithTag:IDC_EDIT_MENU] submenu],
base::scoped_policy::RETAIN);

base::scoped_nsobject<NSMenuItem> clean_link_menu_item(
[edit_submenu itemWithTag:IDC_COPY_CLEAN_LINK],
base::scoped_policy::RETAIN);

[ac menuNeedsUpdate:[clean_link_menu_item menu]];
base::RunLoop().RunUntilIdle();
EXPECT_TRUE([clean_link_menu_item isHidden]);
}

} // namespace
1 change: 1 addition & 0 deletions browser/ui/brave_browser_window.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ BraveBrowserWindow* BraveBrowserWindow::From(BrowserWindow* window) {
sidebar::Sidebar* BraveBrowserWindow::InitSidebar() {
return nullptr;
}

bool BraveBrowserWindow::HasSelectedURL() const {
return false;
}
Expand Down
4 changes: 2 additions & 2 deletions browser/ui/views/frame/brave_browser_view.h
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ class BraveBrowserView : public BrowserView {
#endif
bool ShouldShowWindowTitle() const override;
void OnThemeChanged() override;
bool HasSelectedURL() const override;

views::View* sidebar_host_view() { return sidebar_host_view_; }
bool IsSidebarVisible() const;

Expand Down Expand Up @@ -114,7 +114,7 @@ class BraveBrowserView : public BrowserView {
BraveBrowser* GetBraveBrowser() const;

sidebar::Sidebar* InitSidebar() override;

bool HasSelectedURL() const override;
void UpdateSideBarHorizontalAlignment();

bool closing_confirm_dialog_activated_ = false;
Expand Down
12 changes: 0 additions & 12 deletions browser/ui/views/omnibox/brave_omnibox_view_views.cc
Original file line number Diff line number Diff line change
Expand Up @@ -17,18 +17,6 @@
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "ui/base/clipboard/scoped_clipboard_writer.h"

BraveOmniboxViewViews::BraveOmniboxViewViews(
OmniboxEditController* controller,
std::unique_ptr<OmniboxClient> client,
bool popup_window_mode,
LocationBarView* location_bar,
const gfx::FontList& font_list)
: OmniboxViewViews(controller,
std::move(client),
popup_window_mode,
location_bar,
font_list) {}

BraveOmniboxViewViews::~BraveOmniboxViewViews() = default;

bool BraveOmniboxViewViews::SelectedTextIsURL() {
Expand Down
15 changes: 1 addition & 14 deletions browser/ui/views/omnibox/brave_omnibox_view_views.h
Original file line number Diff line number Diff line change
Expand Up @@ -6,24 +6,11 @@
#ifndef BRAVE_BROWSER_UI_VIEWS_OMNIBOX_BRAVE_OMNIBOX_VIEW_VIEWS_H_
#define BRAVE_BROWSER_UI_VIEWS_OMNIBOX_BRAVE_OMNIBOX_VIEW_VIEWS_H_

#include <memory>

#include "chrome/browser/ui/views/omnibox/omnibox_view_views.h"

class OmniboxEditController;
class OmniboxClient;
class LocationBarView;
namespace gfx {
class FontList;
} // namespace gfx

class BraveOmniboxViewViews : public OmniboxViewViews {
public:
BraveOmniboxViewViews(OmniboxEditController* controller,
std::unique_ptr<OmniboxClient> client,
bool popup_window_mode,
LocationBarView* location_bar,
const gfx::FontList& font_list);
using OmniboxViewViews::OmniboxViewViews;

BraveOmniboxViewViews(const BraveOmniboxViewViews&) = delete;
BraveOmniboxViewViews& operator=(const BraveOmniboxViewViews&) = delete;
Expand Down
1 change: 1 addition & 0 deletions chromium_src/chrome/browser/chrome_browser_main_mac.mm
Original file line number Diff line number Diff line change
Expand Up @@ -8,3 +8,4 @@

#define AppController BraveAppController
#include "src/chrome/browser/chrome_browser_main_mac.mm"
#undef AppController

0 comments on commit f54c3c4

Please sign in to comment.