Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(390)

Side by Side Diff: webkit/fileapi/local_file_stream_writer_unittest.cc

Issue 11595003: webkit: Update the calls from RunAllPending() to RunUntilIdle(). (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 8 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "webkit/fileapi/local_file_stream_writer.h" 5 #include "webkit/fileapi/local_file_stream_writer.h"
6 6
7 #include <string> 7 #include <string>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/file_util.h" 10 #include "base/file_util.h"
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after
75 } 75 }
76 76
77 } // namespace 77 } // namespace
78 78
79 TEST_F(LocalFileStreamWriterTest, Write) { 79 TEST_F(LocalFileStreamWriterTest, Write) {
80 FilePath path = CreateFileWithContent("file_a", ""); 80 FilePath path = CreateFileWithContent("file_a", "");
81 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0)); 81 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0));
82 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo")); 82 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
83 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "bar")); 83 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "bar"));
84 writer.reset(); 84 writer.reset();
85 MessageLoop::current()->RunAllPending(); 85 MessageLoop::current()->RunUntilIdle();
86 EXPECT_TRUE(file_util::PathExists(path)); 86 EXPECT_TRUE(file_util::PathExists(path));
87 EXPECT_EQ("foobar", GetFileContent(path)); 87 EXPECT_EQ("foobar", GetFileContent(path));
88 } 88 }
89 89
90 TEST_F(LocalFileStreamWriterTest, WriteMiddle) { 90 TEST_F(LocalFileStreamWriterTest, WriteMiddle) {
91 FilePath path = CreateFileWithContent("file_a", "foobar"); 91 FilePath path = CreateFileWithContent("file_a", "foobar");
92 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 2)); 92 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 2));
93 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx")); 93 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
94 writer.reset(); 94 writer.reset();
95 MessageLoop::current()->RunAllPending(); 95 MessageLoop::current()->RunUntilIdle();
96 EXPECT_TRUE(file_util::PathExists(path)); 96 EXPECT_TRUE(file_util::PathExists(path));
97 EXPECT_EQ("foxxxr", GetFileContent(path)); 97 EXPECT_EQ("foxxxr", GetFileContent(path));
98 } 98 }
99 99
100 TEST_F(LocalFileStreamWriterTest, WriteEnd) { 100 TEST_F(LocalFileStreamWriterTest, WriteEnd) {
101 FilePath path = CreateFileWithContent("file_a", "foobar"); 101 FilePath path = CreateFileWithContent("file_a", "foobar");
102 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 6)); 102 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 6));
103 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx")); 103 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "xxx"));
104 writer.reset(); 104 writer.reset();
105 MessageLoop::current()->RunAllPending(); 105 MessageLoop::current()->RunUntilIdle();
106 EXPECT_TRUE(file_util::PathExists(path)); 106 EXPECT_TRUE(file_util::PathExists(path));
107 EXPECT_EQ("foobarxxx", GetFileContent(path)); 107 EXPECT_EQ("foobarxxx", GetFileContent(path));
108 } 108 }
109 109
110 TEST_F(LocalFileStreamWriterTest, WriteFailForNonexistingFile) { 110 TEST_F(LocalFileStreamWriterTest, WriteFailForNonexistingFile) {
111 FilePath path = Path("file_a"); 111 FilePath path = Path("file_a");
112 ASSERT_FALSE(file_util::PathExists(path)); 112 ASSERT_FALSE(file_util::PathExists(path));
113 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0)); 113 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0));
114 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, WriteStringToWriter(writer.get(), "foo")); 114 EXPECT_EQ(net::ERR_FILE_NOT_FOUND, WriteStringToWriter(writer.get(), "foo"));
115 writer.reset(); 115 writer.reset();
116 MessageLoop::current()->RunAllPending(); 116 MessageLoop::current()->RunUntilIdle();
117 EXPECT_FALSE(file_util::PathExists(path)); 117 EXPECT_FALSE(file_util::PathExists(path));
118 } 118 }
119 119
120 TEST_F(LocalFileStreamWriterTest, CancelBeforeOperation) { 120 TEST_F(LocalFileStreamWriterTest, CancelBeforeOperation) {
121 FilePath path = Path("file_a"); 121 FilePath path = Path("file_a");
122 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0)); 122 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0));
123 // Cancel immediately fails when there's no in-flight operation. 123 // Cancel immediately fails when there's no in-flight operation.
124 int cancel_result = writer->Cancel(base::Bind(&NeverCalled)); 124 int cancel_result = writer->Cancel(base::Bind(&NeverCalled));
125 EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result); 125 EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result);
126 } 126 }
127 127
128 TEST_F(LocalFileStreamWriterTest, CancelAfterFinishedOperation) { 128 TEST_F(LocalFileStreamWriterTest, CancelAfterFinishedOperation) {
129 FilePath path = CreateFileWithContent("file_a", ""); 129 FilePath path = CreateFileWithContent("file_a", "");
130 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0)); 130 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0));
131 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo")); 131 EXPECT_EQ(net::OK, WriteStringToWriter(writer.get(), "foo"));
132 132
133 // Cancel immediately fails when there's no in-flight operation. 133 // Cancel immediately fails when there's no in-flight operation.
134 int cancel_result = writer->Cancel(base::Bind(&NeverCalled)); 134 int cancel_result = writer->Cancel(base::Bind(&NeverCalled));
135 EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result); 135 EXPECT_EQ(net::ERR_UNEXPECTED, cancel_result);
136 136
137 writer.reset(); 137 writer.reset();
138 MessageLoop::current()->RunAllPending(); 138 MessageLoop::current()->RunUntilIdle();
139 // Write operation is already completed. 139 // Write operation is already completed.
140 EXPECT_TRUE(file_util::PathExists(path)); 140 EXPECT_TRUE(file_util::PathExists(path));
141 EXPECT_EQ("foo", GetFileContent(path)); 141 EXPECT_EQ("foo", GetFileContent(path));
142 } 142 }
143 143
144 TEST_F(LocalFileStreamWriterTest, CancelWrite) { 144 TEST_F(LocalFileStreamWriterTest, CancelWrite) {
145 FilePath path = CreateFileWithContent("file_a", "foobar"); 145 FilePath path = CreateFileWithContent("file_a", "foobar");
146 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0)); 146 scoped_ptr<LocalFileStreamWriter> writer(new LocalFileStreamWriter(path, 0));
147 147
148 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer("xxx")); 148 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer("xxx"));
149 int result = writer->Write(buffer, buffer->size(), base::Bind(&NeverCalled)); 149 int result = writer->Write(buffer, buffer->size(), base::Bind(&NeverCalled));
150 ASSERT_EQ(net::ERR_IO_PENDING, result); 150 ASSERT_EQ(net::ERR_IO_PENDING, result);
151 151
152 net::TestCompletionCallback callback; 152 net::TestCompletionCallback callback;
153 writer->Cancel(callback.callback()); 153 writer->Cancel(callback.callback());
154 int cancel_result = callback.WaitForResult(); 154 int cancel_result = callback.WaitForResult();
155 EXPECT_EQ(net::OK, cancel_result); 155 EXPECT_EQ(net::OK, cancel_result);
156 } 156 }
OLDNEW
« no previous file with comments | « webkit/fileapi/file_system_url_request_job_unittest.cc ('k') | webkit/fileapi/local_file_system_operation_unittest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698