-
Notifications
You must be signed in to change notification settings - Fork 753
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Data url links will now prompt to save to disk. #1315
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,130 @@ | ||
// | ||
// Copyright (c) Microsoft. All rights reserved. | ||
// Licensed under the MIT license. | ||
// | ||
// Microsoft Bot Framework: http://botframework.com | ||
// | ||
// Bot Framework Emulator Github: | ||
// https://github.com/Microsoft/BotFramwork-Emulator | ||
// | ||
// Copyright (c) Microsoft Corporation | ||
// All rights reserved. | ||
// | ||
// MIT License: | ||
// Permission is hereby granted, free of charge, to any person obtaining | ||
// a copy of this software and associated documentation files (the | ||
// "Software"), to deal in the Software without restriction, including | ||
// without limitation the rights to use, copy, modify, merge, publish, | ||
// distribute, sublicense, and/or sell copies of the Software, and to | ||
// permit persons to whom the Software is furnished to do so, subject to | ||
// the following conditions: | ||
// | ||
// The above copyright notice and this permission notice shall be | ||
// included in all copies or substantial portions of the Software. | ||
// | ||
// THE SOFTWARE IS PROVIDED ""AS IS"", WITHOUT WARRANTY OF ANY KIND, | ||
// EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF | ||
// MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND | ||
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE | ||
// LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION | ||
// OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION | ||
// WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. | ||
// | ||
|
||
import { SharedConstants } from '@bfemulator/app-shared'; | ||
|
||
import { navigate } from './hyperlinkHandler'; | ||
|
||
let mockParse; | ||
jest.mock('url', () => ({ | ||
get parse() { | ||
return mockParse; | ||
}, | ||
})); | ||
|
||
const mockUniqueId = 'id1234'; | ||
jest.mock('@bfemulator/sdk-shared', () => ({ | ||
uniqueId: () => mockUniqueId, | ||
})); | ||
|
||
let mockRemoteCallsMade; | ||
let mockRemoteCall; | ||
jest.mock('./platform/commands/commandServiceImpl', () => ({ | ||
CommandServiceImpl: { | ||
get remoteCall() { | ||
return mockRemoteCall; | ||
}, | ||
}, | ||
})); | ||
|
||
describe('hyperlinkHandler', () => { | ||
beforeEach(() => { | ||
mockParse = jest.fn(url => { | ||
if (url) { | ||
const parts = url.split(':'); | ||
return { protocol: parts[0] + ':' || '' }; | ||
} else { | ||
return ''; | ||
} | ||
}); | ||
mockRemoteCallsMade = []; | ||
(window as any)._openExternal.mockClear(); | ||
mockRemoteCall = jest.fn((commandName: string, ...args: any[]) => { | ||
mockRemoteCallsMade.push({ commandName, args }); | ||
return Promise.resolve(true); | ||
}); | ||
}); | ||
|
||
it('should navigate to an emulated ouath url', async () => { | ||
const url = 'oauth://someoauthurl.com/auth&&&ending'; | ||
await navigate(url); | ||
|
||
expect(mockRemoteCallsMade).toHaveLength(1); | ||
expect(mockRemoteCallsMade[0].commandName).toBe(SharedConstants.Commands.OAuth.SendTokenResponse); | ||
expect(mockRemoteCallsMade[0].args).toEqual(['someoauthurl.com/auth', 'ending', 'emulatedToken_' + mockUniqueId]); | ||
}); | ||
|
||
it('should navigate to an ouath url', async () => { | ||
const url = 'oauthlink://someoauthurl.com/auth&&&ending'; | ||
await navigate(url); | ||
|
||
expect(mockRemoteCallsMade).toHaveLength(1); | ||
expect(mockRemoteCallsMade[0].commandName).toBe(SharedConstants.Commands.OAuth.CreateOAuthWindow); | ||
expect(mockRemoteCallsMade[0].args).toEqual(['someoauthurl.com/auth', 'ending']); | ||
}); | ||
|
||
it('should open a data url', async () => { | ||
const url = 'data:image/png;base64;somedata'; | ||
await navigate(url); | ||
|
||
expect(mockRemoteCallsMade).toHaveLength(1); | ||
expect(mockRemoteCallsMade[0].commandName).toBe(SharedConstants.Commands.Telemetry.TrackEvent); | ||
expect(mockRemoteCallsMade[0].args).toEqual(['app_openLink', { url }]); | ||
expect((window as any)._openExternal).not.toHaveBeenCalled(); | ||
}); | ||
|
||
it('should open a normal url', async () => { | ||
const url = 'https://aka.ms/bot-framework-emulator'; | ||
await navigate(url); | ||
|
||
expect(mockRemoteCallsMade).toHaveLength(1); | ||
expect(mockRemoteCallsMade[0].commandName).toBe(SharedConstants.Commands.Telemetry.TrackEvent); | ||
expect(mockRemoteCallsMade[0].args).toEqual(['app_openLink', { url }]); | ||
expect((window as any)._openExternal).toHaveBeenCalled(); | ||
expect((window as any)._openExternal).toHaveBeenCalledWith(url, { activate: true }); | ||
}); | ||
|
||
it('should track opening a url on a throw', async () => { | ||
mockParse = jest.fn(() => { | ||
throw new Error(); | ||
}); | ||
const url = ''; | ||
await navigate(url); | ||
|
||
expect(mockRemoteCallsMade).toHaveLength(1); | ||
expect(mockRemoteCallsMade[0].commandName).toBe(SharedConstants.Commands.Telemetry.TrackEvent); | ||
expect(mockRemoteCallsMade[0].args).toEqual(['app_openLink', { url }]); | ||
expect((window as any)._openExternal).toHaveBeenCalled(); | ||
expect((window as any)._openExternal).toHaveBeenCalledWith(url, { activate: true }); | ||
}); | ||
}); |
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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is inconsequential since the element is never being added to the dom. It can probably be removed.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove the remove?!?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'll change it when I inevitably have to update the branch once the azure gov fix goes into master.