Commit cc7ecdb3 authored by Cecilia Ni's avatar Cecilia Ni Committed by Commit Bot

[App Management] Add PWA Permission View Test

This CL adds PWA Permission View tests that test 1) toggle status reflects permission status, and 2) click toggle will toggle the corresponding permission.

Bug: 906508
Change-Id: I03f77afe2a75afc260c2d0dcdfe907e6d12dc9e8
Reviewed-on: https://chromium-review.googlesource.com/c/1445331
Auto-Submit: Cecilia Ni <ceciliani@google.com>
Reviewed-by: default avatarcalamity <calamity@chromium.org>
Reviewed-by: default avatarEric Willigers <ericwilligers@chromium.org>
Commit-Queue: Cecilia Ni <ceciliani@google.com>
Cr-Commit-Position: refs/heads/master@{#630690}
parent 0897d345
......@@ -32,6 +32,7 @@
<div class="permission-list card-container">
<app-management-permission-item
id="notifications"
class="permission-card-row separated-row header-text"
permission-label="$i18n{notifications}"
permission-type="CONTENT_SETTINGS_TYPE_NOTIFICATIONS">
......@@ -53,18 +54,21 @@
<iron-collapse opened="[[listExpanded_]]">
<app-management-permission-item
id="location"
class="subpermission-row"
icon="cr:location-on"
permission-label="$i18n{location}"
permission-type="CONTENT_SETTINGS_TYPE_GEOLOCATION">
</app-management-permission-item>
<app-management-permission-item
id="camera"
class="subpermission-row"
icon="cr:videocam"
permission-label="$i18n{camera}"
permission-type="CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA">
</app-management-permission-item>
<app-management-permission-item
id="microphone"
class="subpermission-row"
icon="cr:mic"
permission-label="$i18n{microphone}"
......
......@@ -97,3 +97,17 @@ AppManagementReducersTest.prototype = {
TEST_F('AppManagementReducersTest', 'All', function() {
mocha.run();
});
function AppManagementPwaPermissionViewTest() {}
AppManagementPwaPermissionViewTest.prototype = {
__proto__: AppManagementBrowserTest.prototype,
extraLibraries: AppManagementBrowserTest.prototype.extraLibraries.concat([
'pwa_permission_view_test.js',
]),
};
TEST_F('AppManagementPwaPermissionViewTest', 'All', function() {
mocha.run();
});
// Copyright 2018 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.
'use strict';
suite('<app-management-pwa-permission-view>', function() {
let pwaPermissionView;
let fakeHandler;
const TEST_APP_ID = '1';
function getToggleFromPermissionItem(permissionItemId) {
return pwaPermissionView.root.getElementById(permissionItemId)
.root.querySelector('app-management-permission-toggle')
.root.querySelector('cr-toggle');
}
function getPermissionBoolByType(permissionType) {
return app_management.util.getPermissionValueBool(
pwaPermissionView.app_, permissionType);
}
async function clickToggle(permissionItemId) {
getToggleFromPermissionItem(permissionItemId).click();
await fakeHandler.flushForTesting();
}
setup(async function() {
pwaPermissionView =
document.createElement('app-management-pwa-permission-view');
PolymerTest.clearBody();
fakeHandler = setupFakeHandler();
replaceStore();
// Add an app, and make it the currently selected app.
await fakeHandler.addApp(TEST_APP_ID);
app_management.Store.getInstance().dispatch(
app_management.actions.changePage(PageType.DETAIL, TEST_APP_ID));
document.body.appendChild(pwaPermissionView);
});
test('App is rendered correctly', function() {
assertEquals(
app_management.Store.getInstance().data.currentPage.selectedAppId,
pwaPermissionView.app_.id);
});
test(
'Clicking the permission toggle changes the permission of the app',
async function() {
let checkToggle = async function(permissionType, permissionId) {
assertTrue(getPermissionBoolByType(permissionType));
assertTrue(getToggleFromPermissionItem(permissionId).checked);
await clickToggle(permissionId);
assertFalse(getPermissionBoolByType(permissionType));
assertFalse(getToggleFromPermissionItem(permissionId).checked);
};
await checkToggle(
'CONTENT_SETTINGS_TYPE_NOTIFICATIONS', 'notifications');
await checkToggle('CONTENT_SETTINGS_TYPE_GEOLOCATION', 'location');
await checkToggle('CONTENT_SETTINGS_TYPE_MEDIASTREAM_CAMERA', 'camera');
await checkToggle(
'CONTENT_SETTINGS_TYPE_MEDIASTREAM_MIC', 'microphone');
});
});
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment