Skip to content

Commit

Permalink
Ban ASCIIToUTF16() on constant string literals.
Browse files Browse the repository at this point in the history
Bug: 1189439
Change-Id: I8d5340448469bd81b881ee4fa1539ff8ddf30312
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2869088
Commit-Queue: Peter Kasting <pkasting@chromium.org>
Auto-Submit: Peter Kasting <pkasting@chromium.org>
Reviewed-by: Lei Zhang <thestig@chromium.org>
Owners-Override: Lei Zhang <thestig@chromium.org>
Cr-Commit-Position: refs/heads/master@{#879653}
  • Loading branch information
pkasting authored and Chromium LUCI CQ committed May 6, 2021
1 parent 6d248ef commit dc3e1ec
Show file tree
Hide file tree
Showing 40 changed files with 487 additions and 518 deletions.
9 changes: 0 additions & 9 deletions PRESUBMIT.py
Original file line number Diff line number Diff line change
Expand Up @@ -950,15 +950,6 @@
False,
(),
),
(
r'/\bASCIIToUTF16\("(\\.|[^\\"])*"\)',
(
'base::ASCIIToUTF16 should not be used with a string literal.',
'Consider using a UTF16 string literal (u"...") instead.',
),
False,
(),
),
(
r'/\bUTF8ToUTF16\("(\\.|[^\\"])*"\)',
(
Expand Down
5 changes: 0 additions & 5 deletions PRESUBMIT_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -2334,8 +2334,6 @@ def testBannedCppFunctions(self):
['using namespace std; // nocheck']),
MockFile('some/cpp/comment/file.cc',
[' // A comment about `using namespace std;`']),
MockFile('ascii/to/utf16/banned.cc', ['ASCIIToUTF16("Hello World")']),
MockFile('ascii/to/utf16/allowed.cc', ['ASCIIToUTF16("Hello" + kWorld)']),
MockFile('utf8/to/utf16/banned.cc', [r'UTF8ToUTF16("Hello \" World")']),
MockFile('utf8/to/utf16/allowed.cc', ['UTF8ToUTF16(kHello + "World")']),
]
Expand All @@ -2353,9 +2351,6 @@ def testBannedCppFunctions(self):
self.assertFalse('some/cpp/nocheck/file.cc' in results[1].message)
self.assertFalse('some/cpp/comment/file.cc' in results[0].message)
self.assertFalse('some/cpp/comment/file.cc' in results[1].message)
self.assertTrue('ascii/to/utf16/banned.cc' in results[0].message)
self.assertFalse('ascii/to/utf16/allowed.cc' in results[0].message)
self.assertFalse('ascii/to/utf16/allowed.cc' in results[1].message)
self.assertTrue('utf8/to/utf16/banned.cc' in results[0].message)
self.assertFalse('utf8/to/utf16/allowed.cc' in results[0].message)
self.assertFalse('utf8/to/utf16/allowed.cc' in results[1].message)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,9 @@ namespace {

const char kTestUserEmail[] = "test@example.com";
const char kTestHostDeviceName[] = "Test Device";
const char16_t kTestHostDeviceName16[] = u"Test Device";
// This is the expected return value from GetChromeOSDeviceName() in tests.
const char kTestDeviceType[] = "Chrome device";
const char16_t kTestDeviceType[] = u"Chrome device";

class TestMessageCenter : public message_center::FakeMessageCenter {
public:
Expand Down Expand Up @@ -220,8 +221,7 @@ class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase {
std::u16string title = l10n_util::GetStringUTF16(
IDS_ASH_MULTI_DEVICE_WIFI_SYNC_AVAILABLE_TITLE);
std::u16string message = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_WIFI_SYNC_AVAILABLE_MESSAGE,
base::ASCIIToUTF16(kTestDeviceType));
IDS_ASH_MULTI_DEVICE_WIFI_SYNC_AVAILABLE_MESSAGE, kTestDeviceType);
EXPECT_EQ(title, kVisibleNotification->title());
EXPECT_EQ(message, kVisibleNotification->message());
}
Expand Down Expand Up @@ -306,25 +306,25 @@ class MultiDeviceNotificationPresenterTest : public NoSessionAshTestBase {
IDS_ASH_MULTI_DEVICE_SETUP_NEW_USER_POTENTIAL_HOST_EXISTS_TITLE);
message = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_SETUP_NEW_USER_POTENTIAL_HOST_EXISTS_MESSAGE,
base::ASCIIToUTF16(kTestDeviceType));
kTestDeviceType);
break;
case MultiDeviceNotificationPresenter::Status::
kExistingUserHostSwitchedNotificationVisible:
title = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_SETUP_EXISTING_USER_HOST_SWITCHED_TITLE,
base::ASCIIToUTF16(kTestHostDeviceName));
kTestHostDeviceName16);
message = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_SETUP_EXISTING_USER_HOST_SWITCHED_MESSAGE,
base::ASCIIToUTF16(kTestDeviceType));
kTestDeviceType);
break;
case MultiDeviceNotificationPresenter::Status::
kExistingUserNewChromebookNotificationVisible:
title = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_SETUP_EXISTING_USER_NEW_CHROME_DEVICE_ADDED_TITLE,
base::ASCIIToUTF16(kTestHostDeviceName));
kTestHostDeviceName16);
message = l10n_util::GetStringFUTF16(
IDS_ASH_MULTI_DEVICE_SETUP_EXISTING_USER_NEW_CHROME_DEVICE_ADDED_MESSAGE,
base::ASCIIToUTF16(kTestDeviceType));
kTestDeviceType);
break;
case MultiDeviceNotificationPresenter::Status::kNoNotificationVisible:
NOTREACHED();
Expand Down
10 changes: 5 additions & 5 deletions ash/system/power/peripheral_battery_listener_unittest.cc
Original file line number Diff line number Diff line change
Expand Up @@ -459,7 +459,7 @@ TEST_F(PeripheralBatteryListenerTest,
OnUpdatedBatteryLevel(AllOf(
AFIELD(&BI::key, Eq(kBluetoothDeviceId1)), AFIELD(&BI::level, Eq(5)),
AFIELD(&BI::type, Eq(BI::PeripheralType::kOther)),
AFIELD(&BI::name, Eq(base::ASCIIToUTF16(kBluetoothDeviceName1))),
AFIELD(&BI::name, Eq(kBluetoothDeviceName116)),
AFIELD(&BI::bluetooth_address, Eq(kBluetoothDeviceAddress1)))));

EXPECT_CALL(listener_observer_mock,
Expand All @@ -469,7 +469,7 @@ TEST_F(PeripheralBatteryListenerTest,
OnUpdatedBatteryLevel(AllOf(
AFIELD(&BI::key, Eq(kBluetoothDeviceId2)), AFIELD(&BI::level, Eq(0)),
AFIELD(&BI::type, Eq(BI::PeripheralType::kOther)),
AFIELD(&BI::name, Eq(base::ASCIIToUTF16(kBluetoothDeviceName2))),
AFIELD(&BI::name, Eq(kBluetoothDeviceName216)),
AFIELD(&BI::bluetooth_address, Eq(kBluetoothDeviceAddress2)))));

battery_listener_->DeviceBatteryChanged(mock_adapter_.get(),
Expand Down Expand Up @@ -497,7 +497,7 @@ TEST_F(PeripheralBatteryListenerTest,
OnUpdatedBatteryLevel(AllOf(
AFIELD(&BI::key, Eq(kBluetoothDeviceId1)), AFIELD(&BI::level, Eq(5)),
AFIELD(&BI::type, Eq(BI::PeripheralType::kOther)),
AFIELD(&BI::name, Eq(base::ASCIIToUTF16(kBluetoothDeviceName1))),
AFIELD(&BI::name, Eq(kBluetoothDeviceName116)),
AFIELD(&BI::bluetooth_address, Eq(kBluetoothDeviceAddress1)))));

EXPECT_CALL(listener_observer_mock,
Expand All @@ -507,7 +507,7 @@ TEST_F(PeripheralBatteryListenerTest,
OnUpdatedBatteryLevel(AllOf(
AFIELD(&BI::key, Eq(kBluetoothDeviceId2)), AFIELD(&BI::level, Eq(0)),
AFIELD(&BI::type, Eq(BI::PeripheralType::kOther)),
AFIELD(&BI::name, Eq(base::ASCIIToUTF16(kBluetoothDeviceName2))),
AFIELD(&BI::name, Eq(kBluetoothDeviceName216)),
AFIELD(&BI::bluetooth_address, Eq(kBluetoothDeviceAddress2)))));

battery_listener_->DeviceBatteryChanged(mock_adapter_.get(),
Expand Down Expand Up @@ -1160,7 +1160,7 @@ TEST_F(PeripheralBatteryListenerTest, BluetoothDoesNotDiscardZeros) {
OnUpdatedBatteryLevel(AllOf(
AFIELD(&BI::key, Eq(kBluetoothDeviceId1)), AFIELD(&BI::level, Eq(0)),
AFIELD(&BI::type, Eq(BI::PeripheralType::kOther)),
AFIELD(&BI::name, Eq(base::ASCIIToUTF16(kBluetoothDeviceName1))),
AFIELD(&BI::name, Eq(kBluetoothDeviceName116)),
AFIELD(&BI::bluetooth_address, Eq(kBluetoothDeviceAddress1)))));

battery_listener_->DeviceBatteryChanged(mock_adapter_.get(),
Expand Down
Loading

0 comments on commit dc3e1ec

Please sign in to comment.