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