de6d74996384717e77be7f545344492bcaee8b74
[platform/framework/web/crosswalk.git] / src / content / shell / renderer / test_runner / test_runner.cc
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
3 // found in the LICENSE file.
4
5 #include "content/shell/renderer/test_runner/test_runner.h"
6
7 #include <limits>
8
9 #include "content/shell/common/test_runner/WebPreferences.h"
10 #include "content/shell/renderer/test_runner/MockWebSpeechInputController.h"
11 #include "content/shell/renderer/test_runner/MockWebSpeechRecognizer.h"
12 #include "content/shell/renderer/test_runner/TestInterfaces.h"
13 #include "content/shell/renderer/test_runner/WebPermissions.h"
14 #include "content/shell/renderer/test_runner/WebTestDelegate.h"
15 #include "content/shell/renderer/test_runner/WebTestProxy.h"
16 #include "content/shell/renderer/test_runner/notification_presenter.h"
17 #include "gin/arguments.h"
18 #include "gin/array_buffer.h"
19 #include "gin/handle.h"
20 #include "gin/object_template_builder.h"
21 #include "gin/wrappable.h"
22 #include "third_party/WebKit/public/platform/WebCanvas.h"
23 #include "third_party/WebKit/public/platform/WebData.h"
24 #include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
25 #include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
26 #include "third_party/WebKit/public/platform/WebPoint.h"
27 #include "third_party/WebKit/public/platform/WebURLResponse.h"
28 #include "third_party/WebKit/public/web/WebBindings.h"
29 #include "third_party/WebKit/public/web/WebDataSource.h"
30 #include "third_party/WebKit/public/web/WebDocument.h"
31 #include "third_party/WebKit/public/web/WebFindOptions.h"
32 #include "third_party/WebKit/public/web/WebFrame.h"
33 #include "third_party/WebKit/public/web/WebInputElement.h"
34 #include "third_party/WebKit/public/web/WebKit.h"
35 #include "third_party/WebKit/public/web/WebMIDIClientMock.h"
36 #include "third_party/WebKit/public/web/WebPageOverlay.h"
37 #include "third_party/WebKit/public/web/WebScriptSource.h"
38 #include "third_party/WebKit/public/web/WebSecurityPolicy.h"
39 #include "third_party/WebKit/public/web/WebSerializedScriptValue.h"
40 #include "third_party/WebKit/public/web/WebSettings.h"
41 #include "third_party/WebKit/public/web/WebSurroundingText.h"
42 #include "third_party/WebKit/public/web/WebView.h"
43 #include "third_party/skia/include/core/SkCanvas.h"
44
45 #if defined(__linux__) || defined(ANDROID)
46 #include "third_party/WebKit/public/web/linux/WebFontRendering.h"
47 #endif
48
49 using namespace blink;
50 using namespace WebTestRunner;
51
52 namespace {
53
54 WebString V8StringToWebString(v8::Handle<v8::String> v8_str) {
55   int length = v8_str->Utf8Length() + 1;
56   scoped_ptr<char[]> chars(new char[length]);
57   v8_str->WriteUtf8(chars.get(), length);
58   return WebString::fromUTF8(chars.get());
59 }
60
61 class HostMethodTask :
62       public ::WebTestRunner::WebMethodTask<content::TestRunner> {
63  public:
64   typedef void (content::TestRunner::*CallbackMethodType)();
65   HostMethodTask(content::TestRunner* object, CallbackMethodType callback)
66       : WebMethodTask<content::TestRunner>(object), callback_(callback) {}
67
68   virtual void runIfValid() OVERRIDE {
69     (m_object->*callback_)();
70   }
71
72  private:
73   CallbackMethodType callback_;
74 };
75
76 }  // namespace
77
78 namespace content {
79
80 class InvokeCallbackTask : public WebMethodTask<content::TestRunner> {
81  public:
82   InvokeCallbackTask(content::TestRunner* object,
83                      v8::Handle<v8::Function> callback)
84       : WebMethodTask<content::TestRunner>(object),
85         callback_(blink::mainThreadIsolate(), callback) {}
86
87   virtual void runIfValid() OVERRIDE {
88     v8::Isolate* isolate = blink::mainThreadIsolate();
89     v8::HandleScope handle_scope(isolate);
90     WebFrame* frame = m_object->web_view_->mainFrame();
91
92     v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
93     if (context.IsEmpty())
94       return;
95
96     v8::Context::Scope context_scope(context);
97
98     frame->callFunctionEvenIfScriptDisabled(
99         v8::Local<v8::Function>::New(isolate, callback_),
100         context->Global(),
101         0,
102         NULL);
103   }
104
105  private:
106   v8::Persistent<v8::Function> callback_;
107 };
108
109 class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
110  public:
111   static gin::WrapperInfo kWrapperInfo;
112
113   static void Install(base::WeakPtr<TestRunner> controller,
114                       WebFrame* frame);
115
116  private:
117   explicit TestRunnerBindings(
118       base::WeakPtr<TestRunner> controller);
119   virtual ~TestRunnerBindings();
120
121   // gin::Wrappable:
122   virtual gin::ObjectTemplateBuilder GetObjectTemplateBuilder(
123       v8::Isolate* isolate) OVERRIDE;
124
125   void NotifyDone();
126   void WaitUntilDone();
127   void QueueBackNavigation(int how_far_back);
128   void QueueForwardNavigation(int how_far_forward);
129   void QueueReload();
130   void QueueLoadingScript(const std::string& script);
131   void QueueNonLoadingScript(const std::string& script);
132   void QueueLoad(gin::Arguments* args);
133   void QueueLoadHTMLString(gin::Arguments* args);
134   void SetCustomPolicyDelegate(gin::Arguments* args);
135   void WaitForPolicyDelegate();
136   int WindowCount();
137   void SetCloseRemainingWindowsWhenComplete(gin::Arguments* args);
138   void ResetTestHelperControllers();
139   void SetTabKeyCyclesThroughElements(bool tab_key_cycles_through_elements);
140   void ExecCommand(gin::Arguments* args);
141   bool IsCommandEnabled(const std::string& command);
142   bool CallShouldCloseOnWebView();
143   void SetDomainRelaxationForbiddenForURLScheme(bool forbidden,
144                                                 const std::string& scheme);
145   v8::Handle<v8::Value> EvaluateScriptInIsolatedWorldAndReturnValue(
146       int world_id, const std::string& script);
147   void EvaluateScriptInIsolatedWorld(int world_id, const std::string& script);
148   void SetIsolatedWorldSecurityOrigin(int world_id,
149                                       v8::Handle<v8::Value> origin);
150   void SetIsolatedWorldContentSecurityPolicy(int world_id,
151                                              const std::string& policy);
152   void AddOriginAccessWhitelistEntry(const std::string& source_origin,
153                                      const std::string& destination_protocol,
154                                      const std::string& destination_host,
155                                      bool allow_destination_subdomains);
156   void RemoveOriginAccessWhitelistEntry(const std::string& source_origin,
157                                         const std::string& destination_protocol,
158                                         const std::string& destination_host,
159                                         bool allow_destination_subdomains);
160   bool HasCustomPageSizeStyle(int page_index);
161   void ForceRedSelectionColors();
162   void InjectStyleSheet(const std::string& source_code, bool all_frames);
163   bool FindString(const std::string& search_text,
164                   const std::vector<std::string>& options_array);
165   std::string SelectionAsMarkup();
166   void SetTextSubpixelPositioning(bool value);
167   void SetPageVisibility(const std::string& new_visibility);
168   void SetTextDirection(const std::string& direction_name);
169   void UseUnfortunateSynchronousResizeMode();
170   bool EnableAutoResizeMode(int min_width,
171                             int min_height,
172                             int max_width,
173                             int max_height);
174   bool DisableAutoResizeMode(int new_width, int new_height);
175   void SetMockDeviceMotion(gin::Arguments* args);
176   void SetMockDeviceOrientation(gin::Arguments* args);
177   void SetMockScreenOrientation(const std::string& orientation);
178   void DidAcquirePointerLock();
179   void DidNotAcquirePointerLock();
180   void DidLosePointerLock();
181   void SetPointerLockWillFailSynchronously();
182   void SetPointerLockWillRespondAsynchronously();
183   void SetPopupBlockingEnabled(bool block_popups);
184   void SetJavaScriptCanAccessClipboard(bool can_access);
185   void SetXSSAuditorEnabled(bool enabled);
186   void SetAllowUniversalAccessFromFileURLs(bool allow);
187   void SetAllowFileAccessFromFileURLs(bool allow);
188   void OverridePreference(const std::string key, v8::Handle<v8::Value> value);
189   void SetPluginsEnabled(bool enabled);
190   void DumpEditingCallbacks();
191   void DumpAsText();
192   void DumpAsTextWithPixelResults();
193   void DumpChildFrameScrollPositions();
194   void DumpChildFramesAsText();
195   void DumpIconChanges();
196   void SetAudioData(const gin::ArrayBufferView& view);
197   void DumpFrameLoadCallbacks();
198   void DumpPingLoaderCallbacks();
199   void DumpUserGestureInFrameLoadCallbacks();
200   void DumpTitleChanges();
201   void DumpCreateView();
202   void SetCanOpenWindows();
203   void DumpResourceLoadCallbacks();
204   void DumpResourceRequestCallbacks();
205   void DumpResourceResponseMIMETypes();
206   void SetImagesAllowed(bool allowed);
207   void SetScriptsAllowed(bool allowed);
208   void SetStorageAllowed(bool allowed);
209   void SetPluginsAllowed(bool allowed);
210   void SetAllowDisplayOfInsecureContent(bool allowed);
211   void SetAllowRunningOfInsecureContent(bool allowed);
212   void DumpPermissionClientCallbacks();
213   void DumpWindowStatusChanges();
214   void DumpProgressFinishedCallback();
215   void DumpSpellCheckCallbacks();
216   void DumpBackForwardList();
217   void DumpSelectionRect();
218   void TestRepaint();
219   void RepaintSweepHorizontally();
220   void SetPrinting();
221   void SetShouldStayOnPageAfterHandlingBeforeUnload(bool value);
222   void SetWillSendRequestClearHeader(const std::string& header);
223   void DumpResourceRequestPriorities();
224   void SetUseMockTheme(bool use);
225   void ShowWebInspector(gin::Arguments* args);
226   void CloseWebInspector();
227   bool IsChooserShown();
228   void EvaluateInWebInspector(int call_id, const std::string& script);
229   void ClearAllDatabases();
230   void SetDatabaseQuota(int quota);
231   void SetAlwaysAcceptCookies(bool accept);
232   void SetWindowIsKey(bool value);
233   std::string PathToLocalResource(const std::string& path);
234   void SetBackingScaleFactor(double value, v8::Handle<v8::Function> callback);
235   void SetPOSIXLocale(const std::string& locale);
236   void SetMIDIAccessorResult(bool result);
237   void SetMIDISysexPermission(bool value);
238   void GrantWebNotificationPermission(gin::Arguments* args);
239   bool SimulateWebNotificationClick(const std::string& value);
240   void AddMockSpeechInputResult(const std::string& result,
241                                 double confidence,
242                                 const std::string& language);
243   void SetMockSpeechInputDumpRect(bool value);
244   void AddMockSpeechRecognitionResult(const std::string& transcript,
245                                       double confidence);
246   void SetMockSpeechRecognitionError(const std::string& error,
247                                      const std::string& message);
248   bool WasMockSpeechRecognitionAborted();
249   void AddWebPageOverlay();
250   void RemoveWebPageOverlay();
251   void Display();
252   void DisplayInvalidatedRegion();
253
254   bool GlobalFlag();
255   void SetGlobalFlag(bool value);
256   std::string PlatformName();
257   std::string TooltipText();
258   bool DisableNotifyDone();
259   int WebHistoryItemCount();
260   bool InterceptPostMessage();
261   void SetInterceptPostMessage(bool value);
262
263   void NotImplemented(const gin::Arguments& args);
264
265   base::WeakPtr<TestRunner> runner_;
266
267   DISALLOW_COPY_AND_ASSIGN(TestRunnerBindings);
268 };
269
270 gin::WrapperInfo TestRunnerBindings::kWrapperInfo = {
271     gin::kEmbedderNativeGin};
272
273 // static
274 void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
275                                  WebFrame* frame) {
276   v8::Isolate* isolate = blink::mainThreadIsolate();
277   v8::HandleScope handle_scope(isolate);
278   v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
279   if (context.IsEmpty())
280     return;
281
282   v8::Context::Scope context_scope(context);
283
284   gin::Handle<TestRunnerBindings> bindings =
285       gin::CreateHandle(isolate, new TestRunnerBindings(runner));
286   v8::Handle<v8::Object> global = context->Global();
287   v8::Handle<v8::Value> v8_bindings = bindings.ToV8();
288   global->Set(gin::StringToV8(isolate, "testRunner"), v8_bindings);
289   global->Set(gin::StringToV8(isolate, "layoutTestController"), v8_bindings);
290 }
291
292 TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
293     : runner_(runner) {}
294
295 TestRunnerBindings::~TestRunnerBindings() {}
296
297 gin::ObjectTemplateBuilder TestRunnerBindings::GetObjectTemplateBuilder(
298     v8::Isolate* isolate) {
299   return gin::Wrappable<TestRunnerBindings>::GetObjectTemplateBuilder(
300       isolate)
301       // Methods controlling test execution.
302       .SetMethod("notifyDone", &TestRunnerBindings::NotifyDone)
303       .SetMethod("waitUntilDone", &TestRunnerBindings::WaitUntilDone)
304       .SetMethod("queueBackNavigation",
305                  &TestRunnerBindings::QueueBackNavigation)
306       .SetMethod("queueForwardNavigation",
307                  &TestRunnerBindings::QueueForwardNavigation)
308       .SetMethod("queueReload", &TestRunnerBindings::QueueReload)
309       .SetMethod("queueLoadingScript", &TestRunnerBindings::QueueLoadingScript)
310       .SetMethod("queueNonLoadingScript",
311                  &TestRunnerBindings::QueueNonLoadingScript)
312       .SetMethod("queueLoad", &TestRunnerBindings::QueueLoad)
313       .SetMethod("queueLoadHTMLString",
314                  &TestRunnerBindings::QueueLoadHTMLString)
315       .SetMethod("setCustomPolicyDelegate",
316                  &TestRunnerBindings::SetCustomPolicyDelegate)
317       .SetMethod("waitForPolicyDelegate",
318                  &TestRunnerBindings::WaitForPolicyDelegate)
319       .SetMethod("windowCount", &TestRunnerBindings::WindowCount)
320       .SetMethod("setCloseRemainingWindowsWhenComplete",
321                  &TestRunnerBindings::SetCloseRemainingWindowsWhenComplete)
322       .SetMethod("resetTestHelperControllers",
323                  &TestRunnerBindings::ResetTestHelperControllers)
324       .SetMethod("setTabKeyCyclesThroughElements",
325                  &TestRunnerBindings::SetTabKeyCyclesThroughElements)
326       .SetMethod("execCommand", &TestRunnerBindings::ExecCommand)
327       .SetMethod("isCommandEnabled", &TestRunnerBindings::IsCommandEnabled)
328       .SetMethod("callShouldCloseOnWebView",
329                  &TestRunnerBindings::CallShouldCloseOnWebView)
330       .SetMethod("setDomainRelaxationForbiddenForURLScheme",
331                  &TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme)
332       .SetMethod("evaluateScriptInIsolatedWorldAndReturnValue",
333                  &TestRunnerBindings::
334                      EvaluateScriptInIsolatedWorldAndReturnValue)
335       .SetMethod("evaluateScriptInIsolatedWorld",
336                  &TestRunnerBindings::EvaluateScriptInIsolatedWorld)
337       .SetMethod("setIsolatedWorldSecurityOrigin",
338                  &TestRunnerBindings::SetIsolatedWorldSecurityOrigin)
339       .SetMethod("setIsolatedWorldContentSecurityPolicy",
340                  &TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy)
341       .SetMethod("addOriginAccessWhitelistEntry",
342                  &TestRunnerBindings::AddOriginAccessWhitelistEntry)
343       .SetMethod("removeOriginAccessWhitelistEntry",
344                  &TestRunnerBindings::RemoveOriginAccessWhitelistEntry)
345       .SetMethod("hasCustomPageSizeStyle",
346                  &TestRunnerBindings::HasCustomPageSizeStyle)
347       .SetMethod("forceRedSelectionColors",
348                  &TestRunnerBindings::ForceRedSelectionColors)
349       .SetMethod("injectStyleSheet", &TestRunnerBindings::InjectStyleSheet)
350       .SetMethod("findString", &TestRunnerBindings::FindString)
351       .SetMethod("selectionAsMarkup", &TestRunnerBindings::SelectionAsMarkup)
352       .SetMethod("setTextSubpixelPositioning",
353                  &TestRunnerBindings::SetTextSubpixelPositioning)
354       .SetMethod("setPageVisibility", &TestRunnerBindings::SetPageVisibility)
355       .SetMethod("setTextDirection", &TestRunnerBindings::SetTextDirection)
356       .SetMethod("useUnfortunateSynchronousResizeMode",
357                  &TestRunnerBindings::UseUnfortunateSynchronousResizeMode)
358       .SetMethod("enableAutoResizeMode",
359                  &TestRunnerBindings::EnableAutoResizeMode)
360       .SetMethod("disableAutoResizeMode",
361                  &TestRunnerBindings::DisableAutoResizeMode)
362       .SetMethod("setMockDeviceMotion",
363                  &TestRunnerBindings::SetMockDeviceMotion)
364       .SetMethod("setMockDeviceOrientation",
365                  &TestRunnerBindings::SetMockDeviceOrientation)
366       .SetMethod("setMockScreenOrientation",
367                  &TestRunnerBindings::SetMockScreenOrientation)
368       .SetMethod("didAcquirePointerLock",
369                  &TestRunnerBindings::DidAcquirePointerLock)
370       .SetMethod("didNotAcquirePointerLock",
371                  &TestRunnerBindings::DidNotAcquirePointerLock)
372       .SetMethod("didLosePointerLock", &TestRunnerBindings::DidLosePointerLock)
373       .SetMethod("setPointerLockWillFailSynchronously",
374                  &TestRunnerBindings::SetPointerLockWillFailSynchronously)
375       .SetMethod("setPointerLockWillRespondAsynchronously",
376                  &TestRunnerBindings::SetPointerLockWillRespondAsynchronously)
377       .SetMethod("setPopupBlockingEnabled",
378                  &TestRunnerBindings::SetPopupBlockingEnabled)
379       .SetMethod("setJavaScriptCanAccessClipboard",
380                  &TestRunnerBindings::SetJavaScriptCanAccessClipboard)
381       .SetMethod("setXSSAuditorEnabled",
382                  &TestRunnerBindings::SetXSSAuditorEnabled)
383       .SetMethod("setAllowUniversalAccessFromFileURLs",
384                  &TestRunnerBindings::SetAllowUniversalAccessFromFileURLs)
385       .SetMethod("setAllowFileAccessFromFileURLs",
386                  &TestRunnerBindings::SetAllowFileAccessFromFileURLs)
387       .SetMethod("overridePreference", &TestRunnerBindings::OverridePreference)
388       .SetMethod("setPluginsEnabled", &TestRunnerBindings::SetPluginsEnabled)
389       .SetMethod("dumpEditingCallbacks",
390                  &TestRunnerBindings::DumpEditingCallbacks)
391       .SetMethod("dumpAsText", &TestRunnerBindings::DumpAsText)
392       .SetMethod("dumpAsTextWithPixelResults",
393                  &TestRunnerBindings::DumpAsTextWithPixelResults)
394       .SetMethod("dumpChildFrameScrollPositions",
395                  &TestRunnerBindings::DumpChildFrameScrollPositions)
396       .SetMethod("dumpChildFramesAsText",
397                  &TestRunnerBindings::DumpChildFramesAsText)
398       .SetMethod("dumpIconChanges", &TestRunnerBindings::DumpIconChanges)
399       .SetMethod("setAudioData", &TestRunnerBindings::SetAudioData)
400       .SetMethod("dumpFrameLoadCallbacks",
401                  &TestRunnerBindings::DumpFrameLoadCallbacks)
402       .SetMethod("dumpPingLoaderCallbacks",
403                  &TestRunnerBindings::DumpPingLoaderCallbacks)
404       .SetMethod("dumpUserGestureInFrameLoadCallbacks",
405                  &TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks)
406       .SetMethod("dumpTitleChanges", &TestRunnerBindings::DumpTitleChanges)
407       .SetMethod("dumpCreateView", &TestRunnerBindings::DumpCreateView)
408       .SetMethod("setCanOpenWindows", &TestRunnerBindings::SetCanOpenWindows)
409       .SetMethod("dumpResourceLoadCallbacks",
410                  &TestRunnerBindings::DumpResourceLoadCallbacks)
411       .SetMethod("dumpResourceRequestCallbacks",
412                  &TestRunnerBindings::DumpResourceRequestCallbacks)
413       .SetMethod("dumpResourceResponseMIMETypes",
414                  &TestRunnerBindings::DumpResourceResponseMIMETypes)
415       .SetMethod("setImagesAllowed", &TestRunnerBindings::SetImagesAllowed)
416       .SetMethod("setScriptsAllowed", &TestRunnerBindings::SetScriptsAllowed)
417       .SetMethod("setStorageAllowed", &TestRunnerBindings::SetStorageAllowed)
418       .SetMethod("setPluginsAllowed", &TestRunnerBindings::SetPluginsAllowed)
419       .SetMethod("setAllowDisplayOfInsecureContent",
420                  &TestRunnerBindings::SetAllowDisplayOfInsecureContent)
421       .SetMethod("setAllowRunningOfInsecureContent",
422                  &TestRunnerBindings::SetAllowRunningOfInsecureContent)
423       .SetMethod("dumpPermissionClientCallbacks",
424                  &TestRunnerBindings::DumpPermissionClientCallbacks)
425       .SetMethod("dumpWindowStatusChanges",
426                  &TestRunnerBindings::DumpWindowStatusChanges)
427       .SetMethod("dumpProgressFinishedCallback",
428                  &TestRunnerBindings::DumpProgressFinishedCallback)
429       .SetMethod("dumpSpellCheckCallbacks",
430                  &TestRunnerBindings::DumpSpellCheckCallbacks)
431       .SetMethod("dumpBackForwardList",
432                  &TestRunnerBindings::DumpBackForwardList)
433       .SetMethod("dumpSelectionRect", &TestRunnerBindings::DumpSelectionRect)
434       .SetMethod("testRepaint", &TestRunnerBindings::TestRepaint)
435       .SetMethod("repaintSweepHorizontally",
436                  &TestRunnerBindings::RepaintSweepHorizontally)
437       .SetMethod("setPrinting", &TestRunnerBindings::SetPrinting)
438       .SetMethod("setShouldStayOnPageAfterHandlingBeforeUnload",
439                  &TestRunnerBindings::
440                      SetShouldStayOnPageAfterHandlingBeforeUnload)
441       .SetMethod("setWillSendRequestClearHeader",
442                  &TestRunnerBindings::SetWillSendRequestClearHeader)
443       .SetMethod("dumpResourceRequestPriorities",
444                  &TestRunnerBindings::DumpResourceRequestPriorities)
445       .SetMethod("setUseMockTheme", &TestRunnerBindings::SetUseMockTheme)
446       .SetMethod("showWebInspector", &TestRunnerBindings::ShowWebInspector)
447       .SetMethod("closeWebInspector", &TestRunnerBindings::CloseWebInspector)
448       .SetMethod("isChooserShown", &TestRunnerBindings::IsChooserShown)
449       .SetMethod("evaluateInWebInspector",
450                  &TestRunnerBindings::EvaluateInWebInspector)
451       .SetMethod("clearAllDatabases", &TestRunnerBindings::ClearAllDatabases)
452       .SetMethod("setDatabaseQuota", &TestRunnerBindings::SetDatabaseQuota)
453       .SetMethod("setAlwaysAcceptCookies",
454                  &TestRunnerBindings::SetAlwaysAcceptCookies)
455       .SetMethod("setWindowIsKey", &TestRunnerBindings::SetWindowIsKey)
456       .SetMethod("pathToLocalResource",
457                  &TestRunnerBindings::PathToLocalResource)
458       .SetMethod("setBackingScaleFactor",
459                  &TestRunnerBindings::SetBackingScaleFactor)
460       .SetMethod("setPOSIXLocale", &TestRunnerBindings::SetPOSIXLocale)
461       .SetMethod("setMIDIAccessorResult",
462                  &TestRunnerBindings::SetMIDIAccessorResult)
463       .SetMethod("setMIDISysexPermission",
464                  &TestRunnerBindings::SetMIDISysexPermission)
465       .SetMethod("grantWebNotificationPermission",
466                  &TestRunnerBindings::GrantWebNotificationPermission)
467       .SetMethod("simulateWebNotificationClick",
468                  &TestRunnerBindings::SimulateWebNotificationClick)
469       .SetMethod("addMockSpeechInputResult",
470                  &TestRunnerBindings::AddMockSpeechInputResult)
471       .SetMethod("setMockSpeechInputDumpRect",
472                  &TestRunnerBindings::SetMockSpeechInputDumpRect)
473       .SetMethod("addMockSpeechRecognitionResult",
474                  &TestRunnerBindings::AddMockSpeechRecognitionResult)
475       .SetMethod("setMockSpeechRecognitionError",
476                  &TestRunnerBindings::SetMockSpeechRecognitionError)
477       .SetMethod("wasMockSpeechRecognitionAborted",
478                  &TestRunnerBindings::WasMockSpeechRecognitionAborted)
479       .SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
480       .SetMethod("removeWebPageOverlay",
481                  &TestRunnerBindings::RemoveWebPageOverlay)
482       .SetMethod("display", &TestRunnerBindings::Display)
483       .SetMethod("displayInvalidatedRegion",
484                  &TestRunnerBindings::DisplayInvalidatedRegion)
485
486       // Properties.
487       .SetProperty("globalFlag", &TestRunnerBindings::GlobalFlag,
488                    &TestRunnerBindings::SetGlobalFlag)
489       .SetProperty("platformName", &TestRunnerBindings::PlatformName)
490       .SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
491       .SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
492       // webHistoryItemCount is used by tests in LayoutTests\http\tests\history
493       .SetProperty("webHistoryItemCount",
494                    &TestRunnerBindings::WebHistoryItemCount)
495       .SetProperty("interceptPostMessage",
496                    &TestRunnerBindings::InterceptPostMessage,
497                    &TestRunnerBindings::SetInterceptPostMessage)
498
499       // The following are stubs.
500       .SetMethod("dumpDatabaseCallbacks", &TestRunnerBindings::NotImplemented)
501       .SetMethod("setIconDatabaseEnabled", &TestRunnerBindings::NotImplemented)
502       .SetMethod("setScrollbarPolicy", &TestRunnerBindings::NotImplemented)
503       .SetMethod("clearAllApplicationCaches",
504                  &TestRunnerBindings::NotImplemented)
505       .SetMethod("clearApplicationCacheForOrigin",
506                  &TestRunnerBindings::NotImplemented)
507       .SetMethod("clearBackForwardList", &TestRunnerBindings::NotImplemented)
508       .SetMethod("keepWebHistory", &TestRunnerBindings::NotImplemented)
509       .SetMethod("setApplicationCacheOriginQuota",
510                  &TestRunnerBindings::NotImplemented)
511       .SetMethod("setCallCloseOnWebViews", &TestRunnerBindings::NotImplemented)
512       .SetMethod("setMainFrameIsFirstResponder",
513                  &TestRunnerBindings::NotImplemented)
514       .SetMethod("setUseDashboardCompatibilityMode",
515                  &TestRunnerBindings::NotImplemented)
516       .SetMethod("deleteAllLocalStorage", &TestRunnerBindings::NotImplemented)
517       .SetMethod("localStorageDiskUsageForOrigin",
518                  &TestRunnerBindings::NotImplemented)
519       .SetMethod("originsWithLocalStorage", &TestRunnerBindings::NotImplemented)
520       .SetMethod("deleteLocalStorageForOrigin",
521                  &TestRunnerBindings::NotImplemented)
522       .SetMethod("observeStorageTrackerNotifications",
523                  &TestRunnerBindings::NotImplemented)
524       .SetMethod("syncLocalStorage", &TestRunnerBindings::NotImplemented)
525       .SetMethod("addDisallowedURL", &TestRunnerBindings::NotImplemented)
526       .SetMethod("applicationCacheDiskUsageForOrigin",
527                  &TestRunnerBindings::NotImplemented)
528       .SetMethod("abortModal", &TestRunnerBindings::NotImplemented)
529
530       // Aliases.
531       // Used at fast/dom/assign-to-window-status.html
532       .SetMethod("dumpStatusCallbacks",
533                  &TestRunnerBindings::DumpWindowStatusChanges);
534
535 }
536
537 void TestRunnerBindings::NotifyDone() {
538   if (runner_)
539     runner_->NotifyDone();
540 }
541
542 void TestRunnerBindings::WaitUntilDone() {
543   if (runner_)
544     runner_->WaitUntilDone();
545 }
546
547 void TestRunnerBindings::QueueBackNavigation(int how_far_back) {
548   if (runner_)
549     runner_->QueueBackNavigation(how_far_back);
550 }
551
552 void TestRunnerBindings::QueueForwardNavigation(int how_far_forward) {
553   if (runner_)
554     runner_->QueueForwardNavigation(how_far_forward);
555 }
556
557 void TestRunnerBindings::QueueReload() {
558   if (runner_)
559     runner_->QueueReload();
560 }
561
562 void TestRunnerBindings::QueueLoadingScript(const std::string& script) {
563   if (runner_)
564     runner_->QueueLoadingScript(script);
565 }
566
567 void TestRunnerBindings::QueueNonLoadingScript(const std::string& script) {
568   if (runner_)
569     runner_->QueueNonLoadingScript(script);
570 }
571
572 void TestRunnerBindings::QueueLoad(gin::Arguments* args) {
573   if (runner_) {
574     std::string url;
575     std::string target;
576     args->GetNext(&url);
577     args->GetNext(&target);
578     runner_->QueueLoad(url, target);
579   }
580 }
581
582 void TestRunnerBindings::QueueLoadHTMLString(gin::Arguments* args) {
583   if (runner_)
584     runner_->QueueLoadHTMLString(args);
585 }
586
587 void TestRunnerBindings::SetCustomPolicyDelegate(gin::Arguments* args) {
588   if (runner_)
589     runner_->SetCustomPolicyDelegate(args);
590 }
591
592 void TestRunnerBindings::WaitForPolicyDelegate() {
593   if (runner_)
594     runner_->WaitForPolicyDelegate();
595 }
596
597 int TestRunnerBindings::WindowCount() {
598   if (runner_)
599     return runner_->WindowCount();
600   return 0;
601 }
602
603 void TestRunnerBindings::SetCloseRemainingWindowsWhenComplete(
604     gin::Arguments* args) {
605   if (!runner_)
606     return;
607
608   // In the original implementation, nothing happens if the argument is
609   // ommitted.
610   bool close_remaining_windows = false;
611   if (args->GetNext(&close_remaining_windows))
612     runner_->SetCloseRemainingWindowsWhenComplete(close_remaining_windows);
613 }
614
615 void TestRunnerBindings::ResetTestHelperControllers() {
616   if (runner_)
617     runner_->ResetTestHelperControllers();
618 }
619
620 void TestRunnerBindings::SetTabKeyCyclesThroughElements(
621     bool tab_key_cycles_through_elements) {
622   if (runner_)
623     runner_->SetTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
624 }
625
626 void TestRunnerBindings::ExecCommand(gin::Arguments* args) {
627   if (runner_)
628     runner_->ExecCommand(args);
629 }
630
631 bool TestRunnerBindings::IsCommandEnabled(const std::string& command) {
632   if (runner_)
633     return runner_->IsCommandEnabled(command);
634   return false;
635 }
636
637 bool TestRunnerBindings::CallShouldCloseOnWebView() {
638   if (runner_)
639     return runner_->CallShouldCloseOnWebView();
640   return false;
641 }
642
643 void TestRunnerBindings::SetDomainRelaxationForbiddenForURLScheme(
644     bool forbidden, const std::string& scheme) {
645   if (runner_)
646     runner_->SetDomainRelaxationForbiddenForURLScheme(forbidden, scheme);
647 }
648
649 v8::Handle<v8::Value>
650 TestRunnerBindings::EvaluateScriptInIsolatedWorldAndReturnValue(
651     int world_id, const std::string& script) {
652   if (!runner_)
653     return v8::Handle<v8::Value>();
654   return runner_->EvaluateScriptInIsolatedWorldAndReturnValue(world_id,
655                                                               script);
656 }
657
658 void TestRunnerBindings::EvaluateScriptInIsolatedWorld(
659     int world_id, const std::string& script) {
660   if (runner_)
661     runner_->EvaluateScriptInIsolatedWorld(world_id, script);
662 }
663
664 void TestRunnerBindings::SetIsolatedWorldSecurityOrigin(
665     int world_id, v8::Handle<v8::Value> origin) {
666   if (runner_)
667     runner_->SetIsolatedWorldSecurityOrigin(world_id, origin);
668 }
669
670 void TestRunnerBindings::SetIsolatedWorldContentSecurityPolicy(
671     int world_id, const std::string& policy) {
672   if (runner_)
673     runner_->SetIsolatedWorldContentSecurityPolicy(world_id, policy);
674 }
675
676 void TestRunnerBindings::AddOriginAccessWhitelistEntry(
677     const std::string& source_origin,
678     const std::string& destination_protocol,
679     const std::string& destination_host,
680     bool allow_destination_subdomains) {
681   if (runner_) {
682     runner_->AddOriginAccessWhitelistEntry(source_origin,
683                                            destination_protocol,
684                                            destination_host,
685                                            allow_destination_subdomains);
686   }
687 }
688
689 void TestRunnerBindings::RemoveOriginAccessWhitelistEntry(
690     const std::string& source_origin,
691     const std::string& destination_protocol,
692     const std::string& destination_host,
693     bool allow_destination_subdomains) {
694   if (runner_) {
695     runner_->RemoveOriginAccessWhitelistEntry(source_origin,
696                                               destination_protocol,
697                                               destination_host,
698                                               allow_destination_subdomains);
699   }
700 }
701
702 bool TestRunnerBindings::HasCustomPageSizeStyle(int page_index) {
703   if (runner_)
704     return runner_->HasCustomPageSizeStyle(page_index);
705   return false;
706 }
707
708 void TestRunnerBindings::ForceRedSelectionColors() {
709   if (runner_)
710     runner_->ForceRedSelectionColors();
711 }
712
713 void TestRunnerBindings::InjectStyleSheet(const std::string& source_code,
714                                           bool all_frames) {
715   if (runner_)
716     runner_->InjectStyleSheet(source_code, all_frames);
717 }
718
719 bool TestRunnerBindings::FindString(
720     const std::string& search_text,
721     const std::vector<std::string>& options_array) {
722   if (runner_)
723     return runner_->FindString(search_text, options_array);
724   return false;
725 }
726
727 std::string TestRunnerBindings::SelectionAsMarkup() {
728   if (runner_)
729     return runner_->SelectionAsMarkup();
730   return std::string();
731 }
732
733 void TestRunnerBindings::SetTextSubpixelPositioning(bool value) {
734   if (runner_)
735     runner_->SetTextSubpixelPositioning(value);
736 }
737
738 void TestRunnerBindings::SetPageVisibility(const std::string& new_visibility) {
739   if (runner_)
740     runner_->SetPageVisibility(new_visibility);
741 }
742
743 void TestRunnerBindings::SetTextDirection(const std::string& direction_name) {
744   if (runner_)
745     runner_->SetTextDirection(direction_name);
746 }
747
748 void TestRunnerBindings::UseUnfortunateSynchronousResizeMode() {
749   if (runner_)
750     runner_->UseUnfortunateSynchronousResizeMode();
751 }
752
753 bool TestRunnerBindings::EnableAutoResizeMode(int min_width,
754                                               int min_height,
755                                               int max_width,
756                                               int max_height) {
757   if (runner_) {
758     return runner_->EnableAutoResizeMode(min_width, min_height,
759                                          max_width, max_height);
760   }
761   return false;
762 }
763
764 bool TestRunnerBindings::DisableAutoResizeMode(int new_width, int new_height) {
765   if (runner_)
766     return runner_->DisableAutoResizeMode(new_width, new_height);
767   return false;
768 }
769
770 void TestRunnerBindings::SetMockDeviceMotion(gin::Arguments* args) {
771   if (!runner_)
772     return;
773
774   bool has_acceleration_x;
775   double acceleration_x;
776   bool has_acceleration_y;
777   double acceleration_y;
778   bool has_acceleration_z;
779   double acceleration_z;
780   bool has_acceleration_including_gravity_x;
781   double acceleration_including_gravity_x;
782   bool has_acceleration_including_gravity_y;
783   double acceleration_including_gravity_y;
784   bool has_acceleration_including_gravity_z;
785   double acceleration_including_gravity_z;
786   bool has_rotation_rate_alpha;
787   double rotation_rate_alpha;
788   bool has_rotation_rate_beta;
789   double rotation_rate_beta;
790   bool has_rotation_rate_gamma;
791   double rotation_rate_gamma;
792   double interval;
793
794   args->GetNext(&has_acceleration_x);
795   args->GetNext(& acceleration_x);
796   args->GetNext(&has_acceleration_y);
797   args->GetNext(& acceleration_y);
798   args->GetNext(&has_acceleration_z);
799   args->GetNext(& acceleration_z);
800   args->GetNext(&has_acceleration_including_gravity_x);
801   args->GetNext(& acceleration_including_gravity_x);
802   args->GetNext(&has_acceleration_including_gravity_y);
803   args->GetNext(& acceleration_including_gravity_y);
804   args->GetNext(&has_acceleration_including_gravity_z);
805   args->GetNext(& acceleration_including_gravity_z);
806   args->GetNext(&has_rotation_rate_alpha);
807   args->GetNext(& rotation_rate_alpha);
808   args->GetNext(&has_rotation_rate_beta);
809   args->GetNext(& rotation_rate_beta);
810   args->GetNext(&has_rotation_rate_gamma);
811   args->GetNext(& rotation_rate_gamma);
812   args->GetNext(& interval);
813
814   runner_->SetMockDeviceMotion(has_acceleration_x, acceleration_x,
815                                has_acceleration_y, acceleration_y,
816                                has_acceleration_z, acceleration_z,
817                                has_acceleration_including_gravity_x,
818                                acceleration_including_gravity_x,
819                                has_acceleration_including_gravity_y,
820                                acceleration_including_gravity_y,
821                                has_acceleration_including_gravity_z,
822                                acceleration_including_gravity_z,
823                                has_rotation_rate_alpha,
824                                rotation_rate_alpha,
825                                has_rotation_rate_beta,
826                                rotation_rate_beta,
827                                has_rotation_rate_gamma,
828                                rotation_rate_gamma,
829                                interval);
830 }
831
832 void TestRunnerBindings::SetMockDeviceOrientation(gin::Arguments* args) {
833   if (!runner_)
834     return;
835
836   bool has_alpha;
837   double alpha;
838   bool has_beta;
839   double beta;
840   bool has_gamma;
841   double gamma;
842   bool has_absolute;
843   bool absolute;
844
845   args->GetNext(&has_alpha);
846   args->GetNext(&alpha);
847   args->GetNext(&has_beta);
848   args->GetNext(&beta);
849   args->GetNext(&has_gamma);
850   args->GetNext(&gamma);
851   args->GetNext(&has_absolute);
852   args->GetNext(&absolute);
853
854   runner_->SetMockDeviceOrientation(has_alpha, alpha,
855                                     has_beta, beta,
856                                     has_gamma, gamma,
857                                     has_absolute, absolute);
858 }
859
860 void TestRunnerBindings::SetMockScreenOrientation(const std::string& orientation) {
861   if (!runner_)
862     return;
863
864   runner_->SetMockScreenOrientation(orientation);
865 }
866
867 void TestRunnerBindings::DidAcquirePointerLock() {
868   if (runner_)
869     runner_->DidAcquirePointerLock();
870 }
871
872 void TestRunnerBindings::DidNotAcquirePointerLock() {
873   if (runner_)
874     runner_->DidNotAcquirePointerLock();
875 }
876
877 void TestRunnerBindings::DidLosePointerLock() {
878   if (runner_)
879     runner_->DidLosePointerLock();
880 }
881
882 void TestRunnerBindings::SetPointerLockWillFailSynchronously() {
883   if (runner_)
884     runner_->SetPointerLockWillFailSynchronously();
885 }
886
887 void TestRunnerBindings::SetPointerLockWillRespondAsynchronously() {
888   if (runner_)
889     runner_->SetPointerLockWillRespondAsynchronously();
890 }
891
892 void TestRunnerBindings::SetPopupBlockingEnabled(bool block_popups) {
893   if (runner_)
894     runner_->SetPopupBlockingEnabled(block_popups);
895 }
896
897 void TestRunnerBindings::SetJavaScriptCanAccessClipboard(bool can_access) {
898   if (runner_)
899     runner_->SetJavaScriptCanAccessClipboard(can_access);
900 }
901
902 void TestRunnerBindings::SetXSSAuditorEnabled(bool enabled) {
903   if (runner_)
904     runner_->SetXSSAuditorEnabled(enabled);
905 }
906
907 void TestRunnerBindings::SetAllowUniversalAccessFromFileURLs(bool allow) {
908   if (runner_)
909     runner_->SetAllowUniversalAccessFromFileURLs(allow);
910 }
911
912 void TestRunnerBindings::SetAllowFileAccessFromFileURLs(bool allow) {
913   if (runner_)
914     runner_->SetAllowFileAccessFromFileURLs(allow);
915 }
916
917 void TestRunnerBindings::OverridePreference(const std::string key,
918                                             v8::Handle<v8::Value> value) {
919   if (runner_)
920     runner_->OverridePreference(key, value);
921 }
922
923 void TestRunnerBindings::SetPluginsEnabled(bool enabled) {
924   if (runner_)
925     runner_->SetPluginsEnabled(enabled);
926 }
927
928 void TestRunnerBindings::DumpEditingCallbacks() {
929   if (runner_)
930     runner_->DumpEditingCallbacks();
931 }
932
933 void TestRunnerBindings::DumpAsText() {
934   if (runner_)
935     runner_->DumpAsText();
936 }
937
938 void TestRunnerBindings::DumpAsTextWithPixelResults() {
939   if (runner_)
940     runner_->DumpAsTextWithPixelResults();
941 }
942
943 void TestRunnerBindings::DumpChildFrameScrollPositions() {
944   if (runner_)
945     runner_->DumpChildFrameScrollPositions();
946 }
947
948 void TestRunnerBindings::DumpChildFramesAsText() {
949   if (runner_)
950     runner_->DumpChildFramesAsText();
951 }
952
953 void TestRunnerBindings::DumpIconChanges() {
954   if (runner_)
955     runner_->DumpIconChanges();
956 }
957
958 void TestRunnerBindings::SetAudioData(const gin::ArrayBufferView& view) {
959   if (runner_)
960     runner_->SetAudioData(view);
961 }
962
963 void TestRunnerBindings::DumpFrameLoadCallbacks() {
964   if (runner_)
965     runner_->DumpFrameLoadCallbacks();
966 }
967
968 void TestRunnerBindings::DumpPingLoaderCallbacks() {
969   if (runner_)
970     runner_->DumpPingLoaderCallbacks();
971 }
972
973 void TestRunnerBindings::DumpUserGestureInFrameLoadCallbacks() {
974   if (runner_)
975     runner_->DumpUserGestureInFrameLoadCallbacks();
976 }
977
978 void TestRunnerBindings::DumpTitleChanges() {
979   if (runner_)
980     runner_->DumpTitleChanges();
981 }
982
983 void TestRunnerBindings::DumpCreateView() {
984   if (runner_)
985     runner_->DumpCreateView();
986 }
987
988 void TestRunnerBindings::SetCanOpenWindows() {
989   if (runner_)
990     runner_->SetCanOpenWindows();
991 }
992
993 void TestRunnerBindings::DumpResourceLoadCallbacks() {
994   if (runner_)
995     runner_->DumpResourceLoadCallbacks();
996 }
997
998 void TestRunnerBindings::DumpResourceRequestCallbacks() {
999   if (runner_)
1000     runner_->DumpResourceRequestCallbacks();
1001 }
1002
1003 void TestRunnerBindings::DumpResourceResponseMIMETypes() {
1004   if (runner_)
1005     runner_->DumpResourceResponseMIMETypes();
1006 }
1007
1008 void TestRunnerBindings::SetImagesAllowed(bool allowed) {
1009   if (runner_)
1010     runner_->SetImagesAllowed(allowed);
1011 }
1012
1013 void TestRunnerBindings::SetScriptsAllowed(bool allowed) {
1014   if (runner_)
1015     runner_->SetScriptsAllowed(allowed);
1016 }
1017
1018 void TestRunnerBindings::SetStorageAllowed(bool allowed) {
1019   if (runner_)
1020     runner_->SetStorageAllowed(allowed);
1021 }
1022
1023 void TestRunnerBindings::SetPluginsAllowed(bool allowed) {
1024   if (runner_)
1025     runner_->SetPluginsAllowed(allowed);
1026 }
1027
1028 void TestRunnerBindings::SetAllowDisplayOfInsecureContent(bool allowed) {
1029   if (runner_)
1030     runner_->SetAllowDisplayOfInsecureContent(allowed);
1031 }
1032
1033 void TestRunnerBindings::SetAllowRunningOfInsecureContent(bool allowed) {
1034   if (runner_)
1035     runner_->SetAllowRunningOfInsecureContent(allowed);
1036 }
1037
1038 void TestRunnerBindings::DumpPermissionClientCallbacks() {
1039   if (runner_)
1040     runner_->DumpPermissionClientCallbacks();
1041 }
1042
1043 void TestRunnerBindings::DumpWindowStatusChanges() {
1044   if (runner_)
1045     runner_->DumpWindowStatusChanges();
1046 }
1047
1048 void TestRunnerBindings::DumpProgressFinishedCallback() {
1049   if (runner_)
1050     runner_->DumpProgressFinishedCallback();
1051 }
1052
1053 void TestRunnerBindings::DumpSpellCheckCallbacks() {
1054   if (runner_)
1055     runner_->DumpSpellCheckCallbacks();
1056 }
1057
1058 void TestRunnerBindings::DumpBackForwardList() {
1059   if (runner_)
1060     runner_->DumpBackForwardList();
1061 }
1062
1063 void TestRunnerBindings::DumpSelectionRect() {
1064   if (runner_)
1065     runner_->DumpSelectionRect();
1066 }
1067
1068 void TestRunnerBindings::TestRepaint() {
1069   if (runner_)
1070     runner_->TestRepaint();
1071 }
1072
1073 void TestRunnerBindings::RepaintSweepHorizontally() {
1074   if (runner_)
1075     runner_->RepaintSweepHorizontally();
1076 }
1077
1078 void TestRunnerBindings::SetPrinting() {
1079   if (runner_)
1080     runner_->SetPrinting();
1081 }
1082
1083 void TestRunnerBindings::SetShouldStayOnPageAfterHandlingBeforeUnload(
1084     bool value) {
1085   if (runner_)
1086     runner_->SetShouldStayOnPageAfterHandlingBeforeUnload(value);
1087 }
1088
1089 void TestRunnerBindings::SetWillSendRequestClearHeader(
1090     const std::string& header) {
1091   if (runner_)
1092     runner_->SetWillSendRequestClearHeader(header);
1093 }
1094
1095 void TestRunnerBindings::DumpResourceRequestPriorities() {
1096   if (runner_)
1097     runner_->DumpResourceRequestPriorities();
1098 }
1099
1100 void TestRunnerBindings::SetUseMockTheme(bool use) {
1101   if (runner_)
1102     runner_->SetUseMockTheme(use);
1103 }
1104
1105 void TestRunnerBindings::ShowWebInspector(gin::Arguments* args) {
1106   if (runner_) {
1107     std::string str;
1108     args->GetNext(&str);
1109     runner_->ShowWebInspector(str);
1110   }
1111 }
1112
1113 void TestRunnerBindings::CloseWebInspector() {
1114   if (runner_)
1115     runner_->CloseWebInspector();
1116 }
1117
1118 bool TestRunnerBindings::IsChooserShown() {
1119   if (runner_)
1120     return runner_->IsChooserShown();
1121   return false;
1122 }
1123
1124 void TestRunnerBindings::EvaluateInWebInspector(int call_id,
1125                                                 const std::string& script) {
1126   if (runner_)
1127     runner_->EvaluateInWebInspector(call_id, script);
1128 }
1129
1130 void TestRunnerBindings::ClearAllDatabases() {
1131   if (runner_)
1132     runner_->ClearAllDatabases();
1133 }
1134
1135 void TestRunnerBindings::SetDatabaseQuota(int quota) {
1136   if (runner_)
1137     runner_->SetDatabaseQuota(quota);
1138 }
1139
1140 void TestRunnerBindings::SetAlwaysAcceptCookies(bool accept) {
1141   if (runner_)
1142     runner_->SetAlwaysAcceptCookies(accept);
1143 }
1144
1145 void TestRunnerBindings::SetWindowIsKey(bool value) {
1146   if (runner_)
1147     runner_->SetWindowIsKey(value);
1148 }
1149
1150 std::string TestRunnerBindings::PathToLocalResource(const std::string& path) {
1151   if (runner_)
1152     return runner_->PathToLocalResource(path);
1153   return std::string();
1154 }
1155
1156 void TestRunnerBindings::SetBackingScaleFactor(
1157     double value, v8::Handle<v8::Function> callback) {
1158   if (runner_)
1159     runner_->SetBackingScaleFactor(value, callback);
1160 }
1161
1162 void TestRunnerBindings::SetPOSIXLocale(const std::string& locale) {
1163   if (runner_)
1164     runner_->SetPOSIXLocale(locale);
1165 }
1166
1167 void TestRunnerBindings::SetMIDIAccessorResult(bool result) {
1168   if (runner_)
1169     runner_->SetMIDIAccessorResult(result);
1170 }
1171
1172 void TestRunnerBindings::SetMIDISysexPermission(bool value) {
1173   if (runner_)
1174     runner_->SetMIDISysexPermission(value);
1175 }
1176
1177 void TestRunnerBindings::GrantWebNotificationPermission(gin::Arguments* args) {
1178   if (runner_) {
1179     std::string origin;
1180     bool permission_granted = true;
1181     args->GetNext(&origin);
1182     args->GetNext(&permission_granted);
1183     return runner_->GrantWebNotificationPermission(origin, permission_granted);
1184   }
1185 }
1186
1187 bool TestRunnerBindings::SimulateWebNotificationClick(
1188     const std::string& value) {
1189   if (runner_)
1190     return runner_->SimulateWebNotificationClick(value);
1191   return false;
1192 }
1193
1194 void TestRunnerBindings::AddMockSpeechInputResult(const std::string& result,
1195                                                   double confidence,
1196                                                   const std::string& language) {
1197   if (runner_)
1198     runner_->AddMockSpeechInputResult(result, confidence, language);
1199 }
1200
1201 void TestRunnerBindings::SetMockSpeechInputDumpRect(bool value) {
1202   if (runner_)
1203     runner_->SetMockSpeechInputDumpRect(value);
1204 }
1205
1206 void TestRunnerBindings::AddMockSpeechRecognitionResult(
1207     const std::string& transcript, double confidence) {
1208   if (runner_)
1209     runner_->AddMockSpeechRecognitionResult(transcript, confidence);
1210 }
1211
1212 void TestRunnerBindings::SetMockSpeechRecognitionError(
1213     const std::string& error, const std::string& message) {
1214   if (runner_)
1215     runner_->SetMockSpeechRecognitionError(error, message);
1216 }
1217
1218 bool TestRunnerBindings::WasMockSpeechRecognitionAborted() {
1219   if (runner_)
1220     return runner_->WasMockSpeechRecognitionAborted();
1221   return false;
1222 }
1223
1224 void TestRunnerBindings::AddWebPageOverlay() {
1225   if (runner_)
1226     runner_->AddWebPageOverlay();
1227 }
1228
1229 void TestRunnerBindings::RemoveWebPageOverlay() {
1230   if (runner_)
1231     runner_->RemoveWebPageOverlay();
1232 }
1233
1234 void TestRunnerBindings::Display() {
1235   if (runner_)
1236     runner_->Display();
1237 }
1238
1239 void TestRunnerBindings::DisplayInvalidatedRegion() {
1240   if (runner_)
1241     runner_->DisplayInvalidatedRegion();
1242 }
1243
1244 bool TestRunnerBindings::GlobalFlag() {
1245   if (runner_)
1246     return runner_->global_flag_;
1247   return false;
1248 }
1249
1250 void TestRunnerBindings::SetGlobalFlag(bool value) {
1251   if (runner_)
1252     runner_->global_flag_ = value;
1253 }
1254
1255 std::string TestRunnerBindings::PlatformName() {
1256   if (runner_)
1257     return runner_->platform_name_;
1258   return std::string();
1259 }
1260
1261 std::string TestRunnerBindings::TooltipText() {
1262   if (runner_)
1263     return runner_->tooltip_text_;
1264   return std::string();
1265 }
1266
1267 bool TestRunnerBindings::DisableNotifyDone() {
1268   if (runner_)
1269     return runner_->disable_notify_done_;
1270   return false;
1271 }
1272
1273 int TestRunnerBindings::WebHistoryItemCount() {
1274   if (runner_)
1275     return runner_->web_history_item_count_;
1276   return false;
1277 }
1278
1279 bool TestRunnerBindings::InterceptPostMessage() {
1280   if (runner_)
1281     return runner_->intercept_post_message_;
1282   return false;
1283 }
1284
1285 void TestRunnerBindings::SetInterceptPostMessage(bool value) {
1286   if (runner_)
1287     runner_->intercept_post_message_ = value;
1288 }
1289
1290 void TestRunnerBindings::NotImplemented(const gin::Arguments& args) {
1291 }
1292
1293 class TestPageOverlay : public WebPageOverlay {
1294  public:
1295   explicit TestPageOverlay(WebView* web_view)
1296       : web_view_(web_view) {
1297   }
1298   virtual ~TestPageOverlay() {}
1299
1300   virtual void paintPageOverlay(WebCanvas* canvas) OVERRIDE  {
1301     SkRect rect = SkRect::MakeWH(web_view_->size().width,
1302                                  web_view_->size().height);
1303     SkPaint paint;
1304     paint.setColor(SK_ColorCYAN);
1305     paint.setStyle(SkPaint::kFill_Style);
1306     canvas->drawRect(rect, paint);
1307   }
1308
1309  private:
1310   WebView* web_view_;
1311 };
1312
1313 TestRunner::WorkQueue::WorkQueue(TestRunner* controller)
1314     : frozen_(false)
1315     , controller_(controller) {}
1316
1317 TestRunner::WorkQueue::~WorkQueue() {
1318   Reset();
1319 }
1320
1321 void TestRunner::WorkQueue::ProcessWorkSoon() {
1322   if (controller_->topLoadingFrame())
1323     return;
1324
1325   if (!queue_.empty()) {
1326     // We delay processing queued work to avoid recursion problems.
1327     controller_->delegate_->postTask(new WorkQueueTask(this));
1328   } else if (!controller_->wait_until_done_) {
1329     controller_->delegate_->testFinished();
1330   }
1331 }
1332
1333 void TestRunner::WorkQueue::Reset() {
1334   frozen_ = false;
1335   while (!queue_.empty()) {
1336     delete queue_.front();
1337     queue_.pop_front();
1338   }
1339 }
1340
1341 void TestRunner::WorkQueue::AddWork(WorkItem* work) {
1342   if (frozen_) {
1343     delete work;
1344     return;
1345   }
1346   queue_.push_back(work);
1347 }
1348
1349 void TestRunner::WorkQueue::ProcessWork() {
1350   // Quit doing work once a load is in progress.
1351   while (!queue_.empty()) {
1352     bool startedLoad = queue_.front()->Run(controller_->delegate_,
1353                                            controller_->web_view_);
1354     delete queue_.front();
1355     queue_.pop_front();
1356     if (startedLoad)
1357       return;
1358   }
1359
1360   if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
1361     controller_->delegate_->testFinished();
1362 }
1363
1364 void TestRunner::WorkQueue::WorkQueueTask::runIfValid() {
1365   m_object->ProcessWork();
1366 }
1367
1368 TestRunner::TestRunner(TestInterfaces* interfaces)
1369     : test_is_running_(false),
1370       close_remaining_windows_(false),
1371       work_queue_(this),
1372       disable_notify_done_(false),
1373       web_history_item_count_(0),
1374       intercept_post_message_(false),
1375       test_interfaces_(interfaces),
1376       delegate_(NULL),
1377       web_view_(NULL),
1378       page_overlay_(NULL),
1379       web_permissions_(new WebPermissions()),
1380       notification_presenter_(new content::NotificationPresenter()),
1381       weak_factory_(this) {}
1382
1383 TestRunner::~TestRunner() {}
1384
1385 void TestRunner::Install(WebFrame* frame) {
1386   TestRunnerBindings::Install(weak_factory_.GetWeakPtr(), frame);
1387 }
1388
1389 void TestRunner::SetDelegate(WebTestDelegate* delegate) {
1390   delegate_ = delegate;
1391   web_permissions_->setDelegate(delegate);
1392   notification_presenter_->set_delegate(delegate);
1393 }
1394
1395 void TestRunner::SetWebView(WebView* webView, WebTestProxyBase* proxy) {
1396   web_view_ = webView;
1397   proxy_ = proxy;
1398 }
1399
1400 void TestRunner::Reset() {
1401   if (web_view_) {
1402     web_view_->setZoomLevel(0);
1403     web_view_->setTextZoomFactor(1);
1404     web_view_->setTabKeyCyclesThroughElements(true);
1405 #if !defined(__APPLE__) && !defined(WIN32) // Actually, TOOLKIT_GTK
1406     // (Constants copied because we can't depend on the header that defined
1407     // them from this file.)
1408     web_view_->setSelectionColors(
1409         0xff1e90ff, 0xff000000, 0xffc8c8c8, 0xff323232);
1410 #endif
1411     web_view_->removeInjectedStyleSheets();
1412     web_view_->setVisibilityState(WebPageVisibilityStateVisible, true);
1413     web_view_->mainFrame()->enableViewSourceMode(false);
1414
1415     if (page_overlay_) {
1416       web_view_->removePageOverlay(page_overlay_);
1417       delete page_overlay_;
1418       page_overlay_ = NULL;
1419     }
1420   }
1421
1422   top_loading_frame_ = NULL;
1423   wait_until_done_ = false;
1424   policy_delegate_enabled_ = false;
1425   policy_delegate_is_permissive_ = false;
1426   policy_delegate_should_notify_done_ = false;
1427
1428   WebSecurityPolicy::resetOriginAccessWhitelists();
1429 #if defined(__linux__) || defined(ANDROID)
1430   WebFontRendering::setSubpixelPositioning(false);
1431 #endif
1432
1433   if (delegate_) {
1434     // Reset the default quota for each origin to 5MB
1435     delegate_->setDatabaseQuota(5 * 1024 * 1024);
1436     delegate_->setDeviceScaleFactor(1);
1437     delegate_->setAcceptAllCookies(false);
1438     delegate_->setLocale("");
1439     delegate_->useUnfortunateSynchronousResizeMode(false);
1440     delegate_->disableAutoResizeMode(WebSize());
1441     delegate_->deleteAllCookies();
1442   }
1443
1444   dump_editting_callbacks_ = false;
1445   dump_as_text_ = false;
1446   dump_as_markup_ = false;
1447   generate_pixel_results_ = true;
1448   dump_child_frame_scroll_positions_ = false;
1449   dump_child_frames_as_text_ = false;
1450   dump_icon_changes_ = false;
1451   dump_as_audio_ = false;
1452   dump_frame_load_callbacks_ = false;
1453   dump_ping_loader_callbacks_ = false;
1454   dump_user_gesture_in_frame_load_callbacks_ = false;
1455   dump_title_changes_ = false;
1456   dump_create_view_ = false;
1457   can_open_windows_ = false;
1458   dump_resource_load_callbacks_ = false;
1459   dump_resource_request_callbacks_ = false;
1460   dump_resource_reqponse_mime_types_ = false;
1461   dump_window_status_changes_ = false;
1462   dump_progress_finished_callback_ = false;
1463   dump_spell_check_callbacks_ = false;
1464   dump_back_forward_list_ = false;
1465   dump_selection_rect_ = false;
1466   test_repaint_ = false;
1467   sweep_horizontally_ = false;
1468   is_printing_ = false;
1469   midi_accessor_result_ = true;
1470   should_stay_on_page_after_handling_before_unload_ = false;
1471   should_dump_resource_priorities_ = false;
1472
1473   http_headers_to_clear_.clear();
1474
1475   global_flag_ = false;
1476   platform_name_ = "chromium";
1477   tooltip_text_ = std::string();
1478   disable_notify_done_ = false;
1479   web_history_item_count_ = 0;
1480   intercept_post_message_ = false;
1481
1482   web_permissions_->reset();
1483
1484   notification_presenter_->Reset();
1485   use_mock_theme_ = true;
1486   pointer_locked_ = false;
1487   pointer_lock_planned_result_ = PointerLockWillSucceed;
1488
1489   task_list_.revokeAll();
1490   work_queue_.Reset();
1491
1492   if (close_remaining_windows_ && delegate_)
1493     delegate_->closeRemainingWindows();
1494   else
1495     close_remaining_windows_ = true;
1496 }
1497
1498 void TestRunner::SetTestIsRunning(bool running) {
1499   test_is_running_ = running;
1500 }
1501
1502 bool TestRunner::shouldDumpEditingCallbacks() const {
1503   return dump_editting_callbacks_;
1504 }
1505
1506 bool TestRunner::shouldDumpAsText() {
1507   CheckResponseMimeType();
1508   return dump_as_text_;
1509 }
1510
1511 void TestRunner::setShouldDumpAsText(bool value) {
1512   dump_as_text_ = value;
1513 }
1514
1515 bool TestRunner::shouldDumpAsMarkup() {
1516   return dump_as_markup_;
1517 }
1518
1519 void TestRunner::setShouldDumpAsMarkup(bool value) {
1520   dump_as_markup_ = value;
1521 }
1522
1523 bool TestRunner::shouldGeneratePixelResults() {
1524   CheckResponseMimeType();
1525   return generate_pixel_results_;
1526 }
1527
1528 void TestRunner::setShouldGeneratePixelResults(bool value) {
1529   generate_pixel_results_ = value;
1530 }
1531
1532 bool TestRunner::shouldDumpChildFrameScrollPositions() const {
1533   return dump_child_frame_scroll_positions_;
1534 }
1535
1536 bool TestRunner::shouldDumpChildFramesAsText() const {
1537   return dump_child_frames_as_text_;
1538 }
1539
1540 bool TestRunner::shouldDumpAsAudio() const {
1541   return dump_as_audio_;
1542 }
1543
1544 void TestRunner::getAudioData(std::vector<unsigned char>* bufferView) const {
1545   *bufferView = audio_data_;
1546 }
1547
1548 bool TestRunner::shouldDumpFrameLoadCallbacks() const {
1549   return test_is_running_ && dump_frame_load_callbacks_;
1550 }
1551
1552 void TestRunner::setShouldDumpFrameLoadCallbacks(bool value) {
1553   dump_frame_load_callbacks_ = value;
1554 }
1555
1556 bool TestRunner::shouldDumpPingLoaderCallbacks() const {
1557   return test_is_running_ && dump_ping_loader_callbacks_;
1558 }
1559
1560 void TestRunner::setShouldDumpPingLoaderCallbacks(bool value) {
1561   dump_ping_loader_callbacks_ = value;
1562 }
1563
1564 void TestRunner::setShouldEnableViewSource(bool value) {
1565   web_view_->mainFrame()->enableViewSourceMode(value);
1566 }
1567
1568 bool TestRunner::shouldDumpUserGestureInFrameLoadCallbacks() const {
1569   return test_is_running_ && dump_user_gesture_in_frame_load_callbacks_;
1570 }
1571
1572 bool TestRunner::shouldDumpTitleChanges() const {
1573   return dump_title_changes_;
1574 }
1575
1576 bool TestRunner::shouldDumpIconChanges() const {
1577   return dump_icon_changes_;
1578 }
1579
1580 bool TestRunner::shouldDumpCreateView() const {
1581   return dump_create_view_;
1582 }
1583
1584 bool TestRunner::canOpenWindows() const {
1585   return can_open_windows_;
1586 }
1587
1588 bool TestRunner::shouldDumpResourceLoadCallbacks() const {
1589   return test_is_running_ && dump_resource_load_callbacks_;
1590 }
1591
1592 bool TestRunner::shouldDumpResourceRequestCallbacks() const {
1593   return test_is_running_ && dump_resource_request_callbacks_;
1594 }
1595
1596 bool TestRunner::shouldDumpResourceResponseMIMETypes() const {
1597   return test_is_running_ && dump_resource_reqponse_mime_types_;
1598 }
1599
1600 WebPermissionClient* TestRunner::webPermissions() const {
1601   return web_permissions_.get();
1602 }
1603
1604 bool TestRunner::shouldDumpStatusCallbacks() const {
1605   return dump_window_status_changes_;
1606 }
1607
1608 bool TestRunner::shouldDumpProgressFinishedCallback() const {
1609   return dump_progress_finished_callback_;
1610 }
1611
1612 bool TestRunner::shouldDumpSpellCheckCallbacks() const {
1613   return dump_spell_check_callbacks_;
1614 }
1615
1616 bool TestRunner::shouldDumpBackForwardList() const {
1617   return dump_back_forward_list_;
1618 }
1619
1620 bool TestRunner::shouldDumpSelectionRect() const {
1621   return dump_selection_rect_;
1622 }
1623
1624 bool TestRunner::testRepaint() const {
1625   return test_repaint_;
1626 }
1627
1628 bool TestRunner::sweepHorizontally() const {
1629   return sweep_horizontally_;
1630 }
1631
1632 bool TestRunner::isPrinting() const {
1633   return is_printing_;
1634 }
1635
1636 bool TestRunner::shouldStayOnPageAfterHandlingBeforeUnload() const {
1637   return should_stay_on_page_after_handling_before_unload_;
1638 }
1639
1640 const std::set<std::string>* TestRunner::httpHeadersToClear() const {
1641   return &http_headers_to_clear_;
1642 }
1643
1644 void TestRunner::setTopLoadingFrame(WebFrame* frame, bool clear) {
1645   if (frame->top()->view() != web_view_)
1646     return;
1647   if (!test_is_running_)
1648     return;
1649   if (clear) {
1650     top_loading_frame_ = NULL;
1651     LocationChangeDone();
1652   } else if (!top_loading_frame_) {
1653     top_loading_frame_ = frame;
1654   }
1655 }
1656
1657 WebFrame* TestRunner::topLoadingFrame() const {
1658   return top_loading_frame_;
1659 }
1660
1661 void TestRunner::policyDelegateDone() {
1662   BLINK_ASSERT(wait_until_done_);
1663   delegate_->testFinished();
1664   wait_until_done_ = false;
1665 }
1666
1667 bool TestRunner::policyDelegateEnabled() const {
1668   return policy_delegate_enabled_;
1669 }
1670
1671 bool TestRunner::policyDelegateIsPermissive() const {
1672   return policy_delegate_is_permissive_;
1673 }
1674
1675 bool TestRunner::policyDelegateShouldNotifyDone() const {
1676   return policy_delegate_should_notify_done_;
1677 }
1678
1679 bool TestRunner::shouldInterceptPostMessage() const {
1680   return intercept_post_message_;
1681 }
1682
1683 bool TestRunner::shouldDumpResourcePriorities() const {
1684   return should_dump_resource_priorities_;
1685 }
1686
1687 WebNotificationPresenter* TestRunner::notification_presenter() const {
1688   return notification_presenter_.get();
1689 }
1690
1691 bool TestRunner::RequestPointerLock() {
1692   switch (pointer_lock_planned_result_) {
1693     case PointerLockWillSucceed:
1694       delegate_->postDelayedTask(
1695           new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
1696           0);
1697       return true;
1698     case PointerLockWillRespondAsync:
1699       BLINK_ASSERT(!pointer_locked_);
1700       return true;
1701     case PointerLockWillFailSync:
1702       BLINK_ASSERT(!pointer_locked_);
1703       return false;
1704     default:
1705       BLINK_ASSERT_NOT_REACHED();
1706       return false;
1707   }
1708 }
1709
1710 void TestRunner::RequestPointerUnlock() {
1711   delegate_->postDelayedTask(
1712       new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
1713 }
1714
1715 bool TestRunner::isPointerLocked() {
1716   return pointer_locked_;
1717 }
1718
1719 void TestRunner::setToolTipText(const WebString& text) {
1720   tooltip_text_ = text.utf8();
1721 }
1722
1723 bool TestRunner::midiAccessorResult() {
1724   return midi_accessor_result_;
1725 }
1726
1727 void TestRunner::clearDevToolsLocalStorage() {
1728   delegate_->clearDevToolsLocalStorage();
1729 }
1730
1731 void TestRunner::showDevTools(const std::string& settings) {
1732   delegate_->showDevTools(settings);
1733 }
1734
1735 class WorkItemBackForward : public TestRunner::WorkItem {
1736  public:
1737   WorkItemBackForward(int distance) : distance_(distance) {}
1738
1739   virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1740     delegate->goToOffset(distance_);
1741     return true; // FIXME: Did it really start a navigation?
1742   }
1743
1744  private:
1745   int distance_;
1746 };
1747
1748 void TestRunner::NotifyDone() {
1749   if (disable_notify_done_)
1750     return;
1751
1752   // Test didn't timeout. Kill the timeout timer.
1753   taskList()->revokeAll();
1754
1755   CompleteNotifyDone();
1756 }
1757
1758 void TestRunner::WaitUntilDone() {
1759   wait_until_done_ = true;
1760 }
1761
1762 void TestRunner::QueueBackNavigation(int how_far_back) {
1763   work_queue_.AddWork(new WorkItemBackForward(-how_far_back));
1764 }
1765
1766 void TestRunner::QueueForwardNavigation(int how_far_forward) {
1767   work_queue_.AddWork(new WorkItemBackForward(how_far_forward));
1768 }
1769
1770 class WorkItemReload : public TestRunner::WorkItem {
1771  public:
1772   virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1773     delegate->reload();
1774     return true;
1775   }
1776 };
1777
1778 void TestRunner::QueueReload() {
1779   work_queue_.AddWork(new WorkItemReload());
1780 }
1781
1782 class WorkItemLoadingScript : public TestRunner::WorkItem {
1783  public:
1784   WorkItemLoadingScript(const std::string& script)
1785       : script_(script) {}
1786
1787   virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1788     web_view->mainFrame()->executeScript(
1789         WebScriptSource(WebString::fromUTF8(script_)));
1790     return true; // FIXME: Did it really start a navigation?
1791   }
1792
1793  private:
1794   std::string script_;
1795 };
1796
1797 void TestRunner::QueueLoadingScript(const std::string& script) {
1798   work_queue_.AddWork(new WorkItemLoadingScript(script));
1799 }
1800
1801 class WorkItemNonLoadingScript : public TestRunner::WorkItem {
1802  public:
1803   WorkItemNonLoadingScript(const std::string& script)
1804       : script_(script) {}
1805
1806   virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1807     web_view->mainFrame()->executeScript(
1808         WebScriptSource(WebString::fromUTF8(script_)));
1809     return false;
1810   }
1811
1812  private:
1813   std::string script_;
1814 };
1815
1816 void TestRunner::QueueNonLoadingScript(const std::string& script) {
1817   work_queue_.AddWork(new WorkItemNonLoadingScript(script));
1818 }
1819
1820 class WorkItemLoad : public TestRunner::WorkItem {
1821  public:
1822   WorkItemLoad(const WebURL& url, const std::string& target)
1823       : url_(url), target_(target) {}
1824
1825   virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
1826     delegate->loadURLForFrame(url_, target_);
1827     return true; // FIXME: Did it really start a navigation?
1828   }
1829
1830  private:
1831   WebURL url_;
1832   std::string target_;
1833 };
1834
1835 void TestRunner::QueueLoad(const std::string& url, const std::string& target) {
1836   // FIXME: Implement WebURL::resolve() and avoid GURL.
1837   GURL current_url = web_view_->mainFrame()->document().url();
1838   GURL full_url = current_url.Resolve(url);
1839   work_queue_.AddWork(new WorkItemLoad(full_url, target));
1840 }
1841
1842 class WorkItemLoadHTMLString : public TestRunner::WorkItem  {
1843  public:
1844   WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url)
1845       : html_(html), base_url_(base_url) {}
1846
1847   WorkItemLoadHTMLString(const std::string& html, const WebURL& base_url,
1848                          const WebURL& unreachable_url)
1849       : html_(html), base_url_(base_url), unreachable_url_(unreachable_url) {}
1850
1851   virtual bool Run(WebTestDelegate*, WebView* web_view) OVERRIDE {
1852     web_view->mainFrame()->loadHTMLString(
1853         WebData(html_.data(), html_.length()),
1854         base_url_, unreachable_url_);
1855     return true;
1856   }
1857
1858  private:
1859   std::string html_;
1860   WebURL base_url_;
1861   WebURL unreachable_url_;
1862 };
1863
1864 void TestRunner::QueueLoadHTMLString(gin::Arguments* args) {
1865   std::string html;
1866   args->GetNext(&html);
1867
1868   std::string base_url_str;
1869   args->GetNext(&base_url_str);
1870   WebURL base_url = WebURL(GURL(base_url_str));
1871
1872   if (args->PeekNext()->IsString()) {
1873     std::string unreachable_url_str;
1874     args->GetNext(&unreachable_url_str);
1875     WebURL unreachable_url = WebURL(GURL(unreachable_url_str));
1876     work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url,
1877                                                    unreachable_url));
1878   } else {
1879     work_queue_.AddWork(new WorkItemLoadHTMLString(html, base_url));
1880   }
1881 }
1882
1883 void TestRunner::SetCustomPolicyDelegate(gin::Arguments* args) {
1884   args->GetNext(&policy_delegate_enabled_);
1885   if (!args->PeekNext().IsEmpty() && args->PeekNext()->IsBoolean())
1886     args->GetNext(&policy_delegate_is_permissive_);
1887 }
1888
1889 void TestRunner::WaitForPolicyDelegate() {
1890   policy_delegate_enabled_ = true;
1891   policy_delegate_should_notify_done_ = true;
1892   wait_until_done_ = true;
1893 }
1894
1895 int TestRunner::WindowCount() {
1896   return test_interfaces_->windowList().size();
1897 }
1898
1899 void TestRunner::SetCloseRemainingWindowsWhenComplete(
1900     bool close_remaining_windows) {
1901   close_remaining_windows_ = close_remaining_windows;
1902 }
1903
1904 void TestRunner::ResetTestHelperControllers() {
1905   test_interfaces_->resetTestHelperControllers();
1906 }
1907
1908 void TestRunner::SetTabKeyCyclesThroughElements(
1909     bool tab_key_cycles_through_elements) {
1910   web_view_->setTabKeyCyclesThroughElements(tab_key_cycles_through_elements);
1911 }
1912
1913 void TestRunner::ExecCommand(gin::Arguments* args) {
1914   std::string command;
1915   args->GetNext(&command);
1916
1917   std::string value;
1918   if (args->Length() >= 3) {
1919     // Ignore the second parameter (which is userInterface)
1920     // since this command emulates a manual action.
1921     args->Skip();
1922     args->GetNext(&value);
1923   }
1924
1925   // Note: webkit's version does not return the boolean, so neither do we.
1926   web_view_->focusedFrame()->executeCommand(WebString::fromUTF8(command),
1927                                             WebString::fromUTF8(value));
1928 }
1929
1930 bool TestRunner::IsCommandEnabled(const std::string& command) {
1931   return web_view_->focusedFrame()->isCommandEnabled(
1932       WebString::fromUTF8(command));
1933 }
1934
1935 bool TestRunner::CallShouldCloseOnWebView() {
1936   return web_view_->dispatchBeforeUnloadEvent();
1937 }
1938
1939 void TestRunner::SetDomainRelaxationForbiddenForURLScheme(
1940     bool forbidden, const std::string& scheme) {
1941   web_view_->setDomainRelaxationForbidden(forbidden,
1942                                           WebString::fromUTF8(scheme));
1943 }
1944
1945 v8::Handle<v8::Value> TestRunner::EvaluateScriptInIsolatedWorldAndReturnValue(
1946     int world_id,
1947     const std::string& script) {
1948   WebVector<v8::Local<v8::Value> > values;
1949   WebScriptSource source(WebString::fromUTF8(script));
1950   // This relies on the iframe focusing itself when it loads. This is a bit
1951   // sketchy, but it seems to be what other tests do.
1952   web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1953       world_id, &source, 1, 1, &values);
1954   // Since only one script was added, only one result is expected
1955   if (values.size() == 1 && !values[0].IsEmpty())
1956     return values[0];
1957   return v8::Handle<v8::Value>();
1958 }
1959
1960 void TestRunner::EvaluateScriptInIsolatedWorld(int world_id,
1961                                                const std::string& script) {
1962   WebScriptSource source(WebString::fromUTF8(script));
1963   web_view_->focusedFrame()->executeScriptInIsolatedWorld(
1964       world_id, &source, 1, 1);
1965 }
1966
1967 void TestRunner::SetIsolatedWorldSecurityOrigin(int world_id,
1968                                                 v8::Handle<v8::Value> origin) {
1969   if (!(origin->IsString() || !origin->IsNull()))
1970     return;
1971
1972   WebSecurityOrigin web_origin;
1973   if (origin->IsString()) {
1974     web_origin = WebSecurityOrigin::createFromString(
1975         V8StringToWebString(origin->ToString()));
1976   }
1977   web_view_->focusedFrame()->setIsolatedWorldSecurityOrigin(world_id,
1978                                                             web_origin);
1979 }
1980
1981 void TestRunner::SetIsolatedWorldContentSecurityPolicy(
1982     int world_id,
1983     const std::string& policy) {
1984   web_view_->focusedFrame()->setIsolatedWorldContentSecurityPolicy(
1985       world_id, WebString::fromUTF8(policy));
1986 }
1987
1988 void TestRunner::AddOriginAccessWhitelistEntry(
1989     const std::string& source_origin,
1990     const std::string& destination_protocol,
1991     const std::string& destination_host,
1992     bool allow_destination_subdomains) {
1993   WebURL url((GURL(source_origin)));
1994   if (!url.isValid())
1995     return;
1996
1997   WebSecurityPolicy::addOriginAccessWhitelistEntry(
1998       url,
1999       WebString::fromUTF8(destination_protocol),
2000       WebString::fromUTF8(destination_host),
2001       allow_destination_subdomains);
2002 }
2003
2004 void TestRunner::RemoveOriginAccessWhitelistEntry(
2005     const std::string& source_origin,
2006     const std::string& destination_protocol,
2007     const std::string& destination_host,
2008     bool allow_destination_subdomains) {
2009   WebURL url((GURL(source_origin)));
2010   if (!url.isValid())
2011     return;
2012
2013   WebSecurityPolicy::removeOriginAccessWhitelistEntry(
2014       url,
2015       WebString::fromUTF8(destination_protocol),
2016       WebString::fromUTF8(destination_host),
2017       allow_destination_subdomains);
2018 }
2019
2020 bool TestRunner::HasCustomPageSizeStyle(int page_index) {
2021   WebFrame* frame = web_view_->mainFrame();
2022   if (!frame)
2023     return false;
2024   return frame->hasCustomPageSizeStyle(page_index);
2025 }
2026
2027 void TestRunner::ForceRedSelectionColors() {
2028   web_view_->setSelectionColors(0xffee0000, 0xff00ee00, 0xff000000, 0xffc0c0c0);
2029 }
2030
2031 void TestRunner::InjectStyleSheet(const std::string& source_code,
2032                                   bool all_frames) {
2033   WebView::injectStyleSheet(
2034       WebString::fromUTF8(source_code),
2035       WebVector<WebString>(),
2036       all_frames ? WebView::InjectStyleInAllFrames
2037                  : WebView::InjectStyleInTopFrameOnly);
2038 }
2039
2040 bool TestRunner::FindString(const std::string& search_text,
2041                             const std::vector<std::string>& options_array) {
2042   WebFindOptions find_options;
2043   bool wrap_around = false;
2044   find_options.matchCase = true;
2045   find_options.findNext = true;
2046
2047   for (size_t i = 0; i < options_array.size(); ++i) {
2048     const std::string& option = options_array[i];
2049     if (option == "CaseInsensitive")
2050       find_options.matchCase = false;
2051     else if (option == "Backwards")
2052       find_options.forward = false;
2053     else if (option == "StartInSelection")
2054       find_options.findNext = false;
2055     else if (option == "AtWordStarts")
2056       find_options.wordStart = true;
2057     else if (option == "TreatMedialCapitalAsWordStart")
2058       find_options.medialCapitalAsWordStart = true;
2059     else if (option == "WrapAround")
2060       wrap_around = true;
2061   }
2062
2063   WebFrame* frame = web_view_->mainFrame();
2064   const bool find_result = frame->find(0, WebString::fromUTF8(search_text),
2065                                        find_options, wrap_around, 0);
2066   frame->stopFinding(false);
2067   return find_result;
2068 }
2069
2070 std::string TestRunner::SelectionAsMarkup() {
2071   return web_view_->mainFrame()->selectionAsMarkup().utf8();
2072 }
2073
2074 void TestRunner::SetTextSubpixelPositioning(bool value) {
2075 #if defined(__linux__) || defined(ANDROID)
2076   // Since FontConfig doesn't provide a variable to control subpixel
2077   // positioning, we'll fall back to setting it globally for all fonts.
2078   WebFontRendering::setSubpixelPositioning(value);
2079 #endif
2080 }
2081
2082 void TestRunner::SetPageVisibility(const std::string& new_visibility) {
2083   if (new_visibility == "visible")
2084     web_view_->setVisibilityState(WebPageVisibilityStateVisible, false);
2085   else if (new_visibility == "hidden")
2086     web_view_->setVisibilityState(WebPageVisibilityStateHidden, false);
2087   else if (new_visibility == "prerender")
2088     web_view_->setVisibilityState(WebPageVisibilityStatePrerender, false);
2089 }
2090
2091 void TestRunner::SetTextDirection(const std::string& direction_name) {
2092   // Map a direction name to a WebTextDirection value.
2093   WebTextDirection direction;
2094   if (direction_name == "auto")
2095     direction = WebTextDirectionDefault;
2096   else if (direction_name == "rtl")
2097     direction = WebTextDirectionRightToLeft;
2098   else if (direction_name == "ltr")
2099     direction = WebTextDirectionLeftToRight;
2100   else
2101     return;
2102
2103   web_view_->setTextDirection(direction);
2104 }
2105
2106 void TestRunner::UseUnfortunateSynchronousResizeMode() {
2107   delegate_->useUnfortunateSynchronousResizeMode(true);
2108 }
2109
2110 bool TestRunner::EnableAutoResizeMode(int min_width,
2111                                       int min_height,
2112                                       int max_width,
2113                                       int max_height) {
2114   WebSize min_size(min_width, min_height);
2115   WebSize max_size(max_width, max_height);
2116   delegate_->enableAutoResizeMode(min_size, max_size);
2117   return true;
2118 }
2119
2120 bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
2121   WebSize new_size(new_width, new_height);
2122   delegate_->disableAutoResizeMode(new_size);
2123   return true;
2124 }
2125
2126 void TestRunner::SetMockDeviceMotion(
2127     bool has_acceleration_x, double acceleration_x,
2128     bool has_acceleration_y, double acceleration_y,
2129     bool has_acceleration_z, double acceleration_z,
2130     bool has_acceleration_including_gravity_x,
2131     double acceleration_including_gravity_x,
2132     bool has_acceleration_including_gravity_y,
2133     double acceleration_including_gravity_y,
2134     bool has_acceleration_including_gravity_z,
2135     double acceleration_including_gravity_z,
2136     bool has_rotation_rate_alpha, double rotation_rate_alpha,
2137     bool has_rotation_rate_beta, double rotation_rate_beta,
2138     bool has_rotation_rate_gamma, double rotation_rate_gamma,
2139     double interval) {
2140   WebDeviceMotionData motion;
2141
2142   // acceleration
2143   motion.hasAccelerationX = has_acceleration_x;
2144   motion.accelerationX = acceleration_x;
2145   motion.hasAccelerationY = has_acceleration_y;
2146   motion.accelerationY = acceleration_y;
2147   motion.hasAccelerationZ = has_acceleration_z;
2148   motion.accelerationZ = acceleration_z;
2149
2150   // accelerationIncludingGravity
2151   motion.hasAccelerationIncludingGravityX =
2152       has_acceleration_including_gravity_x;
2153   motion.accelerationIncludingGravityX = acceleration_including_gravity_x;
2154   motion.hasAccelerationIncludingGravityY =
2155       has_acceleration_including_gravity_y;
2156   motion.accelerationIncludingGravityY = acceleration_including_gravity_y;
2157   motion.hasAccelerationIncludingGravityZ =
2158       has_acceleration_including_gravity_z;
2159   motion.accelerationIncludingGravityZ = acceleration_including_gravity_z;
2160
2161   // rotationRate
2162   motion.hasRotationRateAlpha = has_rotation_rate_alpha;
2163   motion.rotationRateAlpha = rotation_rate_alpha;
2164   motion.hasRotationRateBeta = has_rotation_rate_beta;
2165   motion.rotationRateBeta = rotation_rate_beta;
2166   motion.hasRotationRateGamma = has_rotation_rate_gamma;
2167   motion.rotationRateGamma = rotation_rate_gamma;
2168
2169   // interval
2170   motion.interval = interval;
2171
2172   delegate_->setDeviceMotionData(motion);
2173 }
2174
2175 void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
2176                                           bool has_beta, double beta,
2177                                           bool has_gamma, double gamma,
2178                                           bool has_absolute, bool absolute) {
2179   WebDeviceOrientationData orientation;
2180
2181   // alpha
2182   orientation.hasAlpha = has_alpha;
2183   orientation.alpha = alpha;
2184
2185   // beta
2186   orientation.hasBeta = has_beta;
2187   orientation.beta = beta;
2188
2189   // gamma
2190   orientation.hasGamma = has_gamma;
2191   orientation.gamma = gamma;
2192
2193   // absolute
2194   orientation.hasAbsolute = has_absolute;
2195   orientation.absolute = absolute;
2196
2197   delegate_->setDeviceOrientationData(orientation);
2198 }
2199
2200 void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
2201   blink::WebScreenOrientation orientation;
2202
2203   if (orientation_str == "portrait-primary") {
2204     orientation = WebScreenOrientationPortraitPrimary;
2205   } else if (orientation_str == "portrait-secondary") {
2206     orientation = WebScreenOrientationPortraitSecondary;
2207   } else if (orientation_str == "landscape-primary") {
2208     orientation = WebScreenOrientationLandscapePrimary;
2209   } else if (orientation_str == "landscape-secondary") {
2210     orientation = WebScreenOrientationLandscapeSecondary;
2211   }
2212
2213   delegate_->setScreenOrientation(orientation);
2214 }
2215
2216 void TestRunner::DidAcquirePointerLock() {
2217   DidAcquirePointerLockInternal();
2218 }
2219
2220 void TestRunner::DidNotAcquirePointerLock() {
2221   DidNotAcquirePointerLockInternal();
2222 }
2223
2224 void TestRunner::DidLosePointerLock() {
2225   DidLosePointerLockInternal();
2226 }
2227
2228 void TestRunner::SetPointerLockWillFailSynchronously() {
2229   pointer_lock_planned_result_ = PointerLockWillFailSync;
2230 }
2231
2232 void TestRunner::SetPointerLockWillRespondAsynchronously() {
2233   pointer_lock_planned_result_ = PointerLockWillRespondAsync;
2234 }
2235
2236 void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
2237   delegate_->preferences()->javaScriptCanOpenWindowsAutomatically =
2238       !block_popups;
2239   delegate_->applyPreferences();
2240 }
2241
2242 void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
2243   delegate_->preferences()->javaScriptCanAccessClipboard = can_access;
2244   delegate_->applyPreferences();
2245 }
2246
2247 void TestRunner::SetXSSAuditorEnabled(bool enabled) {
2248   delegate_->preferences()->XSSAuditorEnabled = enabled;
2249   delegate_->applyPreferences();
2250 }
2251
2252 void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
2253   delegate_->preferences()->allowUniversalAccessFromFileURLs = allow;
2254   delegate_->applyPreferences();
2255 }
2256
2257 void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
2258   delegate_->preferences()->allowFileAccessFromFileURLs = allow;
2259   delegate_->applyPreferences();
2260 }
2261
2262 void TestRunner::OverridePreference(const std::string key,
2263                                     v8::Handle<v8::Value> value) {
2264   WebPreferences* prefs = delegate_->preferences();
2265   if (key == "WebKitDefaultFontSize") {
2266     prefs->defaultFontSize = value->Int32Value();
2267   } else if (key == "WebKitMinimumFontSize") {
2268     prefs->minimumFontSize = value->Int32Value();
2269   } else if (key == "WebKitDefaultTextEncodingName") {
2270     prefs->defaultTextEncodingName = V8StringToWebString(value->ToString());
2271   } else if (key == "WebKitJavaScriptEnabled") {
2272     prefs->javaScriptEnabled = value->BooleanValue();
2273   } else if (key == "WebKitSupportsMultipleWindows") {
2274     prefs->supportsMultipleWindows = value->BooleanValue();
2275   } else if (key == "WebKitDisplayImagesKey") {
2276     prefs->loadsImagesAutomatically = value->BooleanValue();
2277   } else if (key == "WebKitPluginsEnabled") {
2278     prefs->pluginsEnabled = value->BooleanValue();
2279   } else if (key == "WebKitJavaEnabled") {
2280     prefs->javaEnabled = value->BooleanValue();
2281   } else if (key == "WebKitOfflineWebApplicationCacheEnabled") {
2282     prefs->offlineWebApplicationCacheEnabled = value->BooleanValue();
2283   } else if (key == "WebKitTabToLinksPreferenceKey") {
2284     prefs->tabsToLinks = value->BooleanValue();
2285   } else if (key == "WebKitWebGLEnabled") {
2286     prefs->experimentalWebGLEnabled = value->BooleanValue();
2287   } else if (key == "WebKitCSSRegionsEnabled") {
2288     prefs->experimentalCSSRegionsEnabled = value->BooleanValue();
2289   } else if (key == "WebKitCSSGridLayoutEnabled") {
2290     prefs->experimentalCSSGridLayoutEnabled = value->BooleanValue();
2291   } else if (key == "WebKitHyperlinkAuditingEnabled") {
2292     prefs->hyperlinkAuditingEnabled = value->BooleanValue();
2293   } else if (key == "WebKitEnableCaretBrowsing") {
2294     prefs->caretBrowsingEnabled = value->BooleanValue();
2295   } else if (key == "WebKitAllowDisplayingInsecureContent") {
2296     prefs->allowDisplayOfInsecureContent = value->BooleanValue();
2297   } else if (key == "WebKitAllowRunningInsecureContent") {
2298     prefs->allowRunningOfInsecureContent = value->BooleanValue();
2299   } else if (key == "WebKitShouldRespectImageOrientation") {
2300     prefs->shouldRespectImageOrientation = value->BooleanValue();
2301   } else if (key == "WebKitWebAudioEnabled") {
2302     BLINK_ASSERT(value->BooleanValue());
2303   } else {
2304     std::string message("Invalid name for preference: ");
2305     message.append(key);
2306     delegate_->printMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
2307   }
2308   delegate_->applyPreferences();
2309 }
2310
2311 void TestRunner::SetPluginsEnabled(bool enabled) {
2312   delegate_->preferences()->pluginsEnabled = enabled;
2313   delegate_->applyPreferences();
2314 }
2315
2316 void TestRunner::DumpEditingCallbacks() {
2317   dump_editting_callbacks_ = true;
2318 }
2319
2320 void TestRunner::DumpAsText() {
2321   dump_as_text_ = true;
2322   generate_pixel_results_ = false;
2323 }
2324
2325 void TestRunner::DumpAsTextWithPixelResults() {
2326   dump_as_text_ = true;
2327   generate_pixel_results_ = true;
2328 }
2329
2330 void TestRunner::DumpChildFrameScrollPositions() {
2331   dump_child_frame_scroll_positions_ = true;
2332 }
2333
2334 void TestRunner::DumpChildFramesAsText() {
2335   dump_child_frames_as_text_ = true;
2336 }
2337
2338 void TestRunner::DumpIconChanges() {
2339   dump_icon_changes_ = true;
2340 }
2341
2342 void TestRunner::SetAudioData(const gin::ArrayBufferView& view) {
2343   unsigned char* bytes = static_cast<unsigned char*>(view.bytes());
2344   audio_data_.resize(view.num_bytes());
2345   std::copy(bytes, bytes + view.num_bytes(), audio_data_.begin());
2346   dump_as_audio_ = true;
2347 }
2348
2349 void TestRunner::DumpFrameLoadCallbacks() {
2350   dump_frame_load_callbacks_ = true;
2351 }
2352
2353 void TestRunner::DumpPingLoaderCallbacks() {
2354   dump_ping_loader_callbacks_ = true;
2355 }
2356
2357 void TestRunner::DumpUserGestureInFrameLoadCallbacks() {
2358   dump_user_gesture_in_frame_load_callbacks_ = true;
2359 }
2360
2361 void TestRunner::DumpTitleChanges() {
2362   dump_title_changes_ = true;
2363 }
2364
2365 void TestRunner::DumpCreateView() {
2366   dump_create_view_ = true;
2367 }
2368
2369 void TestRunner::SetCanOpenWindows() {
2370   can_open_windows_ = true;
2371 }
2372
2373 void TestRunner::DumpResourceLoadCallbacks() {
2374   dump_resource_load_callbacks_ = true;
2375 }
2376
2377 void TestRunner::DumpResourceRequestCallbacks() {
2378   dump_resource_request_callbacks_ = true;
2379 }
2380
2381 void TestRunner::DumpResourceResponseMIMETypes() {
2382   dump_resource_reqponse_mime_types_ = true;
2383 }
2384
2385 void TestRunner::SetImagesAllowed(bool allowed) {
2386   web_permissions_->setImagesAllowed(allowed);
2387 }
2388
2389 void TestRunner::SetScriptsAllowed(bool allowed) {
2390   web_permissions_->setScriptsAllowed(allowed);
2391 }
2392
2393 void TestRunner::SetStorageAllowed(bool allowed) {
2394   web_permissions_->setStorageAllowed(allowed);
2395 }
2396
2397 void TestRunner::SetPluginsAllowed(bool allowed) {
2398   web_permissions_->setPluginsAllowed(allowed);
2399 }
2400
2401 void TestRunner::SetAllowDisplayOfInsecureContent(bool allowed) {
2402   web_permissions_->setDisplayingInsecureContentAllowed(allowed);
2403 }
2404
2405 void TestRunner::SetAllowRunningOfInsecureContent(bool allowed) {
2406   web_permissions_->setRunningInsecureContentAllowed(allowed);
2407 }
2408
2409 void TestRunner::DumpPermissionClientCallbacks() {
2410   web_permissions_->setDumpCallbacks(true);
2411 }
2412
2413 void TestRunner::DumpWindowStatusChanges() {
2414   dump_window_status_changes_ = true;
2415 }
2416
2417 void TestRunner::DumpProgressFinishedCallback() {
2418   dump_progress_finished_callback_ = true;
2419 }
2420
2421 void TestRunner::DumpSpellCheckCallbacks() {
2422   dump_spell_check_callbacks_ = true;
2423 }
2424
2425 void TestRunner::DumpBackForwardList() {
2426   dump_back_forward_list_ = true;
2427 }
2428
2429 void TestRunner::DumpSelectionRect() {
2430   dump_selection_rect_ = true;
2431 }
2432
2433 void TestRunner::TestRepaint() {
2434   test_repaint_ = true;
2435 }
2436
2437 void TestRunner::RepaintSweepHorizontally() {
2438   sweep_horizontally_ = true;
2439 }
2440
2441 void TestRunner::SetPrinting() {
2442   is_printing_ = true;
2443 }
2444
2445 void TestRunner::SetShouldStayOnPageAfterHandlingBeforeUnload(bool value) {
2446   should_stay_on_page_after_handling_before_unload_ = value;
2447 }
2448
2449 void TestRunner::SetWillSendRequestClearHeader(const std::string& header) {
2450   if (!header.empty())
2451     http_headers_to_clear_.insert(header);
2452 }
2453
2454 void TestRunner::DumpResourceRequestPriorities() {
2455   should_dump_resource_priorities_ = true;
2456 }
2457
2458 void TestRunner::SetUseMockTheme(bool use) {
2459   use_mock_theme_ = use;
2460 }
2461
2462 void TestRunner::ShowWebInspector(const std::string& str) {
2463   showDevTools(str);
2464 }
2465
2466 void TestRunner::CloseWebInspector() {
2467   delegate_->closeDevTools();
2468 }
2469
2470 bool TestRunner::IsChooserShown() {
2471   return proxy_->isChooserShown();
2472 }
2473
2474 void TestRunner::EvaluateInWebInspector(int call_id,
2475                                         const std::string& script) {
2476   delegate_->evaluateInWebInspector(call_id, script);
2477 }
2478
2479 void TestRunner::ClearAllDatabases() {
2480   delegate_->clearAllDatabases();
2481 }
2482
2483 void TestRunner::SetDatabaseQuota(int quota) {
2484   delegate_->setDatabaseQuota(quota);
2485 }
2486
2487 void TestRunner::SetAlwaysAcceptCookies(bool accept) {
2488   delegate_->setAcceptAllCookies(accept);
2489 }
2490
2491 void TestRunner::SetWindowIsKey(bool value) {
2492   delegate_->setFocus(proxy_, value);
2493 }
2494
2495 std::string TestRunner::PathToLocalResource(const std::string& path) {
2496   return delegate_->pathToLocalResource(path);
2497 }
2498
2499 void TestRunner::SetBackingScaleFactor(double value,
2500                                        v8::Handle<v8::Function> callback) {
2501   delegate_->setDeviceScaleFactor(value);
2502   proxy_->discardBackingStore();
2503   delegate_->postTask(new InvokeCallbackTask(this, callback));
2504 }
2505
2506 void TestRunner::SetPOSIXLocale(const std::string& locale) {
2507   delegate_->setLocale(locale);
2508 }
2509
2510 void TestRunner::SetMIDIAccessorResult(bool result) {
2511   midi_accessor_result_ = result;
2512 }
2513
2514 void TestRunner::SetMIDISysexPermission(bool value) {
2515   const std::vector<WebTestProxyBase*>& windowList =
2516       test_interfaces_->windowList();
2517   for (unsigned i = 0; i < windowList.size(); ++i)
2518     windowList.at(i)->midiClientMock()->setSysexPermission(value);
2519 }
2520
2521 void TestRunner::GrantWebNotificationPermission(const std::string& origin,
2522                                                 bool permission_granted) {
2523   notification_presenter_->GrantPermission(origin, permission_granted);
2524 }
2525
2526 bool TestRunner::SimulateWebNotificationClick(const std::string& value) {
2527   return notification_presenter_->SimulateClick(value);
2528 }
2529
2530 void TestRunner::AddMockSpeechInputResult(const std::string& result,
2531                                           double confidence,
2532                                           const std::string& language) {
2533 #if ENABLE_INPUT_SPEECH
2534   proxy_->speechInputControllerMock()->addMockRecognitionResult(
2535       WebString::fromUTF8(result), confidence, WebString::fromUTF8(language));
2536 #endif
2537 }
2538
2539 void TestRunner::SetMockSpeechInputDumpRect(bool value) {
2540 #if ENABLE_INPUT_SPEECH
2541   proxy_->speechInputControllerMock()->setDumpRect(value);
2542 #endif
2543 }
2544
2545 void TestRunner::AddMockSpeechRecognitionResult(const std::string& transcript,
2546                                                 double confidence) {
2547   proxy_->speechRecognizerMock()->addMockResult(
2548       WebString::fromUTF8(transcript), confidence);
2549 }
2550
2551 void TestRunner::SetMockSpeechRecognitionError(const std::string& error,
2552                                                const std::string& message) {
2553   proxy_->speechRecognizerMock()->setError(WebString::fromUTF8(error),
2554                                            WebString::fromUTF8(message));
2555 }
2556
2557 bool TestRunner::WasMockSpeechRecognitionAborted() {
2558   return proxy_->speechRecognizerMock()->wasAborted();
2559 }
2560
2561 void TestRunner::AddWebPageOverlay() {
2562   if (web_view_ && !page_overlay_) {
2563     page_overlay_ = new TestPageOverlay(web_view_);
2564     web_view_->addPageOverlay(page_overlay_, 0);
2565   }
2566 }
2567
2568 void TestRunner::RemoveWebPageOverlay() {
2569   if (web_view_ && page_overlay_) {
2570     web_view_->removePageOverlay(page_overlay_);
2571     delete page_overlay_;
2572     page_overlay_ = NULL;
2573   }
2574 }
2575
2576 void TestRunner::Display() {
2577   proxy_->display();
2578 }
2579
2580 void TestRunner::DisplayInvalidatedRegion() {
2581   proxy_->displayInvalidatedRegion();
2582 }
2583
2584 void TestRunner::LocationChangeDone() {
2585   web_history_item_count_ = delegate_->navigationEntryCount();
2586
2587   // No more new work after the first complete load.
2588   work_queue_.set_frozen(true);
2589
2590   if (!wait_until_done_)
2591     work_queue_.ProcessWorkSoon();
2592 }
2593
2594 void TestRunner::CheckResponseMimeType() {
2595   // Text output: the test page can request different types of output which we
2596   // handle here.
2597   if (!dump_as_text_) {
2598     std::string mimeType =
2599         web_view_->mainFrame()->dataSource()->response().mimeType().utf8();
2600     if (mimeType == "text/plain") {
2601       dump_as_text_ = true;
2602       generate_pixel_results_ = false;
2603     }
2604   }
2605 }
2606
2607 void TestRunner::CompleteNotifyDone() {
2608   if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
2609     delegate_->testFinished();
2610   wait_until_done_ = false;
2611 }
2612
2613 void TestRunner::DidAcquirePointerLockInternal() {
2614   pointer_locked_ = true;
2615   web_view_->didAcquirePointerLock();
2616
2617   // Reset planned result to default.
2618   pointer_lock_planned_result_ = PointerLockWillSucceed;
2619 }
2620
2621 void TestRunner::DidNotAcquirePointerLockInternal() {
2622   BLINK_ASSERT(!pointer_locked_);
2623   pointer_locked_ = false;
2624   web_view_->didNotAcquirePointerLock();
2625
2626   // Reset planned result to default.
2627   pointer_lock_planned_result_ = PointerLockWillSucceed;
2628 }
2629
2630 void TestRunner::DidLosePointerLockInternal() {
2631   bool was_locked = pointer_locked_;
2632   pointer_locked_ = false;
2633   if (was_locked)
2634     web_view_->didLosePointerLock();
2635 }
2636
2637 }  // namespace content