| Index: chrome/browser/chromeos/ui/password_echo_controller_browsertest.cc
|
| diff --git a/chrome/browser/chromeos/ui/password_echo_controller_browsertest.cc b/chrome/browser/chromeos/ui/password_echo_controller_browsertest.cc
|
| new file mode 100644
|
| index 0000000000000000000000000000000000000000..2d7d40d30e65419809f922a1f1a29efd741a837e
|
| --- /dev/null
|
| +++ b/chrome/browser/chromeos/ui/password_echo_controller_browsertest.cc
|
| @@ -0,0 +1,143 @@
|
| +// Copyright 2016 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 "chrome/browser/chromeos/ui/password_echo_controller.h"
|
| +
|
| +#include <memory>
|
| +
|
| +#include "ash/common/ash_switches.h"
|
| +#include "ash/common/wm/maximize_mode/maximize_mode_controller.h"
|
| +#include "ash/common/wm_shell.h"
|
| +#include "base/command_line.h"
|
| +#include "base/macros.h"
|
| +#include "chrome/browser/ui/browser.h"
|
| +#include "chrome/browser/ui/tabs/tab_strip_model.h"
|
| +#include "chrome/test/base/in_process_browser_test.h"
|
| +#include "chrome/test/base/ui_test_utils.cc"
|
| +#include "content/public/browser/render_view_host.h"
|
| +#include "content/public/browser/web_contents.h"
|
| +#include "content/public/common/web_preferences.h"
|
| +#include "testing/gtest/include/gtest/gtest.h"
|
| +#include "ui/views/controls/textfield/textfield.h"
|
| +#include "ui/views/views_delegate.h"
|
| +
|
| +namespace chromeos {
|
| +
|
| +class PasswordEchoControllerTest : public InProcessBrowserTest {
|
| + public:
|
| + PasswordEchoControllerTest() {}
|
| + ~PasswordEchoControllerTest() override {}
|
| +
|
| + // InProcessBrowserTest
|
| + void SetUpCommandLine(base::CommandLine* command_line) override {
|
| + command_line->AppendSwitch(ash::switches::kAshEnableTouchViewTesting);
|
| + }
|
| +
|
| + content::WebPreferences GetWebPreferences() {
|
| + return browser()
|
| + ->tab_strip_model()
|
| + ->GetActiveWebContents()
|
| + ->GetRenderViewHost()
|
| + ->GetWebkitPreferences();
|
| + }
|
| +
|
| + ash::MaximizeModeController* GetMaximizeModeController() {
|
| + return ash::WmShell::Get()->maximize_mode_controller();
|
| + }
|
| +
|
| + private:
|
| + DISALLOW_COPY_AND_ASSIGN(PasswordEchoControllerTest);
|
| +};
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, ExistingWebContents) {
|
| + ash::MaximizeModeController* const controller = GetMaximizeModeController();
|
| +
|
| + // No TouchView mode at the beginning.
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_FALSE(GetWebPreferences().password_echo_enabled);
|
| +
|
| + // Enter TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(true);
|
| + ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_TRUE(GetWebPreferences().password_echo_enabled);
|
| +
|
| + // Leave TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(false);
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_FALSE(GetWebPreferences().password_echo_enabled);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, NewWebContents) {
|
| + ash::MaximizeModeController* const controller = GetMaximizeModeController();
|
| +
|
| + // No TouchView mode at the beginning.
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_FALSE(GetWebPreferences().password_echo_enabled);
|
| +
|
| + // Enter TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(true);
|
| + ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled());
|
| +
|
| + const GURL url("about:blank");
|
| + ui_test_utils::NavigateToURLWithDisposition(browser(), url,
|
| + NEW_FOREGROUND_TAB, 0);
|
| + EXPECT_TRUE(GetWebPreferences().password_echo_enabled);
|
| +
|
| + // Leave TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(false);
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| +
|
| + ui_test_utils::NavigateToURLWithDisposition(browser(), url,
|
| + NEW_FOREGROUND_TAB, 0);
|
| + EXPECT_FALSE(GetWebPreferences().password_echo_enabled);
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, ExistingTextfield) {
|
| + ash::MaximizeModeController* const controller = GetMaximizeModeController();
|
| + views::ViewsDelegate* const views_delegate =
|
| + views::ViewsDelegate::GetInstance();
|
| +
|
| + std::unique_ptr<views::Textfield> textfield(new views::Textfield);
|
| +
|
| + // No TouchView mode at the beginning.
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +
|
| + // Enter TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(true);
|
| + ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_FALSE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +
|
| + // Leave TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(false);
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +}
|
| +
|
| +IN_PROC_BROWSER_TEST_F(PasswordEchoControllerTest, NewTextfield) {
|
| + ash::MaximizeModeController* const controller = GetMaximizeModeController();
|
| + views::ViewsDelegate* const views_delegate =
|
| + views::ViewsDelegate::GetInstance();
|
| +
|
| + std::unique_ptr<views::Textfield> textfield;
|
| +
|
| + // No TouchView mode at the beginning.
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + textfield.reset(new views::Textfield);
|
| + EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +
|
| + // Enter TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(true);
|
| + ASSERT_TRUE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + textfield.reset(new views::Textfield);
|
| + EXPECT_FALSE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +
|
| + // Leave TouchView mode and password echo should be enabled.
|
| + controller->EnableMaximizeModeWindowManager(false);
|
| + ASSERT_FALSE(controller->IsMaximizeModeWindowManagerEnabled());
|
| + textfield.reset(new views::Textfield);
|
| + EXPECT_TRUE(views_delegate->GetTextfieldPasswordRevealDuration().is_zero());
|
| +}
|
| +
|
| +} // namespace chromeos
|
|
|