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

Unified 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: Adressed comments regarding the set passphrase dialog. 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 side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/webui/options/managed_user_passphrase_handler_browsertest.cc
diff --git a/chrome/browser/ui/webui/options/managed_user_passphrase_handler_browsertest.cc b/chrome/browser/ui/webui/options/managed_user_passphrase_handler_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..63ed43fada1116a3c9d9e9a55f9d64cce6054ee1
--- /dev/null
+++ b/chrome/browser/ui/webui/options/managed_user_passphrase_handler_browsertest.cc
@@ -0,0 +1,142 @@
+// Copyright (c) 2013 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 "base/command_line.h"
+#include "base/string_util.h"
+#include "chrome/browser/extensions/extension_browsertest.h"
+#include "chrome/browser/managed_mode/managed_user_service.h"
+#include "chrome/browser/managed_mode/managed_user_service_factory.h"
+#include "chrome/browser/prefs/pref_service.h"
+#include "chrome/browser/profiles/profile.h"
+#include "chrome/browser/ui/browser_navigator.h"
+#include "chrome/browser/ui/browser_tabstrip.h"
+#include "chrome/browser/ui/tabs/tab_strip_model.h"
+#include "chrome/browser/ui/web_contents_modal_dialog_manager.h"
+#include "chrome/common/chrome_switches.h"
+#include "chrome/common/pref_names.h"
+#include "chrome/test/base/in_process_browser_test.h"
+#include "chrome/test/base/ui_test_utils.h"
+#include "content/public/browser/web_contents.h"
+#include "content/public/test/test_utils.h"
+#include "googleurl/src/gurl.h"
+#include "grit/generated_resources.h"
+#include "ui/base/l10n/l10n_util.h"
+
+using content::WebContents;
+
+class ManagedUserPassphraseHandlerTest : public InProcessBrowserTest {
+ public:
+
+ ManagedUserPassphraseHandlerTest() {}
+
+ virtual void SetUpOnMainThread() OVERRIDE {
+ PrefService* prefs = browser()->profile()->GetPrefs();
+ // Set a fake passphrase.
+ prefs->SetString(prefs::kManagedModeLocalPassphrase, "fake");
+ }
+
+ protected:
+ virtual void SetUpCommandLine(CommandLine* command_line) {
+ command_line->AppendSwitch(switches::kManaged);
+ command_line->AppendSwitch(switches::kEnableManagedUsers);
+ }
+ bool IsShowingWebContentsModalDialog(WebContents* web_contents) const {
+ WebContentsModalDialogManager* web_contents_modal_dialog_manager =
+ WebContentsModalDialogManager::FromWebContents(web_contents);
+ return web_contents_modal_dialog_manager->IsShowingDialog();
+ }
+
+ private:
+ DISALLOW_COPY_AND_ASSIGN(ManagedUserPassphraseHandlerTest);
+};
+
+// Try to navigate to the managed user settings page. Since we are not
+// authenticated, the enter passphrase dialog should show up.
+IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, LockedProfile) {
+ GURL settings_url("chrome://settings/managedUser");
+ ui_test_utils::NavigateToURL(browser(), settings_url);
+ WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
+ // Check that the passphrase dialog is shown.
+ EXPECT_TRUE(IsShowingWebContentsModalDialog(tab));
+ // Now check that the settings page is displayed instead of the managed user
+ // settings page.
+ string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
+ string16 title;
+ ui_test_utils::GetCurrentTabTitle(browser(), &title);
+ EXPECT_EQ(title, expected_title);
+}
+
+// Try to navigate to the managed user settings page. Since we are
+// authenticated, the enter passphrase dialog should not show up.
+IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, UnlockedProfile) {
+ // Set the custodian to authenticated.
+ ManagedUserService* managed_user_service =
+ ManagedUserServiceFactory::GetForProfile(browser()->profile());
+ managed_user_service->SetElevated(true);
+ GURL settings_url("chrome://settings/managedUser");
+ // We navigate 3 times when navigation to that URL: the first navigation
+ // sends an asynchronous authentication request, after that is answered, a
+ // call to navigateToPage("managedUser") leads to a load of the url
+ // chrome://settings which is followed by a navigation to
+ // chrome://settings/managedUser, which is now finally displayed because we
+ // are successfully authenticated.
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
+ settings_url,
+ 3);
+ WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
+ // Check that the passphrase dialog is not shown.
+ EXPECT_FALSE(IsShowingWebContentsModalDialog(tab));
+ // Check that the managed user settings page is shown.
+ string16 expected_title =
+ l10n_util::GetStringUTF16(IDS_MANAGED_USER_SETTINGS_TITLE);
+ string16 title;
+ ui_test_utils::GetCurrentTabTitle(browser(), &title);
+ EXPECT_TRUE(EndsWith(title, expected_title, true));
+}
+
+// Try to navigate to the managed user set passphrase page. Since we are not
+// authenticated, the enter passphrase dialog should show up.
+IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, LockedProfile2) {
+ GURL settings_url("chrome://settings/setPassphrase");
+ ui_test_utils::NavigateToURL(browser(), settings_url);
+ WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
+ // Check that the passphrase dialog is shown.
+ EXPECT_TRUE(IsShowingWebContentsModalDialog(tab));
+ // Now check that the settings page is displayed instead of the managed user
+ // set passphrase page.
+ string16 expected_title = l10n_util::GetStringUTF16(IDS_SETTINGS_TITLE);
+ string16 title;
+ ui_test_utils::GetCurrentTabTitle(browser(), &title);
+ EXPECT_EQ(title, expected_title);
+}
+
+// Try to navigate to the managed user set passphrase page. Since we are
+// authenticated, the enter passphrase dialog should not show up. However, we
+// should still not be able to navigate to that page directly, so the managed
+// user settings page should show up instead.
+IN_PROC_BROWSER_TEST_F(ManagedUserPassphraseHandlerTest, UnlockedProfile2) {
+ // Set the custodian to authenticated.
+ ManagedUserService* managed_user_service =
+ ManagedUserServiceFactory::GetForProfile(browser()->profile());
+ managed_user_service->SetElevated(true);
+ GURL settings_url("chrome://settings/setPassphrase");
+ // We navigate 3 times when navigation to that URL: the first navigation
+ // sends an asynchronous authentication request, after that is answered, a
+ // call to navigateToPage("setPassphrase") leads to a load of the url
+ // chrome://settings which is followed by a navigation to
+ // chrome://settings/managedUser, which is now finally displayed because we
+ // are successfully authenticated.
+ ui_test_utils::NavigateToURLBlockUntilNavigationsComplete(browser(),
+ settings_url,
+ 3);
+ WebContents* tab = browser()->tab_strip_model()->GetActiveWebContents();
+ // Check that the passphrase dialog is not shown.
+ EXPECT_FALSE(IsShowingWebContentsModalDialog(tab));
+ // Check that the managed user settings page is shown.
+ string16 expected_title =
+ l10n_util::GetStringUTF16(IDS_MANAGED_USER_SETTINGS_TITLE);
+ string16 title;
+ ui_test_utils::GetCurrentTabTitle(browser(), &title);
+ EXPECT_TRUE(EndsWith(title, expected_title, true));
+}

Powered by Google App Engine
This is Rietveld 408576698