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

Side by Side Diff: components/test_runner/test_runner.h

Issue 1908183002: Use correct WebView from TestRunner methods called via testRunner bindings. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@accessibility-controller-per-view
Patch Set: Explicit constructor for TestRunnerForSpecificView. Created 4 years, 7 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
« no previous file with comments | « components/test_runner/test_interfaces.cc ('k') | components/test_runner/test_runner.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 #ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ 5 #ifndef COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_
6 #define COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ 6 #define COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_
7 7
8 #include <stdint.h> 8 #include <stdint.h>
9 9
10 #include <deque> 10 #include <deque>
11 #include <memory> 11 #include <memory>
12 #include <set> 12 #include <set>
13 #include <string> 13 #include <string>
14 #include <vector> 14 #include <vector>
15 15
16 #include "base/macros.h" 16 #include "base/macros.h"
17 #include "base/memory/weak_ptr.h" 17 #include "base/memory/weak_ptr.h"
18 #include "components/test_runner/layout_test_runtime_flags.h" 18 #include "components/test_runner/layout_test_runtime_flags.h"
19 #include "components/test_runner/test_runner_export.h" 19 #include "components/test_runner/test_runner_export.h"
20 #include "components/test_runner/web_test_runner.h" 20 #include "components/test_runner/web_test_runner.h"
21 #include "third_party/WebKit/public/platform/WebImage.h" 21 #include "third_party/WebKit/public/platform/WebImage.h"
22 #include "v8/include/v8.h" 22 #include "v8/include/v8.h"
23 23
24 class GURL; 24 class GURL;
25 class SkBitmap; 25 class SkBitmap;
26 26
27 namespace blink { 27 namespace blink {
28 class WebContentSettingsClient; 28 class WebContentSettingsClient;
29 class WebFrame; 29 class WebFrame;
30 class WebLocalFrame;
30 class WebMediaStream; 31 class WebMediaStream;
31 class WebString; 32 class WebString;
32 class WebView; 33 class WebView;
33 class WebURLResponse; 34 class WebURLResponse;
34 } 35 }
35 36
36 namespace gin { 37 namespace gin {
37 class ArrayBufferView; 38 class ArrayBufferView;
38 class Arguments; 39 class Arguments;
39 } 40 }
40 41
41 namespace test_runner { 42 namespace test_runner {
42 43
43 class InvokeCallbackTask; 44 class InvokeCallbackTask;
44 class MockContentSettingsClient; 45 class MockContentSettingsClient;
45 class MockCredentialManagerClient; 46 class MockCredentialManagerClient;
46 class MockScreenOrientationClient; 47 class MockScreenOrientationClient;
47 class MockWebSpeechRecognizer; 48 class MockWebSpeechRecognizer;
48 class MockWebUserMediaClient; 49 class MockWebUserMediaClient;
49 class SpellCheckClient; 50 class SpellCheckClient;
50 class TestInterfaces; 51 class TestInterfaces;
52 class TestRunnerForSpecificView;
51 class WebTestDelegate; 53 class WebTestDelegate;
52 class WebTestProxyBase; 54 class WebTestProxyBase;
53 55
56 // TestRunner class currently has dual purpose:
57 // 1. It implements |testRunner| javascript bindings for "global" / "ambient".
58 // Examples:
59 // - testRunner.dumpAsText (test flag affecting test behavior)
60 // - testRunner.setAllowDisplayOfInsecureContent (test flag affecting product
61 // behavior)
62 // - testRunner.setTextSubpixelPositioning (directly interacts with product).
63 // Note that "per-view" (non-"global") bindings are handled by
64 // instances of TestRunnerForSpecificView class.
65 // 2. It manages global test state. Example:
66 // - Tracking topLoadingFrame that can finish the test when it loads.
67 // - WorkQueue holding load requests from the TestInterfaces
68 // - LayoutTestRuntimeFlags
54 class TestRunner : public WebTestRunner { 69 class TestRunner : public WebTestRunner {
55 public: 70 public:
56 explicit TestRunner(TestInterfaces*); 71 explicit TestRunner(TestInterfaces*);
57 virtual ~TestRunner(); 72 virtual ~TestRunner();
58 73
59 void Install(blink::WebFrame* frame); 74 void Install(blink::WebLocalFrame* frame,
75 base::WeakPtr<TestRunnerForSpecificView> view_test_runner);
60 76
61 void SetDelegate(WebTestDelegate*); 77 void SetDelegate(WebTestDelegate*);
62 void SetWebView(blink::WebView*); 78 void SetWebView(blink::WebView*);
63 79
64 void Reset(); 80 void Reset();
65 81
66 void SetTestIsRunning(bool); 82 void SetTestIsRunning(bool);
67 bool TestIsRunning() const { return test_is_running_; } 83 bool TestIsRunning() const { return test_is_running_; }
68 84
69 bool UseMockTheme() const { return use_mock_theme_; } 85 bool UseMockTheme() const { return use_mock_theme_; }
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after
120 bool shouldWaitUntilExternalURLLoad() const; 136 bool shouldWaitUntilExternalURLLoad() const;
121 const std::set<std::string>* httpHeadersToClear() const; 137 const std::set<std::string>* httpHeadersToClear() const;
122 void setTopLoadingFrame(blink::WebFrame*, bool); 138 void setTopLoadingFrame(blink::WebFrame*, bool);
123 blink::WebFrame* topLoadingFrame() const; 139 blink::WebFrame* topLoadingFrame() const;
124 void policyDelegateDone(); 140 void policyDelegateDone();
125 bool policyDelegateEnabled() const; 141 bool policyDelegateEnabled() const;
126 bool policyDelegateIsPermissive() const; 142 bool policyDelegateIsPermissive() const;
127 bool policyDelegateShouldNotifyDone() const; 143 bool policyDelegateShouldNotifyDone() const;
128 bool shouldInterceptPostMessage() const; 144 bool shouldInterceptPostMessage() const;
129 bool shouldDumpResourcePriorities() const; 145 bool shouldDumpResourcePriorities() const;
130 bool RequestPointerLock();
131 void RequestPointerUnlock();
132 bool isPointerLocked();
133 void setToolTipText(const blink::WebString&); 146 void setToolTipText(const blink::WebString&);
134 void setDragImage(const blink::WebImage& drag_image); 147 void setDragImage(const blink::WebImage& drag_image);
135 bool shouldDumpNavigationPolicy() const; 148 bool shouldDumpNavigationPolicy() const;
136 149
137 bool midiAccessorResult(); 150 bool midiAccessorResult();
138 151
139 // Methods used by MockColorChooser: 152 // Methods used by MockColorChooser:
140 void DidOpenChooser(); 153 void DidOpenChooser();
141 void DidCloseChooser(); 154 void DidCloseChooser();
142 155
143 // A single item in the work queue. 156 // A single item in the work queue.
144 class WorkItem { 157 class WorkItem {
145 public: 158 public:
146 virtual ~WorkItem() {} 159 virtual ~WorkItem() {}
147 160
148 // Returns true if this started a load. 161 // Returns true if this started a load.
149 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0; 162 virtual bool Run(WebTestDelegate*, blink::WebView*) = 0;
150 }; 163 };
151 164
152 private: 165 private:
153 friend class TestRunnerBindings; 166 friend class TestRunnerBindings;
154 friend class WorkQueue; 167 friend class WorkQueue;
155 168
156 // Helpers for working with base and V8 callbacks.
157 void PostTask(const base::Closure& callback);
158 void PostDelayedTask(long long delay, const base::Closure& callback);
159 void PostV8Callback(const v8::Local<v8::Function>& callback);
160 void PostV8CallbackWithArgs(v8::UniquePersistent<v8::Function> callback,
161 int argc,
162 v8::Local<v8::Value> argv[]);
163 void InvokeV8Callback(const v8::UniquePersistent<v8::Function>& callback);
164 void InvokeV8CallbackWithArgs(
165 const v8::UniquePersistent<v8::Function>& callback,
166 const std::vector<v8::UniquePersistent<v8::Value>>& args);
167 base::Closure CreateClosureThatPostsV8Callback(
168 const v8::Local<v8::Function>& callback);
169
170 // Helper class for managing events queued by methods like queueLoad or 169 // Helper class for managing events queued by methods like queueLoad or
171 // queueScript. 170 // queueScript.
172 class WorkQueue { 171 class WorkQueue {
173 public: 172 public:
174 explicit WorkQueue(TestRunner* controller); 173 explicit WorkQueue(TestRunner* controller);
175 virtual ~WorkQueue(); 174 virtual ~WorkQueue();
176 void ProcessWorkSoon(); 175 void ProcessWorkSoon();
177 176
178 // Reset the state of the class between tests. 177 // Reset the state of the class between tests.
179 void Reset(); 178 void Reset();
(...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after
216 void SetCustomPolicyDelegate(gin::Arguments* args); 215 void SetCustomPolicyDelegate(gin::Arguments* args);
217 216
218 // Delays completion of the test until the policy delegate runs. 217 // Delays completion of the test until the policy delegate runs.
219 void WaitForPolicyDelegate(); 218 void WaitForPolicyDelegate();
220 219
221 // Functions for dealing with windows. By default we block all new windows. 220 // Functions for dealing with windows. By default we block all new windows.
222 int WindowCount(); 221 int WindowCount();
223 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows); 222 void SetCloseRemainingWindowsWhenComplete(bool close_remaining_windows);
224 void ResetTestHelperControllers(); 223 void ResetTestHelperControllers();
225 224
226 ///////////////////////////////////////////////////////////////////////////
227 // Methods implemented entirely in terms of chromium's public WebKit API
228
229 // Method that controls whether pressing Tab key cycles through page elements
230 // or inserts a '\t' char in text area
231 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
232
233 // Executes an internal command (superset of document.execCommand() commands).
234 void ExecCommand(gin::Arguments* args);
235
236 // Checks if an internal command is currently available.
237 bool IsCommandEnabled(const std::string& command);
238
239 bool CallShouldCloseOnWebView();
240 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
241 const std::string& scheme);
242 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
243 int world_id, const std::string& script);
244 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
245 void SetIsolatedWorldSecurityOrigin(int world_id,
246 v8::Local<v8::Value> origin);
247 void SetIsolatedWorldContentSecurityPolicy(int world_id,
248 const std::string& policy);
249
250 // Allows layout tests to manage origins' whitelisting. 225 // Allows layout tests to manage origins' whitelisting.
251 void AddOriginAccessWhitelistEntry(const std::string& source_origin, 226 void AddOriginAccessWhitelistEntry(const std::string& source_origin,
252 const std::string& destination_protocol, 227 const std::string& destination_protocol,
253 const std::string& destination_host, 228 const std::string& destination_host,
254 bool allow_destination_subdomains); 229 bool allow_destination_subdomains);
255 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin, 230 void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
256 const std::string& destination_protocol, 231 const std::string& destination_protocol,
257 const std::string& destination_host, 232 const std::string& destination_host,
258 bool allow_destination_subdomains); 233 bool allow_destination_subdomains);
259 234
260 // Returns true if the current page box has custom page size style for
261 // printing.
262 bool HasCustomPageSizeStyle(int page_index);
263
264 // Forces the selection colors for testing under Linux.
265 void ForceRedSelectionColors();
266
267 // Add |source_code| as an injected stylesheet to the active document of the 235 // Add |source_code| as an injected stylesheet to the active document of the
268 // window of the current V8 context. 236 // window of the current V8 context.
269 void InsertStyleSheet(const std::string& source_code); 237 void InsertStyleSheet(const std::string& source_code);
270 238
271 bool FindString(const std::string& search_text,
272 const std::vector<std::string>& options_array);
273
274 std::string SelectionAsMarkup();
275
276 // Enables or disables subpixel positioning (i.e. fractional X positions for 239 // Enables or disables subpixel positioning (i.e. fractional X positions for
277 // glyphs) in text rendering on Linux. Since this method changes global 240 // glyphs) in text rendering on Linux. Since this method changes global
278 // settings, tests that call it must use their own custom font family for 241 // settings, tests that call it must use their own custom font family for
279 // all text that they render. If not, an already-cached style will be used, 242 // all text that they render. If not, an already-cached style will be used,
280 // resulting in the changed setting being ignored. 243 // resulting in the changed setting being ignored.
281 void SetTextSubpixelPositioning(bool value); 244 void SetTextSubpixelPositioning(bool value);
282 245
283 // Switch the visibility of the page.
284 void SetPageVisibility(const std::string& new_visibility);
285
286 // Changes the direction of the focused element.
287 void SetTextDirection(const std::string& direction_name);
288
289 // After this function is called, all window-sizing machinery is 246 // After this function is called, all window-sizing machinery is
290 // short-circuited inside the renderer. This mode is necessary for 247 // short-circuited inside the renderer. This mode is necessary for
291 // some tests that were written before browsers had multi-process architecture 248 // some tests that were written before browsers had multi-process architecture
292 // and rely on window resizes to happen synchronously. 249 // and rely on window resizes to happen synchronously.
293 // The function has "unfortunate" it its name because we must strive to remove 250 // The function has "unfortunate" it its name because we must strive to remove
294 // all tests that rely on this... well, unfortunate behavior. See 251 // all tests that rely on this... well, unfortunate behavior. See
295 // http://crbug.com/309760 for the plan. 252 // http://crbug.com/309760 for the plan.
296 void UseUnfortunateSynchronousResizeMode(); 253 void UseUnfortunateSynchronousResizeMode();
297 254
298 bool EnableAutoResizeMode(int min_width, 255 bool EnableAutoResizeMode(int min_width,
(...skipping 22 matching lines...) Expand all
321 double rotation_rate_gamma, 278 double rotation_rate_gamma,
322 double interval); 279 double interval);
323 void SetMockDeviceOrientation(bool has_alpha, double alpha, 280 void SetMockDeviceOrientation(bool has_alpha, double alpha,
324 bool has_beta, double beta, 281 bool has_beta, double beta,
325 bool has_gamma, double gamma, 282 bool has_gamma, double gamma,
326 bool absolute); 283 bool absolute);
327 284
328 void SetMockScreenOrientation(const std::string& orientation); 285 void SetMockScreenOrientation(const std::string& orientation);
329 void DisableMockScreenOrientation(); 286 void DisableMockScreenOrientation();
330 287
331 void DidAcquirePointerLock();
332 void DidNotAcquirePointerLock();
333 void DidLosePointerLock();
334 void SetPointerLockWillFailSynchronously();
335 void SetPointerLockWillRespondAsynchronously();
336
337 /////////////////////////////////////////////////////////////////////////// 288 ///////////////////////////////////////////////////////////////////////////
338 // Methods modifying WebPreferences. 289 // Methods modifying WebPreferences.
339 290
340 // Set the WebPreference that controls webkit's popup blocking. 291 // Set the WebPreference that controls webkit's popup blocking.
341 void SetPopupBlockingEnabled(bool block_popups); 292 void SetPopupBlockingEnabled(bool block_popups);
342 293
343 void SetJavaScriptCanAccessClipboard(bool can_access); 294 void SetJavaScriptCanAccessClipboard(bool can_access);
344 void SetXSSAuditorEnabled(bool enabled); 295 void SetXSSAuditorEnabled(bool enabled);
345 void SetAllowUniversalAccessFromFileURLs(bool allow); 296 void SetAllowUniversalAccessFromFileURLs(bool allow);
346 void SetAllowFileAccessFromFileURLs(bool allow); 297 void SetAllowFileAccessFromFileURLs(bool allow);
(...skipping 137 matching lines...) Expand 10 before | Expand all | Expand 10 after
484 435
485 // This function sets a flag to dump the drag image when the next drag&drop is 436 // This function sets a flag to dump the drag image when the next drag&drop is
486 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel 437 // initiated. It is equivalent to DumpAsTextWithPixelResults but the pixel
487 // results will be the drag image instead of a snapshot of the page. 438 // results will be the drag image instead of a snapshot of the page.
488 void DumpDragImage(); 439 void DumpDragImage();
489 440
490 // Sets a flag that tells the WebTestProxy to dump the default navigation 441 // Sets a flag that tells the WebTestProxy to dump the default navigation
491 // policy passed to the decidePolicyForNavigation callback. 442 // policy passed to the decidePolicyForNavigation callback.
492 void DumpNavigationPolicy(); 443 void DumpNavigationPolicy();
493 444
494 // Dump current PageImportanceSignals for the page.
495 void DumpPageImportanceSignals();
496
497 /////////////////////////////////////////////////////////////////////////// 445 ///////////////////////////////////////////////////////////////////////////
498 // Methods interacting with the WebTestProxy 446 // Methods interacting with the WebTestProxy
499 447
500 /////////////////////////////////////////////////////////////////////////// 448 ///////////////////////////////////////////////////////////////////////////
501 // Methods forwarding to the WebTestDelegate 449 // Methods forwarding to the WebTestDelegate
502 450
503 // Shows DevTools window. 451 // Shows DevTools window.
504 void ShowWebInspector(const std::string& str, 452 void ShowWebInspector(const std::string& str,
505 const std::string& frontend_url); 453 const std::string& frontend_url);
506 void CloseWebInspector(); 454 void CloseWebInspector();
507 455
508 // Inspect chooser state 456 // Inspect chooser state
509 bool IsChooserShown(); 457 bool IsChooserShown();
510 458
511 // Allows layout tests to exec scripts at WebInspector side. 459 // Allows layout tests to exec scripts at WebInspector side.
512 void EvaluateInWebInspector(int call_id, const std::string& script); 460 void EvaluateInWebInspector(int call_id, const std::string& script);
513 // Allows layout tests to evaluate scripts in InspectorOverlay page. 461 // Allows layout tests to evaluate scripts in InspectorOverlay page.
514 // Script may have an output represented as a string, return values of other 462 // Script may have an output represented as a string, return values of other
515 // types would be ignored. 463 // types would be ignored.
516 std::string EvaluateInWebInspectorOverlay(const std::string& script); 464 std::string EvaluateInWebInspectorOverlay(const std::string& script);
517 465
518 // Clears all databases. 466 // Clears all databases.
519 void ClearAllDatabases(); 467 void ClearAllDatabases();
520 // Sets the default quota for all origins 468 // Sets the default quota for all origins
521 void SetDatabaseQuota(int quota); 469 void SetDatabaseQuota(int quota);
522 470
523 // Changes the cookie policy from the default to allow all cookies. 471 // Changes the cookie policy from the default to allow all cookies.
524 void SetAlwaysAcceptCookies(bool accept); 472 void SetAlwaysAcceptCookies(bool accept);
525 473
526 // Gives focus to the main test window.
527 void SetWindowIsKey(bool value);
528
529 // Converts a URL starting with file:///tmp/ to the local mapping. 474 // Converts a URL starting with file:///tmp/ to the local mapping.
530 std::string PathToLocalResource(const std::string& path); 475 std::string PathToLocalResource(const std::string& path);
531 476
532 // Used to set the device scale factor.
533 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
534
535 // Enable zoom-for-dsf option.
536 // TODO(oshima): Remove this once all platforms migrated.
537 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
538
539 // Change the device color profile while running a layout test.
540 void SetColorProfile(const std::string& name,
541 v8::Local<v8::Function> callback);
542
543 // Change the bluetooth test data while running a layout test.
544 void SetBluetoothFakeAdapter(const std::string& adapter_name,
545 v8::Local<v8::Function> callback);
546
547 // If |enable| is true, makes the Bluetooth chooser record its input and wait
548 // for instructions from the test program on how to proceed. Otherwise falls
549 // back to the browser's default chooser.
550 void SetBluetoothManualChooser(bool enable);
551
552 // Calls |callback| with a DOMString[] representing the events recorded since
553 // the last call to this function.
554 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
555
556 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid
557 // event strings are:
558 // * "cancel" - simulates the user canceling the chooser.
559 // * "select" - simulates the user selecting a device whose device ID is in
560 // |argument|.
561 void SendBluetoothManualChooserEvent(const std::string& event,
562 const std::string& argument);
563
564 // Enables mock geofencing service while running a layout test. 477 // Enables mock geofencing service while running a layout test.
565 // |service_available| indicates if the mock service should mock geofencing 478 // |service_available| indicates if the mock service should mock geofencing
566 // being available or not. 479 // being available or not.
567 void SetGeofencingMockProvider(bool service_available); 480 void SetGeofencingMockProvider(bool service_available);
568 481
569 // Disables mock geofencing service while running a layout test. 482 // Disables mock geofencing service while running a layout test.
570 void ClearGeofencingMockProvider(); 483 void ClearGeofencingMockProvider();
571 484
572 // Set the mock geofencing position while running a layout test. 485 // Set the mock geofencing position while running a layout test.
573 void SetGeofencingMockPosition(double latitude, double longitude); 486 void SetGeofencingMockPosition(double latitude, double longitude);
574 487
575 // Sets the permission's |name| to |value| for a given {origin, embedder} 488 // Sets the permission's |name| to |value| for a given {origin, embedder}
576 // tuple. 489 // tuple.
577 void SetPermission(const std::string& name, 490 void SetPermission(const std::string& name,
578 const std::string& value, 491 const std::string& value,
579 const GURL& origin, 492 const GURL& origin,
580 const GURL& embedding_origin); 493 const GURL& embedding_origin);
581 494
582 // Causes the beforeinstallprompt event to be sent to the renderer.
583 void DispatchBeforeInstallPromptEvent(
584 int request_id,
585 const std::vector<std::string>& event_platforms,
586 v8::Local<v8::Function> callback);
587
588 // Resolve the beforeinstallprompt event with the matching request id. 495 // Resolve the beforeinstallprompt event with the matching request id.
589 void ResolveBeforeInstallPromptPromise(int request_id, 496 void ResolveBeforeInstallPromptPromise(int request_id,
590 const std::string& platform); 497 const std::string& platform);
591 498
592 // Immediately run all pending idle tasks, including all pending
593 // requestIdleCallback calls. Invoke the callback when all
594 // idle tasks are complete.
595 void RunIdleTasks(v8::Local<v8::Function> callback);
596
597 // Calls setlocale(LC_ALL, ...) for a specified locale. 499 // Calls setlocale(LC_ALL, ...) for a specified locale.
598 // Resets between tests. 500 // Resets between tests.
599 void SetPOSIXLocale(const std::string& locale); 501 void SetPOSIXLocale(const std::string& locale);
600 502
601 // MIDI function to control permission handling. 503 // MIDI function to control permission handling.
602 void SetMIDIAccessorResult(bool result); 504 void SetMIDIAccessorResult(bool result);
603 505
604 // Simulates a click on a Web Notification. 506 // Simulates a click on a Web Notification.
605 void SimulateWebNotificationClick(const std::string& title, int action_index); 507 void SimulateWebNotificationClick(const std::string& title, int action_index);
606 508
607 // Simulates closing a Web Notification. 509 // Simulates closing a Web Notification.
608 void SimulateWebNotificationClose(const std::string& title, bool by_user); 510 void SimulateWebNotificationClose(const std::string& title, bool by_user);
609 511
610 // Speech recognition related functions. 512 // Speech recognition related functions.
611 void AddMockSpeechRecognitionResult(const std::string& transcript, 513 void AddMockSpeechRecognitionResult(const std::string& transcript,
612 double confidence); 514 double confidence);
613 void SetMockSpeechRecognitionError(const std::string& error, 515 void SetMockSpeechRecognitionError(const std::string& error,
614 const std::string& message); 516 const std::string& message);
615 517
616 // Credential Manager mock functions 518 // Credential Manager mock functions
617 // TODO(mkwst): Support FederatedCredential. 519 // TODO(mkwst): Support FederatedCredential.
618 void AddMockCredentialManagerResponse(const std::string& id, 520 void AddMockCredentialManagerResponse(const std::string& id,
619 const std::string& name, 521 const std::string& name,
620 const std::string& avatar, 522 const std::string& avatar,
621 const std::string& password); 523 const std::string& password);
622 void AddMockCredentialManagerError(const std::string& error); 524 void AddMockCredentialManagerError(const std::string& error);
623 525
624 // WebPageOverlay related functions. Permits the adding and removing of only
625 // one opaque overlay.
626 void AddWebPageOverlay();
627 void RemoveWebPageOverlay();
628
629 void LayoutAndPaintAsync();
630 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
631
632 // Similar to LayoutAndPaintAsyncThen(), but pass parameters of the captured
633 // snapshot (width, height, snapshot) to the callback. The snapshot is in
634 // uint8_t RGBA format.
635 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
636 // Similar to CapturePixelsAsyncThen(). Copies to the clipboard the image
637 // located at a particular point in the WebView (if there is such an image),
638 // reads back its pixels, and provides the snapshot to the callback. If there
639 // is no image at that point, calls the callback with (0, 0, empty_snapshot).
640 void CopyImageAtAndCapturePixelsAsyncThen(
641 int x, int y, const v8::Local<v8::Function> callback);
642
643 void GetManifestThen(v8::Local<v8::Function> callback);
644
645 // Takes care of notifying the delegate after a change to layout test runtime 526 // Takes care of notifying the delegate after a change to layout test runtime
646 // flags. 527 // flags.
647 void OnLayoutTestRuntimeFlagsChanged(); 528 void OnLayoutTestRuntimeFlagsChanged();
648 529
649 /////////////////////////////////////////////////////////////////////////// 530 ///////////////////////////////////////////////////////////////////////////
650 // Internal helpers 531 // Internal helpers
651 532
652 void GetManifestCallback(v8::UniquePersistent<v8::Function> callback,
653 const blink::WebURLResponse& response,
654 const std::string& data);
655 void CapturePixelsCallback(v8::UniquePersistent<v8::Function> callback,
656 const SkBitmap& snapshot);
657 void DispatchBeforeInstallPromptCallback(
658 v8::UniquePersistent<v8::Function> callback,
659 bool canceled);
660 void GetBluetoothManualChooserEventsCallback(
661 v8::UniquePersistent<v8::Function> callback,
662 const std::vector<std::string>& events);
663
664 void CheckResponseMimeType(); 533 void CheckResponseMimeType();
665 void CompleteNotifyDone(); 534 void CompleteNotifyDone();
666 535
667 void DidAcquirePointerLockInternal();
668 void DidNotAcquirePointerLockInternal();
669 void DidLosePointerLockInternal();
670
671 // In the Mac code, this is called to trigger the end of a test after the 536 // In the Mac code, this is called to trigger the end of a test after the
672 // page has finished loading. From here, we can generate the dump for the 537 // page has finished loading. From here, we can generate the dump for the
673 // test. 538 // test.
674 void LocationChangeDone(); 539 void LocationChangeDone();
675 540
676 // Sets a flag causing the next call to WebGLRenderingContext::create to fail.
677 void ForceNextWebGLContextCreationToFail();
678
679 // Sets a flag causing the next call to DrawingBuffer::create to fail.
680 void ForceNextDrawingBufferCreationToFail();
681
682 bool test_is_running_; 541 bool test_is_running_;
683 542
684 // When reset is called, go through and close all but the main test shell 543 // When reset is called, go through and close all but the main test shell
685 // window. By default, set to true but toggled to false using 544 // window. By default, set to true but toggled to false using
686 // setCloseRemainingWindowsWhenComplete(). 545 // setCloseRemainingWindowsWhenComplete().
687 bool close_remaining_windows_; 546 bool close_remaining_windows_;
688 547
689 WorkQueue work_queue_; 548 WorkQueue work_queue_;
690 549
691 // Bound variable to return the name of this platform (chromium). 550 // Bound variable to return the name of this platform (chromium).
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
745 TestInterfaces* test_interfaces_; 604 TestInterfaces* test_interfaces_;
746 WebTestDelegate* delegate_; 605 WebTestDelegate* delegate_;
747 blink::WebView* web_view_; 606 blink::WebView* web_view_;
748 607
749 // This is non-0 IFF a load is in progress. 608 // This is non-0 IFF a load is in progress.
750 blink::WebFrame* top_loading_frame_; 609 blink::WebFrame* top_loading_frame_;
751 610
752 // WebContentSettingsClient mock object. 611 // WebContentSettingsClient mock object.
753 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_; 612 std::unique_ptr<MockContentSettingsClient> mock_content_settings_client_;
754 613
755 bool pointer_locked_;
756 enum {
757 PointerLockWillSucceed,
758 PointerLockWillRespondAsync,
759 PointerLockWillFailSync,
760 } pointer_lock_planned_result_;
761 bool use_mock_theme_; 614 bool use_mock_theme_;
762 615
763 std::unique_ptr<MockCredentialManagerClient> credential_manager_client_; 616 std::unique_ptr<MockCredentialManagerClient> credential_manager_client_;
764 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_; 617 std::unique_ptr<MockScreenOrientationClient> mock_screen_orientation_client_;
765 std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_; 618 std::unique_ptr<MockWebSpeechRecognizer> speech_recognizer_;
766 std::unique_ptr<MockWebUserMediaClient> user_media_client_; 619 std::unique_ptr<MockWebUserMediaClient> user_media_client_;
767 std::unique_ptr<SpellCheckClient> spellcheck_; 620 std::unique_ptr<SpellCheckClient> spellcheck_;
768 621
769 // Number of currently active color choosers. 622 // Number of currently active color choosers.
770 int chooser_count_; 623 int chooser_count_;
771 624
772 // Captured drag image. 625 // Captured drag image.
773 blink::WebImage drag_image_; 626 blink::WebImage drag_image_;
774 627
775 // View that was focused by a previous call to TestRunner::SetFocus method. 628 // View that was focused by a previous call to TestRunner::SetFocus method.
776 // Note - this can be a dangling pointer to an already destroyed WebView (this 629 // Note - this can be a dangling pointer to an already destroyed WebView (this
777 // is ok, because this is taken care of in WebTestDelegate::SetFocus). 630 // is ok, because this is taken care of in WebTestDelegate::SetFocus).
778 blink::WebView* previously_focused_view_; 631 blink::WebView* previously_focused_view_;
779 632
780 std::set<blink::WebView*> views_with_scheduled_animations_; 633 std::set<blink::WebView*> views_with_scheduled_animations_;
781 634
782 base::WeakPtrFactory<TestRunner> weak_factory_; 635 base::WeakPtrFactory<TestRunner> weak_factory_;
783 636
784 DISALLOW_COPY_AND_ASSIGN(TestRunner); 637 DISALLOW_COPY_AND_ASSIGN(TestRunner);
785 }; 638 };
786 639
640 // TestRunnerForSpecificView implements part of |testRunner| javascript bindings
641 // that work with a view where the javascript call originated from. Examples:
642 // - testRunner.capturePixelsAsyncThen
643 // - testRunner.setPageVisibility
644 // Note that "global" bindings are handled by TestRunner class.
645 // TODO(lukasza): Move this class to a separate compilation unit.
646 class TestRunnerForSpecificView {
647 public:
648 explicit TestRunnerForSpecificView(WebTestProxyBase* web_test_proxy_base);
649 ~TestRunnerForSpecificView();
650
651 // Installs view-specific bindings (handled by |this|) and *also* global
652 // TestRunner bindings (both kinds of bindings are exposed via a single
653 // |testRunner| object in javascript).
654 void Install(blink::WebLocalFrame* frame);
655
656 void Reset();
657
658 // Pointer lock methods used by WebViewTestClient.
659 bool RequestPointerLock();
660 void RequestPointerUnlock();
661 bool isPointerLocked();
662
663 private:
664 friend class TestRunnerBindings;
665
666 // Helpers for working with base and V8 callbacks.
667 void PostTask(const base::Closure& callback);
668 void PostDelayedTask(long long delay, const base::Closure& callback);
669 void PostV8Callback(const v8::Local<v8::Function>& callback);
670 void PostV8CallbackWithArgs(v8::UniquePersistent<v8::Function> callback,
671 int argc,
672 v8::Local<v8::Value> argv[]);
673 void InvokeV8Callback(const v8::UniquePersistent<v8::Function>& callback);
674 void InvokeV8CallbackWithArgs(
675 const v8::UniquePersistent<v8::Function>& callback,
676 const std::vector<v8::UniquePersistent<v8::Value>>& args);
677 base::Closure CreateClosureThatPostsV8Callback(
678 const v8::Local<v8::Function>& callback);
679
680 void LayoutAndPaintAsync();
681 void LayoutAndPaintAsyncThen(v8::Local<v8::Function> callback);
682
683 // Similar to LayoutAndPaintAsyncThen(), but pass parameters of the captured
684 // snapshot (width, height, snapshot) to the callback. The snapshot is in
685 // uint8_t RGBA format.
686 void CapturePixelsAsyncThen(v8::Local<v8::Function> callback);
687 void CapturePixelsCallback(v8::UniquePersistent<v8::Function> callback,
688 const SkBitmap& snapshot);
689
690 // Similar to CapturePixelsAsyncThen(). Copies to the clipboard the image
691 // located at a particular point in the WebView (if there is such an image),
692 // reads back its pixels, and provides the snapshot to the callback. If there
693 // is no image at that point, calls the callback with (0, 0, empty_snapshot).
694 void CopyImageAtAndCapturePixelsAsyncThen(
695 int x,
696 int y,
697 const v8::Local<v8::Function> callback);
698
699 void GetManifestThen(v8::Local<v8::Function> callback);
700 void GetManifestCallback(v8::UniquePersistent<v8::Function> callback,
701 const blink::WebURLResponse& response,
702 const std::string& data);
703
704 // Calls |callback| with a DOMString[] representing the events recorded since
705 // the last call to this function.
706 void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
707 void GetBluetoothManualChooserEventsCallback(
708 v8::UniquePersistent<v8::Function> callback,
709 const std::vector<std::string>& events);
710
711 // Change the bluetooth test data while running a layout test.
712 void SetBluetoothFakeAdapter(const std::string& adapter_name,
713 v8::Local<v8::Function> callback);
714
715 // If |enable| is true, makes the Bluetooth chooser record its input and wait
716 // for instructions from the test program on how to proceed. Otherwise falls
717 // back to the browser's default chooser.
718 void SetBluetoothManualChooser(bool enable);
719
720 // Calls the BluetoothChooser::EventHandler with the arguments here. Valid
721 // event strings are:
722 // * "cancel" - simulates the user canceling the chooser.
723 // * "select" - simulates the user selecting a device whose device ID is in
724 // |argument|.
725 void SendBluetoothManualChooserEvent(const std::string& event,
726 const std::string& argument);
727
728 // Used to set the device scale factor.
729 void SetBackingScaleFactor(double value, v8::Local<v8::Function> callback);
730
731 // Enable zoom-for-dsf option.
732 // TODO(oshima): Remove this once all platforms migrated.
733 void EnableUseZoomForDSF(v8::Local<v8::Function> callback);
734
735 // Change the device color profile while running a layout test.
736 void SetColorProfile(const std::string& name,
737 v8::Local<v8::Function> callback);
738
739 // Causes the beforeinstallprompt event to be sent to the renderer.
740 void DispatchBeforeInstallPromptEvent(
741 int request_id,
742 const std::vector<std::string>& event_platforms,
743 v8::Local<v8::Function> callback);
744 void DispatchBeforeInstallPromptCallback(
745 v8::UniquePersistent<v8::Function> callback,
746 bool canceled);
747
748 // Immediately run all pending idle tasks, including all pending
749 // requestIdleCallback calls. Invoke the callback when all
750 // idle tasks are complete.
751 void RunIdleTasks(v8::Local<v8::Function> callback);
752
753 // Method that controls whether pressing Tab key cycles through page elements
754 // or inserts a '\t' char in text area
755 void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
756
757 // Executes an internal command (superset of document.execCommand() commands).
758 void ExecCommand(gin::Arguments* args);
759
760 // Checks if an internal command is currently available.
761 bool IsCommandEnabled(const std::string& command);
762
763 // Returns true if the current page box has custom page size style for
764 // printing.
765 bool HasCustomPageSizeStyle(int page_index);
766
767 // Forces the selection colors for testing under Linux.
768 void ForceRedSelectionColors();
769
770 // Switch the visibility of the page.
771 void SetPageVisibility(const std::string& new_visibility);
772
773 // Changes the direction of the focused element.
774 void SetTextDirection(const std::string& direction_name);
775
776 // Dump current PageImportanceSignals for the page.
777 void DumpPageImportanceSignals();
778
779 // WebPageOverlay related functions. Permits the adding and removing of only
780 // one opaque overlay.
781 void AddWebPageOverlay();
782 void RemoveWebPageOverlay();
783
784 // Sets a flag causing the next call to WebGLRenderingContext::create to fail.
785 void ForceNextWebGLContextCreationToFail();
786
787 // Sets a flag causing the next call to DrawingBuffer::create to fail.
788 void ForceNextDrawingBufferCreationToFail();
789
790 // Gives focus to the view associated with TestRunnerForSpecificView.
791 void SetWindowIsKey(bool value);
792
793 // Pointer lock handling.
794 void DidAcquirePointerLock();
795 void DidNotAcquirePointerLock();
796 void DidLosePointerLock();
797 void SetPointerLockWillFailSynchronously();
798 void SetPointerLockWillRespondAsynchronously();
799 void DidAcquirePointerLockInternal();
800 void DidNotAcquirePointerLockInternal();
801 void DidLosePointerLockInternal();
802 bool pointer_locked_;
803 enum {
804 PointerLockWillSucceed,
805 PointerLockWillRespondAsync,
806 PointerLockWillFailSync,
807 } pointer_lock_planned_result_;
808
809 bool CallShouldCloseOnWebView();
810 void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
811 const std::string& scheme);
812 v8::Local<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
813 int world_id,
814 const std::string& script);
815 void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
816 void SetIsolatedWorldSecurityOrigin(int world_id,
817 v8::Local<v8::Value> origin);
818 void SetIsolatedWorldContentSecurityPolicy(int world_id,
819 const std::string& policy);
820 bool FindString(const std::string& search_text,
821 const std::vector<std::string>& options_array);
822 std::string SelectionAsMarkup();
823 void SetViewSourceForFrame(const std::string& name, bool enabled);
824
825 // Helpers for accessing pointers exposed by |web_test_proxy_base_|.
826 blink::WebView* web_view();
827 WebTestDelegate* delegate();
828 WebTestProxyBase* web_test_proxy_base_;
829
830 base::WeakPtrFactory<TestRunnerForSpecificView> weak_factory_;
831
832 DISALLOW_COPY_AND_ASSIGN(TestRunnerForSpecificView);
833 };
834
787 } // namespace test_runner 835 } // namespace test_runner
788 836
789 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_ 837 #endif // COMPONENTS_TEST_RUNNER_TEST_RUNNER_H_
OLDNEW
« no previous file with comments | « components/test_runner/test_interfaces.cc ('k') | components/test_runner/test_runner.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698