chromium/components/os_crypt/sync/key_storage_kwallet_unittest.cc

// Copyright 2016 The Chromium Authors
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "components/os_crypt/sync/key_storage_kwallet.h"

#include "base/memory/raw_ptr.h"
#include "base/nix/xdg_util.h"
#include "build/branding_buildflags.h"
#include "components/os_crypt/sync/kwallet_dbus.h"
#include "dbus/message.h"
#include "dbus/mock_bus.h"
#include "dbus/mock_object_proxy.h"
#include "dbus/object_path.h"
#include "dbus/object_proxy.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

namespace {

_;
DoAll;
Return;
SaveArg;
SetArgPointee;
StrictMock;

constexpr KWalletDBus::Error SUCCESS =;
constexpr KWalletDBus::Error CANNOT_READ =;
constexpr KWalletDBus::Error CANNOT_CONTACT =;

// These names are not allowed to change in prod, unless we intentionally
// migrate.
#if BUILDFLAG(GOOGLE_CHROME_BRANDING)
const char kExpectedFolderName[] = "Chrome Keys";
const char kExpectedEntryName[] = "Chrome Safe Storage";
#else
const char kExpectedFolderName[] =;
const char kExpectedEntryName[] =;
#endif

const char kAppName[] =;

// Some KWallet operations use return codes. Success is 0.
constexpr int kSuccessReturnCode =;

// Environment-specific behavior is handled and tested with KWalletDBus, not
// here, but we still need a value to instantiate.
const base::nix::DesktopEnvironment kDesktopEnv =;

class MockKWalletDBus : public KWalletDBus {};

class KeyStorageKWalletTest : public testing::Test {};

TEST_F(KeyStorageKWalletTest, InitializeFolder) {}

// Chrome's folder in KWallet exists, but it doesn't contain the key. A new key
// will be generated.
TEST_F(KeyStorageKWalletTest, EmptyFolder) {}

// Chrome's folder in KWallet exists, but it contains a key of the wrong type.
// It will be cleared and a new key will be created.
TEST_F(KeyStorageKWalletTest, WrongEntryType) {}

TEST_F(KeyStorageKWalletTest, ExistingPassword) {}

TEST_F(KeyStorageKWalletTest, GenerateNewPassword) {}

// If an entry exists in KWallet but it's empty, generate a new key.
TEST_F(KeyStorageKWalletTest, GenerateNewPasswordWhenEmpty) {}

TEST_F(KeyStorageKWalletTest, InitKWalletNotEnabled) {}

TEST_F(KeyStorageKWalletTest, InitCannotStart) {}

TEST_F(KeyStorageKWalletTest, InitFailTwice) {}

TEST_F(KeyStorageKWalletTest, InitTryTwiceAndFail) {}

TEST_F(KeyStorageKWalletTest, InitTryTwiceAndSuccess) {}

// Tests for a dbus connection that fails after initialization.
// Any error is expected to return a `nullopt`.
class KeyStorageKWalletFailuresTest
    : public testing::TestWithParam<KWalletDBus::Error> {};

INSTANTIATE_TEST_SUITE_P();

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureOpen) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureHasFolder) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureCreateFolder) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureHasEntry) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureEntryType) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureReadPassword) {}

TEST_P(KeyStorageKWalletFailuresTest, PostInitFailureWritePassword) {}

}  // namespace