OLD | NEW |
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 "chrome/browser/ui/webui/chrome_web_ui_data_source.h" | 8 #include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" |
| 9 #include "grit/common_resources.h" |
9 #include "grit/generated_resources.h" | 10 #include "grit/generated_resources.h" |
10 #include "grit/webui_resources.h" | |
11 #include "testing/gtest/include/gtest/gtest.h" | 11 #include "testing/gtest/include/gtest/gtest.h" |
12 | 12 |
13 class MockChromeWebUIDataSource : public ChromeWebUIDataSource { | 13 class MockChromeWebUIDataSource : public ChromeWebUIDataSource { |
14 public: | 14 public: |
15 MockChromeWebUIDataSource() | 15 MockChromeWebUIDataSource() |
16 : ChromeWebUIDataSource("host"), | 16 : ChromeWebUIDataSource("host"), |
17 result_data_(NULL) { | 17 result_data_(NULL) { |
18 } | 18 } |
19 | 19 |
20 void StartDataRequest(const std::string& path) { | 20 void StartDataRequest(const std::string& path) { |
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
70 source()->AddString("planet", ASCIIToUTF16("pluto")); | 70 source()->AddString("planet", ASCIIToUTF16("pluto")); |
71 source()->AddLocalizedString("button", IDS_OK); | 71 source()->AddLocalizedString("button", IDS_OK); |
72 source()->StartDataRequest("strings.js"); | 72 source()->StartDataRequest("strings.js"); |
73 std::string result(reinterpret_cast<const char*>( | 73 std::string result(reinterpret_cast<const char*>( |
74 source()->result_data_->front()), source()->result_data_->size()); | 74 source()->result_data_->front()), source()->result_data_->size()); |
75 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); | 75 EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); |
76 EXPECT_NE(result.find("\"button\":\"OK\""), std::string::npos); | 76 EXPECT_NE(result.find("\"button\":\"OK\""), std::string::npos); |
77 } | 77 } |
78 | 78 |
79 TEST_F(ChromeWebUIDataSourceTest, DefaultResource) { | 79 TEST_F(ChromeWebUIDataSourceTest, DefaultResource) { |
80 source()->set_default_resource(IDR_WEBUI_I18N_PROCESS_JS); | 80 source()->set_default_resource(IDR_I18N_PROCESS_JS); |
81 source()->StartDataRequest("foobar" ); | 81 source()->StartDataRequest("foobar" ); |
82 std::string result( | 82 std::string result( |
83 reinterpret_cast<const char*>(source()->result_data_->front()), | 83 reinterpret_cast<const char*>(source()->result_data_->front()), |
84 source()->result_data_->size()); | 84 source()->result_data_->size()); |
85 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); | 85 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); |
86 source()->StartDataRequest("strings.js"); | 86 source()->StartDataRequest("strings.js"); |
87 result = std::string( | 87 result = std::string( |
88 reinterpret_cast<const char*>(source()->result_data_->front()), | 88 reinterpret_cast<const char*>(source()->result_data_->front()), |
89 source()->result_data_->size()); | 89 source()->result_data_->size()); |
90 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); | 90 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); |
91 } | 91 } |
92 | 92 |
93 TEST_F(ChromeWebUIDataSourceTest, NamedResource) { | 93 TEST_F(ChromeWebUIDataSourceTest, NamedResource) { |
94 source()->set_default_resource(IDR_WEBUI_I18N_PROCESS_JS); | 94 source()->set_default_resource(IDR_I18N_PROCESS_JS); |
95 source()->add_resource_path("foobar", IDR_WEBUI_I18N_TEMPLATE_JS); | 95 source()->add_resource_path("foobar", IDR_I18N_TEMPLATE_JS); |
96 source()->StartDataRequest("foobar"); | 96 source()->StartDataRequest("foobar"); |
97 std::string result( | 97 std::string result( |
98 reinterpret_cast<const char*>(source()->result_data_->front()), | 98 reinterpret_cast<const char*>(source()->result_data_->front()), |
99 source()->result_data_->size()); | 99 source()->result_data_->size()); |
100 EXPECT_NE(result.find("var i18nTemplate"), std::string::npos); | 100 EXPECT_NE(result.find("var i18nTemplate"), std::string::npos); |
101 source()->StartDataRequest("strings.js"); | 101 source()->StartDataRequest("strings.js"); |
102 result = std::string( | 102 result = std::string( |
103 reinterpret_cast<const char*>(source()->result_data_->front()), | 103 reinterpret_cast<const char*>(source()->result_data_->front()), |
104 source()->result_data_->size()); | 104 source()->result_data_->size()); |
105 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); | 105 EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); |
106 } | 106 } |
107 | 107 |
108 TEST_F(ChromeWebUIDataSourceTest, MimeType) { | 108 TEST_F(ChromeWebUIDataSourceTest, MimeType) { |
109 const char* html = "text/html"; | 109 const char* html = "text/html"; |
110 const char* js = "application/javascript"; | 110 const char* js = "application/javascript"; |
111 EXPECT_EQ(source()->GetMimeType(""), html); | 111 EXPECT_EQ(source()->GetMimeType(""), html); |
112 EXPECT_EQ(source()->GetMimeType("foo"), html); | 112 EXPECT_EQ(source()->GetMimeType("foo"), html); |
113 EXPECT_EQ(source()->GetMimeType("foo.html"), html); | 113 EXPECT_EQ(source()->GetMimeType("foo.html"), html); |
114 EXPECT_EQ(source()->GetMimeType(".js"), js); | 114 EXPECT_EQ(source()->GetMimeType(".js"), js); |
115 EXPECT_EQ(source()->GetMimeType("foo.js"), js); | 115 EXPECT_EQ(source()->GetMimeType("foo.js"), js); |
116 EXPECT_EQ(source()->GetMimeType("js"), html); | 116 EXPECT_EQ(source()->GetMimeType("js"), html); |
117 EXPECT_EQ(source()->GetMimeType("foojs"), html); | 117 EXPECT_EQ(source()->GetMimeType("foojs"), html); |
118 EXPECT_EQ(source()->GetMimeType("foo.jsp"), html); | 118 EXPECT_EQ(source()->GetMimeType("foo.jsp"), html); |
119 } | 119 } |
OLD | NEW |