chromium/extensions/browser/api/feedback_private/feedback_service_unittest.cc

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

#include "extensions/browser/api/feedback_private/feedback_service.h"

#include "base/check.h"
#include "base/files/file_path.h"
#include "base/files/file_util.h"
#include "base/files/scoped_temp_dir.h"
#include "base/memory/weak_ptr.h"
#include "base/run_loop.h"
#include "base/task/thread_pool/thread_pool_instance.h"
#include "base/test/mock_callback.h"
#include "build/build_config.h"
#include "components/feedback/feedback_data.h"
#include "components/feedback/feedback_report.h"
#include "content/public/test/test_utils.h"
#include "extensions/browser/api/feedback_private/mock_feedback_service.h"
#include "extensions/browser/api_unittest.h"
#include "extensions/shell/browser/api/feedback_private/shell_feedback_private_delegate.h"
#include "services/network/public/cpp/shared_url_loader_factory.h"
#include "services/network/public/cpp/weak_wrapper_shared_url_loader_factory.h"
#include "services/network/test/test_url_loader_factory.h"
#include "testing/gmock/include/gmock/gmock.h"
#include "testing/gtest/include/gtest/gtest.h"

#if BUILDFLAG(IS_CHROMEOS_ASH)
#include "chromeos/ash/components/dbus/debug_daemon/debug_daemon_client.h"
#include "components/user_manager/fake_user_manager.h"
#include "components/user_manager/scoped_user_manager.h"
#include "components/user_manager/user_manager.h"
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

namespace extensions {

FeedbackData;
FeedbackUploader;
_;
StrictMock;

namespace {

const std::string kFakeKey =;
const std::string kFakeValue =;
const std::string kTabTitleValue =;
const std::string kLacrosMemUsageWithTitleKey =;

class MockFeedbackUploader : public FeedbackUploader {};

class MockFeedbackPrivateDelegate : public ShellFeedbackPrivateDelegate {};

#if BUILDFLAG(IS_CHROMEOS_ASH)
const FeedbackCommon::AttachedFile* FindAttachment(
    std::string_view name,
    const scoped_refptr<FeedbackData>& feedback_data) {
  size_t num_attachments = feedback_data->attachments();
  for (size_t i = 0; i < num_attachments; i++) {
    const FeedbackCommon::AttachedFile* file = feedback_data->attachment(i);
    if (file->name == name) {
      return file;
    }
  }
  return nullptr;
}

void VerifyAttachment(std::string_view name,
                      std::string_view data,
                      const scoped_refptr<FeedbackData>& feedback_data) {
  const auto* attachment = FindAttachment(name, feedback_data);
  ASSERT_TRUE(attachment);
  EXPECT_EQ(name, attachment->name);
  EXPECT_EQ(data, attachment->data);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace

class FeedbackServiceTest : public ApiUnitTest {};

TEST_F(FeedbackServiceTest, SendFeedbackWithoutSysInfo) {}

TEST_F(FeedbackServiceTest, SendFeedbackLoadSysInfo) {}

// TODO(crbug.com/40908623): Re-enable this test
TEST_F(FeedbackServiceTest, DISABLED_SendFeedbackDoNotSendTabTitles) {}

TEST_F(FeedbackServiceTest, SendFeedbackDoSendTabTitles) {}

TEST_F(FeedbackServiceTest, SendFeedbackAutofillMetadata) {}

#if BUILDFLAG(IS_CHROMEOS_ASH)
TEST_F(FeedbackServiceTest, SendFeedbackWithWifiDebugLogs) {
  TestSendFeedbackConcerningWifiDebugLogs(/*send_wifi_debug_logs=*/true);
}

TEST_F(FeedbackServiceTest, SendFeedbackWithoutWifiDebugLogs) {
  TestSendFeedbackConcerningWifiDebugLogs(/*send_wifi_debug_logs=*/false);
}

TEST_F(FeedbackServiceTest, SendFeedbackWithBluetoothDebugLogs) {
  TestSendFeedbackConcerningBluetoothDebugLogs(/*send_bluetooth_logs=*/true);
}

TEST_F(FeedbackServiceTest, SendFeedbackWithoutBluetoothDebugLogs) {
  TestSendFeedbackConcerningBluetoothDebugLogs(/*send_bluetooth_logs=*/false);
}
#endif  // BUILDFLAG(IS_CHROMEOS_ASH)

}  // namespace extensions