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

Side by Side Diff: content/shell/webkit_test_runner.cc

Issue 11572041: [content shell] implement additional URL handling methods of the WebTestDelegate (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: rebase Created 8 years 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
« no previous file with comments | « content/shell/webkit_test_runner.h ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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/md5.h" 10 #include "base/md5.h"
10 #include "base/memory/scoped_ptr.h" 11 #include "base/memory/scoped_ptr.h"
11 #include "base/message_loop.h" 12 #include "base/message_loop.h"
12 #include "base/stringprintf.h" 13 #include "base/stringprintf.h"
13 #include "base/sys_string_conversions.h" 14 #include "base/sys_string_conversions.h"
14 #include "base/time.h" 15 #include "base/time.h"
15 #include "base/utf_string_conversions.h" 16 #include "base/utf_string_conversions.h"
16 #include "content/public/renderer/render_view.h" 17 #include "content/public/renderer/render_view.h"
17 #include "content/public/test/layouttest_support.h" 18 #include "content/public/test/layouttest_support.h"
18 #include "content/shell/shell_messages.h" 19 #include "content/shell/shell_messages.h"
19 #include "content/shell/shell_render_process_observer.h" 20 #include "content/shell/shell_render_process_observer.h"
20 #include "net/base/net_util.h" 21 #include "net/base/net_util.h"
21 #include "skia/ext/platform_canvas.h" 22 #include "skia/ext/platform_canvas.h"
22 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
23 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h"
24 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
25 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
26 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h" 23 #include "third_party/WebKit/Source/WebKit/chromium/public/WebContextMenuData.h"
28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h" 24 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDevToolsAgent.h"
29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h" 25 #include "third_party/WebKit/Source/WebKit/chromium/public/WebDocument.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h" 26 #include "third_party/WebKit/Source/WebKit/chromium/public/WebElement.h"
31 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h" 27 #include "third_party/WebKit/Source/WebKit/chromium/public/WebFrame.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h" 28 #include "third_party/WebKit/Source/WebKit/chromium/public/WebKit.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h" 29 #include "third_party/WebKit/Source/WebKit/chromium/public/WebView.h"
30 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebCString.h "
31 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebKitPlatfo rmSupport.h"
32 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebRect.h"
33 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebSize.h"
34 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebString.h"
35 #include "third_party/WebKit/Source/WebKit/chromium/public/platform/WebURL.h"
34 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web Task.h" 36 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web Task.h"
35 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web TestProxy.h" 37 #include "third_party/WebKit/Tools/DumpRenderTree/chromium/TestRunner/public/Web TestProxy.h"
36 #include "webkit/base/file_path_string_conversions.h" 38 #include "webkit/base/file_path_string_conversions.h"
37 #include "webkit/glue/webkit_glue.h" 39 #include "webkit/glue/webkit_glue.h"
38 #include "webkit/glue/webpreferences.h" 40 #include "webkit/glue/webpreferences.h"
39 41
40 using WebKit::WebContextMenuData; 42 using WebKit::WebContextMenuData;
41 using WebKit::WebDevToolsAgent; 43 using WebKit::WebDevToolsAgent;
42 using WebKit::WebElement; 44 using WebKit::WebElement;
43 using WebKit::WebFrame; 45 using WebKit::WebFrame;
44 using WebKit::WebGamepads; 46 using WebKit::WebGamepads;
45 using WebKit::WebRect; 47 using WebKit::WebRect;
46 using WebKit::WebSize; 48 using WebKit::WebSize;
47 using WebKit::WebString; 49 using WebKit::WebString;
50 using WebKit::WebURL;
48 using WebKit::WebVector; 51 using WebKit::WebVector;
49 using WebKit::WebView; 52 using WebKit::WebView;
50 using WebTestRunner::WebPreferences; 53 using WebTestRunner::WebPreferences;
51 using WebTestRunner::WebTask; 54 using WebTestRunner::WebTask;
52 55
53 namespace content { 56 namespace content {
54 57
55 namespace { 58 namespace {
56 59
57 void InvokeTaskHelper(void* context) { 60 void InvokeTaskHelper(void* context) {
(...skipping 171 matching lines...) Expand 10 before | Expand all | Expand 10 after
229 #endif 232 #endif
230 if (!path.IsAbsolute()) { 233 if (!path.IsAbsolute()) {
231 GURL base_url = 234 GURL base_url =
232 net::FilePathToFileURL(current_working_directory_.Append( 235 net::FilePathToFileURL(current_working_directory_.Append(
233 FILE_PATH_LITERAL("foo"))); 236 FILE_PATH_LITERAL("foo")));
234 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path); 237 net::FileURLToFilePath(base_url.Resolve(utf8_path), &path);
235 } 238 }
236 return webkit_base::FilePathToWebString(path); 239 return webkit_base::FilePathToWebString(path);
237 } 240 }
238 241
242 WebURL WebKitTestRunner::localFileToDataURL(const WebURL& file_url) {
243 FilePath local_path;
244 if (!net::FileURLToFilePath(file_url, &local_path))
245 return WebURL();
246
247 std::string contents;
248 Send(new ShellViewHostMsg_ReadFileToString(
249 routing_id(), local_path, &contents));
250
251 std::string contents_base64;
252 if (!base::Base64Encode(contents, &contents_base64))
253 return WebURL();
254
255 const char data_url_prefix[] = "data:text/css:charset=utf-8;base64,";
256 return WebURL(GURL(data_url_prefix + contents_base64));
257 }
258
259 WebURL WebKitTestRunner::rewriteLayoutTestsURL(const std::string& utf8_url) {
260 const char kPrefix[] = "file:///tmp/LayoutTests/";
261 const int kPrefixLen = arraysize(kPrefix) - 1;
262
263 if (utf8_url.compare(0, kPrefixLen, kPrefix, kPrefixLen))
264 return WebURL(GURL(utf8_url));
265
266 FilePath replace_path =
267 ShellRenderProcessObserver::GetInstance()->webkit_source_dir().Append(
268 FILE_PATH_LITERAL("LayoutTests/"));
269 #if defined(OS_WIN)
270 std::string utf8_path = WideToUTF8(replace_path.value());
271 #else
272 std::string utf8_path =
273 WideToUTF8(base::SysNativeMBToWide(replace_path.value()));
274 #endif
275 std::string new_url =
276 std::string("file://") + utf8_path + utf8_url.substr(kPrefixLen);
277 return WebURL(GURL(new_url));
278 }
279
239 WebPreferences* WebKitTestRunner::preferences() { 280 WebPreferences* WebKitTestRunner::preferences() {
240 return &prefs_; 281 return &prefs_;
241 } 282 }
242 283
243 void WebKitTestRunner::applyPreferences() { 284 void WebKitTestRunner::applyPreferences() {
244 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences(); 285 webkit_glue::WebPreferences prefs = render_view()->GetWebkitPreferences();
245 prefs_.Export(&prefs); 286 prefs_.Export(&prefs);
246 render_view()->SetWebkitPreferences(prefs); 287 render_view()->SetWebkitPreferences(prefs);
247 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs_)); 288 Send(new ShellViewHostMsg_OverridePreferences(routing_id(), prefs_));
248 } 289 }
(...skipping 229 matching lines...) Expand 10 before | Expand all | Expand 10 after
478 PaintRect(rect); 519 PaintRect(rect);
479 } 520 }
480 CHECK(proxy_->paintRect().isEmpty()); 521 CHECK(proxy_->paintRect().isEmpty());
481 } 522 }
482 523
483 void WebKitTestRunner::DisplayRepaintMask() { 524 void WebKitTestRunner::DisplayRepaintMask() {
484 GetCanvas()->drawARGB(167, 0, 0, 0); 525 GetCanvas()->drawARGB(167, 0, 0, 0);
485 } 526 }
486 527
487 } // namespace content 528 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/webkit_test_runner.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698