This source file includes following definitions.
- FocusUI
- CloseUI
- ui_closed_count_
- ui_shown_count
- ui_closed_count
- OnLoginUIShown
- OnLoginUIClosed
- TEST_F
#include "chrome/browser/ui/webui/signin/login_ui_service.h"
#include "base/compiler_specific.h"
#include "base/logging.h"
#include "testing/gtest/include/gtest/gtest.h"
class TestLoginUI : public LoginUIService::LoginUI {
public:
TestLoginUI() { }
virtual ~TestLoginUI() { }
virtual void FocusUI() OVERRIDE { }
virtual void CloseUI() OVERRIDE { }
private:
DISALLOW_COPY_AND_ASSIGN(TestLoginUI);
};
class TestObserver : public LoginUIService::Observer {
public:
TestObserver() : ui_shown_count_(0),
ui_closed_count_(0) {
}
int ui_shown_count() const { return ui_shown_count_; }
int ui_closed_count() const { return ui_closed_count_; }
private:
virtual void OnLoginUIShown(LoginUIService::LoginUI* ui) OVERRIDE {
++ui_shown_count_;
}
virtual void OnLoginUIClosed(LoginUIService::LoginUI* ui) OVERRIDE {
++ui_closed_count_;
}
int ui_shown_count_;
int ui_closed_count_;
DISALLOW_COPY_AND_ASSIGN(TestObserver);
};
class LoginUIServiceTest : public testing::Test {
public:
LoginUIServiceTest() : service_(NULL) { }
virtual ~LoginUIServiceTest() { }
protected:
LoginUIService service_;
TestObserver observer_;
DISALLOW_COPY_AND_ASSIGN(LoginUIServiceTest);
};
TEST_F(LoginUIServiceTest, LoginUIServiceObserver) {
service_.AddObserver(&observer_);
EXPECT_EQ(NULL, service_.current_login_ui());
TestLoginUI ui;
service_.SetLoginUI(&ui);
EXPECT_EQ(1, observer_.ui_shown_count());
TestLoginUI other_ui;
service_.LoginUIClosed(&other_ui);
EXPECT_EQ(1, observer_.ui_shown_count());
service_.LoginUIClosed(&ui);
EXPECT_EQ(1, observer_.ui_closed_count());
service_.RemoveObserver(&observer_);
}