15821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Copyright (c) 2012 The Chromium Authors. All rights reserved.
25821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
35821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// found in the LICENSE file.
45821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
55821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_navigator_browsertest.h"
65821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
7a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include <string>
8a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
95821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "base/command_line.h"
102a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/chromeos/login/chrome_restart_request.h"
11a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_util.h"
12a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/ash/multi_user/multi_user_window_manager.h"
135821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
142a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/browser_finder.h"
155821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/browser/ui/browser_navigator.h"
16a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)#include "chrome/browser/ui/browser_window.h"
172a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
185821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
195821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h"
20c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)#include "chromeos/chromeos_switches.h"
215821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)#include "content/public/browser/web_contents.h"
225821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
235821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)namespace {
245821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
25a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// This is a test implementation of a MultiUserWindowManager which allows to
26a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// test a visiting window on another desktop. It will install and remove itself
27a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// from the system upon creation / destruction.
28a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// The creation function gets a |browser| which is shown on |desktop_owner|'s
29a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// desktop.
30a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)class TestMultiUserWindowManager : public chrome::MultiUserWindowManager {
31a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) public:
32a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  TestMultiUserWindowManager(
33a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      Browser* visiting_browser,
34a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      const std::string& desktop_owner);
35a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual ~TestMultiUserWindowManager();
36a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
37a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* created_window() { return created_window_; }
38a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
39a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // MultiUserWindowManager overrides:
40a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void SetWindowOwner(
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      aura::Window* window, const std::string& user_id) OVERRIDE;
42010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual const std::string& GetWindowOwner(
43010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      aura::Window* window) const OVERRIDE;
44a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual void ShowWindowForUser(
45a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      aura::Window* window, const std::string& user_id) OVERRIDE;
46010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool AreWindowsSharedAmongUsers() const OVERRIDE;
475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void GetOwnersOfVisibleWindows(
48010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      std::set<std::string>* user_ids) const OVERRIDE;
49010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)  virtual bool IsWindowOnDesktopOfUser(
50010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      aura::Window* window,
51010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      const std::string& user_id) const OVERRIDE;
52a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  virtual const std::string& GetUserPresentingWindow(
53010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)      aura::Window* window) const OVERRIDE;
54a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)  virtual void AddUser(content::BrowserContext* profile) OVERRIDE;
555d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void AddObserver(Observer* observer) OVERRIDE;
565d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)  virtual void RemoveObserver(Observer* observer) OVERRIDE;
57a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
58a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles) private:
59a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The window of the visiting browser.
60a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* browser_window_;
61a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The owner of the visiting browser.
62a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string browser_owner_;
63a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The owner of the currently shown desktop.
64a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string desktop_owner_;
65a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The created window.
66a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  aura::Window* created_window_;
67a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // The location of the window.
68a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  std::string created_window_shown_for_;
69a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
70a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DISALLOW_COPY_AND_ASSIGN(TestMultiUserWindowManager);
71a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)};
72a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
73a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TestMultiUserWindowManager::TestMultiUserWindowManager(
74a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    Browser* visiting_browser,
75a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const std::string& desktop_owner)
76a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    : browser_window_(visiting_browser->window()->GetNativeWindow()),
77a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      browser_owner_(multi_user_util::GetUserIDFromProfile(
78a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)          visiting_browser->profile())),
79a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      desktop_owner_(desktop_owner),
80a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      created_window_(NULL),
81a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      created_window_shown_for_(browser_owner_) {
82a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Create a window manager for a visiting user.
83a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  chrome::MultiUserWindowManager::SetInstanceForTest(
84a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      this,
85a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)      chrome::MultiUserWindowManager::MULTI_PROFILE_MODE_SEPARATED);
86a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
87a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
88a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)TestMultiUserWindowManager::~TestMultiUserWindowManager() {
89a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // This object is owned by the MultiUserWindowManager since the
90a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // SetInstanceForTest call. As such no uninstall is required.
91a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
92a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
93a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// MultiUserWindowManager overrides:
94a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void TestMultiUserWindowManager::SetWindowOwner(
95a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    aura::Window* window, const std::string& user_id) {
96a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  NOTREACHED();
97a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
98a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
99a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const std::string& TestMultiUserWindowManager::GetWindowOwner(
100010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    aura::Window* window) const {
101a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // No matter which window will get queried - all browsers belong to the
102a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // original browser's user.
103a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return browser_owner_;
104a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
105a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
106a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)void TestMultiUserWindowManager::ShowWindowForUser(
107a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    aura::Window* window,
108a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const std::string& user_id) {
109a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // This class is only able to handle one additional window <-> user
110a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // association beside the creation parameters.
111a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // If no association has yet been requested remember it now.
112a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  DCHECK(!created_window_);
113a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  created_window_ = window;
114a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  created_window_shown_for_ = user_id;
115a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
116a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
117010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)bool TestMultiUserWindowManager::AreWindowsSharedAmongUsers() const {
118a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return browser_owner_ != desktop_owner_;
119a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
120a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1215d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TestMultiUserWindowManager::GetOwnersOfVisibleWindows(
122010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    std::set<std::string>* user_ids) const {
1235d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1245d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
125a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)bool TestMultiUserWindowManager::IsWindowOnDesktopOfUser(
126a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    aura::Window* window,
127010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    const std::string& user_id) const {
128a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return GetUserPresentingWindow(window) == user_id;
129a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
130a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
131a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)const std::string& TestMultiUserWindowManager::GetUserPresentingWindow(
132010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles)    aura::Window* window) const {
133a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (window == browser_window_)
134a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return desktop_owner_;
135a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  if (created_window_ && window == created_window_)
136a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    return created_window_shown_for_;
137a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // We can come here before the window gets registered.
138a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  return browser_owner_;
139a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
140a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
141a1401311d1ab56c4ed0a474bd38c108f75cb0cd9Torne (Richard Coles)void TestMultiUserWindowManager::AddUser(content::BrowserContext* profile) {
142a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
143a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
1445d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TestMultiUserWindowManager::AddObserver(Observer* observer) {
1455d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1465d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1475d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)void TestMultiUserWindowManager::RemoveObserver(Observer* observer) {
1485d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)}
1495d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)
1505821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)GURL GetGoogleURL() {
1515821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  return GURL("http://www.google.com/");
1525821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1535821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1545821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// Subclass that tests navigation while in the Guest session.
1555821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)class BrowserGuestSessionNavigatorTest: public BrowserNavigatorTest {
1565821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles) protected:
1572a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
1585821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)    CommandLine command_line_copy = *command_line;
159c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)    command_line_copy.AppendSwitchASCII(
160c2e0dbddbe15c98d52c4786dac06cb8952a8ae6dTorne (Richard Coles)        chromeos::switches::kLoginProfile, "user");
1612a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)    chromeos::GetOffTheRecordCommandLine(GetGoogleURL(),
162effb81e5f8246d0db0270817048dc992db66e9fbBen Murdoch                                         true,
1632a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                         command_line_copy,
1642a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                                         command_line);
1655821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  }
1665821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)};
1675821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1685821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// This test verifies that the settings page is opened in the incognito window
1695821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)// in Guest Session (as well as all other windows in Guest session).
1705821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
1715821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)                       Disposition_Settings_UseIncognitoWindow) {
1725821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  Browser* incognito_browser = CreateIncognitoBrowser();
1735821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1742a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
1752a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, browser()->tab_strip_model()->count());
1762a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(1, incognito_browser->tab_strip_model()->count());
1775821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1785821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Navigate to the settings page.
179a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  chrome::NavigateParams params(MakeNavigateParams(incognito_browser));
180a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.disposition = SINGLETON_TAB;
181a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.url = GURL("chrome://chrome/settings");
182a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.window_action = chrome::NavigateParams::SHOW_WINDOW;
183a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
184a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  chrome::Navigate(&params);
1855821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
1865821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  // Settings page should be opened in incognito window.
187a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_NE(browser(), params.browser);
188a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  EXPECT_EQ(incognito_browser, params.browser);
1892a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)  EXPECT_EQ(2, incognito_browser->tab_strip_model()->count());
1905821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)  EXPECT_EQ(GURL("chrome://chrome/settings"),
1912a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)            incognito_browser->tab_strip_model()->GetActiveWebContents()->
1922a99a7e74a7f215066514fe81d2bfa6639d9edddTorne (Richard Coles)                GetURL());
1935821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}
1945821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)
195a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// Test that in multi user environments a newly created browser gets created
196a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)// on the same desktop as the browser is shown on.
197a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(BrowserGuestSessionNavigatorTest,
198a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                       Browser_Gets_Created_On_Visiting_Desktop) {
199a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Test 1: Test that a browser created from a visiting browser will be on the
200a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // same visiting desktop.
201a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  {
202a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    const std::string desktop_user_id = "desktop_user_id@fake.com";
203a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    TestMultiUserWindowManager* manager =
204a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        new TestMultiUserWindowManager(browser(), desktop_user_id);
205a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
206a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_EQ(1u, chrome::GetTotalBrowserCount());
207a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
208a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Navigate to the settings page.
209a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    chrome::NavigateParams params(MakeNavigateParams(browser()));
210a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.disposition = NEW_POPUP;
211a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.url = GURL("chrome://chrome/settings");
212a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.window_action = chrome::NavigateParams::SHOW_WINDOW;
213a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
214a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.browser = browser();
215a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    chrome::Navigate(&params);
216a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
217a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_EQ(2u, chrome::GetTotalBrowserCount());
218a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
219a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    aura::Window* created_window = manager->created_window();
220a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_TRUE(created_window);
221a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_TRUE(manager->IsWindowOnDesktopOfUser(created_window,
222a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)                                                 desktop_user_id));
223a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
224a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // Test 2: Test that a window which is not visiting does not cause an owner
225a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  // assignment of a newly created browser.
226a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  {
227a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    std::string browser_owner =
228a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        multi_user_util::GetUserIDFromProfile(browser()->profile());
229a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    TestMultiUserWindowManager* manager =
230a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)        new TestMultiUserWindowManager(browser(), browser_owner);
231a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
232a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // Navigate to the settings page.
233a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    chrome::NavigateParams params(MakeNavigateParams(browser()));
234a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.disposition = NEW_POPUP;
235a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.url = GURL("chrome://chrome/settings");
236a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.window_action = chrome::NavigateParams::SHOW_WINDOW;
237a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.path_behavior = chrome::NavigateParams::IGNORE_AND_NAVIGATE;
238a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    params.browser = browser();
239a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    chrome::Navigate(&params);
240a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
241a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    EXPECT_EQ(3u, chrome::GetTotalBrowserCount());
242a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
243a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // The ShowWindowForUser should not have been called since the window is
244a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    // already on the correct desktop.
245a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)    ASSERT_FALSE(manager->created_window());
246a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  }
247a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)}
248a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)
2495821806d5e7f356e8fa4b058a389a808ea183019Torne (Richard Coles)}  // namespace
250