| OLD | NEW |
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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 <memory> | 5 #include <memory> |
| 6 #include <string> | 6 #include <string> |
| 7 | 7 |
| 8 #include "ash/common/login_status.h" | 8 #include "ash/common/login_status.h" |
| 9 #include "ash/common/material_design/material_design_controller.h" | 9 #include "ash/common/material_design/material_design_controller.h" |
| 10 #include "ash/common/strings/grit/ash_strings.h" | 10 #include "ash/common/strings/grit/ash_strings.h" |
| (...skipping 128 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 139 bool result_; | 139 bool result_; |
| 140 std::unique_ptr<base::RunLoop> run_loop_; | 140 std::unique_ptr<base::RunLoop> run_loop_; |
| 141 }; | 141 }; |
| 142 | 142 |
| 143 class ShutdownPolicyInSessionTest | 143 class ShutdownPolicyInSessionTest |
| 144 : public ShutdownPolicyBaseTest { | 144 : public ShutdownPolicyBaseTest { |
| 145 protected: | 145 protected: |
| 146 ShutdownPolicyInSessionTest() {} | 146 ShutdownPolicyInSessionTest() {} |
| 147 ~ShutdownPolicyInSessionTest() override {} | 147 ~ShutdownPolicyInSessionTest() override {} |
| 148 | 148 |
| 149 void SetUpOnMainThread() override { | 149 // Opens the system tray menu. This creates the tray views. |
| 150 ShutdownPolicyBaseTest::SetUpOnMainThread(); | 150 void OpenSystemTrayMenu() { |
| 151 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { | 151 ash::Shell::GetInstance()->GetPrimarySystemTray()->ShowDefaultView( |
| 152 ash::TrayTiles* tray_tiles = ash::Shell::GetInstance() | 152 ash::BUBBLE_CREATE_NEW); |
| 153 ->GetPrimarySystemTray() | |
| 154 ->GetTrayTilesForTesting(); | |
| 155 ASSERT_TRUE(tray_tiles); | |
| 156 tiles_default_view_.reset(static_cast<ash::TilesDefaultView*>( | |
| 157 tray_tiles->CreateDefaultViewForTesting(ash::LoginStatus::USER))); | |
| 158 ASSERT_TRUE(tiles_default_view_); | |
| 159 } else { | |
| 160 ash::TrayDate* tray_date = ash::Shell::GetInstance() | |
| 161 ->GetPrimarySystemTray() | |
| 162 ->GetTrayDateForTesting(); | |
| 163 ASSERT_TRUE(tray_date); | |
| 164 date_default_view_.reset(static_cast<ash::DateDefaultView*>( | |
| 165 tray_date->CreateDefaultViewForTesting(ash::LoginStatus::USER))); | |
| 166 ASSERT_TRUE(date_default_view_); | |
| 167 } | |
| 168 } | 153 } |
| 169 | 154 |
| 170 void TearDownOnMainThread() override { | 155 // Closes the system tray menu. This deletes the tray views. |
| 171 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) | 156 void CloseSystemTrayMenu() { |
| 172 tiles_default_view_.reset(); | 157 ash::Shell::GetInstance()->GetPrimarySystemTray()->CloseSystemBubble(); |
| 173 else | |
| 174 date_default_view_.reset(); | |
| 175 ShutdownPolicyBaseTest::TearDownOnMainThread(); | |
| 176 } | 158 } |
| 177 | 159 |
| 178 // Get the shutdown and reboot button view from the date default view. | 160 // Gets the shutdown button view. |
| 179 const views::CustomButton* GetShutdownButton() { | 161 const views::View* GetShutdownButton() { |
| 180 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) | 162 ash::SystemTray* tray = ash::Shell::GetInstance()->GetPrimarySystemTray(); |
| 181 return tiles_default_view_->GetShutdownButtonViewForTest(); | 163 if (ash::MaterialDesignController::IsSystemTrayMenuMaterial()) { |
| 182 return static_cast<const views::CustomButton*>( | 164 return tray->GetTrayTilesForTesting() |
| 183 date_default_view_->GetShutdownButtonViewForTest()); | 165 ->GetDefaultViewForTesting() |
| 166 ->GetShutdownButtonViewForTest(); |
| 167 } |
| 168 return tray->GetTrayDateForTesting() |
| 169 ->GetDefaultViewForTesting() |
| 170 ->GetShutdownButtonViewForTest(); |
| 184 } | 171 } |
| 185 | 172 |
| 186 bool HasButtonTooltipText(const views::CustomButton* button, | 173 // Returns true if the shutdown button's tooltip matches the text of the |
| 187 int message_id) const { | 174 // resource |message_id|. |
| 175 bool HasShutdownButtonTooltip(int message_id) { |
| 176 const views::View* button = GetShutdownButton(); |
| 188 base::string16 actual_tooltip; | 177 base::string16 actual_tooltip; |
| 189 button->GetTooltipText(gfx::Point(), &actual_tooltip); | 178 button->GetTooltipText(gfx::Point(), &actual_tooltip); |
| 190 return l10n_util::GetStringUTF16(message_id) == actual_tooltip; | 179 return l10n_util::GetStringUTF16(message_id) == actual_tooltip; |
| 191 } | 180 } |
| 192 | 181 |
| 193 private: | 182 private: |
| 194 // Not used in material design. | |
| 195 std::unique_ptr<ash::DateDefaultView> date_default_view_; | |
| 196 | |
| 197 // Only used in material design. | |
| 198 std::unique_ptr<ash::TilesDefaultView> tiles_default_view_; | |
| 199 | |
| 200 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyInSessionTest); | 183 DISALLOW_COPY_AND_ASSIGN(ShutdownPolicyInSessionTest); |
| 201 }; | 184 }; |
| 202 | 185 |
| 186 // Tests that by default the shutdown button tooltip is "shutdown". |
| 203 IN_PROC_BROWSER_TEST_F(ShutdownPolicyInSessionTest, TestBasic) { | 187 IN_PROC_BROWSER_TEST_F(ShutdownPolicyInSessionTest, TestBasic) { |
| 204 const views::CustomButton* shutdown_button = GetShutdownButton(); | 188 OpenSystemTrayMenu(); |
| 205 EXPECT_TRUE( | 189 EXPECT_TRUE(HasShutdownButtonTooltip(IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
| 206 HasButtonTooltipText(shutdown_button, IDS_ASH_STATUS_TRAY_SHUTDOWN)); | 190 CloseSystemTrayMenu(); |
| 207 } | 191 } |
| 208 | 192 |
| 193 // Tests that enabling the reboot-on-shutdown policy changes the shutdown button |
| 194 // tooltip to "restart". Note that the tooltip doesn't change dynamically if the |
| 195 // menu is open during the policy change -- that's a rare condition and |
| 196 // supporting it would add complexity. |
| 209 IN_PROC_BROWSER_TEST_F(ShutdownPolicyInSessionTest, PolicyChange) { | 197 IN_PROC_BROWSER_TEST_F(ShutdownPolicyInSessionTest, PolicyChange) { |
| 210 const views::CustomButton* shutdown_button = GetShutdownButton(); | 198 // Change the policy to reboot and let it propagate over mojo to ash. |
| 211 | |
| 212 UpdateRebootOnShutdownPolicy(true); | 199 UpdateRebootOnShutdownPolicy(true); |
| 213 SyncRefreshDevicePolicy(); | 200 SyncRefreshDevicePolicy(); |
| 214 EXPECT_TRUE( | 201 content::RunAllPendingInMessageLoop(); |
| 215 HasButtonTooltipText(shutdown_button, IDS_ASH_STATUS_TRAY_REBOOT)); | |
| 216 | 202 |
| 203 // When the menu is opened the tooltip reads "reboot". |
| 204 OpenSystemTrayMenu(); |
| 205 EXPECT_TRUE(HasShutdownButtonTooltip(IDS_ASH_STATUS_TRAY_REBOOT)); |
| 206 CloseSystemTrayMenu(); |
| 207 |
| 208 // Change the policy to shutdown and let it propagate over mojo to ash. |
| 217 UpdateRebootOnShutdownPolicy(false); | 209 UpdateRebootOnShutdownPolicy(false); |
| 218 SyncRefreshDevicePolicy(); | 210 SyncRefreshDevicePolicy(); |
| 219 EXPECT_TRUE( | 211 content::RunAllPendingInMessageLoop(); |
| 220 HasButtonTooltipText(shutdown_button, IDS_ASH_STATUS_TRAY_SHUTDOWN)); | 212 |
| 213 // When the menu is opened the tooltip reads "shutdown". |
| 214 OpenSystemTrayMenu(); |
| 215 EXPECT_TRUE(HasShutdownButtonTooltip(IDS_ASH_STATUS_TRAY_SHUTDOWN)); |
| 216 CloseSystemTrayMenu(); |
| 221 } | 217 } |
| 222 | 218 |
| 223 class ShutdownPolicyLockerTest : public ShutdownPolicyBaseTest { | 219 class ShutdownPolicyLockerTest : public ShutdownPolicyBaseTest { |
| 224 protected: | 220 protected: |
| 225 ShutdownPolicyLockerTest() : fake_session_manager_client_(nullptr) {} | 221 ShutdownPolicyLockerTest() : fake_session_manager_client_(nullptr) {} |
| 226 ~ShutdownPolicyLockerTest() override {} | 222 ~ShutdownPolicyLockerTest() override {} |
| 227 | 223 |
| 228 void SetUpInProcessBrowserTestFixture() override { | 224 void SetUpInProcessBrowserTestFixture() override { |
| 229 fake_session_manager_client_ = new FakeSessionManagerClient; | 225 fake_session_manager_client_ = new FakeSessionManagerClient; |
| 230 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( | 226 DBusThreadManager::GetSetterForTesting()->SetSessionManagerClient( |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 345 PrepareAndRunScript("restart-header-bar-item", false); | 341 PrepareAndRunScript("restart-header-bar-item", false); |
| 346 PrepareAndRunScript("shutdown-header-bar-item", true); | 342 PrepareAndRunScript("shutdown-header-bar-item", true); |
| 347 | 343 |
| 348 UpdateRebootOnShutdownPolicy(false); | 344 UpdateRebootOnShutdownPolicy(false); |
| 349 RefreshDevicePolicy(); | 345 RefreshDevicePolicy(); |
| 350 PrepareAndRunScript("restart-header-bar-item", true); | 346 PrepareAndRunScript("restart-header-bar-item", true); |
| 351 PrepareAndRunScript("shutdown-header-bar-item", false); | 347 PrepareAndRunScript("shutdown-header-bar-item", false); |
| 352 } | 348 } |
| 353 | 349 |
| 354 } // namespace chromeos | 350 } // namespace chromeos |
| OLD | NEW |