OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "chrome/browser/chromeos/login/screen_locker_tester.h" | 5 #include "chrome/browser/chromeos/login/screen_locker_tester.h" |
6 | 6 |
7 #include <string> | 7 #include <string> |
8 | 8 |
9 #include "base/strings/string_util.h" | 9 #include "base/strings/string_util.h" |
10 #include "base/strings/stringprintf.h" | 10 #include "base/strings/stringprintf.h" |
(...skipping 10 matching lines...) Expand all Loading... |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "ui/views/controls/button/button.h" | 22 #include "ui/views/controls/button/button.h" |
23 #include "ui/views/controls/label.h" | 23 #include "ui/views/controls/label.h" |
24 #include "ui/views/controls/textfield/textfield.h" | 24 #include "ui/views/controls/textfield/textfield.h" |
25 #include "ui/views/widget/root_view.h" | 25 #include "ui/views/widget/root_view.h" |
26 | 26 |
27 using content::WebContents; | 27 using content::WebContents; |
28 | 28 |
29 namespace { | 29 namespace { |
30 | 30 |
| 31 // This class is used to observe state of the global ScreenLocker instance, |
| 32 // which can go away as a result of a successful authentication. As such, |
| 33 // it needs to directly reference the global ScreenLocker. |
31 class LoginAttemptObserver : public chromeos::LoginStatusConsumer { | 34 class LoginAttemptObserver : public chromeos::LoginStatusConsumer { |
32 public: | 35 public: |
33 explicit LoginAttemptObserver(chromeos::ScreenLocker* locker); | 36 LoginAttemptObserver(); |
34 virtual ~LoginAttemptObserver(); | 37 virtual ~LoginAttemptObserver(); |
35 | 38 |
36 void WaitForAttempt(); | 39 void WaitForAttempt(); |
37 | 40 |
38 // Overridden from LoginStatusConsumer: | 41 // Overridden from LoginStatusConsumer: |
39 virtual void OnLoginFailure(const chromeos::LoginFailure& error) OVERRIDE { | 42 virtual void OnLoginFailure(const chromeos::LoginFailure& error) OVERRIDE { |
40 LoginAttempted(); | 43 LoginAttempted(); |
41 } | 44 } |
42 | 45 |
43 virtual void OnLoginSuccess( | 46 virtual void OnLoginSuccess( |
44 const chromeos::UserContext& credentials, | 47 const chromeos::UserContext& credentials, |
45 bool pending_requests, | 48 bool pending_requests, |
46 bool using_oauth) OVERRIDE { | 49 bool using_oauth) OVERRIDE { |
47 LoginAttempted(); | 50 LoginAttempted(); |
48 } | 51 } |
49 | 52 |
50 private: | 53 private: |
51 void LoginAttempted(); | 54 void LoginAttempted(); |
52 | 55 |
53 chromeos::ScreenLocker* locker_; | |
54 bool login_attempted_; | 56 bool login_attempted_; |
55 bool waiting_; | 57 bool waiting_; |
56 | 58 |
57 DISALLOW_COPY_AND_ASSIGN(LoginAttemptObserver); | 59 DISALLOW_COPY_AND_ASSIGN(LoginAttemptObserver); |
58 }; | 60 }; |
59 | 61 |
60 LoginAttemptObserver::LoginAttemptObserver(chromeos::ScreenLocker* locker) | 62 LoginAttemptObserver::LoginAttemptObserver() |
61 : chromeos::LoginStatusConsumer(), | 63 : chromeos::LoginStatusConsumer(), |
62 locker_(locker), | |
63 login_attempted_(false), | 64 login_attempted_(false), |
64 waiting_(false) { | 65 waiting_(false) { |
65 locker_->SetLoginStatusConsumer(this); | 66 chromeos::ScreenLocker::default_screen_locker()->SetLoginStatusConsumer(this); |
66 } | 67 } |
67 | 68 |
68 LoginAttemptObserver::~LoginAttemptObserver() { | 69 LoginAttemptObserver::~LoginAttemptObserver() { |
69 locker_->SetLoginStatusConsumer(NULL); | 70 chromeos::ScreenLocker* global_locker = |
| 71 chromeos::ScreenLocker::default_screen_locker(); |
| 72 if (global_locker) |
| 73 global_locker->SetLoginStatusConsumer(NULL); |
70 } | 74 } |
71 | 75 |
72 void LoginAttemptObserver::WaitForAttempt() { | 76 void LoginAttemptObserver::WaitForAttempt() { |
73 if (!login_attempted_) { | 77 if (!login_attempted_) { |
74 waiting_ = true; | 78 waiting_ = true; |
75 content::RunMessageLoop(); | 79 content::RunMessageLoop(); |
76 waiting_ = false; | 80 waiting_ = false; |
77 } | 81 } |
78 ASSERT_TRUE(login_attempted_); | 82 ASSERT_TRUE(login_attempted_); |
79 } | 83 } |
80 | 84 |
81 void LoginAttemptObserver::LoginAttempted() { | 85 void LoginAttemptObserver::LoginAttempted() { |
82 login_attempted_ = true; | 86 login_attempted_ = true; |
83 if (waiting_) | 87 if (waiting_) |
84 base::MessageLoopForUI::current()->Quit(); | 88 base::MessageLoopForUI::current()->Quit(); |
85 } | 89 } |
86 | 90 |
87 } | 91 } // anyonymous namespace |
88 | 92 |
89 namespace chromeos { | 93 namespace chromeos { |
90 | 94 |
91 namespace test { | 95 namespace test { |
92 | 96 |
93 class WebUIScreenLockerTester : public ScreenLockerTester { | 97 class WebUIScreenLockerTester : public ScreenLockerTester { |
94 public: | 98 public: |
95 // ScreenLockerTester overrides: | 99 // ScreenLockerTester overrides: |
96 virtual void SetPassword(const std::string& password) OVERRIDE; | 100 virtual void SetPassword(const std::string& password) OVERRIDE; |
97 virtual std::string GetPassword() OVERRIDE; | 101 virtual std::string GetPassword() OVERRIDE; |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
141 ASSERT_EQ(password, GetPassword()); | 145 ASSERT_EQ(password, GetPassword()); |
142 | 146 |
143 // Verify that "signin" button is hidden. | 147 // Verify that "signin" button is hidden. |
144 scoped_ptr<base::Value> v = content::ExecuteScriptAndGetValue( | 148 scoped_ptr<base::Value> v = content::ExecuteScriptAndGetValue( |
145 RenderViewHost(), | 149 RenderViewHost(), |
146 "$('pod-row').pods[0].signinButtonElement.hidden;"); | 150 "$('pod-row').pods[0].signinButtonElement.hidden;"); |
147 ASSERT_TRUE(v->GetAsBoolean(&result)); | 151 ASSERT_TRUE(v->GetAsBoolean(&result)); |
148 ASSERT_TRUE(result); | 152 ASSERT_TRUE(result); |
149 | 153 |
150 // Attempt to sign in. | 154 // Attempt to sign in. |
151 LoginAttemptObserver login(ScreenLocker::screen_locker_); | 155 LoginAttemptObserver login; |
152 v = content::ExecuteScriptAndGetValue( | 156 v = content::ExecuteScriptAndGetValue( |
153 RenderViewHost(), | 157 RenderViewHost(), |
154 "$('pod-row').pods[0].activate();"); | 158 "$('pod-row').pods[0].activate();"); |
155 ASSERT_TRUE(v->GetAsBoolean(&result)); | 159 ASSERT_TRUE(v->GetAsBoolean(&result)); |
156 ASSERT_TRUE(result); | 160 ASSERT_TRUE(result); |
157 | 161 |
158 // Wait for login attempt. | 162 // Wait for login attempt. |
159 login.WaitForAttempt(); | 163 login.WaitForAttempt(); |
160 } | 164 } |
161 | 165 |
(...skipping 43 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
205 new MockAuthenticator(ScreenLocker::screen_locker_, user, password)); | 209 new MockAuthenticator(ScreenLocker::screen_locker_, user, password)); |
206 } | 210 } |
207 | 211 |
208 } // namespace test | 212 } // namespace test |
209 | 213 |
210 test::ScreenLockerTester* ScreenLocker::GetTester() { | 214 test::ScreenLockerTester* ScreenLocker::GetTester() { |
211 return new test::WebUIScreenLockerTester(); | 215 return new test::WebUIScreenLockerTester(); |
212 } | 216 } |
213 | 217 |
214 } // namespace chromeos | 218 } // namespace chromeos |
OLD | NEW |