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

Side by Side Diff: content/browser/webui/web_ui_data_source_unittest.cc

Issue 12093012: Clean up of url data manager classes in content: move URLDataSourceImpl to its own file, move all t… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 7 years, 10 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 | « content/browser/webui/web_ui_data_source_impl.cc ('k') | content/content_browser.gypi » ('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) 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 "base/bind.h" 5 #include "base/bind.h"
6 #include "base/memory/ref_counted_memory.h" 6 #include "base/memory/ref_counted_memory.h"
7 #include "base/utf_string_conversions.h" 7 #include "base/utf_string_conversions.h"
8 #include "content/browser/webui/web_ui_data_source.h" 8 #include "content/browser/webui/web_ui_data_source_impl.h"
9 #include "content/test/test_content_client.h" 9 #include "content/test/test_content_client.h"
10 #include "testing/gtest/include/gtest/gtest.h" 10 #include "testing/gtest/include/gtest/gtest.h"
11 11
12 namespace content { 12 namespace content {
13 namespace { 13 namespace {
14 14
15 const int kDummyStringId = 123; 15 const int kDummyStringId = 123;
16 const int kDummyDefaultResourceId = 456; 16 const int kDummyDefaultResourceId = 456;
17 const int kDummyResourceId = 789; 17 const int kDummyResourceId = 789;
18 18
(...skipping 28 matching lines...) Expand all
47 return bytes; 47 return bytes;
48 } 48 }
49 }; 49 };
50 50
51 } 51 }
52 52
53 class WebUIDataSourceTest : public testing::Test { 53 class WebUIDataSourceTest : public testing::Test {
54 public: 54 public:
55 WebUIDataSourceTest() : result_data_(NULL), old_client_(NULL) {} 55 WebUIDataSourceTest() : result_data_(NULL), old_client_(NULL) {}
56 virtual ~WebUIDataSourceTest() {} 56 virtual ~WebUIDataSourceTest() {}
57 ChromeWebUIDataSource* source() { return source_.get(); } 57 WebUIDataSourceImpl* source() { return source_.get(); }
58 58
59 void StartDataRequest(const std::string& path) { 59 void StartDataRequest(const std::string& path) {
60 source_->StartDataRequest( 60 source_->StartDataRequest(
61 path, 61 path,
62 false, 62 false,
63 base::Bind(&WebUIDataSourceTest::SendResult, 63 base::Bind(&WebUIDataSourceTest::SendResult,
64 base::Unretained(this))); 64 base::Unretained(this)));
65 } 65 }
66 66
67 std::string GetMimeType(const std::string& path) const { 67 std::string GetMimeType(const std::string& path) const {
68 return source_->GetMimeType(path); 68 return source_->GetMimeType(path);
69 } 69 }
70 70
71 scoped_refptr<base::RefCountedMemory> result_data_; 71 scoped_refptr<base::RefCountedMemory> result_data_;
72 72
73 private: 73 private:
74 virtual void SetUp() { 74 virtual void SetUp() {
75 old_client_ = GetContentClient(); 75 old_client_ = GetContentClient();
76 SetContentClient(&client_); 76 SetContentClient(&client_);
77 WebUIDataSource* source = ChromeWebUIDataSource::Create("host"); 77 WebUIDataSource* source = WebUIDataSourceImpl::Create("host");
78 ChromeWebUIDataSource* source_impl = static_cast<ChromeWebUIDataSource*>( 78 WebUIDataSourceImpl* source_impl = static_cast<WebUIDataSourceImpl*>(
79 source); 79 source);
80 source_impl->disable_set_font_strings_for_testing(); 80 source_impl->disable_set_font_strings_for_testing();
81 source_ = make_scoped_refptr(source_impl); 81 source_ = make_scoped_refptr(source_impl);
82 } 82 }
83 83
84 virtual void TearDown() { 84 virtual void TearDown() {
85 SetContentClient(old_client_); 85 SetContentClient(old_client_);
86 } 86 }
87 87
88 // Store response for later comparisons. 88 // Store response for later comparisons.
89 void SendResult(base::RefCountedMemory* data) { 89 void SendResult(base::RefCountedMemory* data) {
90 result_data_ = data; 90 result_data_ = data;
91 } 91 }
92 92
93 scoped_refptr<ChromeWebUIDataSource> source_; 93 scoped_refptr<WebUIDataSourceImpl> source_;
94 TestClient client_; 94 TestClient client_;
95 ContentClient* old_client_; 95 ContentClient* old_client_;
96 }; 96 };
97 97
98 TEST_F(WebUIDataSourceTest, EmptyStrings) { 98 TEST_F(WebUIDataSourceTest, EmptyStrings) {
99 source()->SetJsonPath("strings.js"); 99 source()->SetJsonPath("strings.js");
100 StartDataRequest("strings.js"); 100 StartDataRequest("strings.js");
101 std::string result(reinterpret_cast<const char*>( 101 std::string result(reinterpret_cast<const char*>(
102 result_data_->front()), result_data_->size()); 102 result_data_->front()), result_data_->size());
103 EXPECT_NE(result.find("var templateData = {"), std::string::npos); 103 EXPECT_NE(result.find("var templateData = {"), std::string::npos);
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 EXPECT_EQ(GetMimeType("foo"), html); 151 EXPECT_EQ(GetMimeType("foo"), html);
152 EXPECT_EQ(GetMimeType("foo.html"), html); 152 EXPECT_EQ(GetMimeType("foo.html"), html);
153 EXPECT_EQ(GetMimeType(".js"), js); 153 EXPECT_EQ(GetMimeType(".js"), js);
154 EXPECT_EQ(GetMimeType("foo.js"), js); 154 EXPECT_EQ(GetMimeType("foo.js"), js);
155 EXPECT_EQ(GetMimeType("js"), html); 155 EXPECT_EQ(GetMimeType("js"), html);
156 EXPECT_EQ(GetMimeType("foojs"), html); 156 EXPECT_EQ(GetMimeType("foojs"), html);
157 EXPECT_EQ(GetMimeType("foo.jsp"), html); 157 EXPECT_EQ(GetMimeType("foo.jsp"), html);
158 } 158 }
159 159
160 } // namespace content 160 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/webui/web_ui_data_source_impl.cc ('k') | content/content_browser.gypi » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698