1// Copyright 2014 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/ui/autofill/password_generation_popup_view.h" 6 7#include "base/strings/string16.h" 8#include "chrome/browser/ui/autofill/password_generation_popup_controller_impl.h" 9#include "chrome/browser/ui/autofill/password_generation_popup_view_tester.h" 10#include "chrome/browser/ui/browser.h" 11#include "chrome/browser/ui/browser_window.h" 12#include "chrome/browser/ui/tabs/tab_strip_model.h" 13#include "chrome/test/base/in_process_browser_test.h" 14#include "testing/gtest/include/gtest/gtest.h" 15#include "ui/events/event_utils.h" 16 17namespace autofill { 18 19class TestPasswordGenerationPopupController : 20 public PasswordGenerationPopupControllerImpl { 21 public: 22 TestPasswordGenerationPopupController(content::WebContents* web_contents, 23 gfx::NativeView native_view) 24 : PasswordGenerationPopupControllerImpl( 25 gfx::RectF(0, 0, 10, 10), 26 PasswordForm(), 27 10, 28 NULL /* PasswordManager*/, 29 NULL /* PasswordGenerationPopupObserver*/, 30 web_contents, 31 native_view) {} 32 33 virtual ~TestPasswordGenerationPopupController() {} 34 35 PasswordGenerationPopupView* view() { 36 return view_; 37 } 38}; 39 40class PasswordGenerationPopupViewTest : public InProcessBrowserTest { 41 public: 42 virtual void SetUpOnMainThread() OVERRIDE { 43 gfx::NativeView native_view = 44 browser()->tab_strip_model()->GetActiveWebContents()->GetNativeView(); 45 46 controller_ = 47 new TestPasswordGenerationPopupController( 48 browser()->tab_strip_model()->GetActiveWebContents(), native_view); 49 } 50 51 scoped_ptr<PasswordGenerationPopupViewTester> GetViewTester() { 52 return PasswordGenerationPopupViewTester::For(controller_->view()).Pass(); 53 } 54 55 protected: 56 TestPasswordGenerationPopupController* controller_; 57}; 58 59// TODO(gcasto): Enable on Mac when UI is updated. (crbug.com/394303) 60#if !defined(OS_MACOSX) 61// Regression test for crbug.com/400543. Verifying that moving the mouse in the 62// editing dialog doesn't crash. 63IN_PROC_BROWSER_TEST_F(PasswordGenerationPopupViewTest, 64 MouseMovementInEditingPopup) { 65 controller_->Show(false /* display_password */); 66 67 gfx::Point center_point = 68 static_cast<PasswordGenerationPopupController*>( 69 controller_)->popup_bounds().CenterPoint(); 70 GetViewTester()->SimulateMouseMovementAt(center_point); 71 72 // Deletes |controller_|. 73 controller_->HideAndDestroy(); 74} 75#endif 76 77} // namespace autofill 78