File: preinstalled_web_apps_browsertest.cc

package info (click to toggle)
chromium 139.0.7258.127-1
  • links: PTS, VCS
  • area: main
  • in suites:
  • size: 6,122,068 kB
  • sloc: cpp: 35,100,771; ansic: 7,163,530; javascript: 4,103,002; python: 1,436,920; asm: 946,517; xml: 746,709; pascal: 187,653; perl: 88,691; sh: 88,436; objc: 79,953; sql: 51,488; cs: 44,583; fortran: 24,137; makefile: 22,147; tcl: 15,277; php: 13,980; yacc: 8,984; ruby: 7,485; awk: 3,720; lisp: 3,096; lex: 1,327; ada: 727; jsp: 228; sed: 36
file content (173 lines) | stat: -rw-r--r-- 6,571 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
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
// Copyright 2020 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/web_applications/preinstalled_web_apps/preinstalled_web_apps.h"

#include "ash/constants/web_app_id_constants.h"
#include "base/files/file_path.h"
#include "base/test/bind.h"
#include "build/branding_buildflags.h"
#include "build/build_config.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/web_applications/preinstalled_app_install_features.h"
#include "chrome/browser/web_applications/preinstalled_web_app_config_utils.h"
#include "chrome/browser/web_applications/preinstalled_web_app_manager.h"
#include "chrome/browser/web_applications/test/fake_os_integration_manager.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/common/chrome_switches.h"
#include "chrome/test/base/in_process_browser_test.h"
#include "content/public/test/browser_test.h"

#if BUILDFLAG(IS_CHROMEOS)
#include "chrome/browser/profiles/profile_manager.h"
#include "chrome/browser/ui/browser_commands.h"
#endif  // BUILDFLAG(IS_CHROMEOS)

namespace web_app {

class PreinstalledWebAppsBrowserTest : public WebAppBrowserTestBase {
 public:
  PreinstalledWebAppsBrowserTest()
      :  // Ignore any default app configs on disk.
        config_dir_auto_reset_(
            test::SetPreinstalledWebAppConfigDirForTesting(base::FilePath())),
        skip_preinstalled_web_app_startup_(
            PreinstalledWebAppManager::SkipStartupForTesting()) {}

  ~PreinstalledWebAppsBrowserTest() override = default;

  void SetUpDefaultCommandLine(base::CommandLine* command_line) override {
    WebAppBrowserTestBase::SetUpDefaultCommandLine(command_line);

    // This was added by PrepareBrowserCommandLineForTests(), re-enable default
    // apps as we wish to test that they get installed.
    command_line->RemoveSwitch(switches::kDisableDefaultApps);
  }

  test::ConfigDirAutoReset config_dir_auto_reset_;
  base::AutoReset<bool> skip_preinstalled_web_app_startup_;
};

#if BUILDFLAG(GOOGLE_CHROME_BRANDING) && BUILDFLAG(IS_CHROMEOS)
// TODO(http://crbug.com/328691719): Test is flaky on CHROMEOS.
#define MAYBE_CheckInstalledFields DISABLED_CheckInstalledFields
#else
#define MAYBE_CheckInstalledFields CheckInstalledFields
#endif
IN_PROC_BROWSER_TEST_F(PreinstalledWebAppsBrowserTest,
                       MAYBE_CheckInstalledFields) {
  base::AutoReset<bool> scope =
      SetPreinstalledAppInstallFeatureAlwaysEnabledForTesting();

  auto& provider = *WebAppProvider::GetForTest(browser()->profile());
  struct OfflineOnlyExpectation {
    const char* app_id;
    const char* install_url;
    const char* launch_url;
  } kOfflineOnlyExpectations[] = {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#if BUILDFLAG(IS_CHROMEOS)
      {
          ash::kGoogleCalendarAppId,
          "https://calendar.google.com/calendar/"
          "installwebapp?usp=chrome_default",
          "https://calendar.google.com/calendar/r?usp=installed_webapp",
      },
#endif  // BUILDFLAG(IS_CHROMEOS)
      {
          ash::kGoogleDocsAppId,
          "https://docs.google.com/document/installwebapp?usp=chrome_default",
          "https://docs.google.com/document/?usp=installed_webapp",
      },
      {
          ash::kGoogleSlidesAppId,
          "https://docs.google.com/presentation/"
          "installwebapp?usp=chrome_default",
          "https://docs.google.com/presentation/?usp=installed_webapp",
      },
      {
          ash::kGoogleSheetsAppId,
          "https://docs.google.com/spreadsheets/"
          "installwebapp?usp=chrome_default",
          "https://docs.google.com/spreadsheets/?usp=installed_webapp",
      },
      {
          ash::kGoogleDriveAppId,
          "https://drive.google.com/drive/installwebapp?usp=chrome_default",
          "https://drive.google.com/?lfhs=2&usp=installed_webapp",
      },
      {
          ash::kGmailAppId,
          "https://mail.google.com/mail/installwebapp?usp=chrome_default",
          "https://mail.google.com/mail/?usp=installed_webapp",
      },
      {
          ash::kYoutubeAppId,
          "https://www.youtube.com/s/notifications/manifest/cr_install.html",
          "https://www.youtube.com/?feature=ytca",
      },
      {
          ash::kGoogleChatAppId,
          "https://mail.google.com/chat/download?usp=chrome_default",
          "https://mail.google.com/chat/",
      },
#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  };
  size_t kOfflineOnlyExpectedCount =
      sizeof(kOfflineOnlyExpectations) / sizeof(kOfflineOnlyExpectations[0]);

  struct OnlineOnlyExpectation {
    const char* install_url;
  } kOnlineOnlyExpectations[] = {
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
#if BUILDFLAG(IS_CHROMEOS)
      {
          "https://meet.google.com/download/webapp?usp=chrome_default",
      },
      {
          "https://calculator.apps.chrome/install",
      },
      {
          "https://discover.apps.chrome/install/",
      },
#endif  // BUILDFLAG(IS_CHROMEOS)
#endif  // BUILDFLAG(GOOGLE_CHROME_BRANDING)
  };
  size_t kOnlineOnlyExpectedCount =
      sizeof(kOnlineOnlyExpectations) / sizeof(kOnlineOnlyExpectations[0]);

  base::RunLoop run_loop;
  provider.preinstalled_web_app_manager().LoadAndSynchronizeForTesting(
      base::BindLambdaForTesting(
          [&](std::map<GURL, ExternallyManagedAppManager::InstallResult>
                  install_results,
              std::map<GURL, webapps::UninstallResultCode> uninstall_results) {
            EXPECT_EQ(install_results.size(),
                      kOfflineOnlyExpectedCount + kOnlineOnlyExpectedCount);

            for (const auto& expectation : kOfflineOnlyExpectations) {
              EXPECT_EQ(install_results[GURL(expectation.install_url)].code,
                        webapps::InstallResultCode::kSuccessOfflineOnlyInstall);
            }

            for (const auto& expectation : kOnlineOnlyExpectations) {
              EXPECT_EQ(install_results[GURL(expectation.install_url)].code,
                        webapps::InstallResultCode::kInstallURLLoadFailed);
            }

            EXPECT_EQ(uninstall_results.size(), 0u);

            run_loop.Quit();
          }));
  run_loop.Run();

  for (const auto& expectation : kOfflineOnlyExpectations) {
    EXPECT_EQ(provider.registrar_unsafe().GetAppLaunchUrl(expectation.app_id),
              GURL(expectation.launch_url));
  }
}

}  // namespace web_app