OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 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 "chrome/browser/chromeos/ui/password_echo_controller.h" |
| 6 |
| 7 #include <memory> |
| 8 |
| 9 #include "ash/common/ash_switches.h" |
| 10 #include "ash/common/wm/maximize_mode/maximize_mode_controller.h" |
| 11 #include "ash/common/wm_shell.h" |
| 12 #include "base/command_line.h" |
| 13 #include "base/macros.h" |
| 14 #include "chrome/browser/ui/ash/ash_util.h" |
| 15 #include "chrome/browser/ui/browser.h" |
| 16 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
| 17 #include "chrome/test/base/in_process_browser_test.h" |
| 18 #include "chrome/test/base/ui_test_utils.cc" |
| 19 #include "content/public/browser/render_view_host.h" |
| 20 #include "content/public/browser/web_contents.h" |
| 21 #include "content/public/common/web_preferences.h" |
| 22 #include "testing/gtest/include/gtest/gtest.h" |
| 23 #include "ui/views/controls/textfield/textfield.h" |
| 24 #include "ui/views/views_delegate.h" |
| 25 |
| 26 namespace chromeos { |
| 27 |
| 28 class PasswordEchoControllerTest : public InProcessBrowserTest { |
| 29 public: |
| 30 PasswordEchoControllerTest() {} |
| 31 ~PasswordEchoControllerTest() override {} |
| 32 |
| 33 // InProcessBrowserTest |
| 34 void SetUpCommandLine(base::CommandLine* command_line) override { |
| 35 command_line->AppendSwitch(ash::switches::kAshEnableTouchViewTesting); |
| 36 } |
| 37 |
| 38 content::WebPreferences GetWebPreferences() { |
| 39 return browser() |
| 40 ->tab_strip_model() |
| 41 ->GetActiveWebContents() |
| 42 ->GetRenderViewHost() |
| 43 ->GetWebkitPreferences(); |
| 44 } |
| 45 |
| 46 ash::MaximizeModeController* GetMaximizeModeController() { |
| 47 return ash::WmShell::Get()->maximize_mode_controller(); |
| 48 } |
| 49 |
| 50 private: |
| 51 DISALLOW_COPY_AND_ASSIGN(PasswordEchoControllerTest); |
| 52 }; |
| 53 |
| 54 IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, ExistingWebContents) { |
| 55 if (chrome::IsRunningInMash()) |
| 56 return; |
| 57 |
| 58 ash::MaximizeModeController* const controller = GetMaximizeModeController(); |
| 59 |
| 60 // No TouchView mode at the beginning. |
| 61 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 62 EXPECT_FALSE(GetWebPreferences().password_echo_enabled); |
| 63 |
| 64 // Enter TouchView mode and password echo should be enabled. |
| 65 controller->EnableMaximizeModeWindowManager(true); |
| 66 ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 67 EXPECT_TRUE(GetWebPreferences().password_echo_enabled); |
| 68 |
| 69 // Leave TouchView mode and password echo should be enabled. |
| 70 controller->EnableMaximizeModeWindowManager(false); |
| 71 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 72 EXPECT_FALSE(GetWebPreferences().password_echo_enabled); |
| 73 } |
| 74 |
| 75 IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, NewWebContents) { |
| 76 if (chrome::IsRunningInMash()) |
| 77 return; |
| 78 |
| 79 ash::MaximizeModeController* const controller = GetMaximizeModeController(); |
| 80 |
| 81 // No TouchView mode at the beginning. |
| 82 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 83 EXPECT_FALSE(GetWebPreferences().password_echo_enabled); |
| 84 |
| 85 // Enter TouchView mode and password echo should be enabled. |
| 86 controller->EnableMaximizeModeWindowManager(true); |
| 87 ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 88 |
| 89 const GURL url("about:blank"); |
| 90 ui_test_utils::NavigateToURLWithDisposition(browser(), url, |
| 91 NEW_FOREGROUND_TAB, 0); |
| 92 EXPECT_TRUE(GetWebPreferences().password_echo_enabled); |
| 93 |
| 94 // Leave TouchView mode and password echo should be enabled. |
| 95 controller->EnableMaximizeModeWindowManager(false); |
| 96 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 97 |
| 98 ui_test_utils::NavigateToURLWithDisposition(browser(), url, |
| 99 NEW_FOREGROUND_TAB, 0); |
| 100 EXPECT_FALSE(GetWebPreferences().password_echo_enabled); |
| 101 } |
| 102 |
| 103 IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, ExistingTextfield) { |
| 104 if (chrome::IsRunningInMash()) |
| 105 return; |
| 106 |
| 107 ash::MaximizeModeController* const controller = GetMaximizeModeController(); |
| 108 views::ViewsDelegate* const views_delegate = |
| 109 views::ViewsDelegate::GetInstance(); |
| 110 |
| 111 std::unique_ptr<views::Textfield> textfield(new views::Textfield); |
| 112 |
| 113 // No TouchView mode at the beginning. |
| 114 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 115 EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 116 |
| 117 // Enter TouchView mode and password echo should be enabled. |
| 118 controller->EnableMaximizeModeWindowManager(true); |
| 119 ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 120 EXPECT_FALSE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 121 |
| 122 // Leave TouchView mode and password echo should be enabled. |
| 123 controller->EnableMaximizeModeWindowManager(false); |
| 124 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 125 EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 126 } |
| 127 |
| 128 IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, NewTextfield) { |
| 129 if (chrome::IsRunningInMash()) |
| 130 return; |
| 131 |
| 132 ash::MaximizeModeController* const controller = GetMaximizeModeController(); |
| 133 views::ViewsDelegate* const views_delegate = |
| 134 views::ViewsDelegate::GetInstance(); |
| 135 |
| 136 std::unique_ptr<views::Textfield> textfield; |
| 137 |
| 138 // No TouchView mode at the beginning. |
| 139 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 140 textfield.reset(new views::Textfield); |
| 141 EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 142 |
| 143 // Enter TouchView mode and password echo should be enabled. |
| 144 controller->EnableMaximizeModeWindowManager(true); |
| 145 ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 146 textfield.reset(new views::Textfield); |
| 147 EXPECT_FALSE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 148 |
| 149 // Leave TouchView mode and password echo should be enabled. |
| 150 controller->EnableMaximizeModeWindowManager(false); |
| 151 ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled()); |
| 152 textfield.reset(new views::Textfield); |
| 153 EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero()); |
| 154 } |
| 155 |
| 156 } // namespace chromeos |
OLD | NEW |