chromium/chrome/browser/sync/test/integration/two_client_web_apps_sync_test.cc

// Copyright 2019 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include <string>

#include "base/functional/bind.h"
#include "base/scoped_observation.h"
#include "base/strings/utf_string_conversions.h"
#include "base/test/bind.h"
#include "build/chromeos_buildflags.h"
#include "chrome/app/chrome_command_ids.h"
#include "chrome/browser/sync/test/integration/apps_helper.h"
#include "chrome/browser/sync/test/integration/web_apps_sync_test_base.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/web_applications/test/web_app_browsertest_util.h"
#include "chrome/browser/ui/web_applications/web_app_dialogs.h"
#include "chrome/browser/web_applications/mojom/user_display_mode.mojom.h"
#include "chrome/browser/web_applications/os_integration/os_integration_manager.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/test/web_app_test_observers.h"
#include "chrome/browser/web_applications/web_app_icon_manager.h"
#include "chrome/browser/web_applications/web_app_install_info.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_sync_bridge.h"
#include "chrome/browser/web_applications/web_app_utils.h"
#include "chrome/test/base/ui_test_utils.h"
#include "components/sync/base/features.h"
#include "content/public/test/browser_test.h"
#include "content/public/test/test_utils.h"
#include "third_party/blink/public/mojom/manifest/manifest.mojom.h"
#include "third_party/skia/include/core/SkColor.h"

#if BUILDFLAG(IS_CHROMEOS_LACROS)
#include "chrome/common/chrome_constants.h"
#include "components/sync/service/sync_service_impl.h"
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

namespace web_app {

namespace {

class DisplayModeChangeWaiter : public WebAppRegistrarObserver {};

}  // namespace

class TwoClientWebAppsSyncTest : public WebAppsSyncTestBase {};

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, Basic) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, Minimal) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, ThemeColor) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, IsLocallyInstalled) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, AppFieldsChangeDoesNotSync) {}

// Tests that we don't crash when syncing an icon info with no size.
// Context: https://crbug.com/1058283
IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncFaviconOnly) {}

// Tests that we don't use the manifest start_url if it differs from what came
// through sync.
IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncUsingStartUrlFallback) {}

// Tests that we don't use the page title if there's no manifest.
// Pages without a manifest are usually not the correct page to draw information
// from e.g. login redirects or loading pages.
// Context: https://crbug.com/1078286
IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncUsingNameFallback) {}

// Negative test of SyncUsingNameFallback above. Don't use the app name fallback
// if there's a name provided by the manifest during sync.
IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncWithoutUsingNameFallback) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncUsingIconUrlFallback) {}

IN_PROC_BROWSER_TEST_F(TwoClientWebAppsSyncTest, SyncUserDisplayModeChange) {}

#if BUILDFLAG(IS_CHROMEOS_LACROS)
// On Lacros, syncing of Apps is only enabled in the "main" profile.
// TwoClientWebAppsSyncTest (via WebAppsSyncTestBase) bypasses the "main profile"
// check, so that syncing actually happens. This class does not, so that the
// Lacros restriction (Apps sync only in main profile) applies.
class TwoClientLacrosWebAppsSyncTest : public SyncTest {
 public:
  TwoClientLacrosWebAppsSyncTest() : SyncTest(TWO_CLIENT) {}
  ~TwoClientLacrosWebAppsSyncTest() override = default;

  // SyncTest:
  base::FilePath GetProfileBaseName(int index) override {
    if (index == 0)
      return base::FilePath(chrome::kInitialProfile);
    return SyncTest::GetProfileBaseName(index);
  }
};

IN_PROC_BROWSER_TEST_F(TwoClientLacrosWebAppsSyncTest,
                       SyncDisabledUnlessPrimary) {
  ASSERT_TRUE(SetupClients());
#if BUILDFLAG(IS_CHROMEOS_LACROS)
  // Apps sync is controlled by a dedicated preference on Lacros,
  // corresponding to the Apps toggle in OS Sync settings.
  // Enable the Apps toggle for both clients.
  if (base::FeatureList::IsEnabled(syncer::kSyncChromeOSAppsToggleSharing)) {
    GetSyncService(0)->GetUserSettings()->SetAppsSyncEnabledByOs(true);
    GetSyncService(1)->GetUserSettings()->SetAppsSyncEnabledByOs(true);
  }
#endif
  ASSERT_TRUE(SetupSync());

  {
    EXPECT_TRUE(GetProfile(0)->IsMainProfile());
    syncer::SyncServiceImpl* service = GetSyncService(0);
    syncer::DataTypeSet types = service->GetActiveDataTypes();
    EXPECT_TRUE(types.Has(syncer::APPS));
    EXPECT_TRUE(types.Has(syncer::APP_SETTINGS));
    EXPECT_TRUE(types.Has(syncer::WEB_APPS));
  }

  {
    EXPECT_FALSE(GetProfile(1)->IsMainProfile());
    syncer::SyncServiceImpl* service = GetSyncService(1);
    syncer::DataTypeSet types = service->GetActiveDataTypes();
    EXPECT_FALSE(types.Has(syncer::APPS));
    EXPECT_FALSE(types.Has(syncer::APP_SETTINGS));
    EXPECT_FALSE(types.Has(syncer::WEB_APPS));
  }
}
#endif  // BUILDFLAG(IS_CHROMEOS_LACROS)

}  // namespace web_app