This source file includes following definitions.
- state_changed_count_
- SetUpCommandLine
- SetUpOnMainThread
- CleanUpOnMainThread
- CreateBlocker
- OnBlockingStateChanged
- GetStateChangedCountAndReset
- ShouldShowNotificationAsPopup
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
- IN_PROC_BROWSER_TEST_F
#include "ash/shell.h"
#include "ash/system/system_notifier.h"
#include "base/command_line.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/startup_utils.h"
#include "chrome/browser/chromeos/login/user_adding_screen.h"
#include "chrome/browser/notifications/login_state_notification_blocker_chromeos.h"
#include "chrome/common/chrome_switches.h"
#include "content/public/test/test_utils.h"
#include "ui/message_center/message_center.h"
using namespace testing;
namespace {
const char* kTestUsers[] = {"test-user@gmail.com",
"test-user1@gmail.com"};
}
class LoginStateNotificationBlockerChromeOSBrowserTest
: public chromeos::LoginManagerTest,
public message_center::NotificationBlocker::Observer {
public:
LoginStateNotificationBlockerChromeOSBrowserTest()
: chromeos::LoginManagerTest(false),
state_changed_count_(0) {}
virtual ~LoginStateNotificationBlockerChromeOSBrowserTest() {}
virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE {
LoginManagerTest::SetUpCommandLine(command_line);
command_line->AppendSwitch(::switches::kMultiProfiles);
}
virtual void SetUpOnMainThread() OVERRIDE {
chromeos::LoginState::Get()->set_always_logged_in(false);
}
virtual void CleanUpOnMainThread() OVERRIDE {
if (blocker_)
blocker_->RemoveObserver(this);
blocker_.reset();
chromeos::LoginManagerTest::CleanUpOnMainThread();
}
protected:
void CreateBlocker() {
blocker_.reset(new LoginStateNotificationBlockerChromeOS(
message_center::MessageCenter::Get()));
blocker_->AddObserver(this);
}
virtual void OnBlockingStateChanged(
message_center::NotificationBlocker* blocker) OVERRIDE {
state_changed_count_++;
}
int GetStateChangedCountAndReset() {
int result = state_changed_count_;
state_changed_count_ = 0;
return result;
}
bool ShouldShowNotificationAsPopup(
const message_center::NotifierId& notifier_id) {
return blocker_->ShouldShowNotificationAsPopup(notifier_id);
}
private:
int state_changed_count_;
scoped_ptr<message_center::NotificationBlocker> blocker_;
DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest);
};
IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
PRE_BaseTest) {
RegisterUser(kTestUsers[0]);
RegisterUser(kTestUsers[1]);
chromeos::StartupUtils::MarkOobeCompleted();
}
IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
BaseTest) {
CreateBlocker();
message_center::NotifierId notifier_id(
message_center::NotifierId::APPLICATION, "test-notifier");
EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1);
LoginUser(kTestUsers[0]);
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
chromeos::UserAddingScreen::Get()->Start();
content::RunAllPendingInMessageLoop();
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id));
chromeos::UserAddingScreen::Get()->Cancel();
content::RunAllPendingInMessageLoop();
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
}
IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
PRE_AlwaysAllowedNotifier) {
RegisterUser(kTestUsers[0]);
RegisterUser(kTestUsers[1]);
chromeos::StartupUtils::MarkOobeCompleted();
}
IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
AlwaysAllowedNotifier) {
CreateBlocker();
message_center::NotifierId notifier_id(
message_center::NotifierId::SYSTEM_COMPONENT,
ash::system_notifier::kNotifierDisplay);
EXPECT_CALL(login_utils(), DoBrowserLaunch(_, _)).Times(1);
LoginUser(kTestUsers[0]);
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
chromeos::UserAddingScreen::Get()->Start();
content::RunAllPendingInMessageLoop();
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
chromeos::UserAddingScreen::Get()->Cancel();
content::RunAllPendingInMessageLoop();
EXPECT_EQ(1, GetStateChangedCountAndReset());
EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
}