Update V8 to version 4.6.22.
[chromium-blink-merge.git] / chrome / browser / ui / ash / system_tray_delegate_chromeos_browsertest_chromeos.cc
blobebafe386d4c4e970f6d450223d847ea7a3e7e415
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::DisplayManager* display_manager =
68 ash::Shell::GetInstance()->display_manager();
69 ash::test::DisplayManagerTestApi display_manager_test_api(display_manager);
70 display_manager_test_api.UpdateDisplay(display_specs);
71 display_manager->RunPendingTasksForTest();
74 message_center::NotificationList::Notifications GetVisibleNotifications()
75 const {
76 return message_center::MessageCenter::Get()->GetVisibleNotifications();
80 class SystemTrayDelegateChromeOSTest : public LoginManagerTest {
81 protected:
82 SystemTrayDelegateChromeOSTest()
83 : LoginManagerTest(false /* should_launch_browser */) {}
85 ~SystemTrayDelegateChromeOSTest() override {}
87 void SetupUserProfile(std::string user_name, bool use_24_hour_clock) {
88 const user_manager::User* user =
89 user_manager::UserManager::Get()->FindUser(user_name);
90 Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
91 profile->GetPrefs()->SetBoolean(prefs::kUse24HourClock, use_24_hour_clock);
94 private:
95 DISALLOW_COPY_AND_ASSIGN(SystemTrayDelegateChromeOSTest);
98 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
99 PRE_TestMultiProfile24HourClock) {
100 RegisterUser(kUser1);
101 RegisterUser(kUser2);
102 StartupUtils::MarkOobeCompleted();
105 // Test that clock type is taken from user profile for current active user.
106 IN_PROC_BROWSER_TEST_F(SystemTrayDelegateChromeOSTest,
107 TestMultiProfile24HourClock) {
108 LoginUser(kUser1);
109 SetupUserProfile(kUser1, true /* Use_24_hour_clock. */);
110 CreateDefaultView();
111 EXPECT_EQ(base::k24HourClock, GetHourType());
112 UserAddingScreen::Get()->Start();
113 content::RunAllPendingInMessageLoop();
114 AddUser(kUser2);
115 SetupUserProfile(kUser2, false /* Use_24_hour_clock. */);
116 CreateDefaultView();
117 EXPECT_EQ(base::k12HourClock, GetHourType());
118 user_manager::UserManager::Get()->SwitchActiveUser(kUser1);
119 CreateDefaultView();
120 EXPECT_EQ(base::k24HourClock, GetHourType());
123 // Makes sure that no notifications are shown when rotating the
124 // display on display settings URLs.
125 IN_PROC_BROWSER_TEST_F(DisplayNotificationsTest,
126 TestDisplayOrientationChangeNotification) {
127 // Open the display settings page.
128 ui_test_utils::NavigateToURL(browser(),
129 GURL("chrome://settings-frame/display"));
130 // Rotate the display 90 degrees.
131 UpdateDisplay("400x400/r");
132 // Ensure that no notification was displayed.
133 EXPECT_TRUE(GetVisibleNotifications().empty());
135 // Reset the display.
136 UpdateDisplay("400x400");
138 ui_test_utils::NavigateToURL(browser(), GURL("chrome://settings/display"));
139 UpdateDisplay("400x400/r");
140 EXPECT_TRUE(GetVisibleNotifications().empty());
142 UpdateDisplay("400x400");
144 ui_test_utils::NavigateToURL(browser(),
145 GURL("chrome://settings/displayOverscan"));
146 UpdateDisplay("400x400/r");
147 EXPECT_TRUE(GetVisibleNotifications().empty());
149 UpdateDisplay("400x400");
151 ui_test_utils::NavigateToURL(browser(), GURL("chrome://version"));
152 UpdateDisplay("400x400/r");
153 // Ensure that there is a notification that is shown.
154 EXPECT_FALSE(GetVisibleNotifications().empty());
157 } // namespace chromeos