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

Side by Side Diff: content/browser/loader/temporary_file_stream_unittest.cc

Issue 2785523002: Reduce/remove usage of BrowserThread in content/browser/loader. (Closed)
Patch Set: Fix unittests redness Created 3 years, 8 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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 "content/browser/loader/temporary_file_stream.h" 5 #include "content/browser/loader/temporary_file_stream.h"
6 6
7 #include <string.h> 7 #include <string.h>
8 #include <string> 8 #include <string>
9 #include <utility> 9 #include <utility>
10 10
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/files/file_path.h" 12 #include "base/files/file_path.h"
13 #include "base/files/file_util.h" 13 #include "base/files/file_util.h"
14 #include "base/macros.h" 14 #include "base/macros.h"
15 #include "base/run_loop.h" 15 #include "base/run_loop.h"
16 #include "base/threading/thread_task_runner_handle.h"
17 #include "content/browser/loader/loader_globals.h"
16 #include "content/public/test/test_browser_thread_bundle.h" 18 #include "content/public/test/test_browser_thread_bundle.h"
17 #include "net/base/file_stream.h" 19 #include "net/base/file_stream.h"
18 #include "net/base/io_buffer.h" 20 #include "net/base/io_buffer.h"
19 #include "net/base/net_errors.h" 21 #include "net/base/net_errors.h"
20 #include "net/base/test_completion_callback.h" 22 #include "net/base/test_completion_callback.h"
21 #include "storage/browser/blob/shareable_file_reference.h" 23 #include "storage/browser/blob/shareable_file_reference.h"
22 #include "testing/gtest/include/gtest/gtest.h" 24 #include "testing/gtest/include/gtest/gtest.h"
23 25
24 using storage::ShareableFileReference; 26 using storage::ShareableFileReference;
25 27
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
59 base::RunLoop loop_; 61 base::RunLoop loop_;
60 base::File::Error error_; 62 base::File::Error error_;
61 std::unique_ptr<net::FileStream> file_stream_; 63 std::unique_ptr<net::FileStream> file_stream_;
62 scoped_refptr<ShareableFileReference> deletable_file_; 64 scoped_refptr<ShareableFileReference> deletable_file_;
63 }; 65 };
64 66
65 } // namespace 67 } // namespace
66 68
67 TEST(TemporaryFileStreamTest, Basic) { 69 TEST(TemporaryFileStreamTest, Basic) {
68 TestBrowserThreadBundle thread_bundle(TestBrowserThreadBundle::IO_MAINLOOP); 70 TestBrowserThreadBundle thread_bundle(TestBrowserThreadBundle::IO_MAINLOOP);
71 // Dummy instance of the LoaderGlobals class to ensure that the UI and IO
72 // task runners are available for content/browser/loader code.
73 // TODO(ananta)
74 // Avoid this hack.
75 LoaderGlobals loader_globals(base::ThreadTaskRunnerHandle::Get(),
76 base::ThreadTaskRunnerHandle::Get());
69 77
70 // Create a temporary. 78 // Create a temporary.
71 WaitForFileStream file_stream_waiter; 79 WaitForFileStream file_stream_waiter;
72 CreateTemporaryFileStream(base::Bind(&WaitForFileStream::OnFileStreamCreated, 80 CreateTemporaryFileStream(base::Bind(&WaitForFileStream::OnFileStreamCreated,
73 base::Unretained(&file_stream_waiter))); 81 base::Unretained(&file_stream_waiter)));
74 file_stream_waiter.Wait(); 82 file_stream_waiter.Wait();
75 83
76 // The temporary should exist. 84 // The temporary should exist.
77 EXPECT_EQ(base::File::FILE_OK, file_stream_waiter.error()); 85 EXPECT_EQ(base::File::FILE_OK, file_stream_waiter.error());
78 base::FilePath file_path = file_stream_waiter.deletable_file()->path(); 86 base::FilePath file_path = file_stream_waiter.deletable_file()->path();
(...skipping 32 matching lines...) Expand 10 before | Expand all | Expand 10 after
111 119
112 // Release everything. The file should be gone now. 120 // Release everything. The file should be gone now.
113 file_stream_waiter.Release(); 121 file_stream_waiter.Release();
114 base::RunLoop().RunUntilIdle(); 122 base::RunLoop().RunUntilIdle();
115 123
116 // The temporary should be gone now. 124 // The temporary should be gone now.
117 EXPECT_FALSE(base::PathExists(file_path)); 125 EXPECT_FALSE(base::PathExists(file_path));
118 } 126 }
119 127
120 } // content 128 } // content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698