File: chrome_app_deprecation_browsertest.cc

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 (72 lines) | stat: -rw-r--r-- 2,525 bytes parent folder | download
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
// Copyright 2025 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/apps/app_service/publishers/chrome_app_deprecation.h"

#include "base/notreached.h"
#include "chrome/browser/apps/app_service/app_launch_params.h"
#include "chrome/browser/apps/app_service/app_service_proxy.h"
#include "chrome/browser/apps/app_service/app_service_proxy_factory.h"
#include "chrome/browser/apps/platform_apps/app_browsertest_util.h"
#include "chrome/browser/extensions/extension_browsertest.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/common/pref_names.h"
#include "components/prefs/pref_service.h"
#include "content/public/test/browser_test.h"
#include "extensions/test/test_extension_dir.h"
#include "ui/message_center/message_center.h"

namespace apps {

using extensions::Extension;

class ChromeAppDeprecationUserInstalledAppsBrowserTest
    : public extensions::PlatformAppBrowserTest {
 protected:
  const Extension* LoadPlatformApp() {
    const base::FilePath& root_path = test_data_dir_;
    base::FilePath extension_path =
        root_path.AppendASCII("platform_apps/launch");

    return LoadExtension(extension_path);
  }

  void RunPlatformApp(const Extension* extension) {
    AppLaunchParams params(
        extension->id(), LaunchContainer::kLaunchContainerNone,
        WindowOpenDisposition::NEW_WINDOW, LaunchSource::kFromTest);
    params.command_line = *base::CommandLine::ForCurrentProcess();

    AppServiceProxyFactory::GetForProfile(browser()->profile())
        ->LaunchAppWithParams(std::move(params));
  }
};

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationUserInstalledAppsBrowserTest,
                       NotAllowlisted) {
  auto* center = message_center::MessageCenter::Get();
  auto notifications_count = center->GetNotifications().size();

  const Extension* app = LoadPlatformApp();
  ASSERT_TRUE(app);

  RunPlatformApp(app);
  ASSERT_TRUE(center->GetNotifications().size() == notifications_count + 1);
}

IN_PROC_BROWSER_TEST_F(ChromeAppDeprecationUserInstalledAppsBrowserTest,
                       Allowlisted) {
  auto* center = message_center::MessageCenter::Get();
  auto notifications_count = center->GetNotifications().size();

  const Extension* app = LoadPlatformApp();
  ASSERT_TRUE(app);

  chrome_app_deprecation::AddAppToAllowlistForTesting(app->id());

  RunPlatformApp(app);
  ASSERT_TRUE(center->GetNotifications().size() == notifications_count);
}

}  // namespace apps