{"size": 3178, "ext": "js", "max_stars_repo_path": "chrome/test/data/webui/settings/chromeos/app_management/managed_apps_test.js", "max_stars_repo_name": "zealoussnow/chromium", "max_stars_repo_stars_event_min_datetime": "2015-01-01T01:57:10.000Z", "max_stars_repo_stars_event_max_datetime": "2022-03-31T23:33:32.000Z", "max_issues_repo_path": "chrome/test/data/webui/settings/chromeos/app_management/managed_apps_test.js", "max_issues_repo_name": "zealoussnow/chromium", "max_issues_repo_issues_event_min_datetime": "2015-10-21T13:02:42.000Z", "max_issues_repo_issues_event_max_datetime": "2022-03-14T07:50:50.000Z", "max_forks_repo_path": "chrome/test/data/webui/settings/chromeos/app_management/managed_apps_test.js", "max_forks_repo_name": "zealoussnow/chromium", "max_forks_repo_forks_event_min_datetime": "2015-01-02T11:32:21.000Z", "max_forks_repo_forks_event_max_datetime": "2022-03-31T16:35:46.000Z"}
{"max_stars_count": 14668, "max_issues_count": 86, "max_forks_count": 5941, "avg_line_length": 41.2727272727, "max_line_length": 174, "alphanum_fraction": 0.7020138452}
// Copyright 2019 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

// clang-format off
// #import 'chrome://os-settings/chromeos/os_settings.js';

// #import {PermissionType, TriState, FakePageHandler, AppManagementStore, updateSelectedAppId, createTriStatePermission} from 'chrome://os-settings/chromeos/os_settings.js';
// #import {flushTasks} from 'chrome://test/test_util.js';
// #import {setupFakeHandler, replaceStore, replaceBody, getPermissionToggleByType } from './test_util.m.js';
// clang-format on

'use strict';

suite('<app-management-managed-apps>', () => {
  let appDetailView;
  let fakeHandler;

  setup(async () => {
    fakeHandler = setupFakeHandler();
    replaceStore();

    // Create a Web app which is installed and pinned by policy
    // and has location set to on and camera set to off by policy.
    const permissionOptions = {};
    permissionOptions[PermissionType.kLocation] = createTriStatePermission(
        PermissionType.kLocation, TriState.kAllow, /*isManaged*/ true);
    permissionOptions[PermissionType.kCamera] = createTriStatePermission(
        PermissionType.kCamera, TriState.kBlock, /*isManaged*/ true);
    const policyAppOptions = {
      type: apps.mojom.AppType.kWeb,
      isPinned: apps.mojom.OptionalBool.kTrue,
      isPolicyPinned: apps.mojom.OptionalBool.kTrue,
      installReason: apps.mojom.InstallReason.kPolicy,
      permissions: app_management.FakePageHandler.createWebPermissions(
          permissionOptions),
    };
    const app = await fakeHandler.addApp(null, policyAppOptions);
    // Select created app.
    app_management.AppManagementStore.getInstance().dispatch(
        app_management.actions.updateSelectedAppId(app.id));
    appDetailView = document.createElement('app-management-pwa-detail-view');
    replaceBody(appDetailView);
    await test_util.flushTasks();
  });

  // TODO(crbug.com/999412): rewrite test.
  test.skip('Uninstall button affected by policy', () => {
    const uninstallWrapper =
        appDetailView.$$('app-management-detail-view-header')
            .$$('#uninstall-wrapper');
    expectTrue(!!uninstallWrapper.querySelector('#policy-indicator'));
  });

  test('Permission toggles affected by policy', () => {
    function checkToggle(permissionType, policyAffected) {
      const permissionToggle =
          getPermissionToggleByType(appDetailView, permissionType);
      expectTrue(permissionToggle.$$('cr-toggle').disabled === policyAffected);
      expectTrue(
          !!permissionToggle.root.querySelector('#policyIndicator') ===
          policyAffected);
    }
    checkToggle('kNotifications', false);
    checkToggle('kLocation', true);
    checkToggle('kCamera', true);
    checkToggle('kMicrophone', false);
  });

  test('Pin to shelf toggle effected by policy', () => {
    const pinToShelfSetting = appDetailView.$$('#pin-to-shelf-setting')
                                  .$$('app-management-toggle-row');
    expectTrue(!!pinToShelfSetting.root.querySelector('#policyIndicator'));
    expectTrue(pinToShelfSetting.$$('cr-toggle').disabled);
  });
});
