Commit 18d470b2 authored by Qiang Xu's avatar Qiang Xu Committed by Commit Bot

cros: fix avatar still shown on owner desktop

changes:
- Fix regression from crrev.com/1972033002.
- Rename multi_user_window_manager_test.h to
  multi_user_window_manager_test.h.

Bug: 766834
Test: manual test and added test coverage
Change-Id: I08d9beca388bf71eecb19f9c7b6412c6f8157365
Reviewed-on: https://chromium-review.googlesource.com/977040
Commit-Queue: Qiang Xu <warx@google.com>
Reviewed-by: default avatarScott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#545619}
parent b5ad8942
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h" #include "chrome/browser/ui/ash/multi_user/test_multi_user_window_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/browser_window.h" #include "chrome/browser/ui/browser_window.h"
...@@ -47,7 +47,8 @@ void TestMultiUserWindowManager::ShowWindowForUser( ...@@ -47,7 +47,8 @@ void TestMultiUserWindowManager::ShowWindowForUser(
// This class is only able to handle one additional window <-> user // This class is only able to handle one additional window <-> user
// association beside the creation parameters. // association beside the creation parameters.
// If no association has yet been requested remember it now. // If no association has yet been requested remember it now.
DCHECK(!created_window_); if (browser_owner_ != account_id)
DCHECK(!created_window_);
created_window_ = window; created_window_ = window;
created_window_shown_for_ = account_id; created_window_shown_for_ = account_id;
......
...@@ -2,8 +2,8 @@ ...@@ -2,8 +2,8 @@
// Use of this source code is governed by a BSD-style license that can be // Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file. // found in the LICENSE file.
#ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_ #ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_TEST_MULTI_USER_WINDOW_MANAGER_H_
#define CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_ #define CHROME_BROWSER_UI_ASH_MULTI_USER_TEST_MULTI_USER_WINDOW_MANAGER_H_
#include "base/macros.h" #include "base/macros.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h" #include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
...@@ -57,4 +57,4 @@ class TestMultiUserWindowManager : public MultiUserWindowManager { ...@@ -57,4 +57,4 @@ class TestMultiUserWindowManager : public MultiUserWindowManager {
DISALLOW_COPY_AND_ASSIGN(TestMultiUserWindowManager); DISALLOW_COPY_AND_ASSIGN(TestMultiUserWindowManager);
}; };
#endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_ #endif // CHROME_BROWSER_UI_ASH_MULTI_USER_TEST_MULTI_USER_WINDOW_MANAGER_H_
...@@ -7,7 +7,7 @@ ...@@ -7,7 +7,7 @@
#include "base/command_line.h" #include "base/command_line.h"
#include "chrome/browser/chromeos/login/chrome_restart_request.h" #include "chrome/browser/chromeos/login/chrome_restart_request.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h" #include "chrome/browser/ui/ash/multi_user/test_multi_user_window_manager.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h" #include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h" #include "chrome/browser/ui/browser_navigator.h"
......
...@@ -177,28 +177,14 @@ void BrowserNonClientFrameView::UpdateProfileIcons() { ...@@ -177,28 +177,14 @@ void BrowserNonClientFrameView::UpdateProfileIcons() {
return; return;
} }
Browser* browser = browser_view()->browser(); if (!ShouldShowProfileIndicatorIcon()) {
Profile* profile = browser->profile(); if (profile_indicator_icon_) {
const bool is_incognito = delete profile_indicator_icon_;
profile->GetProfileType() == Profile::INCOGNITO_PROFILE; profile_indicator_icon_ = nullptr;
frame_->GetRootView()->Layout();
// In the touch-optimized UI, we don't show the incognito icon in the browser }
// frame. It's instead shown in the new tab button. However, we still show an
// avatar icon for the teleported browser windows between multi-user sessions
// (Chrome OS only). Note that you can't teleport an incognito window.
if (is_incognito && ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return;
#if defined(OS_CHROMEOS)
// Ash and MUS specific.
if (!browser->is_type_tabbed() && !browser->is_app())
return;
if (!is_incognito && !MultiUserWindowManager::ShouldShowAvatar(
browser_view()->GetNativeWindow())) {
return; return;
} }
#endif // defined(OS_CHROMEOS)
if (!profile_indicator_icon_) { if (!profile_indicator_icon_) {
profile_indicator_icon_ = new ProfileIndicatorIcon(); profile_indicator_icon_ = new ProfileIndicatorIcon();
...@@ -210,6 +196,9 @@ void BrowserNonClientFrameView::UpdateProfileIcons() { ...@@ -210,6 +196,9 @@ void BrowserNonClientFrameView::UpdateProfileIcons() {
} }
gfx::Image icon; gfx::Image icon;
Profile* profile = browser_view()->browser()->profile();
const bool is_incognito =
profile->GetProfileType() == Profile::INCOGNITO_PROFILE;
if (is_incognito) { if (is_incognito) {
icon = gfx::Image(GetIncognitoAvatarIcon()); icon = gfx::Image(GetIncognitoAvatarIcon());
profile_indicator_icon_->set_stroke_color(SK_ColorTRANSPARENT); profile_indicator_icon_->set_stroke_color(SK_ColorTRANSPARENT);
...@@ -424,3 +413,28 @@ void BrowserNonClientFrameView::UpdateTaskbarDecoration() { ...@@ -424,3 +413,28 @@ void BrowserNonClientFrameView::UpdateTaskbarDecoration() {
chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &decoration); chrome::DrawTaskbarDecoration(frame_->GetNativeWindow(), &decoration);
#endif #endif
} }
bool BrowserNonClientFrameView::ShouldShowProfileIndicatorIcon() const {
Browser* browser = browser_view()->browser();
Profile* profile = browser->profile();
const bool is_incognito =
profile->GetProfileType() == Profile::INCOGNITO_PROFILE;
// In the touch-optimized UI, we don't show the incognito icon in the browser
// frame. It's instead shown in the new tab button. However, we still show an
// avatar icon for the teleported browser windows between multi-user sessions
// (Chrome OS only). Note that you can't teleport an incognito window.
if (is_incognito && ui::MaterialDesignController::IsTouchOptimizedUiEnabled())
return false;
#if defined(OS_CHROMEOS)
if (!browser->is_type_tabbed() && !browser->is_app())
return false;
if (!is_incognito && !MultiUserWindowManager::ShouldShowAvatar(
browser_view()->GetNativeWindow())) {
return false;
}
#endif // defined(OS_CHROMEOS)
return true;
}
...@@ -142,6 +142,9 @@ class BrowserNonClientFrameView : public views::NonClientFrameView, ...@@ -142,6 +142,9 @@ class BrowserNonClientFrameView : public views::NonClientFrameView,
// Draws a taskbar icon if avatars are enabled, erases it otherwise. // Draws a taskbar icon if avatars are enabled, erases it otherwise.
void UpdateTaskbarDecoration(); void UpdateTaskbarDecoration();
// Returns true if |profile_indicator_icon_| should be shown.
bool ShouldShowProfileIndicatorIcon() const;
// The frame that hosts this view. // The frame that hosts this view.
BrowserFrame* frame_; BrowserFrame* frame_;
......
...@@ -28,7 +28,7 @@ ...@@ -28,7 +28,7 @@
#include "chrome/browser/command_updater.h" #include "chrome/browser/command_updater.h"
#include "chrome/browser/profiles/profile_avatar_icon_util.h" #include "chrome/browser/profiles/profile_avatar_icon_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_util.h" #include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h" #include "chrome/browser/ui/ash/multi_user/test_multi_user_window_manager.h"
#include "chrome/browser/ui/ash/tablet_mode_client.h" #include "chrome/browser/ui/ash/tablet_mode_client.h"
#include "chrome/browser/ui/browser.h" #include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_command_controller.h" #include "chrome/browser/ui/browser_command_controller.h"
...@@ -296,10 +296,10 @@ IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewAshTest, ...@@ -296,10 +296,10 @@ IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewAshTest,
EXPECT_FALSE(MultiUserWindowManager::ShouldShowAvatar(window)); EXPECT_FALSE(MultiUserWindowManager::ShouldShowAvatar(window));
EXPECT_FALSE(frame_view->profile_indicator_icon()); EXPECT_FALSE(frame_view->profile_indicator_icon());
const AccountId current_account_id = const AccountId account_id1 =
multi_user_util::GetAccountIdFromProfile(browser()->profile()); multi_user_util::GetAccountIdFromProfile(browser()->profile());
TestMultiUserWindowManager* manager = TestMultiUserWindowManager* manager =
new TestMultiUserWindowManager(browser(), current_account_id); new TestMultiUserWindowManager(browser(), account_id1);
// Teleport the window to another desktop. // Teleport the window to another desktop.
const AccountId account_id2(AccountId::FromUserEmail("user2")); const AccountId account_id2(AccountId::FromUserEmail("user2"));
...@@ -309,6 +309,11 @@ IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewAshTest, ...@@ -309,6 +309,11 @@ IN_PROC_BROWSER_TEST_P(BrowserNonClientFrameViewAshTest,
// An icon should show on the top left corner of the teleported browser // An icon should show on the top left corner of the teleported browser
// window. // window.
EXPECT_TRUE(frame_view->profile_indicator_icon()); EXPECT_TRUE(frame_view->profile_indicator_icon());
// Teleport the window back to owner desktop.
manager->ShowWindowForUser(window, account_id1);
EXPECT_FALSE(MultiUserWindowManager::ShouldShowAvatar(window));
EXPECT_FALSE(frame_view->profile_indicator_icon());
} }
// Hit Test for Avatar Menu Button on ChromeOS. // Hit Test for Avatar Menu Button on ChromeOS.
......
...@@ -1665,8 +1665,8 @@ test("browser_tests") { ...@@ -1665,8 +1665,8 @@ test("browser_tests") {
"../browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc", "../browser/ui/ash/launcher/chrome_launcher_controller_browsertest.cc",
"../browser/ui/ash/launcher/chrome_launcher_controller_test_util.cc", "../browser/ui/ash/launcher/chrome_launcher_controller_test_util.cc",
"../browser/ui/ash/launcher/chrome_launcher_controller_test_util.h", "../browser/ui/ash/launcher/chrome_launcher_controller_test_util.h",
"../browser/ui/ash/multi_user/multi_user_window_manager_test.cc", "../browser/ui/ash/multi_user/test_multi_user_window_manager.cc",
"../browser/ui/ash/multi_user/multi_user_window_manager_test.h", "../browser/ui/ash/multi_user/test_multi_user_window_manager.h",
"../browser/ui/ash/network/networking_config_delegate_chromeos_browsertest.cc", "../browser/ui/ash/network/networking_config_delegate_chromeos_browsertest.cc",
"../browser/ui/ash/shelf_browsertest.cc", "../browser/ui/ash/shelf_browsertest.cc",
"../browser/ui/ash/system_tray_client_browsertest.cc", "../browser/ui/ash/system_tray_client_browsertest.cc",
......
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