| OLD | NEW |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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/ash/system_tray_client.h" | 5 #include "chrome/browser/ui/ash/system_tray_client.h" |
| 6 | 6 |
| 7 #include "ash/root_window_controller.h" | 7 #include "ash/root_window_controller.h" |
| 8 #include "ash/shell_port.h" | 8 #include "ash/shell_port.h" |
| 9 #include "ash/system/enterprise/tray_enterprise.h" |
| 10 #include "ash/system/tray/label_tray_view.h" |
| 9 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 10 #include "ash/system/update/tray_update.h" | 12 #include "ash/system/update/tray_update.h" |
| 13 #include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h" |
| 11 #include "chrome/browser/upgrade_detector.h" | 14 #include "chrome/browser/upgrade_detector.h" |
| 12 #include "chrome/test/base/in_process_browser_test.h" | 15 #include "chrome/test/base/in_process_browser_test.h" |
| 13 #include "content/public/test/test_utils.h" | 16 #include "content/public/test/test_utils.h" |
| 14 | 17 |
| 15 ash::TrayUpdate* GetTrayUpdate() { | 18 namespace { |
| 19 |
| 20 // TODO(jamescook): Add a test-only mojo API to get system tray details. |
| 21 ash::SystemTray* GetSystemTray() { |
| 16 return ash::ShellPort::Get() | 22 return ash::ShellPort::Get() |
| 17 ->GetPrimaryRootWindowController() | 23 ->GetPrimaryRootWindowController() |
| 18 ->GetSystemTray() | 24 ->GetSystemTray(); |
| 19 ->tray_update(); | |
| 20 } | 25 } |
| 21 | 26 |
| 27 } // namespace |
| 28 |
| 22 using SystemTrayClientTest = InProcessBrowserTest; | 29 using SystemTrayClientTest = InProcessBrowserTest; |
| 23 | 30 |
| 24 // Test that a chrome update shows the update icon in the system menu. | 31 // Test that a chrome update shows the update icon in the system menu. |
| 25 IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, UpdateTrayIcon) { | 32 IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, UpdateTrayIcon) { |
| 26 ash::TrayUpdate* tray_update = GetTrayUpdate(); | 33 ash::TrayUpdate* tray_update = GetSystemTray()->tray_update(); |
| 27 | 34 |
| 28 // When no update is pending, the icon isn't visible. | 35 // When no update is pending, the icon isn't visible. |
| 29 EXPECT_FALSE(tray_update->tray_view()->visible()); | 36 EXPECT_FALSE(tray_update->tray_view()->visible()); |
| 30 | 37 |
| 31 // Simulate an upgrade. This sends a mojo message to ash. | 38 // Simulate an upgrade. This sends a mojo message to ash. |
| 32 UpgradeDetector::GetInstance()->NotifyUpgradeRecommended(); | 39 UpgradeDetector::GetInstance()->NotifyUpgradeRecommended(); |
| 33 content::RunAllPendingInMessageLoop(); | 40 content::RunAllPendingInMessageLoop(); |
| 34 | 41 |
| 35 // Tray icon is now visible. | 42 // Tray icon is now visible. |
| 36 EXPECT_TRUE(tray_update->tray_view()->visible()); | 43 EXPECT_TRUE(tray_update->tray_view()->visible()); |
| 37 } | 44 } |
| 38 | 45 |
| 39 // Test that a flash update causes the update UI to show in the system menu. | 46 // Test that a flash update causes the update UI to show in the system menu. |
| 40 IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, FlashUpdateTrayIcon) { | 47 IN_PROC_BROWSER_TEST_F(SystemTrayClientTest, FlashUpdateTrayIcon) { |
| 41 ash::TrayUpdate* tray_update = GetTrayUpdate(); | 48 ash::TrayUpdate* tray_update = GetSystemTray()->tray_update(); |
| 42 | 49 |
| 43 // When no update is pending, the icon isn't visible. | 50 // When no update is pending, the icon isn't visible. |
| 44 EXPECT_FALSE(tray_update->tray_view()->visible()); | 51 EXPECT_FALSE(tray_update->tray_view()->visible()); |
| 45 | 52 |
| 46 // Simulate a Flash update. This sends a mojo message to ash. | 53 // Simulate a Flash update. This sends a mojo message to ash. |
| 47 SystemTrayClient::Get()->SetFlashUpdateAvailable(); | 54 SystemTrayClient::Get()->SetFlashUpdateAvailable(); |
| 48 content::RunAllPendingInMessageLoop(); | 55 content::RunAllPendingInMessageLoop(); |
| 49 | 56 |
| 50 // Tray icon is now visible. | 57 // Tray icon is now visible. |
| 51 EXPECT_TRUE(tray_update->tray_view()->visible()); | 58 EXPECT_TRUE(tray_update->tray_view()->visible()); |
| 52 } | 59 } |
| 60 |
| 61 using SystemTrayClientEnterpriseTest = policy::DevicePolicyCrosBrowserTest; |
| 62 |
| 63 IN_PROC_BROWSER_TEST_F(SystemTrayClientEnterpriseTest, TrayEnterprise) { |
| 64 // Mark the device as enterprise managed. |
| 65 policy::DevicePolicyCrosTestHelper::MarkAsEnterpriseOwnedBy("example.com"); |
| 66 content::RunAllPendingInMessageLoop(); |
| 67 |
| 68 // Open the system tray menu. |
| 69 ash::SystemTray* system_tray = GetSystemTray(); |
| 70 system_tray->ShowDefaultView(ash::BUBBLE_CREATE_NEW); |
| 71 |
| 72 // Managed devices show an item in the menu. |
| 73 ash::TrayEnterprise* tray_enterprise = |
| 74 system_tray->GetTrayEnterpriseForTesting(); |
| 75 ASSERT_TRUE(tray_enterprise->tray_view()); |
| 76 EXPECT_TRUE(tray_enterprise->tray_view()->visible()); |
| 77 |
| 78 system_tray->CloseSystemBubble(); |
| 79 } |
| OLD | NEW |