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: chrome/browser/net/file_reader_unittest.cc

Issue 256022: Loads local resources from current locale subtree if available, if not it fal... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 11 years, 2 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
« no previous file with comments | « chrome/browser/net/file_reader.cc ('k') | chrome/browser/views/browser_actions_container.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2009 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.
4
5 #include "base/file_util.h"
6 #include "base/message_loop.h"
7 #include "base/path_service.h"
8 #include "chrome/browser/chrome_thread.h"
9 #include "chrome/browser/net/file_reader.h"
10 #include "chrome/common/chrome_paths.h"
11 #include "testing/gtest/include/gtest/gtest.h"
12
13 namespace {
14
15 class FileReaderTest : public testing::Test {
16 public:
17 FileReaderTest() : file_thread_(ChromeThread::FILE) {
18 file_thread_.Start();
19 }
20 private:
21 MessageLoop message_loop_;
22 ChromeThread file_thread_;
23 };
24
25 class Receiver {
26 public:
27 Receiver() : succeeded_(false) {
28 }
29
30 FileReader::Callback* NewCallback() {
31 return ::NewCallback(this, &Receiver::DidReadFile);
32 }
33
34 bool succeeded() const { return succeeded_; }
35 const std::string& data() const { return data_; }
36
37 private:
38 void DidReadFile(bool success, const std::string& data) {
39 succeeded_ = success;
40 data_ = data;
41 MessageLoop::current()->Quit();
42 }
43
44 bool succeeded_;
45 std::string data_;
46 };
47
48 void RunBasicTest(const char* filename) {
49 FilePath path;
50 PathService::Get(chrome::DIR_TEST_DATA, &path);
51 path = path.AppendASCII(filename);
52
53 std::string file_contents;
54 bool file_exists = file_util::ReadFileToString(path, &file_contents);
55
56 Receiver receiver;
57
58 scoped_refptr<FileReader> file_reader(
59 new FileReader(path, receiver.NewCallback()));
60 file_reader->Start();
61
62 MessageLoop::current()->Run();
63
64 EXPECT_EQ(file_exists, receiver.succeeded());
65 EXPECT_EQ(file_contents, receiver.data());
66 }
67
68 TEST_F(FileReaderTest, SmallFile) {
69 RunBasicTest("title1.html");
70 }
71
72 TEST_F(FileReaderTest, BiggerFile) {
73 RunBasicTest("download-test1.lib");
74 }
75
76 TEST_F(FileReaderTest, NonExistantFile) {
77 FilePath path;
78 PathService::Get(chrome::DIR_TEST_DATA, &path);
79 path = path.AppendASCII("file_that_does_not_exist");
80
81 Receiver receiver;
82
83 scoped_refptr<FileReader> file_reader(
84 new FileReader(path, receiver.NewCallback()));
85 file_reader->Start();
86
87 MessageLoop::current()->Run();
88
89 EXPECT_FALSE(receiver.succeeded());
90 }
91
92 } // namespace
OLDNEW
« no previous file with comments | « chrome/browser/net/file_reader.cc ('k') | chrome/browser/views/browser_actions_container.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698