Commit fbf94922 authored by spqchan's avatar spqchan Committed by Commit Bot

[Mac] Update the Touch Bar for Default Search Engine changes

Currently, if the user changes the default search engine in
settings, the touch bar does not update to reflect the change.

To fix this issue, the BrowserWindowTouchBar is modified so
that it observers changes to the default search engine.

Tests: browser test BrowserWindowTouchBarTest.SearchEngineChanges

Bug: 696702
Change-Id: I92861aabf9ab2e87ba6d1d32fda975d9a10bdf26
Reviewed-on: https://chromium-review.googlesource.com/792034
Commit-Queue: Sarah Chan <spqchan@chromium.org>
Reviewed-by: default avatarAvi Drissman <avi@chromium.org>
Cr-Commit-Position: refs/heads/master@{#519761}
parent ff664a5d
...@@ -123,7 +123,7 @@ ui::TouchBarAction TouchBarActionFromCommand(int command) { ...@@ -123,7 +123,7 @@ ui::TouchBarAction TouchBarActionFromCommand(int command) {
} }
// A class registered for C++ notifications. This is used to detect changes in // A class registered for C++ notifications. This is used to detect changes in
// the home button preferences and the back/forward commands. // the profile preferences and the back/forward commands.
class BrowserTouchBarNotificationBridge : public CommandObserver { class BrowserTouchBarNotificationBridge : public CommandObserver {
public: public:
BrowserTouchBarNotificationBridge(BrowserWindowTouchBar* observer, BrowserTouchBarNotificationBridge(BrowserWindowTouchBar* observer,
...@@ -162,6 +162,9 @@ class BrowserTouchBarNotificationBridge : public CommandObserver { ...@@ -162,6 +162,9 @@ class BrowserTouchBarNotificationBridge : public CommandObserver {
// Used to monitor the optional home button pref. // Used to monitor the optional home button pref.
BooleanPrefMember showHomeButton_; BooleanPrefMember showHomeButton_;
// Used to listen for default search engine pref changes.
PrefChangeRegistrar profilePrefRegistrar_;
// Used to receive and handle notifications. // Used to receive and handle notifications.
std::unique_ptr<BrowserTouchBarNotificationBridge> notificationBridge_; std::unique_ptr<BrowserTouchBarNotificationBridge> notificationBridge_;
...@@ -212,6 +215,12 @@ class BrowserTouchBarNotificationBridge : public CommandObserver { ...@@ -212,6 +215,12 @@ class BrowserTouchBarNotificationBridge : public CommandObserver {
prefs::kShowHomeButton, prefs, prefs::kShowHomeButton, prefs,
base::Bind(&BrowserTouchBarNotificationBridge::UpdateTouchBar, base::Bind(&BrowserTouchBarNotificationBridge::UpdateTouchBar,
base::Unretained(notificationBridge_.get()))); base::Unretained(notificationBridge_.get())));
profilePrefRegistrar_.Init(prefs);
profilePrefRegistrar_.Add(
DefaultSearchManager::kDefaultSearchProviderDataPrefName,
base::Bind(&BrowserTouchBarNotificationBridge::UpdateTouchBar,
base::Unretained(notificationBridge_.get())));
} }
return self; return self;
......
...@@ -7,7 +7,10 @@ ...@@ -7,7 +7,10 @@
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
#import "chrome/browser/ui/cocoa/browser_window_controller.h" #import "chrome/browser/ui/cocoa/browser_window_controller.h"
#import "chrome/browser/ui/cocoa/browser_window_touch_bar.h" #import "chrome/browser/ui/cocoa/browser_window_touch_bar.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h" #include "chrome/test/base/in_process_browser_test.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/search_engines_test_util.cc"
#include "content/public/test/browser_test_utils.h" #include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h" #include "content/public/test/test_utils.h"
#include "testing/gtest_mac.h" #include "testing/gtest_mac.h"
...@@ -105,3 +108,26 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarTest, StarredChanges) { ...@@ -105,3 +108,26 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarTest, StarredChanges) {
EXPECT_NE(touch_bar, [window touchBar]); EXPECT_NE(touch_bar, [window touchBar]);
} }
} }
// Tests if the touch bar gets invalidated if the default search engine has
// changed.
IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarTest, SearchEngineChanges) {
if (@available(macOS 10.12.2, *)) {
PrefService* prefs = browser()->profile()->GetPrefs();
DCHECK(prefs);
NSWindow* window = [browser_window_controller() window];
NSTouchBar* touch_bar = [browser_touch_bar() makeTouchBar];
[window setTouchBar:touch_bar];
EXPECT_TRUE([window touchBar]);
// Change the default search engine.
std::unique_ptr<TemplateURLData> data =
GenerateDummyTemplateURLData("poutine");
prefs->Set(DefaultSearchManager::kDefaultSearchProviderDataPrefName,
*TemplateURLDataToDictionary(*data));
// The window should have a new touch bar.
EXPECT_NE(touch_bar, [window touchBar]);
}
}
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