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

Side by Side Diff: content/shell/renderer/test_runner/web_test_proxy.cc

Issue 396953002: Add testRunner.copyAtAndCapturePixelsAsyncThen() method (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: added initialization for members Created 6 years, 5 months 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
OLDNEW
1 // Copyright 2014 The Chromium Authors. All rights reserved. 1 // Copyright 2014 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/renderer/test_runner/web_test_proxy.h" 5 #include "content/shell/renderer/test_runner/web_test_proxy.h"
6 6
7 #include <cctype> 7 #include <cctype>
8 8
9 #include "base/callback_helpers.h" 9 #include "base/callback_helpers.h"
10 #include "base/debug/trace_event.h" 10 #include "base/debug/trace_event.h"
11 #include "base/logging.h" 11 #include "base/logging.h"
12 #include "content/shell/renderer/test_runner/MockColorChooser.h" 12 #include "content/shell/renderer/test_runner/MockColorChooser.h"
13 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h" 13 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
14 #include "content/shell/renderer/test_runner/SpellCheckClient.h" 14 #include "content/shell/renderer/test_runner/SpellCheckClient.h"
15 #include "content/shell/renderer/test_runner/TestCommon.h" 15 #include "content/shell/renderer/test_runner/TestCommon.h"
16 #include "content/shell/renderer/test_runner/TestInterfaces.h" 16 #include "content/shell/renderer/test_runner/TestInterfaces.h"
17 #include "content/shell/renderer/test_runner/TestPlugin.h" 17 #include "content/shell/renderer/test_runner/TestPlugin.h"
18 #include "content/shell/renderer/test_runner/WebTestDelegate.h" 18 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
19 #include "content/shell/renderer/test_runner/WebTestInterfaces.h" 19 #include "content/shell/renderer/test_runner/WebTestInterfaces.h"
20 #include "content/shell/renderer/test_runner/accessibility_controller.h" 20 #include "content/shell/renderer/test_runner/accessibility_controller.h"
21 #include "content/shell/renderer/test_runner/event_sender.h" 21 #include "content/shell/renderer/test_runner/event_sender.h"
22 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h" 22 #include "content/shell/renderer/test_runner/mock_screen_orientation_client.h"
23 #include "content/shell/renderer/test_runner/mock_web_push_client.h" 23 #include "content/shell/renderer/test_runner/mock_web_push_client.h"
24 #include "content/shell/renderer/test_runner/mock_web_user_media_client.h" 24 #include "content/shell/renderer/test_runner/mock_web_user_media_client.h"
25 #include "content/shell/renderer/test_runner/test_runner.h" 25 #include "content/shell/renderer/test_runner/test_runner.h"
26 #include "content/shell/renderer/test_runner/web_test_runner.h" 26 #include "content/shell/renderer/test_runner/web_test_runner.h"
27 // FIXME: Including platform_canvas.h here is a layering violation. 27 // FIXME: Including platform_canvas.h here is a layering violation.
28 #include "skia/ext/platform_canvas.h" 28 #include "skia/ext/platform_canvas.h"
29 #include "third_party/WebKit/public/platform/Platform.h"
29 #include "third_party/WebKit/public/platform/WebCString.h" 30 #include "third_party/WebKit/public/platform/WebCString.h"
31 #include "third_party/WebKit/public/platform/WebClipboard.h"
30 #include "third_party/WebKit/public/platform/WebURLError.h" 32 #include "third_party/WebKit/public/platform/WebURLError.h"
31 #include "third_party/WebKit/public/platform/WebURLRequest.h" 33 #include "third_party/WebKit/public/platform/WebURLRequest.h"
32 #include "third_party/WebKit/public/platform/WebURLResponse.h" 34 #include "third_party/WebKit/public/platform/WebURLResponse.h"
33 #include "third_party/WebKit/public/web/WebAXEnums.h" 35 #include "third_party/WebKit/public/web/WebAXEnums.h"
34 #include "third_party/WebKit/public/web/WebAXObject.h" 36 #include "third_party/WebKit/public/web/WebAXObject.h"
35 #include "third_party/WebKit/public/web/WebCachedURLRequest.h" 37 #include "third_party/WebKit/public/web/WebCachedURLRequest.h"
36 #include "third_party/WebKit/public/web/WebConsoleMessage.h" 38 #include "third_party/WebKit/public/web/WebConsoleMessage.h"
37 #include "third_party/WebKit/public/web/WebDataSource.h" 39 #include "third_party/WebKit/public/web/WebDataSource.h"
38 #include "third_party/WebKit/public/web/WebDocument.h" 40 #include "third_party/WebKit/public/web/WebDocument.h"
39 #include "third_party/WebKit/public/web/WebElement.h" 41 #include "third_party/WebKit/public/web/WebElement.h"
(...skipping 421 matching lines...) Expand 10 before | Expand all | Expand 10 after
461 } 463 }
462 464
463 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) { 465 void WebTestProxyBase::SetAcceptLanguages(const std::string& accept_languages) {
464 bool notify = accept_languages_ != accept_languages; 466 bool notify = accept_languages_ != accept_languages;
465 accept_languages_ = accept_languages; 467 accept_languages_ = accept_languages;
466 468
467 if (notify) 469 if (notify)
468 GetWebView()->acceptLanguagesChanged(); 470 GetWebView()->acceptLanguagesChanged();
469 } 471 }
470 472
473 void WebTestProxyBase::CopyImageAtAndCapturePixels(
474 int x, int y, const base::Callback<void(const SkBitmap&)>& callback) {
475 DCHECK(web_widget_->isAcceleratedCompositingActive());
476 DCHECK(!callback.is_null());
477 uint64_t sequence_number = blink::Platform::current()->clipboard()->
478 sequenceNumber(blink::WebClipboard::Buffer());
479 GetWebView()->copyImageAt(blink::WebPoint(x, y));
480 if (sequence_number == blink::Platform::current()->clipboard()->
481 sequenceNumber(blink::WebClipboard::Buffer())) {
482 SkBitmap emptyBitmap;
483 callback.Run(emptyBitmap);
484 return;
485 }
486
487 blink::WebData data = blink::Platform::current()->clipboard()->readImage(
488 blink::WebClipboard::Buffer());
489 blink::WebImage image = blink::WebImage::fromData(data, blink::WebSize());
490 const SkBitmap& bitmap = image.getSkBitmap();
491 SkAutoLockPixels autoLock(bitmap);
492 callback.Run(bitmap);
493 }
494
471 void WebTestProxyBase::CapturePixelsForPrinting( 495 void WebTestProxyBase::CapturePixelsForPrinting(
472 const base::Callback<void(const SkBitmap&)>& callback) { 496 const base::Callback<void(const SkBitmap&)>& callback) {
473 web_widget_->layout(); 497 web_widget_->layout();
474 498
475 blink::WebSize page_size_in_pixels = web_widget_->size(); 499 blink::WebSize page_size_in_pixels = web_widget_->size();
476 blink::WebFrame* web_frame = GetWebView()->mainFrame(); 500 blink::WebFrame* web_frame = GetWebView()->mainFrame();
477 501
478 int page_count = web_frame->printBegin(page_size_in_pixels); 502 int page_count = web_frame->printBegin(page_size_in_pixels);
479 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1; 503 int totalHeight = page_count * (page_size_in_pixels.height + 1) - 1;
480 504
(...skipping 764 matching lines...) Expand 10 before | Expand all | Expand 10 after
1245 if (!push_client_.get()) 1269 if (!push_client_.get())
1246 push_client_.reset(new MockWebPushClient); 1270 push_client_.reset(new MockWebPushClient);
1247 return push_client_.get(); 1271 return push_client_.get();
1248 } 1272 }
1249 1273
1250 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() { 1274 blink::WebPushClient* WebTestProxyBase::GetWebPushClient() {
1251 return GetPushClientMock(); 1275 return GetPushClientMock();
1252 } 1276 }
1253 1277
1254 } // namespace content 1278 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/web_test_proxy.h ('k') | content/test/mock_webclipboard_impl.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698