1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74
|
// 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.
#include "chrome/browser/device_notifications/device_connection_tracker_unittest.h"
#include "chrome/browser/hid/hid_connection_tracker_factory.h"
#include "chrome/browser/hid/hid_test_utils.h"
#include "chrome/test/base/testing_browser_process.h"
#include "testing/gtest/include/gtest/gtest.h"
class HidConnectionTrackerTest : public DeviceConnectionTrackerTestBase {
public:
HidConnectionTrackerTest() = default;
HidConnectionTrackerTest(const HidConnectionTrackerTest&) = delete;
HidConnectionTrackerTest& operator=(const HidConnectionTrackerTest&) = delete;
~HidConnectionTrackerTest() override = default;
void SetUp() override {
DeviceConnectionTrackerTestBase::SetUp();
auto hid_system_tray_icon = std::make_unique<TestHidSystemTrayIcon>();
TestingBrowserProcess::GetGlobal()->SetHidSystemTrayIcon(
std::move(hid_system_tray_icon));
}
void TearDown() override {
// Set the system tray icon to null to avoid uninteresting call to it during
// profile destruction.
TestingBrowserProcess::GetGlobal()->SetHidSystemTrayIcon(nullptr);
DeviceConnectionTrackerTestBase::TearDown();
}
DeviceConnectionTracker* GetDeviceConnectionTracker(Profile* profile,
bool create) override {
return HidConnectionTrackerFactory::GetForProfile(profile, create);
}
MockDeviceSystemTrayIcon* GetMockDeviceSystemTrayIcon() override {
TestHidSystemTrayIcon* test_hid_system_tray_icon =
static_cast<TestHidSystemTrayIcon*>(
TestingBrowserProcess::GetGlobal()->hid_system_tray_icon());
if (!test_hid_system_tray_icon) {
return nullptr;
}
return test_hid_system_tray_icon->mock_device_system_tray_icon();
}
};
#if BUILDFLAG(ENABLE_EXTENSIONS)
TEST_F(HidConnectionTrackerTest, DeviceConnectionExtensionOrigins) {
TestDeviceConnectionExtensionOrigins(/*has_system_tray_icon=*/true);
}
TEST_F(HidConnectionTrackerTest,
DeviceConnectionExtensionOriginsWithNullSystemTrayIcon) {
TestingBrowserProcess::GetGlobal()->SetHidSystemTrayIcon(nullptr);
TestDeviceConnectionExtensionOrigins(/*has_system_tray_icon=*/false);
}
TEST_F(HidConnectionTrackerTest, ProfileDestroyedExtensionOrigin) {
TestProfileDestroyedExtensionOrigin();
}
TEST_F(HidConnectionTrackerTest, WhitelistedGnubbyDev) {
TestSingleProfileWhitelistedExtension("gnubbyd-v3 dev",
"ckcendljdlmgnhghiaomidhiiclmapok");
}
TEST_F(HidConnectionTrackerTest, WhitelistedGnubbyProd) {
TestSingleProfileWhitelistedExtension("gnubbyd-v3 prod",
"lfboplenmmjcmpbkeemecobbadnmpfhi");
}
#endif // BUILDFLAG(ENABLE_EXTENSIONS)
|