diff options
author | abhishek.a21@samsung.com <abhishek.a21@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-04 18:48:46 +0000 |
---|---|---|
committer | abhishek.a21@samsung.com <abhishek.a21@samsung.com@0039d316-1c4b-4281-b951-d872f2087c98> | 2014-08-04 18:48:46 +0000 |
commit | 61ff6ae4a377fd69955f524db79a4112dc5b3732 (patch) | |
tree | e16131b4818b6120f3297e4420a22655767b43f5 | |
parent | e5f88338dc05542758f9b542c3a3c3451653205e (diff) | |
download | chromium_src-61ff6ae4a377fd69955f524db79a4112dc5b3732.zip chromium_src-61ff6ae4a377fd69955f524db79a4112dc5b3732.tar.gz chromium_src-61ff6ae4a377fd69955f524db79a4112dc5b3732.tar.bz2 |
Migrate TestCommon to Chromium c++ style and remove un-used header.
Changes:
1) Run clang-format through source and header files.
2) Rename data member variables to use unix_hacker_ style.
3) Rename methods to use CamelCase style.
4) Rename file name to test_common.
5) Removed un-used test_common header.
BUG=331299
Review URL: https://codereview.chromium.org/436133002
git-svn-id: svn://svn.chromium.org/chrome/trunk/src@287382 0039d316-1c4b-4281-b951-d872f2087c98
19 files changed, 86 insertions, 103 deletions
diff --git a/content/content_shell.gypi b/content/content_shell.gypi index 48e29a3..b7f25a7 100644 --- a/content/content_shell.gypi +++ b/content/content_shell.gypi @@ -175,8 +175,6 @@ 'shell/renderer/shell_render_process_observer.h', 'shell/renderer/shell_render_view_observer.cc', 'shell/renderer/shell_render_view_observer.h', - 'shell/renderer/test_runner/TestCommon.cpp', - 'shell/renderer/test_runner/TestCommon.h', 'shell/renderer/test_runner/TestInterfaces.cpp', 'shell/renderer/test_runner/TestInterfaces.h', 'shell/renderer/test_runner/TestPlugin.cpp', @@ -228,6 +226,8 @@ 'shell/renderer/test_runner/notification_presenter.h', 'shell/renderer/test_runner/spell_check_client.cc', 'shell/renderer/test_runner/spell_check_client.h', + 'shell/renderer/test_runner/test_common.cc', + 'shell/renderer/test_runner/test_common.h', 'shell/renderer/test_runner/test_runner.cc', 'shell/renderer/test_runner/test_runner.h', 'shell/renderer/test_runner/text_input_controller.cc', diff --git a/content/shell/BUILD.gn b/content/shell/BUILD.gn index d7e0573..591e395 100644 --- a/content/shell/BUILD.gn +++ b/content/shell/BUILD.gn @@ -125,8 +125,6 @@ static_library("content_shell_lib") { "renderer/shell_render_process_observer.h", "renderer/shell_render_view_observer.cc", "renderer/shell_render_view_observer.h", - "renderer/test_runner/TestCommon.cpp", - "renderer/test_runner/TestCommon.h", "renderer/test_runner/TestInterfaces.cpp", "renderer/test_runner/TestInterfaces.h", "renderer/test_runner/TestPlugin.cpp", @@ -178,6 +176,8 @@ static_library("content_shell_lib") { "renderer/test_runner/notification_presenter.h", "renderer/test_runner/spell_check_client.cc", "renderer/test_runner/spell_check_client.h", + "renderer/test_runner/test_common.cc", + "renderer/test_runner/test_common.h", "renderer/test_runner/test_runner.cc", "renderer/test_runner/test_runner.h", "renderer/test_runner/text_input_controller.cc", diff --git a/content/shell/renderer/test_runner/TestCommon.cpp b/content/shell/renderer/test_runner/TestCommon.cpp deleted file mode 100644 index a4976a0..0000000 --- a/content/shell/renderer/test_runner/TestCommon.cpp +++ /dev/null @@ -1,35 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#include "content/shell/renderer/test_runner/TestCommon.h" - -namespace content { - -namespace { - -const char layoutTestsPattern[] = "/LayoutTests/"; -const std::string::size_type layoutTestsPatternSize = sizeof(layoutTestsPattern) - 1; -const char fileUrlPattern[] = "file:/"; -const char fileTestPrefix[] = "(file test):"; -const char dataUrlPattern[] = "data:"; -const std::string::size_type dataUrlPatternSize = sizeof(dataUrlPattern) - 1; - -} // namespace - -std::string normalizeLayoutTestURL(const std::string& url) -{ - std::string result = url; - size_t pos; - if (!url.find(fileUrlPattern) && ((pos = url.find(layoutTestsPattern)) != std::string::npos)) { - // adjust file URLs to match upstream results. - result.replace(0, pos + layoutTestsPatternSize, fileTestPrefix); - } else if (!url.find(dataUrlPattern)) { - // URL-escape data URLs to match results upstream. - std::string path = url.substr(dataUrlPatternSize); - result.replace(dataUrlPatternSize, url.length(), path); - } - return result; -} - -} // namespace content diff --git a/content/shell/renderer/test_runner/TestCommon.h b/content/shell/renderer/test_runner/TestCommon.h deleted file mode 100644 index 7144158..0000000 --- a/content/shell/renderer/test_runner/TestCommon.h +++ /dev/null @@ -1,27 +0,0 @@ -// Copyright 2013 The Chromium Authors. All rights reserved. -// Use of this source code is governed by a BSD-style license that can be -// found in the LICENSE file. - -#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTCOMMON_H_ -#define CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTCOMMON_H_ - -#include <stdio.h> -#include <string> - -#include "base/compiler_specific.h" - -#if defined(WIN32) -#define snprintf(str, size, ...) _snprintf_s(str, size, size, __VA_ARGS__) -#endif - -namespace content { - -inline bool isASCIIAlpha(char ch) { return (ch | 0x20) >= 'a' && (ch | 0x20) <= 'z'; } - -inline bool isNotASCIIAlpha(char ch) { return !isASCIIAlpha(ch); } - -std::string normalizeLayoutTestURL(const std::string& url); - -} // namespace content - -#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TESTCOMMON_H_ diff --git a/content/shell/renderer/test_runner/TestPlugin.cpp b/content/shell/renderer/test_runner/TestPlugin.cpp index 3bd80a0..a42721b 100644 --- a/content/shell/renderer/test_runner/TestPlugin.cpp +++ b/content/shell/renderer/test_runner/TestPlugin.cpp @@ -8,8 +8,8 @@ #include "base/bind.h" #include "base/logging.h" #include "base/memory/shared_memory.h" +#include "base/strings/stringprintf.h" #include "content/public/renderer/render_thread.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTestDelegate.h" #include "third_party/skia/include/core/SkBitmap.h" #include "third_party/skia/include/core/SkCanvas.h" @@ -87,14 +87,10 @@ const char* pointState(WebTouchPoint::State state) void printTouchList(WebTestDelegate* delegate, const WebTouchPoint* points, int length) { for (int i = 0; i < length; ++i) { - char buffer[100]; - snprintf(buffer, - sizeof(buffer), - "* %.2f, %.2f: %s\n", - points[i].position.x, - points[i].position.y, - pointState(points[i].state)); - delegate->printMessage(buffer); + base::StringPrintf("* %.2f, %.2f: %s\n", + points[i].position.x, + points[i].position.y, + pointState(points[i].state)); } } @@ -107,14 +103,10 @@ void printEventDetails(WebTestDelegate* delegate, const WebInputEvent& event) printTouchList(delegate, touch.targetTouches, touch.targetTouchesLength); } else if (WebInputEvent::isMouseEventType(event.type) || event.type == WebInputEvent::MouseWheel) { const WebMouseEvent& mouse = static_cast<const WebMouseEvent&>(event); - char buffer[100]; - snprintf(buffer, sizeof(buffer), "* %d, %d\n", mouse.x, mouse.y); - delegate->printMessage(buffer); + base::StringPrintf("* %d, %d\n", mouse.x, mouse.y); } else if (WebInputEvent::isGestureEventType(event.type)) { const WebGestureEvent& gesture = static_cast<const WebGestureEvent&>(event); - char buffer[100]; - snprintf(buffer, sizeof(buffer), "* %d, %d\n", gesture.x, gesture.y); - delegate->printMessage(buffer); + base::StringPrintf("* %d, %d\n", gesture.x, gesture.y); } } diff --git a/content/shell/renderer/test_runner/mock_color_chooser.h b/content/shell/renderer/test_runner/mock_color_chooser.h index 672ad2b..3040738 100644 --- a/content/shell/renderer/test_runner/mock_color_chooser.h +++ b/content/shell/renderer/test_runner/mock_color_chooser.h @@ -6,7 +6,6 @@ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_COLOR_CHOOSER_H_ #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/web/WebColorChooser.h" #include "third_party/WebKit/public/web/WebColorChooserClient.h" diff --git a/content/shell/renderer/test_runner/mock_grammar_check.cc b/content/shell/renderer/test_runner/mock_grammar_check.cc index 7cee706..cd5a6ed 100644 --- a/content/shell/renderer/test_runner/mock_grammar_check.cc +++ b/content/shell/renderer/test_runner/mock_grammar_check.cc @@ -7,7 +7,7 @@ #include <algorithm> #include "base/logging.h" -#include "content/shell/renderer/test_runner/TestCommon.h" +#include "content/shell/renderer/test_runner/test_common.h" #include "third_party/WebKit/public/platform/WebCString.h" #include "third_party/WebKit/public/platform/WebString.h" #include "third_party/WebKit/public/web/WebTextCheckingResult.h" @@ -19,7 +19,7 @@ bool MockGrammarCheck::CheckGrammarOfString( std::vector<blink::WebTextCheckingResult>* results) { DCHECK(results); base::string16 string_text = text; - if (std::find_if(string_text.begin(), string_text.end(), isASCIIAlpha) == + if (std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha) == string_text.end()) return true; diff --git a/content/shell/renderer/test_runner/mock_spell_check.cc b/content/shell/renderer/test_runner/mock_spell_check.cc index 6c86148..4d4a3ce 100644 --- a/content/shell/renderer/test_runner/mock_spell_check.cc +++ b/content/shell/renderer/test_runner/mock_spell_check.cc @@ -5,7 +5,7 @@ #include "content/shell/renderer/test_runner/mock_spell_check.h" #include "base/logging.h" -#include "content/shell/renderer/test_runner/TestCommon.h" +#include "content/shell/renderer/test_runner/test_common.h" #include "third_party/WebKit/public/platform/WebCString.h" namespace content { @@ -56,7 +56,7 @@ bool MockSpellCheck::SpellCheckWord(const blink::WebString& text, // If the given string doesn't include any ASCII characters, we can treat // the string as valid one. base::string16::iterator first_char = - std::find_if(string_text.begin(), string_text.end(), isASCIIAlpha); + std::find_if(string_text.begin(), string_text.end(), IsASCIIAlpha); if (first_char == string_text.end()) return true; int word_offset = std::distance(string_text.begin(), first_char); @@ -78,7 +78,7 @@ bool MockSpellCheck::SpellCheckWord(const blink::WebString& text, if (word == misspelled_words_.at(i) && (static_cast<int>(string_text.length()) == word_offset + word_length || - isNotASCIIAlpha(string_text[word_offset + word_length]))) { + IsNotASCIIAlpha(string_text[word_offset + word_length]))) { *misspelled_offset = word_offset + skipped_length; *misspelled_length = word_length; break; @@ -89,7 +89,7 @@ bool MockSpellCheck::SpellCheckWord(const blink::WebString& text, break; base::string16::iterator last_char = std::find_if( - string_text.begin() + word_offset, string_text.end(), isNotASCIIAlpha); + string_text.begin() + word_offset, string_text.end(), IsNotASCIIAlpha); if (last_char == string_text.end()) word_length = static_cast<int>(string_text.length()) - word_offset; else diff --git a/content/shell/renderer/test_runner/mock_web_media_stream_center.h b/content/shell/renderer/test_runner/mock_web_media_stream_center.h index b931a65..61bf45f 100644 --- a/content/shell/renderer/test_runner/mock_web_media_stream_center.h +++ b/content/shell/renderer/test_runner/mock_web_media_stream_center.h @@ -8,7 +8,6 @@ #include "third_party/WebKit/public/platform/WebMediaStreamCenter.h" #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" namespace blink { diff --git a/content/shell/renderer/test_runner/mock_web_midi_accessor.h b/content/shell/renderer/test_runner/mock_web_midi_accessor.h index 92fae32..4fba9ba 100644 --- a/content/shell/renderer/test_runner/mock_web_midi_accessor.h +++ b/content/shell/renderer/test_runner/mock_web_midi_accessor.h @@ -6,7 +6,6 @@ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCK_WEB_MIDI_ACCESSOR_H_ #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/platform/WebMIDIAccessor.h" diff --git a/content/shell/renderer/test_runner/mock_web_speech_recognizer.h b/content/shell/renderer/test_runner/mock_web_speech_recognizer.h index 142b5df..05dbb34 100644 --- a/content/shell/renderer/test_runner/mock_web_speech_recognizer.h +++ b/content/shell/renderer/test_runner/mock_web_speech_recognizer.h @@ -9,7 +9,6 @@ #include <vector> #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/web/WebSpeechRecognizer.h" diff --git a/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h b/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h index 7262ae2..b49ae27 100644 --- a/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h +++ b/content/shell/renderer/test_runner/mock_webrtc_data_channel_handler.h @@ -6,7 +6,6 @@ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCDATACHANNELHANDLER_H_ #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/platform/WebRTCDataChannelHandler.h" #include "third_party/WebKit/public/platform/WebRTCDataChannelInit.h" diff --git a/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h b/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h index 70341c6..fb48710 100644 --- a/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h +++ b/content/shell/renderer/test_runner/mock_webrtc_dtmf_sender_handler.h @@ -6,7 +6,6 @@ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCDTMFSENDERHANDLER_H_ #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/platform/WebMediaStreamTrack.h" #include "third_party/WebKit/public/platform/WebRTCDTMFSenderHandler.h" diff --git a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h index 313a51a..980f26d 100644 --- a/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h +++ b/content/shell/renderer/test_runner/mock_webrtc_peer_connection_handler.h @@ -6,7 +6,6 @@ #define CONTENT_SHELL_RENDERER_TEST_RUNNER_MOCKWEBRTCPEERCONNECTIONHANDLER_H_ #include "base/basictypes.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTask.h" #include "third_party/WebKit/public/platform/WebRTCPeerConnectionHandler.h" #include "third_party/WebKit/public/platform/WebRTCSessionDescription.h" diff --git a/content/shell/renderer/test_runner/test_common.cc b/content/shell/renderer/test_runner/test_common.cc new file mode 100644 index 0000000..79f9dd1 --- /dev/null +++ b/content/shell/renderer/test_runner/test_common.cc @@ -0,0 +1,37 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#include "content/shell/renderer/test_runner/test_common.h" + +namespace content { + +namespace { + +const char layout_tests_pattern[] = "/LayoutTests/"; +const std::string::size_type layout_tests_pattern_size = + sizeof(layout_tests_pattern) - 1; +const char file_url_pattern[] = "file:/"; +const char file_test_prefix[] = "(file test):"; +const char data_url_pattern[] = "data:"; +const std::string::size_type data_url_pattern_size = + sizeof(data_url_pattern) - 1; + +} // namespace + +std::string NormalizeLayoutTestURL(const std::string& url) { + std::string result = url; + size_t pos; + if (!url.find(file_url_pattern) && + ((pos = url.find(layout_tests_pattern)) != std::string::npos)) { + // adjust file URLs to match upstream results. + result.replace(0, pos + layout_tests_pattern_size, file_test_prefix); + } else if (!url.find(data_url_pattern)) { + // URL-escape data URLs to match results upstream. + std::string path = url.substr(data_url_pattern_size); + result.replace(data_url_pattern_size, url.length(), path); + } + return result; +} + +} // namespace content diff --git a/content/shell/renderer/test_runner/test_common.h b/content/shell/renderer/test_runner/test_common.h new file mode 100644 index 0000000..6110c52 --- /dev/null +++ b/content/shell/renderer/test_runner/test_common.h @@ -0,0 +1,24 @@ +// Copyright 2014 The Chromium Authors. All rights reserved. +// Use of this source code is governed by a BSD-style license that can be +// found in the LICENSE file. + +#ifndef CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_COMMON_H_ +#define CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_COMMON_H_ + +#include <string> + +namespace content { + +inline bool IsASCIIAlpha(char ch) { + return (ch | 0x20) >= 'a' && (ch | 0x20) <= 'z'; +} + +inline bool IsNotASCIIAlpha(char ch) { + return !IsASCIIAlpha(ch); +} + +std::string NormalizeLayoutTestURL(const std::string& url); + +} // namespace content + +#endif // CONTENT_SHELL_RENDERER_TEST_RUNNER_TEST_COMMON_H_ diff --git a/content/shell/renderer/test_runner/web_permissions.cc b/content/shell/renderer/test_runner/web_permissions.cc index 4d11f7a..c861e09 100644 --- a/content/shell/renderer/test_runner/web_permissions.cc +++ b/content/shell/renderer/test_runner/web_permissions.cc @@ -4,8 +4,8 @@ #include "content/shell/renderer/test_runner/web_permissions.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/WebTestDelegate.h" +#include "content/shell/renderer/test_runner/test_common.h" #include "third_party/WebKit/public/platform/WebCString.h" #include "third_party/WebKit/public/platform/WebURL.h" @@ -22,8 +22,8 @@ bool WebPermissions::allowImage(bool enabled_per_settings, bool allowed = enabled_per_settings && images_allowed_; if (dump_callbacks_ && delegate_) { delegate_->printMessage(std::string("PERMISSION CLIENT: allowImage(") + - normalizeLayoutTestURL(image_url.spec()) + "): " + - (allowed ? "true" : "false") + "\n"); + NormalizeLayoutTestURL(image_url.spec()) + "): " + + (allowed ? "true" : "false") + "\n"); } return allowed; } @@ -32,8 +32,8 @@ bool WebPermissions::allowMedia(const blink::WebURL& image_url) { bool allowed = media_allowed_; if (dump_callbacks_ && delegate_) delegate_->printMessage(std::string("PERMISSION CLIENT: allowMedia(") + - normalizeLayoutTestURL(image_url.spec()) + "): " + - (allowed ? "true" : "false") + "\n"); + NormalizeLayoutTestURL(image_url.spec()) + "): " + + (allowed ? "true" : "false") + "\n"); return allowed; } @@ -43,7 +43,7 @@ bool WebPermissions::allowScriptFromSource(bool enabled_per_settings, if (dump_callbacks_ && delegate_) { delegate_->printMessage( std::string("PERMISSION CLIENT: allowScriptFromSource(") + - normalizeLayoutTestURL(scriptURL.spec()) + "): " + + NormalizeLayoutTestURL(scriptURL.spec()) + "): " + (allowed ? "true" : "false") + "\n"); } return allowed; diff --git a/content/shell/renderer/test_runner/web_test_proxy.cc b/content/shell/renderer/test_runner/web_test_proxy.cc index 0448750b..d4524ee 100644 --- a/content/shell/renderer/test_runner/web_test_proxy.cc +++ b/content/shell/renderer/test_runner/web_test_proxy.cc @@ -10,7 +10,6 @@ #include "base/debug/trace_event.h" #include "base/logging.h" #include "base/strings/stringprintf.h" -#include "content/shell/renderer/test_runner/TestCommon.h" #include "content/shell/renderer/test_runner/TestInterfaces.h" #include "content/shell/renderer/test_runner/TestPlugin.h" #include "content/shell/renderer/test_runner/WebTestDelegate.h" diff --git a/content/test/layouttest_support.cc b/content/test/layouttest_support.cc index 09c15a3..b57dadc 100644 --- a/content/test/layouttest_support.cc +++ b/content/test/layouttest_support.cc @@ -16,7 +16,7 @@ #include "content/renderer/render_thread_impl.h" #include "content/renderer/render_view_impl.h" #include "content/renderer/renderer_webkitplatformsupport_impl.h" -#include "content/shell/renderer/test_runner/TestCommon.h" +#include "content/shell/renderer/test_runner/test_common.h" #include "content/shell/renderer/test_runner/web_frame_test_proxy.h" #include "content/shell/renderer/test_runner/web_test_proxy.h" #include "third_party/WebKit/public/platform/WebBatteryStatus.h" @@ -253,7 +253,7 @@ std::string DumpHistoryItem(HistoryEntry::HistoryNode* node, result.append(indent, ' '); } - std::string url = normalizeLayoutTestURL(item.urlString().utf8()); + std::string url = NormalizeLayoutTestURL(item.urlString().utf8()); result.append(url); if (!item.target().isEmpty()) { result.append(" (in frame \""); |