Check USB device path access when prompting users to select a device.
[chromium-blink-merge.git] / chrome / browser / notifications / login_state_notification_blocker_chromeos_browsertest.cc
blob23f09c34e1509d9bc72b8a3d4f63ab727fbea862
1 // Copyright 2013 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.
5 #include "ash/shell.h"
6 #include "ash/system/system_notifier.h"
7 #include "base/command_line.h"
8 #include "chrome/browser/chromeos/login/login_manager_test.h"
9 #include "chrome/browser/chromeos/login/startup_utils.h"
10 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
11 #include "chrome/browser/notifications/login_state_notification_blocker_chromeos.h"
12 #include "content/public/test/test_utils.h"
13 #include "ui/message_center/message_center.h"
15 using namespace testing;
17 namespace {
19 const char* kTestUsers[] = {"test-user@gmail.com",
20 "test-user1@gmail.com"};
22 } // anonymous namespace
24 class LoginStateNotificationBlockerChromeOSBrowserTest
25 : public chromeos::LoginManagerTest,
26 public message_center::NotificationBlocker::Observer {
27 public:
28 LoginStateNotificationBlockerChromeOSBrowserTest()
29 : chromeos::LoginManagerTest(false),
30 state_changed_count_(0) {}
31 ~LoginStateNotificationBlockerChromeOSBrowserTest() override {}
33 void SetUpOnMainThread() override {
34 chromeos::LoginState::Get()->set_always_logged_in(false);
35 chromeos::LoginManagerTest::SetUpOnMainThread();
38 void TearDownOnMainThread() override {
39 if (blocker_)
40 blocker_->RemoveObserver(this);
41 blocker_.reset();
42 chromeos::LoginManagerTest::TearDownOnMainThread();
45 protected:
46 void CreateBlocker() {
47 blocker_.reset(new LoginStateNotificationBlockerChromeOS(
48 message_center::MessageCenter::Get()));
49 blocker_->AddObserver(this);
52 // message_center::NotificationBlocker::Observer ovverrides:
53 void OnBlockingStateChanged(
54 message_center::NotificationBlocker* blocker) override {
55 state_changed_count_++;
58 int GetStateChangedCountAndReset() {
59 int result = state_changed_count_;
60 state_changed_count_ = 0;
61 return result;
64 bool ShouldShowNotificationAsPopup(
65 const message_center::NotifierId& notifier_id) {
66 return blocker_->ShouldShowNotificationAsPopup(notifier_id);
69 private:
70 int state_changed_count_;
71 scoped_ptr<message_center::NotificationBlocker> blocker_;
73 DISALLOW_COPY_AND_ASSIGN(LoginStateNotificationBlockerChromeOSBrowserTest);
76 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
77 PRE_BaseTest) {
78 RegisterUser(kTestUsers[0]);
79 RegisterUser(kTestUsers[1]);
80 chromeos::StartupUtils::MarkOobeCompleted();
83 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
84 BaseTest) {
85 CreateBlocker();
86 message_center::NotifierId notifier_id(
87 message_center::NotifierId::APPLICATION, "test-notifier");
89 // Logged in as a normal user.
90 LoginUser(kTestUsers[0]);
91 EXPECT_EQ(1, GetStateChangedCountAndReset());
92 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
94 // Multi-login user switch.
95 chromeos::UserAddingScreen::Get()->Start();
96 content::RunAllPendingInMessageLoop();
97 EXPECT_EQ(1, GetStateChangedCountAndReset());
98 EXPECT_FALSE(ShouldShowNotificationAsPopup(notifier_id));
100 // Multi-login user switch off.
101 chromeos::UserAddingScreen::Get()->Cancel();
102 content::RunAllPendingInMessageLoop();
103 EXPECT_EQ(1, GetStateChangedCountAndReset());
104 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
107 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
108 PRE_AlwaysAllowedNotifier) {
109 RegisterUser(kTestUsers[0]);
110 RegisterUser(kTestUsers[1]);
111 chromeos::StartupUtils::MarkOobeCompleted();
114 IN_PROC_BROWSER_TEST_F(LoginStateNotificationBlockerChromeOSBrowserTest,
115 AlwaysAllowedNotifier) {
116 CreateBlocker();
118 // NOTIFIER_DISPLAY is allowed to shown in the login screen.
119 message_center::NotifierId notifier_id(
120 message_center::NotifierId::SYSTEM_COMPONENT,
121 ash::system_notifier::kNotifierDisplay);
123 // Logged in as a normal user.
124 LoginUser(kTestUsers[0]);
125 EXPECT_EQ(1, GetStateChangedCountAndReset());
126 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
128 // Multi-login user switch.
129 chromeos::UserAddingScreen::Get()->Start();
130 content::RunAllPendingInMessageLoop();
131 EXPECT_EQ(1, GetStateChangedCountAndReset());
132 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));
134 // Multi-login user switch off.
135 chromeos::UserAddingScreen::Get()->Cancel();
136 content::RunAllPendingInMessageLoop();
137 EXPECT_EQ(1, GetStateChangedCountAndReset());
138 EXPECT_TRUE(ShouldShowNotificationAsPopup(notifier_id));