1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61
|
// Copyright 2018 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#include "chrome/browser/ash/arc/arc_migration_guide_notification.h"
#include "base/strings/utf_string_conversions.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/test/base/testing_profile.h"
#include "chromeos/dbus/power/fake_power_manager_client.h"
#include "components/sync_preferences/pref_service_syncable.h"
#include "content/public/test/browser_task_environment.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace arc {
using ArcMigrationGuideNotificationTest = ::testing::Test;
using ::testing::HasSubstr;
using ::testing::Not;
TEST_F(ArcMigrationGuideNotificationTest, BatteryPercent) {
content::BrowserTaskEnvironment task_environment;
TestingProfile profile;
// Set a high battery state.
chromeos::PowerManagerClient::InitializeFake();
auto* power_manager = chromeos::FakePowerManagerClient::Get();
power_manager::PowerSupplyProperties props = *power_manager->GetLastStatus();
props.set_battery_percent(99);
power_manager->UpdatePowerProperties(props);
// Show notification with sufficient battery.
NotificationDisplayServiceTester notification_service(&profile);
ShowArcMigrationGuideNotification(&profile);
auto notifications = notification_service.GetDisplayedNotificationsForType(
NotificationHandler::Type::TRANSIENT);
ASSERT_EQ(1U, notifications.size());
EXPECT_EQ("arc_fs_migration/suggest", notifications[0].id());
std::u16string message = notifications[0].message();
EXPECT_THAT(base::UTF16ToUTF8(notifications[0].message()),
Not(HasSubstr("charge")));
// Set a low battery state.
props.set_battery_percent(5);
power_manager->UpdatePowerProperties(props);
// Show notification with low battery.
ShowArcMigrationGuideNotification(&profile);
notifications = notification_service.GetDisplayedNotificationsForType(
NotificationHandler::Type::TRANSIENT);
ASSERT_EQ(1U, notifications.size());
EXPECT_EQ("arc_fs_migration/suggest", notifications[0].id());
EXPECT_NE(message, notifications[0].message());
EXPECT_THAT(base::UTF16ToUTF8(notifications[0].message()),
HasSubstr("charge"));
chromeos::PowerManagerClient::Shutdown();
}
} // namespace arc
|