Update To 11.40.268.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / ui / webui / signin / user_manager_ui_browsertest.cc
1 // Copyright 2013 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
4
5 #include "base/command_line.h"
6 #include "base/strings/stringprintf.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "chrome/browser/profiles/profile_manager.h"
9 #include "chrome/browser/profiles/profile_window.h"
10 #include "chrome/browser/profiles/profiles_state.h"
11 #include "chrome/browser/ui/browser.h"
12 #include "chrome/browser/ui/tabs/tab_strip_model.h"
13 #include "chrome/common/chrome_switches.h"
14 #include "chrome/common/url_constants.h"
15 #include "chrome/grit/chromium_strings.h"
16 #include "chrome/test/base/in_process_browser_test.h"
17 #include "chrome/test/base/testing_browser_process.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "components/signin/core/common/profile_management_switches.h"
20 #include "content/public/browser/web_contents.h"
21 #include "content/public/test/browser_test_utils.h"
22 #include "ui/base/l10n/l10n_util.h"
23
24 class UserManagerUIBrowserTest : public InProcessBrowserTest,
25                                  public testing::WithParamInterface<bool> {
26  public:
27   UserManagerUIBrowserTest() {}
28
29  protected:
30   void SetUp() override {
31     InProcessBrowserTest::SetUp();
32     DCHECK(switches::IsNewAvatarMenu());
33   }
34
35   void SetUpCommandLine(CommandLine* command_line) override {
36     switches::EnableNewAvatarMenuForTesting(command_line);
37   }
38 };
39
40 IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageLoads) {
41   ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
42       browser(), GURL(chrome::kChromeUIUserManagerURL), 1);
43   content::WebContents* web_contents =
44       browser()->tab_strip_model()->GetActiveWebContents();
45
46   base::string16 title = web_contents->GetTitle();
47   EXPECT_EQ(l10n_util::GetStringUTF16(IDS_PRODUCT_NAME), title);
48
49   // If the page has loaded correctly, then there should be an account picker.
50   int num_account_pickers = -1;
51   ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
52       web_contents,
53       "domAutomationController.send("
54       "document.getElementsByClassName('account-picker').length)",
55       &num_account_pickers));
56   EXPECT_EQ(1, num_account_pickers);
57
58   int num_pods = -1;
59   ASSERT_TRUE(content::ExecuteScriptAndExtractInt(
60       web_contents,
61       "domAutomationController.send("
62       "parseInt(document.getElementById('pod-row').getAttribute('ncolumns')))",
63       &num_pods));
64
65   // There should be one user pod for each profile.
66   ProfileManager* profile_manager = g_browser_process->profile_manager();
67   EXPECT_EQ(num_pods, static_cast<int>(profile_manager->GetNumberOfProfiles()));
68 }
69
70 IN_PROC_BROWSER_TEST_F(UserManagerUIBrowserTest, PageRedirectsToAboutChrome) {
71   std::string user_manager_url = chrome::kChromeUIUserManagerURL;
72   user_manager_url += profiles::kUserManagerSelectProfileAboutChrome;
73
74   ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(
75       browser(), GURL(user_manager_url), 1);
76   content::WebContents* web_contents =
77       browser()->tab_strip_model()->GetActiveWebContents();
78
79   base::string16 profile_name =
80       profiles::GetAvatarNameForProfile(browser()->profile()->GetPath());
81
82   std::string launch_js =
83       base::StringPrintf("Oobe.launchUser('', '%s')",
84                          base::UTF16ToUTF8(profile_name).c_str());
85   bool result = content::ExecuteScript(web_contents, launch_js);
86   EXPECT_TRUE(result);
87   base::RunLoop().RunUntilIdle();
88
89   content::WebContents* about_chrome_contents =
90       browser()->tab_strip_model()->GetActiveWebContents();
91   GURL current_URL = about_chrome_contents->GetVisibleURL();
92   EXPECT_EQ(GURL(chrome::kChromeUIUberURL), current_URL);
93 }