13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved.
23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be
33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file.
43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "base/command_line.h"
53551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/profiles/profile_manager.h"
63551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/browser.h"
73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h"
83551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/common/chrome_switches.h"
93551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/common/url_constants.h"
101320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci#include "chrome/grit/chromium_strings.h"
113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/test/base/in_process_browser_test.h"
123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/test/base/testing_browser_process.h"
133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h"
14f8ee788a64d60abd8f2d742a5fdedde054ecd910Torne (Richard Coles)#include "components/signin/core/common/profile_management_switches.h"
153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/browser/web_contents.h"
163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/test/browser_test_utils.h"
173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "ui/base/l10n/l10n_util.h"
183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)class UserManagerUIBrowserTest : public InProcessBrowserTest,
203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)                                 public testing::WithParamInterface<bool> {
213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public:
223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  UserManagerUIBrowserTest() {}
233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected:
251320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci  virtual void SetUp() OVERRIDE {
263551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)    InProcessBrowserTest::SetUp();
275f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    DCHECK(switches::IsNewAvatarMenu());
283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
315f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles)    switches::EnableNewAvatarMenuForTesting(command_line);
323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  }
333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)};
343551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
353551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageLoads) {
360529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch  ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
370529e5d033099cbfc42635f6f6183833b09dff6eBen Murdoch      browser(), GURL(chrome::kChromeUIUserManagerURL), 1);
383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  content::WebContents* web_contents =
393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      browser()->tab_strip_model()->GetActiveWebContents();
403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
41a3f6a49ab37290eeeb8db0f41ec0f1cb74a68be7Torne (Richard Coles)  base::string16 title = web_contents->GetTitle();
426e8cce623b6e4fe0c9e4af605d675dd9d0338c38Torne (Richard Coles)  EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), title);
433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // If the page has loaded correctly, then there should be an account picker.
453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  int num_account_pickers = -1;
463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      web_contents,
483551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      "domAutomationController.send("
493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      "document.getElementsByClassName('account-picker').length)",
503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      &num_account_pickers));
513551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(1, num_account_pickers);
523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  int num_pods = -1;
543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      web_contents,
563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      "domAutomationController.send("
573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      "parseInt(document.getElementById('pod-row').getAttribute('ncolumns')))",
583551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)      &num_pods));
593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)
603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  // There should be one user pod for each profile.
613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  ProfileManager* profile_manager = g_browser_process->profile_manager();
623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)  EXPECT_EQ(num_pods, static_cast<int>(profile_manager->GetNumberOfProfiles()));
633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}
64