diff options
-rw-r--r-- | chrome/chrome_tests_unit.gypi | 1 | ||||
-rw-r--r-- | content/browser/webui/web_ui_data_source.cc | 6 | ||||
-rw-r--r-- | content/browser/webui/web_ui_data_source.h | 11 | ||||
-rw-r--r-- | content/browser/webui/web_ui_data_source_unittest.cc (renamed from chrome/browser/ui/webui/chrome_web_ui_data_source_unittest.cc) | 92 | ||||
-rw-r--r-- | content/content_browser.gypi | 18 | ||||
-rw-r--r-- | content/content_tests.gypi | 1 |
6 files changed, 94 insertions, 35 deletions
diff --git a/chrome/chrome_tests_unit.gypi b/chrome/chrome_tests_unit.gypi index 6d84c29..62ce459 100644 --- a/chrome/chrome_tests_unit.gypi +++ b/chrome/chrome_tests_unit.gypi @@ -1405,7 +1405,6 @@ 'browser/ui/views/tabs/tab_strip_unittest.cc', 'browser/ui/web_contents_modal_dialog_manager_unittest.cc', 'browser/ui/website_settings/website_settings_unittest.cc', - 'browser/ui/webui/chrome_web_ui_data_source_unittest.cc', 'browser/ui/webui/fileicon_source_unittest.cc', 'browser/ui/webui/ntp/android/partner_bookmarks_shim_unittest.cc', 'browser/ui/webui/ntp/suggestions_combiner_unittest.cc', diff --git a/content/browser/webui/web_ui_data_source.cc b/content/browser/webui/web_ui_data_source.cc index 4f1bfb6..523d217 100644 --- a/content/browser/webui/web_ui_data_source.cc +++ b/content/browser/webui/web_ui_data_source.cc @@ -73,7 +73,8 @@ ChromeWebUIDataSource::ChromeWebUIDataSource(const std::string& source_name) add_csp_(true), object_src_set_(false), frame_src_set_(false), - deny_xframe_options_(true) { + deny_xframe_options_(true), + disable_set_font_strings_(false) { } ChromeWebUIDataSource::~ChromeWebUIDataSource() { @@ -189,7 +190,8 @@ void ChromeWebUIDataSource::StartDataRequest( void ChromeWebUIDataSource::SendLocalizedStringsAsJSON( const content::URLDataSource::GotDataCallback& callback) { std::string template_data; - webui::SetFontAndTextDirection(&localized_strings_); + if (!disable_set_font_strings_) + webui::SetFontAndTextDirection(&localized_strings_); scoped_ptr<webui::UseVersion2> version2; if (json_js_format_v2_) diff --git a/content/browser/webui/web_ui_data_source.h b/content/browser/webui/web_ui_data_source.h index 94d09c9..040d2ba 100644 --- a/content/browser/webui/web_ui_data_source.h +++ b/content/browser/webui/web_ui_data_source.h @@ -17,6 +17,10 @@ #include "content/public/browser/url_data_source.h" #include "content/public/browser/web_ui_data_source.h" +namespace content { +class WebUIDataSourceTest; +} + // A data source that can help with implementing the common operations // needed by the chrome WEBUI settings/history/downloads pages. class CONTENT_EXPORT ChromeWebUIDataSource @@ -63,7 +67,7 @@ class CONTENT_EXPORT ChromeWebUIDataSource private: class InternalDataSource; friend class InternalDataSource; - friend class ChromeWebUIDataSourceTest; + friend class content::WebUIDataSourceTest; explicit ChromeWebUIDataSource(const std::string& source_name); @@ -76,6 +80,10 @@ class CONTENT_EXPORT ChromeWebUIDataSource bool is_incognito, const content::URLDataSource::GotDataCallback& callback); + void disable_set_font_strings_for_testing() { + disable_set_font_strings_ = true; + } + // The name of this source. // E.g., for favicons, this could be "favicon", which results in paths for // specific resources like "favicon/34" getting sent to this source. @@ -92,6 +100,7 @@ class CONTENT_EXPORT ChromeWebUIDataSource bool frame_src_set_; std::string frame_src_; bool deny_xframe_options_; + bool disable_set_font_strings_; DISALLOW_COPY_AND_ASSIGN(ChromeWebUIDataSource); }; diff --git a/chrome/browser/ui/webui/chrome_web_ui_data_source_unittest.cc b/content/browser/webui/web_ui_data_source_unittest.cc index 6c6c16e69..a4429ef 100644 --- a/chrome/browser/ui/webui/chrome_web_ui_data_source_unittest.cc +++ b/content/browser/webui/web_ui_data_source_unittest.cc @@ -5,22 +5,62 @@ #include "base/bind.h" #include "base/memory/ref_counted_memory.h" #include "base/utf_string_conversions.h" -#include "chrome/browser/ui/webui/chrome_web_ui_data_source.h" -#include "grit/generated_resources.h" -#include "grit/webui_resources.h" +#include "content/browser/webui/web_ui_data_source.h" +#include "content/test/test_content_client.h" #include "testing/gtest/include/gtest/gtest.h" -class ChromeWebUIDataSourceTest : public testing::Test { +namespace content { +namespace { + +const int kDummyStringId = 123; +const int kDummyDefaultResourceId = 456; +const int kDummyResourceId = 789; + +const char kDummyString[] = "foo"; +const char kDummyDefaultResource[] = "<html>foo</html>"; +const char kDummytResource[] = "<html>blah</html>"; + +class TestClient : public TestContentClient { + public: + TestClient() {} + virtual ~TestClient() {} + + virtual string16 GetLocalizedString(int message_id) const OVERRIDE { + if (message_id == kDummyStringId) + return UTF8ToUTF16(kDummyString); + return string16(); + + } + + virtual base::RefCountedStaticMemory* GetDataResourceBytes( + int resource_id) const OVERRIDE { + base::RefCountedStaticMemory* bytes = NULL; + if (resource_id == kDummyDefaultResourceId) { + bytes = new base::RefCountedStaticMemory( + reinterpret_cast<const unsigned char*>(kDummyDefaultResource), + arraysize(kDummyDefaultResource)); + } else if (resource_id == kDummyResourceId) { + bytes = new base::RefCountedStaticMemory( + reinterpret_cast<const unsigned char*>(kDummytResource), + arraysize(kDummytResource)); + } + return bytes; + } +}; + +} + +class WebUIDataSourceTest : public testing::Test { public: - ChromeWebUIDataSourceTest() : result_data_(NULL) {} - virtual ~ChromeWebUIDataSourceTest() {} + WebUIDataSourceTest() : result_data_(NULL), old_client_(NULL) {} + virtual ~WebUIDataSourceTest() {} ChromeWebUIDataSource* source() { return source_.get(); } void StartDataRequest(const std::string& path) { source_->StartDataRequest( path, false, - base::Bind(&ChromeWebUIDataSourceTest::SendResult, + base::Bind(&WebUIDataSourceTest::SendResult, base::Unretained(this))); } @@ -32,13 +72,17 @@ class ChromeWebUIDataSourceTest : public testing::Test { private: virtual void SetUp() { - content::WebUIDataSource* source = ChromeWebUIDataSource::Create("host"); + old_client_ = GetContentClient(); + SetContentClient(&client_); + WebUIDataSource* source = ChromeWebUIDataSource::Create("host"); ChromeWebUIDataSource* source_impl = static_cast<ChromeWebUIDataSource*>( source); + source_impl->disable_set_font_strings_for_testing(); source_ = make_scoped_refptr(source_impl); } virtual void TearDown() { + SetContentClient(old_client_); } // Store response for later comparisons. @@ -47,9 +91,11 @@ class ChromeWebUIDataSourceTest : public testing::Test { } scoped_refptr<ChromeWebUIDataSource> source_; + TestClient client_; + ContentClient* old_client_; }; -TEST_F(ChromeWebUIDataSourceTest, EmptyStrings) { +TEST_F(WebUIDataSourceTest, EmptyStrings) { source()->SetJsonPath("strings.js"); StartDataRequest("strings.js"); std::string result(reinterpret_cast<const char*>( @@ -58,47 +104,47 @@ TEST_F(ChromeWebUIDataSourceTest, EmptyStrings) { EXPECT_NE(result.find("};"), std::string::npos); } -TEST_F(ChromeWebUIDataSourceTest, SomeStrings) { +TEST_F(WebUIDataSourceTest, SomeStrings) { source()->SetJsonPath("strings.js"); source()->AddString("planet", ASCIIToUTF16("pluto")); - source()->AddLocalizedString("button", IDS_OK); + source()->AddLocalizedString("button", kDummyStringId); StartDataRequest("strings.js"); std::string result(reinterpret_cast<const char*>( result_data_->front()), result_data_->size()); EXPECT_NE(result.find("\"planet\":\"pluto\""), std::string::npos); - EXPECT_NE(result.find("\"button\":\"OK\""), std::string::npos); + EXPECT_NE(result.find("\"button\":\"foo\""), std::string::npos); } -TEST_F(ChromeWebUIDataSourceTest, DefaultResource) { - source()->SetDefaultResource(IDR_WEBUI_I18N_PROCESS_JS); +TEST_F(WebUIDataSourceTest, DefaultResource) { + source()->SetDefaultResource(kDummyDefaultResourceId); StartDataRequest("foobar" ); std::string result( reinterpret_cast<const char*>(result_data_->front()), result_data_->size()); - EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); + EXPECT_NE(result.find(kDummyDefaultResource), std::string::npos); StartDataRequest("strings.js"); result = std::string( reinterpret_cast<const char*>(result_data_->front()), result_data_->size()); - EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); + EXPECT_NE(result.find(kDummyDefaultResource), std::string::npos); } -TEST_F(ChromeWebUIDataSourceTest, NamedResource) { - source()->SetDefaultResource(IDR_WEBUI_I18N_PROCESS_JS); - source()->AddResourcePath("foobar", IDR_WEBUI_I18N_TEMPLATE_JS); +TEST_F(WebUIDataSourceTest, NamedResource) { + source()->SetDefaultResource(kDummyDefaultResourceId); + source()->AddResourcePath("foobar", kDummyResourceId); StartDataRequest("foobar"); std::string result( reinterpret_cast<const char*>(result_data_->front()), result_data_->size()); - EXPECT_NE(result.find("var i18nTemplate"), std::string::npos); + EXPECT_NE(result.find(kDummytResource), std::string::npos); StartDataRequest("strings.js"); result = std::string( reinterpret_cast<const char*>(result_data_->front()), result_data_->size()); - EXPECT_NE(result.find("i18nTemplate.process"), std::string::npos); + EXPECT_NE(result.find(kDummyDefaultResource), std::string::npos); } -TEST_F(ChromeWebUIDataSourceTest, MimeType) { +TEST_F(WebUIDataSourceTest, MimeType) { const char* html = "text/html"; const char* js = "application/javascript"; EXPECT_EQ(GetMimeType(""), html); @@ -110,3 +156,5 @@ TEST_F(ChromeWebUIDataSourceTest, MimeType) { EXPECT_EQ(GetMimeType("foojs"), html); EXPECT_EQ(GetMimeType("foo.jsp"), html); } + +} // namespace content diff --git a/content/content_browser.gypi b/content/content_browser.gypi index 68ca6a4..018a3d2 100644 --- a/content/content_browser.gypi +++ b/content/content_browser.gypi @@ -832,8 +832,17 @@ 'browser/system_message_window_win.h', 'browser/tcmalloc_internals_request_job.cc', 'browser/tcmalloc_internals_request_job.h', + 'browser/trace_controller_impl.cc', + 'browser/trace_controller_impl.h', + 'browser/trace_message_filter.cc', + 'browser/trace_message_filter.h', + 'browser/trace_subscriber_stdio.cc', + 'browser/trace_subscriber_stdio.h', 'browser/udev_linux.cc', 'browser/udev_linux.h', + 'browser/user_metrics.cc', + 'browser/utility_process_host_impl.cc', + 'browser/utility_process_host_impl.h', 'browser/web_contents/debug_urls.cc', 'browser/web_contents/debug_urls.h', 'browser/web_contents/drag_utils_gtk.cc', @@ -876,15 +885,6 @@ 'browser/web_contents/web_drag_source_win.h', 'browser/web_contents/web_drag_utils_win.cc', 'browser/web_contents/web_drag_utils_win.h', - 'browser/trace_controller_impl.cc', - 'browser/trace_controller_impl.h', - 'browser/trace_message_filter.cc', - 'browser/trace_message_filter.h', - 'browser/trace_subscriber_stdio.cc', - 'browser/trace_subscriber_stdio.h', - 'browser/user_metrics.cc', - 'browser/utility_process_host_impl.cc', - 'browser/utility_process_host_impl.h', 'browser/webui/shared_resources_data_source.cc', 'browser/webui/shared_resources_data_source.h', 'browser/webui/url_data_manager.cc', diff --git a/content/content_tests.gypi b/content/content_tests.gypi index c77d4f5..d9cb693 100644 --- a/content/content_tests.gypi +++ b/content/content_tests.gypi @@ -342,6 +342,7 @@ 'browser/web_contents/web_contents_view_mac_unittest.mm', 'browser/web_contents/web_drag_dest_mac_unittest.mm', 'browser/web_contents/web_drag_source_mac_unittest.mm', + 'browser/webui/web_ui_data_source_unittest.cc', 'browser/webui/web_ui_message_handler_unittest.cc', 'common/android/address_parser_unittest.cc', 'common/cc_messages_unittest.cc', |