| 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/ui/webui/signin/login_ui_service.h" | 5 #include "chrome/browser/ui/webui/signin/login_ui_service.h" |
| 6 | 6 |
| 7 #include "base/compiler_specific.h" | 7 #include "base/compiler_specific.h" |
| 8 #include "base/logging.h" | 8 #include "base/logging.h" |
| 9 #include "testing/gtest/include/gtest/gtest.h" | 9 #include "testing/gtest/include/gtest/gtest.h" |
| 10 | 10 |
| (...skipping 28 matching lines...) Expand all Loading... |
| 39 | 39 |
| 40 int ui_shown_count_; | 40 int ui_shown_count_; |
| 41 int ui_closed_count_; | 41 int ui_closed_count_; |
| 42 | 42 |
| 43 DISALLOW_COPY_AND_ASSIGN(TestObserver); | 43 DISALLOW_COPY_AND_ASSIGN(TestObserver); |
| 44 }; | 44 }; |
| 45 | 45 |
| 46 class LoginUIServiceTest : public testing::Test { | 46 class LoginUIServiceTest : public testing::Test { |
| 47 public: | 47 public: |
| 48 LoginUIServiceTest() : service_(NULL) { } | 48 LoginUIServiceTest() : service_(NULL) { } |
| 49 virtual ~LoginUIServiceTest() { } | 49 ~LoginUIServiceTest() override {} |
| 50 | 50 |
| 51 protected: | 51 protected: |
| 52 LoginUIService service_; | 52 LoginUIService service_; |
| 53 TestObserver observer_; | 53 TestObserver observer_; |
| 54 | 54 |
| 55 DISALLOW_COPY_AND_ASSIGN(LoginUIServiceTest); | 55 DISALLOW_COPY_AND_ASSIGN(LoginUIServiceTest); |
| 56 }; | 56 }; |
| 57 | 57 |
| 58 // Test that the observer is called back when login UI is shown | 58 // Test that the observer is called back when login UI is shown |
| 59 // or closed. | 59 // or closed. |
| 60 TEST_F(LoginUIServiceTest, LoginUIServiceObserver) { | 60 TEST_F(LoginUIServiceTest, LoginUIServiceObserver) { |
| 61 service_.AddObserver(&observer_); | 61 service_.AddObserver(&observer_); |
| 62 EXPECT_EQ(NULL, service_.current_login_ui()); | 62 EXPECT_EQ(NULL, service_.current_login_ui()); |
| 63 TestLoginUI ui; | 63 TestLoginUI ui; |
| 64 service_.SetLoginUI(&ui); | 64 service_.SetLoginUI(&ui); |
| 65 EXPECT_EQ(1, observer_.ui_shown_count()); | 65 EXPECT_EQ(1, observer_.ui_shown_count()); |
| 66 | 66 |
| 67 // If a different UI is closed than the one that was shown, no | 67 // If a different UI is closed than the one that was shown, no |
| 68 // notification should be fired. | 68 // notification should be fired. |
| 69 TestLoginUI other_ui; | 69 TestLoginUI other_ui; |
| 70 service_.LoginUIClosed(&other_ui); | 70 service_.LoginUIClosed(&other_ui); |
| 71 EXPECT_EQ(1, observer_.ui_shown_count()); | 71 EXPECT_EQ(1, observer_.ui_shown_count()); |
| 72 | 72 |
| 73 // If the right UI is closed, notification should be fired. | 73 // If the right UI is closed, notification should be fired. |
| 74 service_.LoginUIClosed(&ui); | 74 service_.LoginUIClosed(&ui); |
| 75 EXPECT_EQ(1, observer_.ui_closed_count()); | 75 EXPECT_EQ(1, observer_.ui_closed_count()); |
| 76 service_.RemoveObserver(&observer_); | 76 service_.RemoveObserver(&observer_); |
| 77 } | 77 } |
| OLD | NEW |