Enable rotate style visibility animation for new style web contents modal dialog
[chromium-blink-merge.git] / net / disk_cache / mapped_file_unittest.cc
blob06f87601a76de2bacbcaf46b96b659dda66d8929
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file.
5 #include "base/basictypes.h"
6 #include "base/file_util.h"
7 #include "base/string_util.h"
8 #include "net/disk_cache/disk_cache_test_base.h"
9 #include "net/disk_cache/disk_cache_test_util.h"
10 #include "net/disk_cache/mapped_file.h"
11 #include "testing/gtest/include/gtest/gtest.h"
13 namespace {
15 // Implementation of FileIOCallback for the tests.
16 class FileCallbackTest: public disk_cache::FileIOCallback {
17 public:
18 FileCallbackTest(int id, MessageLoopHelper* helper, int* max_id)
19 : id_(id),
20 helper_(helper),
21 max_id_(max_id) {
23 virtual ~FileCallbackTest() {}
25 virtual void OnFileIOComplete(int bytes_copied) OVERRIDE;
27 private:
28 int id_;
29 MessageLoopHelper* helper_;
30 int* max_id_;
33 void FileCallbackTest::OnFileIOComplete(int bytes_copied) {
34 if (id_ > *max_id_) {
35 NOTREACHED();
36 helper_->set_callback_reused_error(true);
39 helper_->CallbackWasCalled();
42 } // namespace
44 TEST_F(DiskCacheTest, MappedFile_SyncIO) {
45 base::FilePath filename = cache_path_.AppendASCII("a_test");
46 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
47 ASSERT_TRUE(CreateCacheTestFile(filename));
48 ASSERT_TRUE(file->Init(filename, 8192));
50 char buffer1[20];
51 char buffer2[20];
52 CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
53 base::strlcpy(buffer1, "the data", arraysize(buffer1));
54 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 8192));
55 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 8192));
56 EXPECT_STREQ(buffer1, buffer2);
59 TEST_F(DiskCacheTest, MappedFile_AsyncIO) {
60 base::FilePath filename = cache_path_.AppendASCII("a_test");
61 scoped_refptr<disk_cache::MappedFile> file(new disk_cache::MappedFile);
62 ASSERT_TRUE(CreateCacheTestFile(filename));
63 ASSERT_TRUE(file->Init(filename, 8192));
65 int max_id = 0;
66 MessageLoopHelper helper;
67 FileCallbackTest callback(1, &helper, &max_id);
69 char buffer1[20];
70 char buffer2[20];
71 CacheTestFillBuffer(buffer1, sizeof(buffer1), false);
72 base::strlcpy(buffer1, "the data", arraysize(buffer1));
73 bool completed;
74 EXPECT_TRUE(file->Write(buffer1, sizeof(buffer1), 1024 * 1024, &callback,
75 &completed));
76 int expected = completed ? 0 : 1;
78 max_id = 1;
79 helper.WaitUntilCacheIoFinished(expected);
81 EXPECT_TRUE(file->Read(buffer2, sizeof(buffer2), 1024 * 1024, &callback,
82 &completed));
83 if (!completed)
84 expected++;
86 helper.WaitUntilCacheIoFinished(expected);
88 EXPECT_EQ(expected, helper.callbacks_called());
89 EXPECT_FALSE(helper.callback_reused_error());
90 EXPECT_STREQ(buffer1, buffer2);