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

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

Issue 16155009: Update webkit/ to use scoped_refptr<T>::get() rather than implicit "operator T*" (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 7 years, 6 months 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/browser/fileapi/local_file_stream_writer.h" 5 #include "webkit/browser/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 19 matching lines...) Expand all
30 30
31 protected: 31 protected:
32 base::FilePath Path(const std::string& name) { 32 base::FilePath Path(const std::string& name) {
33 return temp_dir_.path().AppendASCII(name); 33 return temp_dir_.path().AppendASCII(name);
34 } 34 }
35 35
36 int WriteStringToWriter(LocalFileStreamWriter* writer, 36 int WriteStringToWriter(LocalFileStreamWriter* writer,
37 const std::string& data) { 37 const std::string& data) {
38 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer(data)); 38 scoped_refptr<net::StringIOBuffer> buffer(new net::StringIOBuffer(data));
39 scoped_refptr<net::DrainableIOBuffer> drainable( 39 scoped_refptr<net::DrainableIOBuffer> drainable(
40 new net::DrainableIOBuffer(buffer, buffer->size())); 40 new net::DrainableIOBuffer(buffer.get(), buffer->size()));
41 41
42 while (drainable->BytesRemaining() > 0) { 42 while (drainable->BytesRemaining() > 0) {
43 net::TestCompletionCallback callback; 43 net::TestCompletionCallback callback;
44 int result = writer->Write(drainable, drainable->BytesRemaining(), 44 int result = writer->Write(
45 callback.callback()); 45 drainable.get(), drainable->BytesRemaining(), callback.callback());
46 if (result == net::ERR_IO_PENDING) 46 if (result == net::ERR_IO_PENDING)
47 result = callback.WaitForResult(); 47 result = callback.WaitForResult();
48 if (result <= 0) 48 if (result <= 0)
49 return result; 49 return result;
50 drainable->DidConsume(result); 50 drainable->DidConsume(result);
51 } 51 }
52 return net::OK; 52 return net::OK;
53 } 53 }
54 54
55 std::string GetFileContent(const base::FilePath& path) { 55 std::string GetFileContent(const base::FilePath& path) {
(...skipping 83 matching lines...) Expand 10 before | Expand all | Expand 10 after
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 base::FilePath path = CreateFileWithContent("file_a", "foobar"); 145 base::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 =
150 writer->Write(buffer.get(), buffer->size(), base::Bind(&NeverCalled));
150 ASSERT_EQ(net::ERR_IO_PENDING, result); 151 ASSERT_EQ(net::ERR_IO_PENDING, result);
151 152
152 net::TestCompletionCallback callback; 153 net::TestCompletionCallback callback;
153 writer->Cancel(callback.callback()); 154 writer->Cancel(callback.callback());
154 int cancel_result = callback.WaitForResult(); 155 int cancel_result = callback.WaitForResult();
155 EXPECT_EQ(net::OK, cancel_result); 156 EXPECT_EQ(net::OK, cancel_result);
156 } 157 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698