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 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91
|
// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
//
// Helper functions to create and modify Usage Time Limit policies.
#ifndef CHROME_BROWSER_ASH_CHILD_ACCOUNTS_TIME_LIMIT_TEST_UTILS_H_
#define CHROME_BROWSER_ASH_CHILD_ACCOUNTS_TIME_LIMIT_TEST_UTILS_H_
#include <memory>
#include <string>
#include "base/time/time.h"
#include "base/values.h"
#include "chrome/browser/ash/child_accounts/time_limit_override.h"
namespace ash {
namespace time_limit_test_utils {
// Days of the week that should be used to create the Time Limit policy.
extern const char kMonday[];
extern const char kTuesday[];
extern const char kWednesday[];
extern const char kThursday[];
extern const char kFriday[];
extern const char kSaturday[];
extern const char kSunday[];
// Parses a string time to a base::Time object, see
// |base::Time::FromUTCString| for compatible input formats.
base::Time TimeFromString(const char* time_string);
// Creates a timestamp with the correct format that is used in the Time Limit
// policy. See |base::Time::FromUTCString| for compatible input formats.
std::string CreatePolicyTimestamp(const char* time_string);
std::string CreatePolicyTimestamp(base::Time time);
// Creates a TimeDelta representing an hour in a day. This representation is
// widely used on the Time Limit policy.
base::TimeDelta CreateTime(int hour, int minute);
// Creates a time object with the correct format that is used in the Time Limit
// policy.
base::Value::Dict CreatePolicyTime(base::TimeDelta time);
// Creates a time window limit dictionary used in the Time Limit policy.
base::Value::Dict CreateTimeWindow(const std::string& day,
base::TimeDelta start_time,
base::TimeDelta end_time,
base::Time last_updated);
// Creates a time usage limit dictionary used in the Time Limit policy.
base::Value::Dict CreateTimeUsage(base::TimeDelta usage_quota,
base::Time last_updated);
// Creates dictionary with a minimalist Time Limit policy, containing only the
// time usage limit reset time.
base::Value::Dict CreateTimeLimitPolicy(base::TimeDelta reset_time);
// Adds a time usage limit dictionary to the provided Time Limit policy.
void AddTimeUsageLimit(base::Value::Dict* policy,
std::string day,
base::TimeDelta quota,
base::Time last_updated);
// Adds a time window limit dictionary to the provided Time Limit policy.
void AddTimeWindowLimit(base::Value::Dict* policy,
const std::string& day,
base::TimeDelta start_time,
base::TimeDelta end_time,
base::Time last_updated);
// Adds a time limit override dictionary to the provided Time Limit policy.
void AddOverride(base::Value::Dict* policy,
usage_time_limit::TimeLimitOverride::Action action,
base::Time created_at);
// Adds a time limit override with duration dictionary to the provided
// Time Limit policy.
void AddOverrideWithDuration(base::Value::Dict* policy,
usage_time_limit::TimeLimitOverride::Action action,
base::Time created_at,
base::TimeDelta duration);
// Converts the Time Limit policy to a string.
std::string PolicyToString(const base::Value::Dict& policy);
} // namespace time_limit_test_utils
} // namespace ash
#endif // CHROME_BROWSER_ASH_CHILD_ACCOUNTS_TIME_LIMIT_TEST_UTILS_H_
|