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

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

Issue 121033002: Update uses of UTF conversions in content/ to use the base:: namespace. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Created 6 years, 12 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/strings/utf_string_conversions.h" 7 #include "base/strings/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"
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
19 const char kDummyString[] = "foo"; 19 const char kDummyString[] = "foo";
20 const char kDummyDefaultResource[] = "<html>foo</html>"; 20 const char kDummyDefaultResource[] = "<html>foo</html>";
21 const char kDummytResource[] = "<html>blah</html>"; 21 const char kDummytResource[] = "<html>blah</html>";
22 22
23 class TestClient : public TestContentClient { 23 class TestClient : public TestContentClient {
24 public: 24 public:
25 TestClient() {} 25 TestClient() {}
26 virtual ~TestClient() {} 26 virtual ~TestClient() {}
27 27
28 virtual base::string16 GetLocalizedString(int message_id) const OVERRIDE { 28 virtual base::string16 GetLocalizedString(int message_id) const OVERRIDE {
29 if (message_id == kDummyStringId) 29 if (message_id == kDummyStringId)
30 return UTF8ToUTF16(kDummyString); 30 return base::UTF8ToUTF16(kDummyString);
31 return base::string16(); 31 return base::string16();
32 32
33 } 33 }
34 34
35 virtual base::RefCountedStaticMemory* GetDataResourceBytes( 35 virtual base::RefCountedStaticMemory* GetDataResourceBytes(
36 int resource_id) const OVERRIDE { 36 int resource_id) const OVERRIDE {
37 base::RefCountedStaticMemory* bytes = NULL; 37 base::RefCountedStaticMemory* bytes = NULL;
38 if (resource_id == kDummyDefaultResourceId) { 38 if (resource_id == kDummyDefaultResourceId) {
39 bytes = new base::RefCountedStaticMemory( 39 bytes = new base::RefCountedStaticMemory(
40 reinterpret_cast<const unsigned char*>(kDummyDefaultResource), 40 reinterpret_cast<const unsigned char*>(kDummyDefaultResource),
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
93 source()->SetJsonPath("strings.js"); 93 source()->SetJsonPath("strings.js");
94 StartDataRequest("strings.js"); 94 StartDataRequest("strings.js");
95 std::string result(reinterpret_cast<const char*>( 95 std::string result(reinterpret_cast<const char*>(
96 result_data_->front()), result_data_->size()); 96 result_data_->front()), result_data_->size());
97 EXPECT_NE(result.find("var templateData = {"), std::string::npos); 97 EXPECT_NE(result.find("var templateData = {"), std::string::npos);
98 EXPECT_NE(result.find("};"), std::string::npos); 98 EXPECT_NE(result.find("};"), std::string::npos);
99 } 99 }
100 100
101 TEST_F(WebUIDataSourceTest, SomeStrings) { 101 TEST_F(WebUIDataSourceTest, SomeStrings) {
102 source()->SetJsonPath("strings.js"); 102 source()->SetJsonPath("strings.js");
103 source()->AddString("planet", ASCIIToUTF16("pluto")); 103 source()->AddString("planet", base::ASCIIToUTF16("pluto"));
104 source()->AddLocalizedString("button", kDummyStringId); 104 source()->AddLocalizedString("button", kDummyStringId);
105 StartDataRequest("strings.js"); 105 StartDataRequest("strings.js");
106 std::string result(reinterpret_cast<const char*>( 106 std::string result(reinterpret_cast<const char*>(
107 result_data_->front()), result_data_->size()); 107 result_data_->front()), result_data_->size());
108 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); 108 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos);
109 EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos); 109 EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos);
110 } 110 }
111 111
112 TEST_F(WebUIDataSourceTest, DefaultResource) { 112 TEST_F(WebUIDataSourceTest, DefaultResource) {
113 source()->SetDefaultResource(kDummyDefaultResourceId); 113 source()->SetDefaultResource(kDummyDefaultResourceId);
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
145 EXPECT_EQ(GetMimeType("foo"), html); 145 EXPECT_EQ(GetMimeType("foo"), html);
146 EXPECT_EQ(GetMimeType("foo.html"), html); 146 EXPECT_EQ(GetMimeType("foo.html"), html);
147 EXPECT_EQ(GetMimeType(".js"), js); 147 EXPECT_EQ(GetMimeType(".js"), js);
148 EXPECT_EQ(GetMimeType("foo.js"), js); 148 EXPECT_EQ(GetMimeType("foo.js"), js);
149 EXPECT_EQ(GetMimeType("js"), html); 149 EXPECT_EQ(GetMimeType("js"), html);
150 EXPECT_EQ(GetMimeType("foojs"), html); 150 EXPECT_EQ(GetMimeType("foojs"), html);
151 EXPECT_EQ(GetMimeType("foo.jsp"), html); 151 EXPECT_EQ(GetMimeType("foo.jsp"), html);
152 } 152 }
153 153
154 } // namespace content 154 } // namespace content
OLDNEW
« no previous file with comments | « content/browser/web_contents/web_drag_source_mac.mm ('k') | content/browser/webui/web_ui_impl.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698