Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[FilesBreadcrumb] Escape "/" in path component for breadcrumb
XfBreadcrumb uses "/" to split the path, before setting path of breadcrumb component, we need to escape the "/" in the path (e.g. Nexus/Pixel (MTP) => Nexus%2FPixel (MTP)) so it won't break the split logic. Add a unit test to check breadcrumb_container. Note: breadcrumb itself already has a unit test to check the unescape logic. Demo: http://go/scrcast/NjUwODY2Nzc4NTQ0NTM3NnwwZWRlMzA2ZS1iYw Bug: b:263042677 Test: browser_test --gtest_filter="*BreadcrumbContainer" Change-Id: I40b744fa6db523f87059322b6d7ccb9d936913a0 Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/4113705 Reviewed-by: Noel Gordon <noel@chromium.org> Commit-Queue: Wenbo Jie <wenbojie@chromium.org> Cr-Commit-Position: refs/heads/main@{#1084850}
- Loading branch information
Showing
4 changed files
with
75 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
68 changes: 68 additions & 0 deletions
68
ui/file_manager/file_manager/containers/breadcrumb_container_unittest.ts
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,68 @@ | ||
// Copyright 2022 The Chromium Authors | ||
// Use of this source code is governed by a BSD-style license that can be | ||
// found in the LICENSE file. | ||
|
||
import {assertEquals, assertNotEquals} from 'chrome://webui-test/chai_assert.js'; | ||
|
||
import {CurrentDirectory, PropStatus} from '../externs/ts/state.js'; | ||
import {getEmptyState, getStore} from '../state/store.js'; | ||
|
||
import {BreadcrumbContainer} from './breadcrumb_container.js'; | ||
|
||
|
||
/** An instance of BreadcrumbContainer. */ | ||
let breadcrumbContainer: BreadcrumbContainer|null = null; | ||
|
||
export function setUp() { | ||
document.body.innerHTML = '<div id="breadcrumb-container"></div>'; | ||
breadcrumbContainer = | ||
new BreadcrumbContainer(document.querySelector('#breadcrumb-container')!); | ||
} | ||
|
||
/** | ||
* Tests that when current directory has "/" in the path, it will be escaped | ||
* before passing to the underlying breadcrumb. | ||
*/ | ||
export function testPathWithSlash(done: () => void) { | ||
const store = getStore(); | ||
store.init(getEmptyState()); | ||
const currentDirectory: CurrentDirectory = { | ||
key: 'filesystem:chrome://file-manager/external/aaa/bbb', | ||
status: PropStatus.SUCCESS, | ||
rootType: undefined, | ||
pathComponents: [ | ||
{name: 'Nexus/Pixel(MTP)', label: 'Nexus/Pixel(MTP)', key: ''}, | ||
{name: 'DCIM', label: 'DCIM', key: ''}, | ||
], | ||
content: { | ||
keys: [], | ||
}, | ||
selection: { | ||
keys: [], | ||
dirCount: 0, | ||
fileCount: 0, | ||
hostedCount: undefined, | ||
offlineCachedCount: undefined, | ||
fileTasks: { | ||
policyDefaultHandlerStatus: undefined, | ||
defaultTask: undefined, | ||
tasks: [], | ||
status: PropStatus.SUCCESS, | ||
}, | ||
}, | ||
hasDlpDisabledFiles: false, | ||
}; | ||
|
||
// Simulate a state change from the store. | ||
breadcrumbContainer!.onStateChanged({...store.getState(), currentDirectory}); | ||
|
||
// Check that breadcrumb's path has been escaped. | ||
const breadcrumb = document.querySelector('xf-breadcrumb'); | ||
assertNotEquals(null, breadcrumb); | ||
assertEquals( | ||
breadcrumb!.path, | ||
'Nexus%2FPixel(MTP)/DCIM', | ||
); | ||
|
||
done(); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters