chromium/third_party/crashpad/crashpad/client/crash_report_database_test.cc

// Copyright 2015 The Crashpad Authors
//
// Licensed under the Apache License, Version 2.0 (the "License");
// you may not use this file except in compliance with the License.
// You may obtain a copy of the License at
//
//     http://www.apache.org/licenses/LICENSE-2.0
//
// Unless required by applicable law or agreed to in writing, software
// distributed under the License is distributed on an "AS IS" BASIS,
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
// See the License for the specific language governing permissions and
// limitations under the License.

#include "client/crash_report_database.h"

#include "build/build_config.h"
#include "client/settings.h"
#include "gtest/gtest.h"
#include "test/errors.h"
#include "test/file.h"
#include "test/filesystem.h"
#include "test/scoped_temp_dir.h"
#include "util/file/file_io.h"
#include "util/file/filesystem.h"

#if BUILDFLAG(IS_IOS)
#include "util/mac/xattr.h"
#endif

namespace crashpad {
namespace test {
namespace {

class CrashReportDatabaseTest : public testing::Test {};

TEST_F(CrashReportDatabaseTest, Initialize) {}

TEST_F(CrashReportDatabaseTest, Settings) {}

TEST_F(CrashReportDatabaseTest, NewCrashReport) {}

TEST_F(CrashReportDatabaseTest, LookUpCrashReport) {}

TEST_F(CrashReportDatabaseTest, RecordUploadAttempt) {}

// This test covers both query functions since they are related.
TEST_F(CrashReportDatabaseTest, GetCompletedAndNotUploadedReports) {}

TEST_F(CrashReportDatabaseTest, DuelingUploads) {}

#if BUILDFLAG(IS_IOS)
TEST_F(CrashReportDatabaseTest, InterruptedIOSUploads) {
  CrashReportDatabase::Report report;
  CreateCrashReport(&report);

  std::unique_ptr<const CrashReportDatabase::UploadReport> upload_report;
  EXPECT_EQ(db()->GetReportForUploading(report.uuid, &upload_report),
            CrashReportDatabase::kNoError);

  // Set upload_start_time to 10 minutes ago.
  time_t ten_minutes_ago = time(nullptr) - 10 * 60;
  ASSERT_TRUE(
      WriteXattrTimeT(report.file_path,
                      "org.chromium.crashpad.database.upload_start_time",
                      ten_minutes_ago));

  std::vector<CrashReportDatabase::Report> reports;
  EXPECT_EQ(db()->GetPendingReports(&reports), CrashReportDatabase::kNoError);
  ASSERT_EQ(reports.size(), 1u);
  reports.clear();
  EXPECT_EQ(db()->GetCompletedReports(&reports), CrashReportDatabase::kNoError);
  EXPECT_TRUE(reports.empty());

  // Getting a stale report will automatically skip it.
  std::unique_ptr<const CrashReportDatabase::UploadReport> upload_report_2;
  EXPECT_EQ(db()->GetReportForUploading(report.uuid, &upload_report_2),
            CrashReportDatabase::kReportNotFound);
  EXPECT_FALSE(upload_report_2);

  // Confirm report was moved from pending to completed.
  EXPECT_EQ(db()->GetPendingReports(&reports), CrashReportDatabase::kNoError);
  EXPECT_TRUE(reports.empty());
  EXPECT_EQ(db()->GetCompletedReports(&reports), CrashReportDatabase::kNoError);
  ASSERT_EQ(reports.size(), 1u);

  EXPECT_EQ(db()->RecordUploadComplete(std::move(upload_report), std::string()),
            CrashReportDatabase::kReportNotFound);
}
#endif

TEST_F(CrashReportDatabaseTest, UploadAlreadyUploaded) {}

TEST_F(CrashReportDatabaseTest, MoveDatabase) {}

TEST_F(CrashReportDatabaseTest, ReportRemoved) {}

TEST_F(CrashReportDatabaseTest, DeleteReport) {}

TEST_F(CrashReportDatabaseTest, DeleteReportEmptyingDatabase) {}

TEST_F(CrashReportDatabaseTest, ReadEmptyDatabase) {}

TEST_F(CrashReportDatabaseTest, RequestUpload) {}

TEST_F(CrashReportDatabaseTest, Attachments) {}

TEST_F(CrashReportDatabaseTest, OrphanedAttachments) {}

// This test uses knowledge of the database format to break it, so it only
// applies to the unfified database implementation.
#if !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_WIN)
TEST_F(CrashReportDatabaseTest, CleanBrokenDatabase) {}
#endif  // !BUILDFLAG(IS_APPLE) && !BUILDFLAG(IS_WIN)

TEST_F(CrashReportDatabaseTest, TotalSize_MainReportOnly) {}

TEST_F(CrashReportDatabaseTest, GetReportSize_RightSizeWithAttachments) {}

}  // namespace
}  // namespace test
}  // namespace crashpad