blob: a35f7462e19599b3757a693bb9b14ecf1ec3d2c8 [file] [log] [blame]
// Copyright 2016 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ui/ash/system_tray_client.h"
#include "ash/public/cpp/ash_view_ids.h"
#include "ash/public/cpp/system_tray_test_api.h"
#include "chrome/browser/chromeos/login/login_manager_test.h"
#include "chrome/browser/chromeos/login/test/login_manager_mixin.h"
#include "chrome/browser/chromeos/login/ui/user_adding_screen.h"
#include "chrome/browser/chromeos/policy/device_policy_cros_browser_test.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/pref_names.h"
#include "chrome/common/webui_url_constants.h"
#include "chromeos/strings/grit/chromeos_strings.h"
#include "components/account_id/account_id.h"
#include "components/prefs/pref_service.h"
#include "components/user_manager/user_manager.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "ui/base/l10n/l10n_util.h"
#include "url/gurl.h"
using chromeos::ProfileHelper;
using user_manager::UserManager;
using SystemTrayClientEnterpriseTest = policy::DevicePolicyCrosBrowserTest;
IN_PROC_BROWSER_TEST_F(SystemTrayClientEnterpriseTest, TrayEnterprise) {
auto test_api = ash::SystemTrayTestApi::Create();
// Managed devices show an item in the menu.
EXPECT_TRUE(test_api->IsBubbleViewVisible(ash::VIEW_ID_TRAY_ENTERPRISE,
true /* open_tray */));
// The tooltip shows the domain.
EXPECT_EQ(l10n_util::GetStringFUTF16(IDS_ASH_ENTERPRISE_DEVICE_MANAGED_BY,
base::UTF8ToUTF16("example.com")),
test_api->GetBubbleViewTooltip(ash::VIEW_ID_TRAY_ENTERPRISE));
// Clicking the item opens the management page.
test_api->ClickBubbleView(ash::VIEW_ID_TRAY_ENTERPRISE);
EXPECT_EQ(
GURL(chrome::kChromeUIManagementURL),
browser()->tab_strip_model()->GetActiveWebContents()->GetVisibleURL());
}
class SystemTrayClientClockTest : public chromeos::LoginManagerTest {
public:
SystemTrayClientClockTest() : LoginManagerTest() {
// Use consumer emails to avoid having to fake a policy fetch.
login_mixin_.AppendRegularUsers(2);
account_id1_ = login_mixin_.users()[0].account_id;
account_id2_ = login_mixin_.users()[1].account_id;
}
~SystemTrayClientClockTest() override = default;
void SetupUserProfile(const AccountId& account_id, bool use_24_hour_clock) {
const user_manager::User* user = UserManager::Get()->FindUser(account_id);
Profile* profile = ProfileHelper::Get()->GetProfileByUser(user);
profile->GetPrefs()->SetBoolean(prefs::kUse24HourClock, use_24_hour_clock);
// Allow clock setting to be sent to ash over mojo.
content::RunAllPendingInMessageLoop();
}
protected:
AccountId account_id1_;
AccountId account_id2_;
chromeos::LoginManagerMixin login_mixin_{&mixin_host_};
private:
DISALLOW_COPY_AND_ASSIGN(SystemTrayClientClockTest);
};
// Test that clock type is taken from user profile for current active user.
IN_PROC_BROWSER_TEST_F(SystemTrayClientClockTest, TestMultiProfile24HourClock) {
auto tray_test_api = ash::SystemTrayTestApi::Create();
// Login a user with a 24-hour clock.
LoginUser(account_id1_);
SetupUserProfile(account_id1_, true /* use_24_hour_clock */);
EXPECT_TRUE(tray_test_api->Is24HourClock());
// Add a user with a 12-hour clock.
chromeos::UserAddingScreen::Get()->Start();
content::RunAllPendingInMessageLoop();
AddUser(account_id2_);
SetupUserProfile(account_id2_, false /* use_24_hour_clock */);
EXPECT_FALSE(tray_test_api->Is24HourClock());
// Switch back to the user with the 24-hour clock.
UserManager::Get()->SwitchActiveUser(account_id1_);
// Allow clock setting to be sent to ash over mojo.
content::RunAllPendingInMessageLoop();
EXPECT_TRUE(tray_test_api->Is24HourClock());
}