1 // Copyright (c) 2011 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/login/screen_locker_tester.h" 6 7 #include <gdk/gdkkeysyms.h> 8 9 #include "base/string_util.h" 10 #include "base/utf_string_conversions.h" 11 #include "chrome/browser/chromeos/login/mock_authenticator.h" 12 #include "chrome/browser/chromeos/login/screen_lock_view.h" 13 #include "chrome/browser/chromeos/login/screen_locker.h" 14 #include "views/controls/button/button.h" 15 #include "views/controls/label.h" 16 #include "views/controls/textfield/textfield.h" 17 #include "views/events/event.h" 18 #include "views/widget/root_view.h" 19 #include "views/widget/widget_gtk.h" 20 21 namespace chromeos { 22 23 test::ScreenLockerTester* ScreenLocker::GetTester() { 24 return new test::ScreenLockerTester(); 25 } 26 27 namespace test { 28 29 bool ScreenLockerTester::IsLocked() { 30 return ScreenLocker::screen_locker_ && 31 ScreenLocker::screen_locker_->locked_; 32 } 33 34 void ScreenLockerTester::InjectMockAuthenticator( 35 const std::string& user, const std::string& password) { 36 DCHECK(ScreenLocker::screen_locker_); 37 ScreenLocker::screen_locker_->SetAuthenticator( 38 new MockAuthenticator(ScreenLocker::screen_locker_, user, password)); 39 } 40 41 void ScreenLockerTester::SetPassword(const std::string& password) { 42 DCHECK(ScreenLocker::screen_locker_); 43 views::Textfield* pass = GetPasswordField(); 44 pass->SetText(ASCIIToUTF16(password.c_str())); 45 } 46 47 std::string ScreenLockerTester::GetPassword() const { 48 DCHECK(ScreenLocker::screen_locker_); 49 views::Textfield* pass = GetPasswordField(); 50 return UTF16ToUTF8(pass->text()); 51 } 52 53 void ScreenLockerTester::EnterPassword(const std::string& password) { 54 SetPassword(password); 55 views::Textfield* pass = GetPasswordField(); 56 GdkEvent* event = gdk_event_new(GDK_KEY_PRESS); 57 event->key.keyval = GDK_Return; 58 views::KeyEvent key_event(event); 59 ScreenLocker::screen_locker_->screen_lock_view_->HandleKeyEvent( 60 pass, key_event); 61 gdk_event_free(event); 62 } 63 64 void ScreenLockerTester::EmulateWindowManagerReady() { 65 DCHECK(ScreenLocker::screen_locker_); 66 ScreenLocker::screen_locker_->OnWindowManagerReady(); 67 } 68 69 views::Textfield* ScreenLockerTester::GetPasswordField() const { 70 DCHECK(ScreenLocker::screen_locker_); 71 return ScreenLocker::screen_locker_->screen_lock_view_->password_field_; 72 } 73 74 views::Widget* ScreenLockerTester::GetWidget() const { 75 DCHECK(ScreenLocker::screen_locker_); 76 return ScreenLocker::screen_locker_->lock_window_; 77 } 78 79 views::Widget* ScreenLockerTester::GetChildWidget() const { 80 DCHECK(ScreenLocker::screen_locker_); 81 return ScreenLocker::screen_locker_->lock_widget_; 82 } 83 84 } // namespace test 85 86 } // namespace chromeos 87