Commit 6cd75c79 authored by Elly Fong-Jones's avatar Elly Fong-Jones Committed by Commit Bot

mac: remove TranslateBubbleController

This piece of Cocoa secondary UI has been obsolete for several releases now
and its tests are broken in MacViews mode.

Bug: 832676
Change-Id: I2cf1fa087f29a288005913424396fc399eabf210
Reviewed-on: https://chromium-review.googlesource.com/1148012Reviewed-by: default avatarRobert Sesek <rsesek@chromium.org>
Commit-Queue: Elly Fong-Jones <ellyjones@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577514}
parent 44abf4c7
...@@ -543,8 +543,6 @@ jumbo_split_static_library("ui") { ...@@ -543,8 +543,6 @@ jumbo_split_static_library("ui") {
"cocoa/touchbar/web_textfield_touch_bar_controller.mm", "cocoa/touchbar/web_textfield_touch_bar_controller.mm",
"cocoa/translate/translate_bubble_bridge_views.h", "cocoa/translate/translate_bubble_bridge_views.h",
"cocoa/translate/translate_bubble_bridge_views.mm", "cocoa/translate/translate_bubble_bridge_views.mm",
"cocoa/translate/translate_bubble_controller.h",
"cocoa/translate/translate_bubble_controller.mm",
"cocoa/url_drop_target.h", "cocoa/url_drop_target.h",
"cocoa/url_drop_target.mm", "cocoa/url_drop_target.mm",
"cocoa/vertical_gradient_view.h", "cocoa/vertical_gradient_view.h",
......
...@@ -57,7 +57,6 @@ class StatusBubbleMac; ...@@ -57,7 +57,6 @@ class StatusBubbleMac;
@class TabStripControllerCocoa; @class TabStripControllerCocoa;
@class TabStripView; @class TabStripView;
@class ToolbarController; @class ToolbarController;
@class TranslateBubbleController;
namespace content { namespace content {
class WebContents; class WebContents;
...@@ -109,8 +108,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122); ...@@ -109,8 +108,6 @@ constexpr const gfx::Size kMinCocoaPopupWindowSize(100, 122);
BOOL initializing_; // YES while we are currently in initWithBrowser: BOOL initializing_; // YES while we are currently in initWithBrowser:
BOOL ownsBrowser_; // Only ever NO when testing BOOL ownsBrowser_; // Only ever NO when testing
TranslateBubbleController* translateBubbleController_; // Weak.
// The total amount by which we've grown the window up or down (to display a // The total amount by which we've grown the window up or down (to display a
// bookmark bar and/or download shelf), respectively; reset to 0 when moved // bookmark bar and/or download shelf), respectively; reset to 0 when moved
// away from the bottom/top or resized (or zoomed). // away from the bottom/top or resized (or zoomed).
......
...@@ -79,7 +79,6 @@ ...@@ -79,7 +79,6 @@
#import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h" #import "chrome/browser/ui/cocoa/toolbar/toolbar_controller.h"
#import "chrome/browser/ui/cocoa/touchbar/browser_window_touch_bar_controller.h" #import "chrome/browser/ui/cocoa/touchbar/browser_window_touch_bar_controller.h"
#include "chrome/browser/ui/cocoa/translate/translate_bubble_bridge_views.h" #include "chrome/browser/ui/cocoa/translate/translate_bubble_bridge_views.h"
#import "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
#include "chrome/browser/ui/exclusive_access/fullscreen_controller.h" #include "chrome/browser/ui/exclusive_access/fullscreen_controller.h"
#include "chrome/browser/ui/location_bar/location_bar.h" #include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h" #include "chrome/browser/ui/tabs/tab_strip_model.h"
...@@ -1599,54 +1598,8 @@ bool IsTabDetachingInFullscreenEnabled() { ...@@ -1599,54 +1598,8 @@ bool IsTabDetachingInFullscreenEnabled() {
step:(translate::TranslateStep)step step:(translate::TranslateStep)step
errorType:(translate::TranslateErrors::Type) errorType:(translate::TranslateErrors::Type)
errorType { errorType {
if (chrome::ShowAllDialogsWithViewsToolkit()) { ShowTranslateBubbleViews([self window], [self locationBarBridge], contents,
ShowTranslateBubbleViews([self window], [self locationBarBridge], contents, step, errorType, true);
step, errorType, true);
return;
}
// TODO(hajimehoshi): The similar logic exists at TranslateBubbleView::
// ShowBubble. This should be unified.
if (translateBubbleController_) {
// When the user reads the advanced setting panel, the bubble should not be
// changed because they are focusing on the bubble.
if (translateBubbleController_.webContents == contents &&
translateBubbleController_.model->GetViewState() ==
TranslateBubbleModel::VIEW_STATE_ADVANCED) {
return;
}
if (step != translate::TRANSLATE_STEP_TRANSLATE_ERROR) {
TranslateBubbleModel::ViewState viewState =
TranslateBubbleModelImpl::TranslateStepToViewState(step);
[translateBubbleController_ switchView:viewState];
} else {
[translateBubbleController_ switchToErrorView:errorType];
}
return;
}
std::string sourceLanguage;
std::string targetLanguage;
ChromeTranslateClient::GetTranslateLanguages(
contents, &sourceLanguage, &targetLanguage);
std::unique_ptr<translate::TranslateUIDelegate> uiDelegate(
new translate::TranslateUIDelegate(
ChromeTranslateClient::GetManagerFromWebContents(contents)
->GetWeakPtr(),
sourceLanguage, targetLanguage));
std::unique_ptr<TranslateBubbleModel> model(
new TranslateBubbleModelImpl(step, std::move(uiDelegate)));
translateBubbleController_ =
[[TranslateBubbleController alloc] initWithParentWindow:self
model:std::move(model)
webContents:contents];
[translateBubbleController_ showWindow:nil];
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center addObserver:self
selector:@selector(translateBubbleWindowWillClose:)
name:NSWindowWillCloseNotification
object:[translateBubbleController_ window]];
} }
- (void)dismissPermissionBubble { - (void)dismissPermissionBubble {
...@@ -1655,17 +1608,6 @@ bool IsTabDetachingInFullscreenEnabled() { ...@@ -1655,17 +1608,6 @@ bool IsTabDetachingInFullscreenEnabled() {
delegate->Closing(); delegate->Closing();
} }
// Nil out the weak translate bubble controller reference.
- (void)translateBubbleWindowWillClose:(NSNotification*)notification {
DCHECK_EQ([notification object], [translateBubbleController_ window]);
NSNotificationCenter* center = [NSNotificationCenter defaultCenter];
[center removeObserver:self
name:NSWindowWillCloseNotification
object:[translateBubbleController_ window]];
translateBubbleController_ = nil;
}
// If the browser is in incognito mode or has multi-profiles, install the image // If the browser is in incognito mode or has multi-profiles, install the image
// view to decorate the window at the upper right. Use the same base y // view to decorate the window at the upper right. Use the same base y
// coordinate as the tab strip. // coordinate as the tab strip.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_COCOA_TRANSLATE_TRANSLATE_BUBBLE_CONTROLLER_H_
#define CHROME_BROWSER_UI_COCOA_TRANSLATE_TRANSLATE_BUBBLE_CONTROLLER_H_
#import <Cocoa/Cocoa.h>
#include <memory>
#include "base/mac/scoped_nsobject.h"
#include "chrome/browser/translate/chrome_translate_client.h"
#import "chrome/browser/ui/cocoa/omnibox_decoration_bubble_controller.h"
#include "components/translate/core/common/translate_errors.h"
@class BrowserWindowController;
class TranslateBubbleModel;
namespace content {
class WebContents;
}
// Displays the Translate bubble. The Translate bubble is a bubble which
// pops up when clicking the Translate icon on Omnibox. This bubble
// allows us to translate a foreign page into user-selected language,
// revert this, and configure the translate setting.
@interface TranslateBubbleController
: OmniboxDecorationBubbleController<NSTextViewDelegate> {
// The views of each state. The keys are TranslateBubbleModel::ViewState,
// and the values are NSView*.
base::scoped_nsobject<NSDictionary<NSNumber*, NSView*>> views_;
// The 'Try again' button on the error panel.
NSButton* tryAgainButton_;
}
@property(readonly, nonatomic) const content::WebContents* webContents;
@property(readonly, nonatomic) const TranslateBubbleModel* model;
- (id)initWithParentWindow:(BrowserWindowController*)controller
model:(std::unique_ptr<TranslateBubbleModel>)model
webContents:(content::WebContents*)webContents;
- (void)switchView:(TranslateBubbleModel::ViewState)viewState;
- (void)switchToErrorView:(translate::TranslateErrors::Type)errorType;
@end
// The methods on this category are used internally by the controller and are
// only exposed for testing purposes. DO NOT USE OTHERWISE.
@interface TranslateBubbleController (ExposedForTesting)
- (IBAction)handleCloseButtonPressed:(id)sender;
- (IBAction)handleTranslateButtonPressed:(id)sender;
@end
#endif // CHROME_BROWSER_UI_COCOA_TRANSLATE_TRANSLATE_BUBBLE_CONTROLLER_H_
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
#include "base/test/metrics/histogram_tester.h"
#include "base/test/scoped_feature_list.h"
#import "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/info_bubble_window.h"
#import "chrome/browser/ui/cocoa/test/cocoa_profile_test.h"
#include "chrome/browser/ui/cocoa/test/run_loop_testing.h"
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "chrome/common/url_constants.h"
#include "content/public/browser/site_instance.h"
#include "ui/base/ui_base_features.h"
@implementation BrowserWindowController (ForTesting)
- (TranslateBubbleController*)translateBubbleController{
return translateBubbleController_;
}
@end
@implementation TranslateBubbleController (ForTesting)
- (NSView*)errorView {
NSNumber* key = @(TranslateBubbleModel::VIEW_STATE_ERROR);
return [views_ objectForKey:key];
}
- (NSButton*)tryAgainButton {
return tryAgainButton_;
}
@end
class TranslateBubbleControllerTest : public CocoaProfileTest {
public:
TranslateBubbleControllerTest() {}
// CocoaProfileTest:
void SetUp() override {
// This file only tests Cocoa UI and can be deleted when kSecondaryUiMd is
// default.
scoped_feature_list_.InitAndDisableFeature(features::kSecondaryUiMd);
CocoaProfileTest::SetUp();
site_instance_ = content::SiteInstance::Create(profile());
NSWindow* nativeWindow = browser()->window()->GetNativeWindow();
bwc_ =
[BrowserWindowController browserWindowControllerForWindow:nativeWindow];
web_contents_ = AppendToTabStrip();
}
content::WebContents* AppendToTabStrip() {
std::unique_ptr<content::WebContents> web_contents =
content::WebContents::Create(content::WebContents::CreateParams(
profile(), site_instance_.get()));
content::WebContents* raw_web_contents = web_contents.get();
browser()->tab_strip_model()->AppendWebContents(std::move(web_contents),
/*foreground=*/true);
return raw_web_contents;
}
BrowserWindowController* bwc() { return bwc_; }
TranslateBubbleController* bubble() {
return [bwc() translateBubbleController];
}
void ShowBubble() {
ASSERT_FALSE(bubble());
translate::TranslateStep step = translate::TRANSLATE_STEP_BEFORE_TRANSLATE;
[bwc_ showTranslateBubbleForWebContents:web_contents_
step:step
errorType:translate::TranslateErrors::NONE];
// Ensure that there are no closing animations.
InfoBubbleWindow* window = (InfoBubbleWindow*)[bubble() window];
[window setAllowedAnimations:info_bubble::kAnimateNone];
}
void SwitchToErrorView() {
translate::TranslateStep step = translate::TRANSLATE_STEP_TRANSLATE_ERROR;
[bwc_
showTranslateBubbleForWebContents:web_contents_
step:step
errorType:translate::TranslateErrors::NETWORK];
}
void CloseBubble() {
[bubble() close];
chrome::testing::NSRunLoopRunAllPending();
}
private:
base::test::ScopedFeatureList scoped_feature_list_;
scoped_refptr<content::SiteInstance> site_instance_;
BrowserWindowController* bwc_;
content::WebContents* web_contents_;
DISALLOW_COPY_AND_ASSIGN(TranslateBubbleControllerTest);
};
TEST_F(TranslateBubbleControllerTest, ShowAndClose) {
EXPECT_FALSE(bubble());
ShowBubble();
EXPECT_TRUE(bubble());
CloseBubble();
EXPECT_FALSE(bubble());
}
TEST_F(TranslateBubbleControllerTest, SwitchToErrorView) {
EXPECT_FALSE(bubble());
ShowBubble();
const TranslateBubbleModel* model = [bubble() model];
EXPECT_TRUE(bubble());
EXPECT_EQ(TranslateBubbleModel::ViewState::VIEW_STATE_BEFORE_TRANSLATE,
model->GetViewState());
SwitchToErrorView();
NSView* errorView = [bubble() errorView];
// We should have 4 subview inside the error view:
// A NSTextField, a NSImageView and two NSButton.
EXPECT_EQ(4UL, [[errorView subviews] count]);
// one of the subview should be "Try again" button.
EXPECT_TRUE([[errorView subviews] containsObject:[bubble() tryAgainButton]]);
EXPECT_EQ(TranslateBubbleModel::ViewState::VIEW_STATE_ERROR,
model->GetViewState());
EXPECT_TRUE(bubble());
CloseBubble();
}
TEST_F(TranslateBubbleControllerTest, SwitchViews) {
// A basic test which just switch between views to make sure no crash.
EXPECT_FALSE(bubble());
ShowBubble();
EXPECT_TRUE(bubble());
// Switch to during translating view.
[bubble()
switchView:(TranslateBubbleModel::ViewState::VIEW_STATE_TRANSLATING)];
EXPECT_TRUE(bubble());
// Switch to after translating view.
[bubble()
switchView:(TranslateBubbleModel::ViewState::VIEW_STATE_AFTER_TRANSLATE)];
EXPECT_TRUE(bubble());
// Switch to advanced view.
[bubble() switchView:(TranslateBubbleModel::ViewState::VIEW_STATE_ADVANCED)];
EXPECT_TRUE(bubble());
// Switch to before translating view.
[bubble() switchView:
(TranslateBubbleModel::ViewState::VIEW_STATE_BEFORE_TRANSLATE)];
EXPECT_TRUE(bubble());
CloseBubble();
EXPECT_FALSE(bubble());
}
TEST_F(TranslateBubbleControllerTest, CloseRegistersDecline) {
const char kDeclineTranslateDismissUI[] =
"Translate.DeclineTranslateDismissUI";
const char kDeclineTranslate[] = "Translate.DeclineTranslate";
// A simple close without any interactions registers as a dismissal.
{
base::HistogramTester histogram_tester;
ShowBubble();
CloseBubble();
histogram_tester.ExpectTotalCount(kDeclineTranslateDismissUI, 1);
histogram_tester.ExpectTotalCount(kDeclineTranslate, 0);
}
// A close while pressing e.g. 'x', registers as decline.
{
base::HistogramTester histogram_tester;
ShowBubble();
[bubble() handleCloseButtonPressed:nil];
CloseBubble();
histogram_tester.ExpectTotalCount(kDeclineTranslateDismissUI, 0);
histogram_tester.ExpectTotalCount(kDeclineTranslate, 1);
}
}
// Copyright 2015 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/translate/translate_bubble_test_utils.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/cocoa/browser_dialogs_views_mac.h"
#include "chrome/browser/ui/cocoa/browser_window_controller.h"
#include "chrome/browser/ui/cocoa/translate/translate_bubble_controller.h"
#include "chrome/browser/ui/translate/translate_bubble_model.h"
#include "chrome/browser/ui/views/translate/translate_bubble_view.h"
#include "ui/events/keycodes/dom/dom_code.h"
#include "ui/views/controls/button/label_button.h"
// TODO(groby): Share with translate_bubble_controller_unittest.mm
@implementation BrowserWindowController (ForTesting)
- (TranslateBubbleController*)translateBubbleController {
return translateBubbleController_;
}
@end
namespace translate {
namespace test_utils {
const TranslateBubbleModel* GetCurrentModel(Browser* browser) {
DCHECK(browser);
if (chrome::ShowAllDialogsWithViewsToolkit()) {
TranslateBubbleView* view = TranslateBubbleView::GetCurrentBubble();
return view ? view->model() : nullptr;
}
NSWindow* native_window = browser->window()->GetNativeWindow();
BrowserWindowController* controller =
[BrowserWindowController browserWindowControllerForWindow:native_window];
return [[controller translateBubbleController] model];
}
void PressTranslate(Browser* browser) {
DCHECK(browser);
if (chrome::ShowAllDialogsWithViewsToolkit()) {
TranslateBubbleView* bubble = TranslateBubbleView::GetCurrentBubble();
DCHECK(bubble);
views::LabelButton button(nullptr, base::string16());
button.set_id(TranslateBubbleView::BUTTON_ID_TRANSLATE);
bubble->ButtonPressed(&button,
ui::KeyEvent(ui::ET_KEY_PRESSED, ui::VKEY_RETURN,
ui::DomCode::ENTER, ui::EF_NONE));
return;
}
NSWindow* native_window = browser->window()->GetNativeWindow();
BrowserWindowController* controller =
[BrowserWindowController browserWindowControllerForWindow:native_window];
[[controller translateBubbleController] handleTranslateButtonPressed:nil];
}
} // namespace test_utils
} // namespace translate
...@@ -4198,7 +4198,6 @@ test("unit_tests") { ...@@ -4198,7 +4198,6 @@ test("unit_tests") {
"../browser/ui/cocoa/touchbar/browser_window_default_touch_bar_unittest.mm", "../browser/ui/cocoa/touchbar/browser_window_default_touch_bar_unittest.mm",
"../browser/ui/cocoa/touchbar/credit_card_autofill_touch_bar_controller_unittest.mm", "../browser/ui/cocoa/touchbar/credit_card_autofill_touch_bar_controller_unittest.mm",
"../browser/ui/cocoa/touchbar/suggested_text_touch_bar_controller_unittest.mm", "../browser/ui/cocoa/touchbar/suggested_text_touch_bar_controller_unittest.mm",
"../browser/ui/cocoa/translate/translate_bubble_controller_unittest.mm",
"../browser/ui/cocoa/url_drop_target_unittest.mm", "../browser/ui/cocoa/url_drop_target_unittest.mm",
"../browser/ui/cocoa/vertical_gradient_view_unittest.mm", "../browser/ui/cocoa/vertical_gradient_view_unittest.mm",
"../browser/ui/cocoa/view_resizer_pong.h", "../browser/ui/cocoa/view_resizer_pong.h",
...@@ -5101,10 +5100,6 @@ if (!is_android) { ...@@ -5101,10 +5100,6 @@ if (!is_android) {
# toolkit-views secondary UI. It should not be deleted with the Cocoa # toolkit-views secondary UI. It should not be deleted with the Cocoa
# bubble (but it can be deleted with the Cocoa browser window). # bubble (but it can be deleted with the Cocoa browser window).
"../browser/ui/cocoa/permission_bubble/permission_bubble_cocoa_interactive_uitest.mm", "../browser/ui/cocoa/permission_bubble/permission_bubble_cocoa_interactive_uitest.mm",
# The translate bubble tests only obsolete Cocoa UI and doesn't link.
# Ensure the corresponding file is deleted when removing the next line.
# "../browser/ui/cocoa/translate/translate_bubble_test_utils_views_cocoa.mm",
] ]
} }
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment