File: wake_task_unittest.mm

package info (click to toggle)
chromium 138.0.7204.183-1
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 6,071,908 kB
  • sloc: cpp: 34,937,088; ansic: 7,176,967; javascript: 4,110,704; python: 1,419,953; asm: 946,768; xml: 739,971; pascal: 187,324; sh: 89,623; perl: 88,663; objc: 79,944; sql: 50,304; cs: 41,786; fortran: 24,137; makefile: 21,806; php: 13,980; tcl: 13,166; yacc: 8,925; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (82 lines) | stat: -rw-r--r-- 3,150 bytes parent folder | download | duplicates (5)
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