Bug 1894865 - Concat nsStrings to avoid issues converting wide characters to char and back again. r=bytesized
Differential Revision: https://phabricator.services.mozilla.com/D210247
This commit is contained in:
54
browser/components/shell/test/gtest/ShellLinkTests.cpp
Normal file
54
browser/components/shell/test/gtest/ShellLinkTests.cpp
Normal file
@@ -0,0 +1,54 @@
|
||||
/* -*- Mode: C++; tab-width: 8; indent-tabs-mode: nil; c-basic-offset: 2 -*- */
|
||||
/* This Source Code Form is subject to the terms of the Mozilla Public
|
||||
* License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
* file, You can obtain one at http://mozilla.org/MPL/2.0/. */
|
||||
|
||||
#include "gtest/gtest.h"
|
||||
|
||||
#include "nsDirectoryServiceDefs.h"
|
||||
#include "nsDirectoryServiceUtils.h"
|
||||
#include "nsWindowsShellServiceInternal.h"
|
||||
#include "nsXULAppAPI.h"
|
||||
|
||||
TEST(ShellLink, NarrowCharacterArguments)
|
||||
{
|
||||
nsCOMPtr<nsIFile> exe;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(exe));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
RefPtr<IShellLinkW> link;
|
||||
rv = CreateShellLinkObject(exe, {u"test"_ns}, u"test"_ns, exe, 0, u"aumid"_ns,
|
||||
getter_AddRefs(link));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
ASSERT_TRUE(link != nullptr);
|
||||
|
||||
std::wstring testArgs = L"\"test\" ";
|
||||
|
||||
wchar_t resultArgs[sizeof(testArgs)];
|
||||
HRESULT hr = link->GetArguments(resultArgs, sizeof(resultArgs));
|
||||
ASSERT_TRUE(SUCCEEDED(hr));
|
||||
|
||||
ASSERT_TRUE(testArgs == resultArgs);
|
||||
}
|
||||
|
||||
TEST(ShellLink, WideCharacterArguments)
|
||||
{
|
||||
nsCOMPtr<nsIFile> exe;
|
||||
nsresult rv = NS_GetSpecialDirectory(NS_OS_TEMP_DIR, getter_AddRefs(exe));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
|
||||
RefPtr<IShellLinkW> link;
|
||||
rv = CreateShellLinkObject(exe, {u"Test\\テスト用アカウント\\Test"_ns},
|
||||
u"test"_ns, exe, 0, u"aumid"_ns,
|
||||
getter_AddRefs(link));
|
||||
ASSERT_TRUE(NS_SUCCEEDED(rv));
|
||||
ASSERT_TRUE(link != nullptr);
|
||||
|
||||
std::wstring testArgs = L"\"Test\\テスト用アカウント\\Test\" ";
|
||||
|
||||
wchar_t resultArgs[sizeof(testArgs)];
|
||||
HRESULT hr = link->GetArguments(resultArgs, sizeof(resultArgs));
|
||||
ASSERT_TRUE(SUCCEEDED(hr));
|
||||
|
||||
ASSERT_TRUE(testArgs == resultArgs);
|
||||
}
|
||||
14
browser/components/shell/test/gtest/moz.build
Normal file
14
browser/components/shell/test/gtest/moz.build
Normal file
@@ -0,0 +1,14 @@
|
||||
# -*- Mode: python; indent-tabs-mode: nil; tab-width: 40 -*-
|
||||
# vim: set filetype=python:
|
||||
# This Source Code Form is subject to the terms of the Mozilla Public
|
||||
# License, v. 2.0. If a copy of the MPL was not distributed with this
|
||||
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
|
||||
|
||||
if CONFIG["MOZ_WIDGET_TOOLKIT"] == "windows":
|
||||
LOCAL_INCLUDES += ["/browser/components/shell"]
|
||||
|
||||
UNIFIED_SOURCES += [
|
||||
"ShellLinkTests.cpp",
|
||||
]
|
||||
|
||||
FINAL_LIBRARY = "xul-gtest"
|
||||
Reference in New Issue
Block a user