chromium/chrome/browser/ui/web_applications/sub_apps_service_impl_browsertest.cc

// Copyright 2021 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/ui/web_applications/sub_apps_service_impl.h"

#include <memory>
#include <string>
#include <utility>
#include <vector>

#include "base/test/bind.h"
#include "base/test/scoped_feature_list.h"
#include "base/test/simple_test_clock.h"
#include "base/test/test_future.h"
#include "chrome/browser/notifications/notification_display_service_tester.h"
#include "chrome/browser/permissions/permission_decision_auto_blocker_factory.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/browser/ui/web_applications/sub_apps_install_dialog_controller.h"
#include "chrome/browser/ui/web_applications/test/isolated_web_app_test_utils.h"
#include "chrome/browser/ui/web_applications/web_app_browsertest_base.h"
#include "chrome/browser/web_applications/isolated_web_apps/isolated_web_app_url_info.h"
#include "chrome/browser/web_applications/proto/web_app_install_state.pb.h"
#include "chrome/browser/web_applications/test/web_app_install_test_utils.h"
#include "chrome/browser/web_applications/web_app.h"
#include "chrome/browser/web_applications/web_app_command_scheduler.h"
#include "chrome/browser/web_applications/web_app_constants.h"
#include "chrome/browser/web_applications/web_app_helpers.h"
#include "chrome/browser/web_applications/web_app_provider.h"
#include "chrome/browser/web_applications/web_app_registrar.h"
#include "chrome/browser/web_applications/web_app_registry_update.h"
#include "chrome/browser/web_applications/web_app_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_ui_manager.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/permissions/permission_decision_auto_blocker.h"
#include "components/webapps/browser/uninstall_result_code.h"
#include "content/public/browser/render_frame_host.h"
#include "content/public/browser/web_contents.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/browser_test_utils.h"
#include "mojo/public/cpp/bindings/remote.h"
#include "testing/gtest/include/gtest/gtest.h"
#include "third_party/blink/public/common/features.h"
#include "url/gurl.h"
#include "url/origin.h"

SubAppsService;
SubAppsServiceAddParameters;
SubAppsServiceAddParametersPtr;
SubAppsServiceListResultEntry;
SubAppsServiceListResultEntryPtr;
SubAppsServiceListResultPtr;
SubAppsServiceRemoveResult;
SubAppsServiceRemoveResultPtr;
SubAppsServiceResultCode;

namespace web_app {

namespace {

// `kDomain` must be just a hostname, not a full URL.
constexpr const char kDomain[] =;
constexpr const char kDifferentDomain[] =;
constexpr const char kParentAppPath[] =;
constexpr const char kSubAppPath[] =;
constexpr const char kSubAppName[] =;
constexpr const char kSubAppPathMinimalUi[] =;
constexpr const char kSubAppPath2[] =;
constexpr const char kSubAppName2[] =;
constexpr const char kSubAppPath3[] =;
constexpr const char kSubAppName3[] =;
constexpr const char kSubAppPathInvalid[] =;
constexpr const char kSubAppIdInvalid[] =;

constexpr const char kSub1[] =;
constexpr const char kSub2[] =;

}  // namespace

RemoveResultsMojo;

AddResults;

// There's one simple end-to-end test that actually calls the JS API interface,
// the rest test the mojo interface (since the first layer listening to the API
// calls is almost a direct passthrough to the mojo service).
//
// JS API interface tests are in
// third_party/blink/web_tests/external/wpt/subapps/.

class SubAppsServiceImplBrowserTest : public IsolatedWebAppBrowserTestHarness {};

/********** End-to-end test (one is enough!). **********/

// Simple end-to-end test for add().
// NOTE: Only one E2E test is enough, test everything else through the Mojo
// interface (as all the other tests do).
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, EndToEndAdd) {}

IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       ApiUndefinedForNonIsolatedApp) {}

/********** Tests for the Add API call. **********/

// Add a single sub-app and verify all sorts of things.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddSingle) {}

// Verify that Add works if PWA is launched as standalone window.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddStandaloneWindow) {}

// Verify that adding the same app as standalone and as subapp results in two
// separate apps being registered with different manifest_id and app_id.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       AddSameAppAsSubAndStandalone) {}

// Add call should fail if the parent app isn't installed.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       AddFailParentAppNotInstalled) {}

// Add call should fail if the call wasn't made from the context of parent app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       AddFailNotInParentAppContext) {}

// Verify that Add call rejects a sub-app with the wrong specified app_id.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddFailIncorrectId) {}

// Verify that Add fails when trying to add the parent app as sub-app of
// itself.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddFailForParentApp) {}

// Verify that Add fails for an invalid (non-existing) sub-app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddFailNonExistent) {}

// Add call closes the mojo connection if the argument is wrong origin to the
// calling app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddFailWrongOrigin) {}

// Make sure the Add API can't force manifest update. Add sub-app, verify
// display mode, then add the same one again with different display mode in the
// manifest, and verify that it didn't change.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddDoesntForceReinstall) {}

// Add call should fail if calling app is already a sub app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddFailAppIsSubApp) {}

/******** Tests for the Add API call - adding multiple/zero sub-apps. ********/

// Add one sub-app, verify count is one. Add it again, still same count. Add a
// second sub-app, verify count is two.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddTwo) {}

// Verify that Adding multiple sub-apps works correctly.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddMultiple) {}

// Verify that Adding a mix of valid and invalid sub-apps works.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       AddMultipleWithInvalidSubApps) {}

// Verify that Add works correctly for 0 sub-apps to be installed.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, AddZero) {}

/******** Tests for the Add API call - dialog behaviour ********/

// Verify that all sub apps are returned with the failure result code when the
// permissions dialog is declined.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       DialogNotAcceptedReturnsAllSubApps) {}

IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       DialogEmbargoedIfDeclinedThreeTimes) {}

IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, DialogEmbargoTiming) {}
/********** Tests for uninstallation behaviour. **********/

// Verify that uninstalling an app with sub-apps causes sub-apps to be
// uninstalled as well.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       UninstallingParentAppUninstallsSubApps) {}

// Verify that uninstalling one source of the parent app which has multiple
// sources of installation doesn't actually uninstall it (or the sub-apps it has
// added).
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       UninstallingParentAppSourceDoesntUninstallSubApps) {}

// Verify that uninstalling an app that has a sub-app with more than one install
// source removes all the "sub-app" install sources and uninstalls it.
IN_PROC_BROWSER_TEST_F(
    SubAppsServiceImplBrowserTest,
    UninstallingParentAppUninstallsOnlySubAppIfMultipleSources) {}

/********** Tests for the List API call. **********/

// List call returns the correct value for three sub-apps.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, ListSuccess) {}

// Verify that the list call doesn't return a non-sub-apps installed app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       ListDoesntReturnNonSubApp) {}

// List call returns failure if the parent app isn't installed.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       ListFailParentAppNotInstalled) {}

// Verify that List does not return subapps installed outside of the parent app
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       ListReturnsOnlyAppsInstalledByTheCurrentParent) {}

/********** Tests for the Remove API call. **********/

// Remove works with one app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveOneApp) {}

// Remove works with a list of apps.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveListOfApps) {}

// Calling remove with an empty list doesn't crash.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveEmptyList) {}

// Remove fails for a regular installed app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveFailRegularApp) {}

// Remove fails for a sub-app with a different parent_app_id.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveFailWrongParent) {}

// Remove call returns failure if the calling app isn't installed.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest,
                       RemoveFailCallingAppNotInstalled) {}

// Remove call closes the mojo connection if the argument is wrong origin to the
// calling app.
IN_PROC_BROWSER_TEST_F(SubAppsServiceImplBrowserTest, RemoveFailWrongOrigin) {}

}  // namespace web_app