summaryrefslogtreecommitdiffstats
path: root/chromium/net/disk_cache/simple/simple_test_util.cc
blob: 2d3edcb22a16e5576afb8257824ab112b3fed8cb (plain)
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
// Copyright 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#include "net/disk_cache/simple/simple_test_util.h"

#include "base/files/file.h"
#include "base/files/file_path.h"
#include "net/disk_cache/simple/simple_util.h"

namespace disk_cache {
namespace simple_util {

bool CreateCorruptFileForTests(const std::string& key,
                               const base::FilePath& cache_path) {
  base::FilePath entry_file_path = cache_path.AppendASCII(
      disk_cache::simple_util::GetFilenameFromKeyAndFileIndex(key, 0));
  int flags = base::File::FLAG_CREATE_ALWAYS | base::File::FLAG_WRITE;
  base::File entry_file(entry_file_path, flags);

  if (!entry_file.IsValid())
    return false;

  return entry_file.Write(0, "dummy", 1) == 1;
}

}  // namespace simple_util
}  // namespace disk_cache