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

Side by Side Diff: content/shell/renderer/test_runner/test_runner.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/test_runner.h" 5 #include "content/shell/renderer/test_runner/test_runner.h"
6 6
7 #include <limits> 7 #include <limits>
8 8
9 #include "base/logging.h" 9 #include "base/logging.h"
10 #include "content/shell/common/test_runner/test_preferences.h" 10 #include "content/shell/common/test_runner/test_preferences.h"
(...skipping 263 matching lines...) Expand 10 before | Expand all | Expand 10 after
274 void AddMockSpeechRecognitionResult(const std::string& transcript, 274 void AddMockSpeechRecognitionResult(const std::string& transcript,
275 double confidence); 275 double confidence);
276 void SetMockSpeechRecognitionError(const std::string& error, 276 void SetMockSpeechRecognitionError(const std::string& error,
277 const std::string& message); 277 const std::string& message);
278 bool WasMockSpeechRecognitionAborted(); 278 bool WasMockSpeechRecognitionAborted();
279 void AddWebPageOverlay(); 279 void AddWebPageOverlay();
280 void RemoveWebPageOverlay(); 280 void RemoveWebPageOverlay();
281 void DisplayAsync(); 281 void DisplayAsync();
282 void DisplayAsyncThen(v8::Handle<v8::Function> callback); 282 void DisplayAsyncThen(v8::Handle<v8::Function> callback);
283 void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback); 283 void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback);
284 void CopyImageAtAndCapturePixelsAsyncThen(int x,
285 int y,
286 v8::Handle<v8::Function> callback);
284 void SetCustomTextOutput(std::string output); 287 void SetCustomTextOutput(std::string output);
285 void SetViewSourceForFrame(const std::string& name, bool enabled); 288 void SetViewSourceForFrame(const std::string& name, bool enabled);
286 void SetMockPushClientSuccess(const std::string& endpoint, 289 void SetMockPushClientSuccess(const std::string& endpoint,
287 const std::string& registration_id); 290 const std::string& registration_id);
288 void SetMockPushClientError(const std::string& message); 291 void SetMockPushClientError(const std::string& message);
289 292
290 bool GlobalFlag(); 293 bool GlobalFlag();
291 void SetGlobalFlag(bool value); 294 void SetGlobalFlag(bool value);
292 std::string PlatformName(); 295 std::string PlatformName();
293 std::string TooltipText(); 296 std::string TooltipText();
(...skipping 227 matching lines...) Expand 10 before | Expand all | Expand 10 after
521 &TestRunnerBindings::SetMockSpeechRecognitionError) 524 &TestRunnerBindings::SetMockSpeechRecognitionError)
522 .SetMethod("wasMockSpeechRecognitionAborted", 525 .SetMethod("wasMockSpeechRecognitionAborted",
523 &TestRunnerBindings::WasMockSpeechRecognitionAborted) 526 &TestRunnerBindings::WasMockSpeechRecognitionAborted)
524 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay) 527 .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
525 .SetMethod("removeWebPageOverlay", 528 .SetMethod("removeWebPageOverlay",
526 &TestRunnerBindings::RemoveWebPageOverlay) 529 &TestRunnerBindings::RemoveWebPageOverlay)
527 .SetMethod("displayAsync", &TestRunnerBindings::DisplayAsync) 530 .SetMethod("displayAsync", &TestRunnerBindings::DisplayAsync)
528 .SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen) 531 .SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen)
529 .SetMethod("capturePixelsAsyncThen", 532 .SetMethod("capturePixelsAsyncThen",
530 &TestRunnerBindings::CapturePixelsAsyncThen) 533 &TestRunnerBindings::CapturePixelsAsyncThen)
534 .SetMethod("copyImageAtAndCapturePixelsAsyncThen",
535 &TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen)
531 .SetMethod("setCustomTextOutput", 536 .SetMethod("setCustomTextOutput",
532 &TestRunnerBindings::SetCustomTextOutput) 537 &TestRunnerBindings::SetCustomTextOutput)
533 .SetMethod("setViewSourceForFrame", 538 .SetMethod("setViewSourceForFrame",
534 &TestRunnerBindings::SetViewSourceForFrame) 539 &TestRunnerBindings::SetViewSourceForFrame)
535 .SetMethod("setMockPushClientSuccess", 540 .SetMethod("setMockPushClientSuccess",
536 &TestRunnerBindings::SetMockPushClientSuccess) 541 &TestRunnerBindings::SetMockPushClientSuccess)
537 .SetMethod("setMockPushClientError", 542 .SetMethod("setMockPushClientError",
538 &TestRunnerBindings::SetMockPushClientError) 543 &TestRunnerBindings::SetMockPushClientError)
539 544
540 // Properties. 545 // Properties.
(...skipping 802 matching lines...) Expand 10 before | Expand all | Expand 10 after
1343 if (runner_) 1348 if (runner_)
1344 runner_->DisplayAsyncThen(callback); 1349 runner_->DisplayAsyncThen(callback);
1345 } 1350 }
1346 1351
1347 void TestRunnerBindings::CapturePixelsAsyncThen( 1352 void TestRunnerBindings::CapturePixelsAsyncThen(
1348 v8::Handle<v8::Function> callback) { 1353 v8::Handle<v8::Function> callback) {
1349 if (runner_) 1354 if (runner_)
1350 runner_->CapturePixelsAsyncThen(callback); 1355 runner_->CapturePixelsAsyncThen(callback);
1351 } 1356 }
1352 1357
1358 void TestRunnerBindings::CopyImageAtAndCapturePixelsAsyncThen(
1359 int x, int y, v8::Handle<v8::Function> callback) {
1360 if (runner_)
1361 runner_->CopyImageAtAndCapturePixelsAsyncThen(x, y, callback);
1362 }
1363
1353 void TestRunnerBindings::SetCustomTextOutput(std::string output) { 1364 void TestRunnerBindings::SetCustomTextOutput(std::string output) {
1354 runner_->setCustomTextOutput(output); 1365 runner_->setCustomTextOutput(output);
1355 } 1366 }
1356 1367
1357 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name, 1368 void TestRunnerBindings::SetViewSourceForFrame(const std::string& name,
1358 bool enabled) { 1369 bool enabled) {
1359 if (runner_ && runner_->web_view_) { 1370 if (runner_ && runner_->web_view_) {
1360 WebFrame* target_frame = 1371 WebFrame* target_frame =
1361 runner_->web_view_->findFrameByName(WebString::fromUTF8(name)); 1372 runner_->web_view_->findFrameByName(WebString::fromUTF8(name));
1362 if (target_frame) 1373 if (target_frame)
(...skipping 1419 matching lines...) Expand 10 before | Expand all | Expand 10 after
2782 } 2793 }
2783 2794
2784 void TestRunner::CapturePixelsAsyncThen(v8::Handle<v8::Function> callback) { 2795 void TestRunner::CapturePixelsAsyncThen(v8::Handle<v8::Function> callback) {
2785 scoped_ptr<InvokeCallbackTask> task( 2796 scoped_ptr<InvokeCallbackTask> task(
2786 new InvokeCallbackTask(this, callback)); 2797 new InvokeCallbackTask(this, callback));
2787 proxy_->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback, 2798 proxy_->CapturePixelsAsync(base::Bind(&TestRunner::CapturePixelsCallback,
2788 base::Unretained(this), 2799 base::Unretained(this),
2789 base::Passed(&task))); 2800 base::Passed(&task)));
2790 } 2801 }
2791 2802
2803 void TestRunner::CopyImageAtAndCapturePixelsAsyncThen(
2804 int x, int y, v8::Handle<v8::Function> callback) {
2805 scoped_ptr<InvokeCallbackTask> task(
2806 new InvokeCallbackTask(this, callback));
2807 proxy_->CopyImageAtAndCapturePixels(
2808 x, y, base::Bind(&TestRunner::CapturePixelsCallback,
2809 base::Unretained(this),
2810 base::Passed(&task)));
2811 }
2812
2792 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task, 2813 void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
2793 const SkBitmap& snapshot) { 2814 const SkBitmap& snapshot) {
2794 v8::Isolate* isolate = blink::mainThreadIsolate(); 2815 v8::Isolate* isolate = blink::mainThreadIsolate();
2795 v8::HandleScope handle_scope(isolate); 2816 v8::HandleScope handle_scope(isolate);
2796 2817
2797 v8::Handle<v8::Context> context = 2818 v8::Handle<v8::Context> context =
2798 web_view_->mainFrame()->mainWorldScriptContext(); 2819 web_view_->mainFrame()->mainWorldScriptContext();
2799 if (context.IsEmpty()) 2820 if (context.IsEmpty())
2800 return; 2821 return;
2801 2822
2802 v8::Context::Scope context_scope(context); 2823 v8::Context::Scope context_scope(context);
2803 v8::Handle<v8::Value> argv[3]; 2824 v8::Handle<v8::Value> argv[3];
2804 SkAutoLockPixels snapshot_lock(snapshot); 2825 SkAutoLockPixels snapshot_lock(snapshot);
2805 2826
2827 // Size can be 0 for cases where copyImageAt was called on position
2828 // that doesn't have an image.
2806 int width = snapshot.info().fWidth; 2829 int width = snapshot.info().fWidth;
2807 DCHECK_NE(0, width);
2808 argv[0] = v8::Number::New(isolate, width); 2830 argv[0] = v8::Number::New(isolate, width);
2809 2831
2810 int height = snapshot.info().fHeight; 2832 int height = snapshot.info().fHeight;
2811 DCHECK_NE(0, height);
2812 argv[1] = v8::Number::New(isolate, height); 2833 argv[1] = v8::Number::New(isolate, height);
2813 2834
2814 blink::WebArrayBuffer buffer = 2835 blink::WebArrayBuffer buffer =
2815 blink::WebArrayBuffer::create(snapshot.getSize(), 1); 2836 blink::WebArrayBuffer::create(snapshot.getSize(), 1);
2816 memcpy(buffer.data(), snapshot.getPixels(), buffer.byteLength()); 2837 memcpy(buffer.data(), snapshot.getPixels(), buffer.byteLength());
2817 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT 2838 #if (SK_R32_SHIFT == 16) && !SK_B32_SHIFT
2818 { 2839 {
2819 // Skia's internal byte order is BGRA. Must swap the B and R channels in 2840 // Skia's internal byte order is BGRA. Must swap the B and R channels in
2820 // order to provide a consistent ordering to the layout tests. 2841 // order to provide a consistent ordering to the layout tests.
2821 unsigned char* pixels = static_cast<unsigned char*>(buffer.data()); 2842 unsigned char* pixels = static_cast<unsigned char*>(buffer.data());
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
2889 } 2910 }
2890 2911
2891 void TestRunner::DidLosePointerLockInternal() { 2912 void TestRunner::DidLosePointerLockInternal() {
2892 bool was_locked = pointer_locked_; 2913 bool was_locked = pointer_locked_;
2893 pointer_locked_ = false; 2914 pointer_locked_ = false;
2894 if (was_locked) 2915 if (was_locked)
2895 web_view_->didLosePointerLock(); 2916 web_view_->didLosePointerLock();
2896 } 2917 }
2897 2918
2898 } // namespace content 2919 } // namespace content
OLDNEW
« no previous file with comments | « content/shell/renderer/test_runner/test_runner.h ('k') | content/shell/renderer/test_runner/web_test_proxy.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698