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
|
// Copyright 2023 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/updater/mac/setup/wake_task.h"
#include <Foundation/Foundation.h>
#include "base/apple/scoped_cftyperef.h"
#include "base/files/file_path.h"
#include "base/logging.h"
#include "base/strings/strcat.h"
#include "base/strings/sys_string_conversions.h"
#include "chrome/updater/constants.h"
#include "chrome/updater/test/test_scope.h"
#include "chrome/updater/updater_branding.h"
#include "chrome/updater/updater_scope.h"
#include "chrome/updater/util/util.h"
#include "testing/gtest/include/gtest/gtest.h"
namespace updater {
// This is a change detector test. If the wake plist changes, macOS may notify
// the user that the updater has registered new background tasks. Therefore, to
// minimize user annoyance, do not change the plist unintentionally.
TEST(WakeTask, NotModified) {
NSDictionary<NSString*, id>* expected;
switch (GetUpdaterScopeForTesting()) {
case UpdaterScope::kSystem:
expected = @{
@LAUNCH_JOBKEY_LABEL : base::SysUTF8ToNSString(
MAC_BUNDLE_IDENTIFIER_STRING ".wake.system"),
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : @[
base::SysUTF8ToNSString(base::StrCat(
{GetInstallDirectory(GetUpdaterScopeForTesting())->value(),
"/Current/" PRODUCT_FULLNAME_STRING, kExecutableSuffix,
".app/Contents/MacOS/" PRODUCT_FULLNAME_STRING,
kExecutableSuffix})),
@"--wake-all",
@"--enable-logging",
base::SysUTF8ToNSString(
base::StrCat({"--vmodule=", kLoggingModuleSwitchValue})),
@"--system",
],
@LAUNCH_JOBKEY_STARTINTERVAL : @3600,
@LAUNCH_JOBKEY_ABANDONPROCESSGROUP : @YES,
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @"System",
@LAUNCH_JOBKEY_ASSOCIATEDBUNDLEIDENTIFIERS : @[
base::SysUTF8ToNSString(MAC_BUNDLE_IDENTIFIER_STRING),
]
};
break;
case UpdaterScope::kUser:
expected = @{
@LAUNCH_JOBKEY_LABEL :
base::SysUTF8ToNSString(MAC_BUNDLE_IDENTIFIER_STRING ".wake"),
@LAUNCH_JOBKEY_PROGRAMARGUMENTS : @[
base::SysUTF8ToNSString(base::StrCat(
{GetInstallDirectory(GetUpdaterScopeForTesting())->value(),
"/Current/" PRODUCT_FULLNAME_STRING, kExecutableSuffix,
".app/Contents/MacOS/" PRODUCT_FULLNAME_STRING,
kExecutableSuffix})),
@"--wake-all",
@"--enable-logging",
base::SysUTF8ToNSString(
base::StrCat({"--vmodule=", kLoggingModuleSwitchValue})),
],
@LAUNCH_JOBKEY_STARTINTERVAL : @3600,
@LAUNCH_JOBKEY_ABANDONPROCESSGROUP : @YES,
@LAUNCH_JOBKEY_LIMITLOADTOSESSIONTYPE : @"Aqua",
@LAUNCH_JOBKEY_ASSOCIATEDBUNDLEIDENTIFIERS : @[
base::SysUTF8ToNSString(MAC_BUNDLE_IDENTIFIER_STRING),
]
};
break;
}
EXPECT_TRUE([expected
isEqualToDictionary:CreateWakeLaunchdPlist(GetUpdaterScopeForTesting())]);
}
} // namespace updater
|