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

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

Issue 13409003: Hide ContentClient getters from embedders so that they they don't reuse content's embedder API. The… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: sync Created 7 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 | Annotate | Revision Log
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_impl.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"
(...skipping 34 matching lines...) Expand 10 before | Expand all | Expand 10 after
45 arraysize(kDummytResource)); 45 arraysize(kDummytResource));
46 } 46 }
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) {}
56 virtual ~WebUIDataSourceTest() {} 56 virtual ~WebUIDataSourceTest() {}
57 WebUIDataSourceImpl* 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();
76 SetContentClient(&client_); 75 SetContentClient(&client_);
77 WebUIDataSource* source = WebUIDataSourceImpl::Create("host"); 76 WebUIDataSource* source = WebUIDataSourceImpl::Create("host");
78 WebUIDataSourceImpl* source_impl = static_cast<WebUIDataSourceImpl*>( 77 WebUIDataSourceImpl* source_impl = static_cast<WebUIDataSourceImpl*>(
79 source); 78 source);
80 source_impl->disable_set_font_strings_for_testing(); 79 source_impl->disable_set_font_strings_for_testing();
81 source_ = make_scoped_refptr(source_impl); 80 source_ = make_scoped_refptr(source_impl);
82 } 81 }
83 82
84 virtual void TearDown() {
85 SetContentClient(old_client_);
86 }
87
88 // Store response for later comparisons. 83 // Store response for later comparisons.
89 void SendResult(base::RefCountedMemory* data) { 84 void SendResult(base::RefCountedMemory* data) {
90 result_data_ = data; 85 result_data_ = data;
91 } 86 }
92 87
93 scoped_refptr<WebUIDataSourceImpl> source_; 88 scoped_refptr<WebUIDataSourceImpl> source_;
94 TestClient client_; 89 TestClient client_;
95 ContentClient* old_client_;
96 }; 90 };
97 91
98 TEST_F(WebUIDataSourceTest, EmptyStrings) { 92 TEST_F(WebUIDataSourceTest, EmptyStrings) {
99 source()->SetJsonPath("strings.js"); 93 source()->SetJsonPath("strings.js");
100 StartDataRequest("strings.js"); 94 StartDataRequest("strings.js");
101 std::string result(reinterpret_cast<const char*>( 95 std::string result(reinterpret_cast<const char*>(
102 result_data_->front()), result_data_->size()); 96 result_data_->front()), result_data_->size());
103 EXPECT_NE(result.find("var templateData = {"), std::string::npos); 97 EXPECT_NE(result.find("var templateData = {"), std::string::npos);
104 EXPECT_NE(result.find("};"), std::string::npos); 98 EXPECT_NE(result.find("};"), std::string::npos);
105 } 99 }
(...skipping 45 matching lines...) Expand 10 before | Expand all | Expand 10 after
151 EXPECT_EQ(GetMimeType("foo"), html); 145 EXPECT_EQ(GetMimeType("foo"), html);
152 EXPECT_EQ(GetMimeType("foo.html"), html); 146 EXPECT_EQ(GetMimeType("foo.html"), html);
153 EXPECT_EQ(GetMimeType(".js"), js); 147 EXPECT_EQ(GetMimeType(".js"), js);
154 EXPECT_EQ(GetMimeType("foo.js"), js); 148 EXPECT_EQ(GetMimeType("foo.js"), js);
155 EXPECT_EQ(GetMimeType("js"), html); 149 EXPECT_EQ(GetMimeType("js"), html);
156 EXPECT_EQ(GetMimeType("foojs"), html); 150 EXPECT_EQ(GetMimeType("foojs"), html);
157 EXPECT_EQ(GetMimeType("foo.jsp"), html); 151 EXPECT_EQ(GetMimeType("foo.jsp"), html);
158 } 152 }
159 153
160 } // namespace content 154 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/site_instance_impl_unittest.cc ('k') | content/browser/worker_host/test/worker_browsertest.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698