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

Side by Side Diff: extensions/browser/file_reader_unittest.cc

Issue 12578008: Move CrxFile, FileReader, ExtensionResource to src/extensions. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 7 years, 9 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 | « extensions/browser/file_reader.cc ('k') | extensions/common/DEPS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/bind_helpers.h" 6 #include "base/bind_helpers.h"
7 #include "base/file_util.h" 7 #include "base/file_util.h"
8 #include "base/files/file_path.h" 8 #include "base/files/file_path.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "base/path_service.h" 10 #include "base/path_service.h"
11 #include "chrome/browser/extensions/file_reader.h"
12 #include "chrome/common/chrome_paths.h" 11 #include "chrome/common/chrome_paths.h"
13 #include "chrome/common/extensions/extension.h"
14 #include "chrome/common/extensions/extension_resource.h"
15 #include "chrome/common/extensions/extension_test_util.h"
16 #include "content/public/test/test_browser_thread.h" 12 #include "content/public/test/test_browser_thread.h"
13 #include "extensions/browser/file_reader.h"
14 #include "extensions/common/extension_resource.h"
15 #include "extensions/common/id_util.h"
17 #include "testing/gtest/include/gtest/gtest.h" 16 #include "testing/gtest/include/gtest/gtest.h"
18 17
19 using content::BrowserThread; 18 using content::BrowserThread;
20 19
21 namespace { 20 namespace {
22 21
23 class FileReaderTest : public testing::Test { 22 class FileReaderTest : public testing::Test {
24 public: 23 public:
25 FileReaderTest() : file_thread_(BrowserThread::FILE) { 24 FileReaderTest() : file_thread_(BrowserThread::FILE) {
26 file_thread_.Start(); 25 file_thread_.Start();
(...skipping 22 matching lines...) Expand all
49 MessageLoop::current()->Quit(); 48 MessageLoop::current()->Quit();
50 } 49 }
51 50
52 bool succeeded_; 51 bool succeeded_;
53 std::string data_; 52 std::string data_;
54 }; 53 };
55 54
56 void RunBasicTest(const char* filename) { 55 void RunBasicTest(const char* filename) {
57 base::FilePath path; 56 base::FilePath path;
58 PathService::Get(chrome::DIR_TEST_DATA, &path); 57 PathService::Get(chrome::DIR_TEST_DATA, &path);
59 std::string extension_id = extension_test_util::MakeId("test"); 58 std::string extension_id = extensions::id_util::GenerateId("test");
60 ExtensionResource resource(extension_id, path, 59 extensions::ExtensionResource resource(
61 base::FilePath().AppendASCII(filename)); 60 extension_id, path, base::FilePath().AppendASCII(filename));
62 path = path.AppendASCII(filename); 61 path = path.AppendASCII(filename);
63 62
64 std::string file_contents; 63 std::string file_contents;
65 bool file_exists = file_util::ReadFileToString(path, &file_contents); 64 bool file_exists = file_util::ReadFileToString(path, &file_contents);
66 65
67 Receiver receiver; 66 Receiver receiver;
68 67
69 scoped_refptr<FileReader> file_reader( 68 scoped_refptr<FileReader> file_reader(
70 new FileReader(resource, receiver.NewCallback())); 69 new FileReader(resource, receiver.NewCallback()));
71 file_reader->Start(); 70 file_reader->Start();
72 71
73 MessageLoop::current()->Run(); 72 MessageLoop::current()->Run();
74 73
75 EXPECT_EQ(file_exists, receiver.succeeded()); 74 EXPECT_EQ(file_exists, receiver.succeeded());
76 EXPECT_EQ(file_contents, receiver.data()); 75 EXPECT_EQ(file_contents, receiver.data());
77 } 76 }
78 77
79 TEST_F(FileReaderTest, SmallFile) { 78 TEST_F(FileReaderTest, SmallFile) {
80 RunBasicTest("title1.html"); 79 RunBasicTest("title1.html");
81 } 80 }
82 81
83 TEST_F(FileReaderTest, BiggerFile) { 82 TEST_F(FileReaderTest, BiggerFile) {
84 RunBasicTest("download-test1.lib"); 83 RunBasicTest("download-test1.lib");
85 } 84 }
86 85
87 TEST_F(FileReaderTest, NonExistantFile) { 86 TEST_F(FileReaderTest, NonExistantFile) {
88 base::FilePath path; 87 base::FilePath path;
89 PathService::Get(chrome::DIR_TEST_DATA, &path); 88 PathService::Get(chrome::DIR_TEST_DATA, &path);
90 std::string extension_id = extension_test_util::MakeId("test"); 89 std::string extension_id = extensions::id_util::GenerateId("test");
91 ExtensionResource resource(extension_id, path, base::FilePath( 90 extensions::ExtensionResource resource(extension_id, path, base::FilePath(
92 FILE_PATH_LITERAL("file_that_does_not_exist"))); 91 FILE_PATH_LITERAL("file_that_does_not_exist")));
93 path = path.AppendASCII("file_that_does_not_exist"); 92 path = path.AppendASCII("file_that_does_not_exist");
94 93
95 Receiver receiver; 94 Receiver receiver;
96 95
97 scoped_refptr<FileReader> file_reader( 96 scoped_refptr<FileReader> file_reader(
98 new FileReader(resource, receiver.NewCallback())); 97 new FileReader(resource, receiver.NewCallback()));
99 file_reader->Start(); 98 file_reader->Start();
100 99
101 MessageLoop::current()->Run(); 100 MessageLoop::current()->Run();
102 101
103 EXPECT_FALSE(receiver.succeeded()); 102 EXPECT_FALSE(receiver.succeeded());
104 } 103 }
105 104
106 } // namespace 105 } // namespace
OLDNEW
« no previous file with comments | « extensions/browser/file_reader.cc ('k') | extensions/common/DEPS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698