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

Side by Side Diff: net/base/file_stream_unittest.cc

Issue 1496493004: Revert of Tests: Simplify SequencedWorkerPoolOwner, call Shutdown on destructor. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 5 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
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 "net/base/file_stream.h" 5 #include "net/base/file_stream.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/callback.h" 8 #include "base/callback.h"
9 #include "base/files/file.h" 9 #include "base/files/file.h"
10 #include "base/files/file_util.h" 10 #include "base/files/file_util.h"
11 #include "base/message_loop/message_loop.h" 11 #include "base/message_loop/message_loop.h"
12 #include "base/path_service.h" 12 #include "base/path_service.h"
13 #include "base/run_loop.h" 13 #include "base/run_loop.h"
14 #include "base/strings/string_util.h" 14 #include "base/strings/string_util.h"
15 #include "base/synchronization/waitable_event.h" 15 #include "base/synchronization/waitable_event.h"
16 #include "base/test/sequenced_worker_pool_owner.h"
17 #include "base/test/test_timeouts.h" 16 #include "base/test/test_timeouts.h"
18 #include "base/thread_task_runner_handle.h" 17 #include "base/thread_task_runner_handle.h"
18 #include "base/threading/sequenced_worker_pool.h"
19 #include "base/threading/thread_restrictions.h" 19 #include "base/threading/thread_restrictions.h"
20 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
21 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
22 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
23 #include "net/log/test_net_log.h" 23 #include "net/log/test_net_log.h"
24 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
25 #include "testing/platform_test.h" 25 #include "testing/platform_test.h"
26 26
27 #if defined(OS_ANDROID) 27 #if defined(OS_ANDROID)
28 #include "base/test/test_file_util.h" 28 #include "base/test/test_file_util.h"
(...skipping 678 matching lines...) Expand 10 before | Expand all | Expand 10 after
707 EXPECT_LT(0, total_bytes_written); 707 EXPECT_LT(0, total_bytes_written);
708 EXPECT_EQ(kTestDataSize, total_bytes_written); 708 EXPECT_EQ(kTestDataSize, total_bytes_written);
709 709
710 stream.reset(); 710 stream.reset();
711 711
712 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size)); 712 EXPECT_TRUE(base::GetFileSize(temp_file_path(), &file_size));
713 EXPECT_EQ(kTestDataSize * 2, file_size); 713 EXPECT_EQ(kTestDataSize * 2, file_size);
714 } 714 }
715 715
716 TEST_F(FileStreamTest, OpenAndDelete) { 716 TEST_F(FileStreamTest, OpenAndDelete) {
717 base::SequencedWorkerPoolOwner pool_owner(1, "StreamTest"); 717 scoped_refptr<base::SequencedWorkerPool> pool(
718 new base::SequencedWorkerPool(1, "StreamTest"));
718 719
719 bool prev = base::ThreadRestrictions::SetIOAllowed(false); 720 bool prev = base::ThreadRestrictions::SetIOAllowed(false);
720 scoped_ptr<FileStream> stream(new FileStream(pool_owner.pool())); 721 scoped_ptr<FileStream> stream(new FileStream(pool.get()));
721 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE | 722 int flags = base::File::FLAG_OPEN | base::File::FLAG_WRITE |
722 base::File::FLAG_ASYNC; 723 base::File::FLAG_ASYNC;
723 TestCompletionCallback open_callback; 724 TestCompletionCallback open_callback;
724 int rv = stream->Open(temp_file_path(), flags, open_callback.callback()); 725 int rv = stream->Open(temp_file_path(), flags, open_callback.callback());
725 EXPECT_EQ(ERR_IO_PENDING, rv); 726 EXPECT_EQ(ERR_IO_PENDING, rv);
726 727
727 // Delete the stream without waiting for the open operation to be 728 // Delete the stream without waiting for the open operation to be
728 // complete. Should be safe. 729 // complete. Should be safe.
729 stream.reset(); 730 stream.reset();
730 731
731 // Force an operation through the pool. 732 // Force an operation through the pool.
732 scoped_ptr<FileStream> stream2(new FileStream(pool_owner.pool())); 733 scoped_ptr<FileStream> stream2(new FileStream(pool.get()));
733 TestCompletionCallback open_callback2; 734 TestCompletionCallback open_callback2;
734 rv = stream2->Open(temp_file_path(), flags, open_callback2.callback()); 735 rv = stream2->Open(temp_file_path(), flags, open_callback2.callback());
735 EXPECT_EQ(OK, open_callback2.GetResult(rv)); 736 EXPECT_EQ(OK, open_callback2.GetResult(rv));
736 stream2.reset(); 737 stream2.reset();
737 738
739 pool->Shutdown();
740
738 // open_callback won't be called. 741 // open_callback won't be called.
739 base::RunLoop().RunUntilIdle(); 742 base::RunLoop().RunUntilIdle();
740 EXPECT_FALSE(open_callback.have_result()); 743 EXPECT_FALSE(open_callback.have_result());
741 base::ThreadRestrictions::SetIOAllowed(prev); 744 base::ThreadRestrictions::SetIOAllowed(prev);
742 } 745 }
743 746
744 // Verify that Write() errors are mapped correctly. 747 // Verify that Write() errors are mapped correctly.
745 TEST_F(FileStreamTest, WriteError) { 748 TEST_F(FileStreamTest, WriteError) {
746 // Try opening file as read-only and then writing to it using FileStream. 749 // Try opening file as read-only and then writing to it using FileStream.
747 uint32_t flags = 750 uint32_t flags =
(...skipping 82 matching lines...) Expand 10 before | Expand all | Expand 10 after
830 total_bytes_read += rv; 833 total_bytes_read += rv;
831 data_read.append(buf->data(), rv); 834 data_read.append(buf->data(), rv);
832 } 835 }
833 EXPECT_EQ(file_size, total_bytes_read); 836 EXPECT_EQ(file_size, total_bytes_read);
834 } 837 }
835 #endif 838 #endif
836 839
837 } // namespace 840 } // namespace
838 841
839 } // namespace net 842 } // namespace net
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698