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 "content/shell/webkit_test_runner.h" | 5 #include "content/shell/webkit_test_runner.h" |
6 | 6 |
7 #include <cmath> | 7 #include <cmath> |
8 | 8 |
9 #include "base/base64.h" | 9 #include "base/base64.h" |
10 #include "base/md5.h" | 10 #include "base/md5.h" |
(...skipping 198 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
209 | 209 |
210 void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) { | 210 void WebKitTestRunner::postDelayedTask(WebTask* task, long long ms) { |
211 MessageLoop::current()->PostDelayedTask( | 211 MessageLoop::current()->PostDelayedTask( |
212 FROM_HERE, | 212 FROM_HERE, |
213 base::Bind(&WebTask::run, base::Owned(task)), | 213 base::Bind(&WebTask::run, base::Owned(task)), |
214 base::TimeDelta::FromMilliseconds(ms)); | 214 base::TimeDelta::FromMilliseconds(ms)); |
215 } | 215 } |
216 | 216 |
217 WebString WebKitTestRunner::registerIsolatedFileSystem( | 217 WebString WebKitTestRunner::registerIsolatedFileSystem( |
218 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) { | 218 const WebKit::WebVector<WebKit::WebString>& absolute_filenames) { |
219 std::vector<FilePath> files; | 219 std::vector<base::FilePath> files; |
220 for (size_t i = 0; i < absolute_filenames.size(); ++i) | 220 for (size_t i = 0; i < absolute_filenames.size(); ++i) |
221 files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i])); | 221 files.push_back(webkit_base::WebStringToFilePath(absolute_filenames[i])); |
222 std::string filesystem_id; | 222 std::string filesystem_id; |
223 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem( | 223 Send(new ShellViewHostMsg_RegisterIsolatedFileSystem( |
224 routing_id(), files, &filesystem_id)); | 224 routing_id(), files, &filesystem_id)); |
225 return WebString::fromUTF8(filesystem_id); | 225 return WebString::fromUTF8(filesystem_id); |
226 } | 226 } |
227 | 227 |
228 long long WebKitTestRunner::getCurrentTimeInMillisecond() { | 228 long long WebKitTestRunner::getCurrentTimeInMillisecond() { |
229 return base::TimeTicks::Now().ToInternalValue() / | 229 return base::TimeTicks::Now().ToInternalValue() / |
230 base::Time::kMicrosecondsPerMillisecond; | 230 base::Time::kMicrosecondsPerMillisecond; |
231 } | 231 } |
232 | 232 |
233 WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path( | 233 WebString WebKitTestRunner::getAbsoluteWebStringFromUTF8Path( |
234 const std::string& utf8_path) { | 234 const std::string& utf8_path) { |
235 #if defined(OS_WIN) | 235 #if defined(OS_WIN) |
236 FilePath path(UTF8ToWide(utf8_path)); | 236 base::FilePath path(UTF8ToWide(utf8_path)); |
237 #else | 237 #else |
238 FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path))); | 238 base::FilePath path(base::SysWideToNativeMB(base::SysUTF8ToWide(utf8_path))); |
239 #endif | 239 #endif |
240 if (!path.IsAbsolute()) { | 240 if (!path.IsAbsolute()) { |
241 GURL base_url = | 241 GURL base_url = |
242 net::FilePathToFileURL(current_working_directory_.Append( | 242 net::FilePathToFileURL(current_working_directory_.Append( |
243 FILE_PATH_LITERAL("foo"))); | 243 FILE_PATH_LITERAL("foo"))); |
244 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path); | 244 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path); |
245 } | 245 } |
246 return webkit_base::FilePathToWebString(path); | 246 return webkit_base::FilePathToWebString(path); |
247 } | 247 } |
248 | 248 |
249 WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) { | 249 WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) { |
250 FilePath local_path; | 250 base::FilePath local_path; |
251 if (!net::FileURLToFilePath(file_url, &local_path)) | 251 if (!net::FileURLToFilePath(file_url, &local_path)) |
252 return WebURL(); | 252 return WebURL(); |
253 | 253 |
254 std::string contents; | 254 std::string contents; |
255 Send(new ShellViewHostMsg_ReadFileToString( | 255 Send(new ShellViewHostMsg_ReadFileToString( |
256 routing_id(), local_path, &contents)); | 256 routing_id(), local_path, &contents)); |
257 | 257 |
258 std::string contents_base64; | 258 std::string contents_base64; |
259 if (!base::Base64Encode(contents, &contents_base64)) | 259 if (!base::Base64Encode(contents, &contents_base64)) |
260 return WebURL(); | 260 return WebURL(); |
261 | 261 |
262 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; | 262 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,"; |
263 return WebURL(GURL(data_url_prefix + contents_base64)); | 263 return WebURL(GURL(data_url_prefix + contents_base64)); |
264 } | 264 } |
265 | 265 |
266 WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) { | 266 WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) { |
267 const char kPrefix[] = "file:///tmp/LayoutTests/"; | 267 const char kPrefix[] = "file:///tmp/LayoutTests/"; |
268 const int kPrefixLen = arraysize(kPrefix) - 1; | 268 const int kPrefixLen = arraysize(kPrefix) - 1; |
269 | 269 |
270 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) | 270 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen)) |
271 return WebURL(GURL(utf8_url)); | 271 return WebURL(GURL(utf8_url)); |
272 | 272 |
273 FilePath replace_path = | 273 base::FilePath replace_path = |
274 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append( | 274 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append( |
275 FILE_PATH_LITERAL("LayoutTests/")); | 275 FILE_PATH_LITERAL("LayoutTests/")); |
276 #if defined(OS_WIN) | 276 #if defined(OS_WIN) |
277 std::string utf8_path = WideToUTF8(replace_path.value()); | 277 std::string utf8_path = WideToUTF8(replace_path.value()); |
278 #else | 278 #else |
279 std::string utf8_path = | 279 std::string utf8_path = |
280 WideToUTF8(base::SysNativeMBToWide(replace_path.value())); | 280 WideToUTF8(base::SysNativeMBToWide(replace_path.value())); |
281 #endif | 281 #endif |
282 std::string new_url = | 282 std::string new_url = |
283 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen); | 283 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen); |
(...skipping 324 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
608 SkBitmap empty_image; | 608 SkBitmap empty_image; |
609 Send(new ShellViewHostMsg_ImageDump( | 609 Send(new ShellViewHostMsg_ImageDump( |
610 routing_id(), actual_pixel_hash, empty_image)); | 610 routing_id(), actual_pixel_hash, empty_image)); |
611 return; | 611 return; |
612 } | 612 } |
613 Send(new ShellViewHostMsg_ImageDump( | 613 Send(new ShellViewHostMsg_ImageDump( |
614 routing_id(), actual_pixel_hash, snapshot)); | 614 routing_id(), actual_pixel_hash, snapshot)); |
615 } | 615 } |
616 | 616 |
617 void WebKitTestRunner::OnSetCurrentWorkingDirectory( | 617 void WebKitTestRunner::OnSetCurrentWorkingDirectory( |
618 const FilePath& current_working_directory) { | 618 const base::FilePath& current_working_directory) { |
619 current_working_directory_ = current_working_directory; | 619 current_working_directory_ = current_working_directory; |
620 std::vector<FilePath::StringType> components; | 620 std::vector<base::FilePath::StringType> components; |
621 current_working_directory_.GetComponents(&components); | 621 current_working_directory_.GetComponents(&components); |
622 for (unsigned i = 0; i < components.size(); ++i) { | 622 for (unsigned i = 0; i < components.size(); ++i) { |
623 if (components[i] == FILE_PATH_LITERAL("loading")) | 623 if (components[i] == FILE_PATH_LITERAL("loading")) |
624 dump_frame_load_callbacks_ = true; | 624 dump_frame_load_callbacks_ = true; |
625 } | 625 } |
626 } | 626 } |
627 | 627 |
628 SkCanvas* WebKitTestRunner::GetCanvas() { | 628 SkCanvas* WebKitTestRunner::GetCanvas() { |
629 WebView* view = render_view()->GetWebView(); | 629 WebView* view = render_view()->GetWebView(); |
630 const WebSize& size = view->size(); | 630 const WebSize& size = view->size(); |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
684 PaintRect(rect); | 684 PaintRect(rect); |
685 } | 685 } |
686 CHECK(proxy_->paintRect().isEmpty()); | 686 CHECK(proxy_->paintRect().isEmpty()); |
687 } | 687 } |
688 | 688 |
689 void WebKitTestRunner::DisplayRepaintMask() { | 689 void WebKitTestRunner::DisplayRepaintMask() { |
690 GetCanvas()->drawARGB(167, 0, 0, 0); | 690 GetCanvas()->drawARGB(167, 0, 0, 0); |
691 } | 691 } |
692 | 692 |
693 } // namespace content | 693 } // namespace content |
OLD | NEW |