[Run] Open in console functionality (#4739)

* Added open in console for indexer

* Added open in console fpr indexer and folder plugin

* Added open in console to program plugin

* Added string localization for program plugin

* Added test for win32 program

* Added test for win32 programs

* Added test for indexer plugin

* Localization for context menu title

* Added tests for folder plugin

* Added tests for indexer plugin

* Code cleanup

* Improved logging and nit fixes

* Updated tooltip for open in console

* Updates tests

* Removed subtitle property from contextmenuresult class

* Improved logging for context menu loaders
This commit is contained in:
Divyansh Srivastava
2020-07-08 09:56:26 -07:00
committed by GitHub
parent e3e6b23b7c
commit 638cd1dd48
32 changed files with 402 additions and 80 deletions

View File

@@ -0,0 +1,54 @@
using Moq;
using NUnit.Framework;
using System;
using System.Collections.Generic;
using System.Text;
using Wox.Plugin;
using Microsoft.Plugin.Folder;
namespace Wox.Test.Plugins
{
class FolderPluginTest
{
[Test]
public void ContextMenuLoader_ReturnContextMenuForFolderWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Type = ResultType.Folder, FullPath = "C:/DummyFolder" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_in_console"), Times.Once());
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFileWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Type = ResultType.File, FullPath = "C:/DummyFile.cs" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_folder_open_in_console"), Times.Once());
}
}
}

View File

@@ -8,125 +8,142 @@ using Wox.Plugin;
using Microsoft.Plugin.Program.Programs;
using Moq;
using System.IO;
using Microsoft.Plugin.Program;
using System.IO.Packaging;
using Windows.ApplicationModel;
namespace Wox.Test.Plugins
{
[TestFixture]
public class Win32Tests
{
Win32 notepad_appdata = new Win32
static Win32 notepad_appdata = new Win32
{
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk"
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
};
Win32 notepad_users = new Win32
static Win32 notepad_users = new Win32
{
Name = "Notepad",
ExecutableName = "notepad.exe",
FullPath = "c:\\windows\\system32\\notepad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\notepad.lnk",
AppType = 2
};
Win32 azure_command_prompt = new Win32
static Win32 azure_command_prompt = new Win32
{
Name = "Microsoft Azure Command Prompt - v2.9",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft azure\\microsoft azure sdk for .net\\v2.9\\microsoft azure command prompt - v2.9.lnk",
AppType = 2
};
Win32 visual_studio_command_prompt = new Win32
static Win32 visual_studio_command_prompt = new Win32
{
Name = "x64 Native Tools Command Prompt for VS 2019",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\visual studio 2019\\visual studio tools\\vc\\x64 native tools command prompt for vs 2019.lnk",
AppType = 2
};
Win32 command_prompt = new Win32
static Win32 command_prompt = new Win32
{
Name = "Command Prompt",
ExecutableName = "cmd.exe",
FullPath = "c:\\windows\\system32\\cmd.exe",
LnkResolvedPath ="c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk"
LnkResolvedPath ="c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\command prompt.lnk",
AppType = 2
};
Win32 file_explorer = new Win32
static Win32 file_explorer = new Win32
{
Name = "File Explorer",
ExecutableName = "File Explorer.lnk",
FullPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\system tools\\file explorer.lnk",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 2
};
Win32 wordpad = new Win32
static Win32 wordpad = new Win32
{
Name = "Wordpad",
ExecutableName = "wordpad.exe",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\accessories\\wordpad.lnk",
AppType = 2
};
Win32 wordpad_duplicate = new Win32
static Win32 wordpad_duplicate = new Win32
{
Name = "WORDPAD",
ExecutableName = "WORDPAD.EXE",
FullPath = "c:\\program files\\windows nt\\accessories\\wordpad.exe",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 2
};
Win32 twitter_pwa = new Win32
static Win32 twitter_pwa = new Win32
{
Name = "Twitter",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\chrome apps\\twitter.lnk",
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi"
Arguments = " --profile-directory=Default --app-id=jgeosdfsdsgmkedfgdfgdfgbkmhcgcflmi",
AppType = 0
};
Win32 pinned_webpage = new Win32
static Win32 pinned_webpage = new Win32
{
Name = "Web page",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\web page.lnk",
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd"
Arguments = "--profile-directory=Default --app-id=homljgmgpmcbpjbnjpfijnhipfkiclkd",
AppType = 0
};
Win32 edge_named_pinned_webpage = new Win32
static Win32 edge_named_pinned_webpage = new Win32
{
Name = "edge - Bing",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge_proxy.exe",
LnkResolvedPath = "c:\\users\\powertoys\\appdata\\roaming\\microsoft\\windows\\start menu\\programs\\edge - bing.lnk",
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd"
Arguments = " --profile-directory=Default --app-id=aocfnapldcnfbofgmbbllojgocaelgdd",
AppType = 0
};
Win32 msedge = new Win32
static Win32 msedge = new Win32
{
Name = "Microsoft Edge",
ExecutableName = "msedge.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\msedge.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\microsoft edge.lnk",
AppType = 2
};
Win32 chrome = new Win32
static Win32 chrome = new Win32
{
Name = "Google Chrome",
ExecutableName = "chrome.exe",
FullPath = "c:\\program files (x86)\\google\\chrome\\application\\chrome.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\google chrome.lnk",
AppType = 2
};
Win32 dummy_proxy_app = new Win32
static Win32 dummy_proxy_app = new Win32
{
Name = "Proxy App",
ExecutableName = "test_proxy.exe",
FullPath = "c:\\program files (x86)\\microsoft\\edge\\application\\test_proxy.exe",
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk"
LnkResolvedPath = "c:\\programdata\\microsoft\\windows\\start menu\\programs\\test proxy.lnk",
AppType = 2
};
Win32 cmd_run_command = new Win32
static Win32 cmd_run_command = new Win32
{
Name = "cmd",
ExecutableName = "cmd.exe",
@@ -135,7 +152,7 @@ namespace Wox.Test.Plugins
AppType = 3 // Run command
};
Win32 cmder_run_command = new Win32
static Win32 cmder_run_command = new Win32
{
Name = "Cmder",
Description = "Cmder: Lovely Console Emulator",
@@ -145,22 +162,24 @@ namespace Wox.Test.Plugins
AppType = 3 // Run command
};
Win32 dummy_internetShortcut_app = new Win32
static Win32 dummy_internetShortcut_app = new Win32
{
Name = "Shop Titans",
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\AppData\\Roaming\\Microsoft\\Windows\\Start Menu\\Programs\\Steam",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 1
};
Win32 dummy_internetShortcut_app_duplicate = new Win32
static Win32 dummy_internetShortcut_app_duplicate = new Win32
{
Name = "Shop Titans",
ExecutableName = "Shop Titans.url",
FullPath = "steam://rungameid/1258080",
ParentDirectory = "C:\\Users\\temp\\Desktop",
LnkResolvedPath = null
LnkResolvedPath = null,
AppType = 1
};
[Test]
@@ -336,11 +355,77 @@ namespace Wox.Test.Plugins
}
[Test]
public void Win32Apps_ShouldSetNameAsTitle_WhileCreatingResult()
public void WEB_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = pinned_webpage.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void INTERNET_SHORTCUT_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = dummy_internetShortcut_app.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void WIN32_APPLICATION_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = chrome.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void RUN_COMMAND_ReturnContextMenuWithOpenInConsole_WhenContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
// Act
List<ContextMenuResult> contextMenuResults = cmd_run_command.ContextMenus(mock.Object);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("wox_plugin_program_run_as_administrator"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("wox_plugin_program_open_in_console"), Times.Once());
}
[Test]
public void Win32Apps_ShouldSetNameAsTitle_WhileCreatingResult()
{
var mock = new Mock<IPublicAPI>();
mock.Setup(x => x.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
StringMatcher.Instance = new StringMatcher();
// Act

View File

@@ -7,6 +7,8 @@ using Microsoft.Plugin.Indexer.SearchHelper;
using Microsoft.Plugin.Indexer.Interface;
using Moq;
using System.Linq;
using Microsoft.Plugin.Indexer;
using Wox.Plugin;
namespace Wox.Test.Plugins
{
@@ -214,5 +216,46 @@ namespace Wox.Test.Plugins
Assert.IsFalse(windowsSearchAPIResults.Any(x => x.Title == "file1.txt"));
Assert.IsTrue(windowsSearchAPIResults.Any(x => x.Title == "file2.txt"));
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFolderWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Path = "C:/DummyFolder", Title = "DummyFolder" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 2);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once());
}
[Test]
public void ContextMenuLoader_ReturnContextMenuForFileWithOpenInConsole_WhenLoadContextMenusIsCalled()
{
// Arrange
var mock = new Mock<IPublicAPI>();
mock.Setup(api => api.GetTranslation(It.IsAny<string>())).Returns(It.IsAny<string>());
var pluginInitContext = new PluginInitContext() { API = mock.Object };
var contextMenuLoader = new ContextMenuLoader(pluginInitContext);
var searchResult = new SearchResult() { Path = "C:/DummyFile.cs", Title = "DummyFile.cs" };
var result = new Result() { ContextData = searchResult };
// Act
List<ContextMenuResult> contextMenuResults = contextMenuLoader.LoadContextMenus(result);
// Assert
Assert.AreEqual(contextMenuResults.Count, 3);
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_copy_path"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_containing_folder"), Times.Once());
mock.Verify(x => x.GetTranslation("Microsoft_plugin_indexer_open_in_console"), Times.Once());
}
}
}

View File

@@ -39,6 +39,7 @@
</PropertyGroup>
<ItemGroup>
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Folder\Microsoft.Plugin.Folder.csproj" />
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Indexer\Microsoft.Plugin.Indexer.csproj" />
<ProjectReference Include="..\Plugins\Microsoft.Plugin.Program\Microsoft.Plugin.Program.csproj" />
<ProjectReference Include="..\Wox.Core\Wox.Core.csproj" />