Commit 2b1bcbaf authored by Robert Sesek's avatar Robert Sesek Committed by Commit Bot

Sever BrowserWindowTouchBarControllerTest dependency on BrowserWindowController.

Bug: 832676
Change-Id: Ife9b271854db2b4379d9df1869cc51eb9c2dbaa0
Reviewed-on: https://chromium-review.googlesource.com/1246722
Commit-Queue: Robert Sesek <rsesek@chromium.org>
Reviewed-by: default avatarLeonard Grey <lgrey@chromium.org>
Cr-Commit-Position: refs/heads/master@{#594458}
parent bdc9e1dc
......@@ -7,12 +7,12 @@
#include "chrome/browser/ui/bookmarks/bookmark_tab_helper_observer.h"
#include "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/touchbar/browser_window_default_touch_bar.h"
#import "chrome/browser/ui/cocoa/touchbar/browser_window_touch_bar_controller.h"
#include "chrome/browser/ui/views/frame/browser_frame_mac.h"
#include "chrome/browser/ui/views/frame/browser_view.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "chrome/test/views/scoped_macviews_browser_mode.h"
#include "components/prefs/pref_service.h"
#include "components/search_engines/default_search_manager.h"
#include "components/search_engines/search_engines_test_util.h"
......@@ -21,6 +21,7 @@
#include "content/public/test/browser_test_utils.h"
#include "content/public/test/test_utils.h"
#include "testing/gtest_mac.h"
#include "ui/views/cocoa/window_touch_bar_delegate.h"
// TODO(spqchan): Write tests that will check for page load and bookmark
// updates.
......@@ -29,59 +30,43 @@ class BrowserWindowTouchBarControllerTest : public InProcessBrowserTest {
public:
BrowserWindowTouchBarControllerTest() : InProcessBrowserTest() {}
void SetUpOnMainThread() override {
if (@available(macOS 10.12.2, *)) {
browser_touch_bar_controller_.reset(
[[BrowserWindowTouchBarController alloc]
initWithBrowser:browser()
window:[browser_window_controller() window]]);
[browser_window_controller()
setBrowserWindowTouchBarController:browser_touch_bar_controller_
.get()];
}
}
void TearDownOnMainThread() override {
if (@available(macOS 10.12.2, *))
DestroyBrowserWindowTouchBar();
InProcessBrowserTest::TearDownOnMainThread();
}
API_AVAILABLE(macos(10.12.2))
void DestroyBrowserWindowTouchBar() {
[browser_window_controller() setBrowserWindowTouchBarController:nil];
browser_touch_bar_controller_.reset();
NSTouchBar* MakeTouchBar() {
auto* delegate =
static_cast<NSObject<WindowTouchBarDelegate>*>(native_window());
return [delegate makeTouchBar];
}
BrowserWindowController* browser_window_controller() {
return [BrowserWindowController
browserWindowControllerForWindow:browser()
->window()
->GetNativeWindow()];
NSWindow* native_window() const {
return browser()->window()->GetNativeWindow();
}
API_AVAILABLE(macos(10.12.2))
BrowserWindowTouchBarController* browser_touch_bar_controller() const {
return browser_touch_bar_controller_;
BrowserView* browser_view =
BrowserView::GetBrowserViewForNativeWindow(native_window());
EXPECT_TRUE(browser_view);
if (!browser_view)
return nil;
BrowserFrameMac* browser_frame = static_cast<BrowserFrameMac*>(
browser_view->frame()->native_browser_frame());
return browser_frame->GetTouchBarController();
}
private:
API_AVAILABLE(macos(10.12.2))
base::scoped_nsobject<BrowserWindowTouchBarController>
browser_touch_bar_controller_;
test::ScopedMacViewsBrowserMode cocoa_browser_mode_{false};
DISALLOW_COPY_AND_ASSIGN(BrowserWindowTouchBarControllerTest);
};
// Test if the touch bar gets invalidated when the active tab is changed.
IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest, TabChanges) {
if (@available(macOS 10.12.2, *)) {
NSWindow* window = [browser_window_controller() window];
NSTouchBar* touch_bar = [browser_touch_bar_controller() makeTouchBar];
[window setTouchBar:touch_bar];
EXPECT_TRUE([window touchBar]);
EXPECT_FALSE(browser_touch_bar_controller());
MakeTouchBar();
EXPECT_TRUE(browser_touch_bar_controller());
auto* current_touch_bar = [native_window() touchBar];
EXPECT_TRUE(current_touch_bar);
// Insert a new tab in the foreground. The window should have a new touch
// bar.
......@@ -89,7 +74,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest, TabChanges) {
content::WebContents::Create(
content::WebContents::CreateParams(browser()->profile()));
browser()->tab_strip_model()->AppendWebContents(std::move(contents), true);
EXPECT_NE(touch_bar, [window touchBar]);
EXPECT_NE(current_touch_bar, [native_window() touchBar]);
}
}
......@@ -101,10 +86,11 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest,
PrefService* prefs = browser()->profile()->GetPrefs();
DCHECK(prefs);
NSWindow* window = [browser_window_controller() window];
NSTouchBar* touch_bar = [browser_touch_bar_controller() makeTouchBar];
[window setTouchBar:touch_bar];
EXPECT_TRUE([window touchBar]);
EXPECT_FALSE(browser_touch_bar_controller());
MakeTouchBar();
auto* current_touch_bar = [native_window() touchBar];
EXPECT_TRUE(current_touch_bar);
// Change the default search engine.
std::unique_ptr<TemplateURLData> data =
......@@ -113,7 +99,7 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest,
*TemplateURLDataToDictionary(*data));
// The window should have a new touch bar.
EXPECT_NE(touch_bar, [window touchBar]);
EXPECT_NE(current_touch_bar, [native_window() touchBar]);
}
}
......@@ -122,6 +108,10 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest,
IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest,
DestroyNotificationBridge) {
if (@available(macOS 10.12.2, *)) {
MakeTouchBar();
ASSERT_TRUE([browser_touch_bar_controller() defaultTouchBar]);
BookmarkTabHelperObserver* observer =
[[browser_touch_bar_controller() defaultTouchBar] bookmarkTabObserver];
std::unique_ptr<content::WebContents> contents =
......@@ -131,10 +121,11 @@ IN_PROC_BROWSER_TEST_F(BrowserWindowTouchBarControllerTest,
BookmarkTabHelper* tab_helper = BookmarkTabHelper::FromWebContents(
browser()->tab_strip_model()->GetActiveWebContents());
DCHECK(tab_helper);
ASSERT_TRUE(tab_helper);
EXPECT_TRUE(tab_helper->HasObserver(observer));
DestroyBrowserWindowTouchBar();
CloseBrowserSynchronously(browser());
EXPECT_FALSE(tab_helper->HasObserver(observer));
}
}
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