Skip to content

Commit

Permalink
Make avatar badged on the top left of the browser window in ChromeOS …
Browse files Browse the repository at this point in the history
…draggable.

Also add two test cases:
1) Teleport a browser window to another desktop. Avatar icon should show on the top left corner of the teleported browser window. (Test case for bug 433420)
2) The avatar icon of the teleported browser window should be draggable.

BUG=342933

Review URL: https://codereview.chromium.org/843153002

Cr-Commit-Position: refs/heads/master@{#312016}
  • Loading branch information
xdai authored and Commit bot committed Jan 17, 2015
1 parent 747ff24 commit f7e24a2
Show file tree
Hide file tree
Showing 6 changed files with 232 additions and 132 deletions.
96 changes: 96 additions & 0 deletions chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.cc
Original file line number Diff line number Diff line change
@@ -0,0 +1,96 @@
// 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/ash/multi_user/multi_user_window_manager_test.h"

#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
#include "chrome/browser/ui/browser_window.h"
#include "ui/aura/window.h"

TestMultiUserWindowManager::TestMultiUserWindowManager(
Browser* visiting_browser,
const std::string& desktop_owner)
: browser_window_(visiting_browser->window()->GetNativeWindow()),
browser_owner_(
multi_user_util::GetUserIDFromProfile(visiting_browser->profile())),
desktop_owner_(desktop_owner),
created_window_(NULL),
created_window_shown_for_(browser_owner_),
current_user_id_(desktop_owner) {
// Register this object with the system (which will take ownership). It will
// be deleted by ChromeLauncherController::~ChromeLauncherController().
chrome::MultiUserWindowManager::SetInstanceForTest(
this, chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
}

TestMultiUserWindowManager::~TestMultiUserWindowManager() {
// This object is owned by the MultiUserWindowManager since the
// SetInstanceForTest call. As such no uninstall is required.
}

void TestMultiUserWindowManager::SetWindowOwner(aura::Window* window,
const std::string& user_id) {
NOTREACHED();
}

const std::string& TestMultiUserWindowManager::GetWindowOwner(
aura::Window* window) const {
// No matter which window will get queried - all browsers belong to the
// original browser's user.
return browser_owner_;
}

void TestMultiUserWindowManager::ShowWindowForUser(aura::Window* window,
const std::string& user_id) {
// This class is only able to handle one additional window <-> user
// association beside the creation parameters.
// If no association has yet been requested remember it now.
DCHECK(!created_window_);
created_window_ = window;
created_window_shown_for_ = user_id;

if (browser_window_ == window)
desktop_owner_ = user_id;

if (user_id == current_user_id_)
return;

// Change the visibility of the window to update the view recursively.
window->Hide();
window->Show();
current_user_id_ = user_id;
}

bool TestMultiUserWindowManager::AreWindowsSharedAmongUsers() const {
return browser_owner_ != desktop_owner_;
}

void TestMultiUserWindowManager::GetOwnersOfVisibleWindows(
std::set<std::string>* user_ids) const {
}

bool TestMultiUserWindowManager::IsWindowOnDesktopOfUser(
aura::Window* window,
const std::string& user_id) const {
return GetUserPresentingWindow(window) == user_id;
}

const std::string& TestMultiUserWindowManager::GetUserPresentingWindow(
aura::Window* window) const {
if (window == browser_window_)
return desktop_owner_;
if (created_window_ && window == created_window_)
return created_window_shown_for_;
// We can come here before the window gets registered.
return browser_owner_;
}

void TestMultiUserWindowManager::AddUser(content::BrowserContext* profile) {
}

void TestMultiUserWindowManager::AddObserver(Observer* observer) {
}

void TestMultiUserWindowManager::RemoveObserver(Observer* observer) {
}
58 changes: 58 additions & 0 deletions chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
// 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.

#ifndef CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_
#define CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_

#include "base/macros.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"

// This is a test implementation of a MultiUserWindowManager which allows to
// test a visiting window on another desktop. It will install and remove itself
// from the system upon creation / destruction.
// The creation function gets a |browser| which is shown on |desktop_owner|'s
// desktop.
class TestMultiUserWindowManager : public chrome::MultiUserWindowManager {
public:
TestMultiUserWindowManager(Browser* visiting_browser,
const std::string& desktop_owner);
~TestMultiUserWindowManager() override;

aura::Window* created_window() { return created_window_; }

// MultiUserWindowManager overrides:
void SetWindowOwner(aura::Window* window,
const std::string& user_id) override;
const std::string& GetWindowOwner(aura::Window* window) const override;
void ShowWindowForUser(aura::Window* window,
const std::string& user_id) override;
bool AreWindowsSharedAmongUsers() const override;
void GetOwnersOfVisibleWindows(
std::set<std::string>* user_ids) const override;
bool IsWindowOnDesktopOfUser(aura::Window* window,
const std::string& user_id) const override;
const std::string& GetUserPresentingWindow(
aura::Window* window) const override;
void AddUser(content::BrowserContext* profile) override;
void AddObserver(Observer* observer) override;
void RemoveObserver(Observer* observer) override;

private:
// The window of the visiting browser.
aura::Window* browser_window_;
// The owner of the visiting browser.
std::string browser_owner_;
// The owner of the currently shown desktop.
std::string desktop_owner_;
// The created window.
aura::Window* created_window_;
// The location of the window.
std::string created_window_shown_for_;
// The current selected active user.
std::string current_user_id_;

DISALLOW_COPY_AND_ASSIGN(TestMultiUserWindowManager);
};

#endif // CHROME_BROWSER_UI_ASH_MULTI_USER_MULTI_USER_WINDOW_MANAGER_TEST_H_
132 changes: 2 additions & 130 deletions chrome/browser/ui/browser_navigator_browsertest_chromeos.cc
Original file line number Diff line number Diff line change
@@ -1,151 +1,23 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2012 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/browser_navigator_browsertest.h"

#include <string>

#include "base/command_line.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_window_manager.h"
#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager_test.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/browser_navigator.h"
#include "chrome/browser/ui/browser_window.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_switches.h"
#include "chromeos/chromeos_switches.h"
#include "content/public/browser/web_contents.h"

namespace {

// This is a test implementation of a MultiUserWindowManager which allows to
// test a visiting window on another desktop. It will install and remove itself
// from the system upon creation / destruction.
// The creation function gets a |browser| which is shown on |desktop_owner|'s
// desktop.
class TestMultiUserWindowManager : public chrome::MultiUserWindowManager {
public:
TestMultiUserWindowManager(
Browser* visiting_browser,
const std::string& desktop_owner);
virtual ~TestMultiUserWindowManager();

aura::Window* created_window() { return created_window_; }

// MultiUserWindowManager overrides:
virtual void SetWindowOwner(
aura::Window* window, const std::string& user_id) override;
virtual const std::string& GetWindowOwner(
aura::Window* window) const override;
virtual void ShowWindowForUser(
aura::Window* window, const std::string& user_id) override;
virtual bool AreWindowsSharedAmongUsers() const override;
virtual void GetOwnersOfVisibleWindows(
std::set<std::string>* user_ids) const override;
virtual bool IsWindowOnDesktopOfUser(
aura::Window* window,
const std::string& user_id) const override;
virtual const std::string& GetUserPresentingWindow(
aura::Window* window) const override;
virtual void AddUser(content::BrowserContext* profile) override;
virtual void AddObserver(Observer* observer) override;
virtual void RemoveObserver(Observer* observer) override;

private:
// The window of the visiting browser.
aura::Window* browser_window_;
// The owner of the visiting browser.
std::string browser_owner_;
// The owner of the currently shown desktop.
std::string desktop_owner_;
// The created window.
aura::Window* created_window_;
// The location of the window.
std::string created_window_shown_for_;

DISALLOW_COPY_AND_ASSIGN(TestMultiUserWindowManager);
};

TestMultiUserWindowManager::TestMultiUserWindowManager(
Browser* visiting_browser,
const std::string& desktop_owner)
: browser_window_(visiting_browser->window()->GetNativeWindow()),
browser_owner_(multi_user_util::GetUserIDFromProfile(
visiting_browser->profile())),
desktop_owner_(desktop_owner),
created_window_(NULL),
created_window_shown_for_(browser_owner_) {
// Create a window manager for a visiting user.
chrome::MultiUserWindowManager::SetInstanceForTest(
this,
chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
}

TestMultiUserWindowManager::~TestMultiUserWindowManager() {
// This object is owned by the MultiUserWindowManager since the
// SetInstanceForTest call. As such no uninstall is required.
}

// MultiUserWindowManager overrides:
void TestMultiUserWindowManager::SetWindowOwner(
aura::Window* window, const std::string& user_id) {
NOTREACHED();
}

const std::string& TestMultiUserWindowManager::GetWindowOwner(
aura::Window* window) const {
// No matter which window will get queried - all browsers belong to the
// original browser's user.
return browser_owner_;
}

void TestMultiUserWindowManager::ShowWindowForUser(
aura::Window* window,
const std::string& user_id) {
// This class is only able to handle one additional window <-> user
// association beside the creation parameters.
// If no association has yet been requested remember it now.
DCHECK(!created_window_);
created_window_ = window;
created_window_shown_for_ = user_id;
}

bool TestMultiUserWindowManager::AreWindowsSharedAmongUsers() const {
return browser_owner_ != desktop_owner_;
}

void TestMultiUserWindowManager::GetOwnersOfVisibleWindows(
std::set<std::string>* user_ids) const {
}

bool TestMultiUserWindowManager::IsWindowOnDesktopOfUser(
aura::Window* window,
const std::string& user_id) const {
return GetUserPresentingWindow(window) == user_id;
}

const std::string& TestMultiUserWindowManager::GetUserPresentingWindow(
aura::Window* window) const {
if (window == browser_window_)
return desktop_owner_;
if (created_window_ && window == created_window_)
return created_window_shown_for_;
// We can come here before the window gets registered.
return browser_owner_;
}

void TestMultiUserWindowManager::AddUser(content::BrowserContext* profile) {
}

void TestMultiUserWindowManager::AddObserver(Observer* observer) {
}

void TestMultiUserWindowManager::RemoveObserver(Observer* observer) {
}

GURL GetGoogleURL() {
return GURL("http://www.google.com/");
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) 2012 The Chromium Authors. All rights reserved.
// Copyright 2012 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.

Expand All @@ -13,6 +13,7 @@
#include "ash/shell.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/extensions/extension_util.h"
#include "chrome/browser/profiles/profiles_state.h"
#include "chrome/browser/themes/theme_properties.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
Expand Down Expand Up @@ -246,7 +247,15 @@ int BrowserNonClientFrameViewAsh::NonClientHitTest(const gfx::Point& point) {
// See if the point is actually within either of the avatar menu buttons.
if (hit_test == HTCAPTION && avatar_button() &&
ConvertedHitTest(this, avatar_button(), point)) {
#if defined(OS_CHROMEOS)
// In ChromeOS, a browser window which has an avatar badging on the top
// left corner means it's a teleported browser window. We should treat the
// avatar as part of the browser non client frame (e.g., clicking on it
// allows the user to drag the browser window around.)
return HTCAPTION;
#else
return HTCLIENT;
#endif
}

if (hit_test == HTCAPTION && new_avatar_button() &&
Expand Down
Loading

0 comments on commit f7e24a2

Please sign in to comment.