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