Switch global error menu icon to vectorized MD asset
[chromium-blink-merge.git] / chrome / browser / ui / ash / system_tray_delegate_chromeos_browsertest_chromeos.cc
blob0bb1fcd9c0bcb2074fe47a38a761789da57cea51
1 // Copyright 2014 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 "chrome/browser/ui/ash/system_tray_delegate_chromeos.h"
7 #include <string>
9 #include "ash/display/display_manager.h"
10 #include "ash/shell.h"
11 #include "ash/system/date/date_default_view.h"
12 #include "ash/system/date/date_view.h"
13 #include "ash/system/date/tray_date.h"
14 #include "ash/test/display_manager_test_api.h"
15 #include "base/prefs/pref_service.h"
16 #include "chrome/browser/chromeos/login/login_manager_test.h"
17 #include "chrome/browser/chromeos/login/session/user_session_manager.h"
18 #include "chrome/browser/chromeos/login/startup_utils.h"
19 #include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
20 #include "chrome/browser/chromeos/profiles/profile_helper.h"
21 #include "chrome/browser/ui/browser.h"
22 #include "chrome/browser/ui/chrome_pages.h"
23 #include "chrome/browser/ui/tabs/tab_strip_model.h"
24 #include "chrome/common/pref_names.h"
25 #include "chrome/common/url_constants.h"
26 #include "chrome/test/base/in_process_browser_test.h"
27 #include "chrome/test/base/ui_test_utils.h"
28 #include "components/user_manager/user_manager.h"
29 #include "content/public/test/test_utils.h"
30 #include "ui/message_center/message_center.h"
31 #include "ui/message_center/notification_list.h"
33 namespace chromeos {
35 namespace {
37 const char* kUser1 = "user1@test.com";
38 const char* kUser2 = "user2@test.com";
40 base::HourClockType GetHourType() {
41 const ash::TrayDate* tray_date = ash::Shell::GetInstance()
42 ->GetPrimarySystemTray()
43 ->GetTrayDateForTesting();
44 const ash::DateDefaultView* date_default_view =
45 tray_date->GetDefaultViewForTesting();
47 return date_default_view->GetDateView()->GetHourTypeForTesting();
50 void CreateDefaultView() {
51 ash::TrayDate* tray_date = ash::Shell::GetInstance()
52 ->GetPrimarySystemTray()
53 ->GetTrayDateForTesting();
54 tray_date->CreateDefaultViewForTesting(ash::user::LOGGED_IN_NONE);
57 } // namespace
59 class DisplayNotificationsTest : public InProcessBrowserTest {
60 public:
61 DisplayNotificationsTest() {}
62 ~DisplayNotificationsTest() override {}
64 void SetUp() override { InProcessBrowserTest::SetUp(); }
66 void UpdateDisplay(const std::string& display_specs) {
67 ash::test::DisplayManagerTestApi().UpdateDisplay(display_specs);
70 message_center::NotificationList::Notifications GetVisibleNotifications()
71 const {
72 return message_center::MessageCenter::Get()->GetVisibleNotifications();
76 class SystemTrayDelegateChromeOSTest : public LoginManagerTest {
77 protected:
78 SystemTrayDelegateChromeOSTest()
79 : LoginManagerTest(false /* should_launch_browser */) {}
81 ~SystemTrayDelegateChromeOSTest() override {}
83 void SetupUserProfile(std::string user_name, bool use_24_hour_clock) {
84 const user_manager::User* user =
85 user_manager::UserManager::Get()->FindUser(user_name);
86 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
87 profile->GetPrefs()->SetBoolean(prefs::kUse24HourClock, use_24_hour_clock);
90 private:
91 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest);
94 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
95 PRE_TestMultiProfile24HourClock) {
96 RegisterUser(kUser1);
97 RegisterUser(kUser2);
98 StartupUtils::MarkOobeCompleted();
101 // Test that clock type is taken from user profile for current active user.
102 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
103 TestMultiProfile24HourClock) {
104 LoginUser(kUser1);
105 SetupUserProfile(kUser1, true /* Use_24_hour_clock. */);
106 CreateDefaultView();
107 EXPECT_EQ(base::k24HourClock, GetHourType());
108 UserAddingScreen::Get()->Start();
109 content::RunAllPendingInMessageLoop();
110 AddUser(kUser2);
111 SetupUserProfile(kUser2, false /* Use_24_hour_clock. */);
112 CreateDefaultView();
113 EXPECT_EQ(base::k12HourClock, GetHourType());
114 user_manager::UserManager::Get()->SwitchActiveUser(kUser1);
115 CreateDefaultView();
116 EXPECT_EQ(base::k24HourClock, GetHourType());
119 // Makes sure that no notifications are shown when rotating the
120 // display on display settings URLs.
121 IN_PROC_BROWSER_TEST_F(DisplayNotificationsTest,
122 TestDisplayOrientationChangeNotification) {
123 // Open the display settings page.
124 ui_test_utils::NavigateToURL(browser(),
125 GURL("chrome://settings-frame/display"));
126 // Rotate the display 90 degrees.
127 UpdateDisplay("400x400/r");
128 // Ensure that no notification was displayed.
129 EXPECT_TRUE(GetVisibleNotifications().empty());
131 // Reset the display.
132 UpdateDisplay("400x400");
134 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings/display"));
135 UpdateDisplay("400x400/r");
136 EXPECT_TRUE(GetVisibleNotifications().empty());
138 UpdateDisplay("400x400");
140 ui_test_utils::NavigateToURL(browser(),
141 GURL("chrome://settings/displayOverscan"));
142 UpdateDisplay("400x400/r");
143 EXPECT_TRUE(GetVisibleNotifications().empty());
145 UpdateDisplay("400x400");
147 ui_test_utils::NavigateToURL(browser(), GURL("chrome://version"));
148 UpdateDisplay("400x400/r");
149 // Ensure that there is a notification that is shown.
150 EXPECT_FALSE(GetVisibleNotifications().empty());
153 } // namespace chromeos