Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(664)

Side by Side Diff: chrome/browser/ui/webui/options/managed_user_passphrase_handler_browsertest.cc

Issue 11783008: Add a lock to the managed user settings page and require authentication for unlocking. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Add browser test for ManagedUserSetPassphraseOverlay Created 7 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
(Empty)
1 // Copyright (c) 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/string_util.h"
7 #include "chrome/browser/extensions/extension_browsertest.h"
8 #include "chrome/browser/managed_mode/managed_user_service.h"
9 #include "chrome/browser/managed_mode/managed_user_service_factory.h"
10 #include "chrome/browser/prefs/pref_service.h"
11 #include "chrome/browser/profiles/profile.h"
12 #include "chrome/browser/ui/browser_navigator.h"
13 #include "chrome/browser/ui/browser_tabstrip.h"
14 #include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
15 #include "chrome/common/chrome_switches.h"
16 #include "chrome/common/pref_names.h"
17 #include "chrome/test/base/in_process_browser_test.h"
18 #include "chrome/test/base/ui_test_utils.h"
19 #include "content/public/browser/web_contents.h"
20 #include "content/public/test/test_utils.h"
21 #include "googleurl/src/gurl.h"
22 #include "grit/generated_resources.h"
23 #include "ui/base/l10n/l10n_util.h"
24
25 using content::WebContents;
26
27 class ManagedUserPassphraseHandlerTest : public InProcessBrowserTest {
28 public:
29
30 ManagedUserPassphraseHandlerTest() {}
31
32 virtual void SetUpOnMainThread() OVERRIDE {
33 PrefService* prefs = browser()->profile()->GetPrefs();
34 // Set a fake passphrase.
35 prefs->SetString(prefs::kManagedModeLocalPassphrase, "fake");
36 }
37
38 protected:
39 virtual void SetUpCommandLine(CommandLine* command_line) {
40 command_line->AppendSwitch(switches::kManaged);
41 command_line->AppendSwitch(switches::kEnableManagedUsers);
42 }
43 bool IsShowingWebContentsModalDialog(WebContents* web_contents) const {
44 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
45 WebContentsModalDialogManager::FromWebContents(web_contents);
46 return web_contents_modal_dialog_manager->IsShowingDialog();
47 }
48
49 private:
50 DISALLOW_COPY_AND_ASSIGN(ManagedUserPassphraseHandlerTest);
51 };
52
53 // Try to navigate to the managed user settings page. Since we are not
54 // authenticated, the enter passphrase dialog should show up.
55 IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, LockedProfile) {
56 GURL settings_url("chrome://settings/managedUser");
57 ui_test_utils::NavigateToURL(browser(), settings_url);
58 WebContents* tab = chrome::GetActiveWebContents(browser());
59 // Check that the passphrase dialog is shown.
60 EXPECT_TRUE(IsShowingWebContentsModalDialog(tab));
61 // Now check that the settings page is displayed instead of the managed user
62 // settings page.
63 string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
64 string16 title;
65 ui_test_utils::GetCurrentTabTitle(browser(), &title);
66 EXPECT_EQ(title, expected_title);
67 }
68
69 // Try to navigate to the managed user settings page. Since we are
70 // authenticated, the enter passphrase dialog should not show up.
71 IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, UnlockedProfile) {
72 // Set the custodian to authenticated.
73 ManagedUserService* managed_user_service =
74 ManagedUserServiceFactory::GetForProfile(browser()->profile());
75 managed_user_service->SetElevated(true);
76 GURL settings_url("chrome://settings/managedUser");
77 // We navigate 3 times when navigation to that URL: the first navigation
78 // sends an asynchronous authentication request, after that is answered, a
79 // call to navigateToPage("managedUser") leads to a load of the url
80 // chrome://settings which is followed by a navigation to
81 // chrome://settings/managedUser, which is now finally displayed because we
82 // are successfully authenticated.
83 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
84 settings_url,
85 3);
86 WebContents* tab = chrome::GetActiveWebContents(browser());
87 // Check that the passphrase dialog is not shown.
88 EXPECT_FALSE(IsShowingWebContentsModalDialog(tab));
89 // Check that the managed user settings page is shown.
90 string16 expected_title =
91 l10n_util::GetStringUTF16(IDS_MANAGED_USER_SETTINGS_TITLE);
92 string16 title;
93 ui_test_utils::GetCurrentTabTitle(browser(), &title);
94 EXPECT_TRUE(EndsWith(title, expected_title, true));
95 }
96
97 // Try to navigate to the managed user set passphrase page. Since we are not
98 // authenticated, the enter passphrase dialog should show up.
99 IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, LockedProfile2) {
100 GURL settings_url("chrome://settings/setPassphrase");
101 ui_test_utils::NavigateToURL(browser(), settings_url);
102 WebContents* tab = chrome::GetActiveWebContents(browser());
103 // Check that the passphrase dialog is shown.
104 EXPECT_TRUE(IsShowingWebContentsModalDialog(tab));
105 // Now check that the settings page is displayed instead of the managed user
106 // set passphrase page.
107 string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
108 string16 title;
109 ui_test_utils::GetCurrentTabTitle(browser(), &title);
110 EXPECT_EQ(title, expected_title);
111 }
112
113 // Try to navigate to the managed user set passphrase page. Since we are
114 // authenticated, the enter passphrase dialog should not show up. However, we
115 // should still not be able to navigate to that page directly, so the managed
116 // user settings page should show up instead.
117 IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, UnlockedProfile2) {
118 // Set the custodian to authenticated.
119 ManagedUserService* managed_user_service =
120 ManagedUserServiceFactory::GetForProfile(browser()->profile());
121 managed_user_service->SetElevated(true);
122 GURL settings_url("chrome://settings/setPassphrase");
123 // We navigate 3 times when navigation to that URL: the first navigation
124 // sends an asynchronous authentication request, after that is answered, a
125 // call to navigateToPage("setPassphrase") leads to a load of the url
126 // chrome://settings which is followed by a navigation to
127 // chrome://settings/managedUser, which is now finally displayed because we
128 // are successfully authenticated.
129 ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
130 settings_url,
131 3);
132 WebContents* tab = chrome::GetActiveWebContents(browser());
133 // Check that the passphrase dialog is not shown.
134 EXPECT_FALSE(IsShowingWebContentsModalDialog(tab));
135 // Check that the managed user settings page is shown.
136 string16 expected_title =
137 l10n_util::GetStringUTF16(IDS_MANAGED_USER_SETTINGS_TITLE);
138 string16 title;
139 ui_test_utils::GetCurrentTabTitle(browser(), &title);
140 EXPECT_TRUE(EndsWith(title, expected_title, true));
141 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698