#include <limits>
#include "base/logging.h"
+#include "content/public/test/layouttest_support.h"
#include "content/shell/common/test_runner/test_preferences.h"
-#include "content/shell/renderer/test_runner/WebTestDelegate.h"
+#include "content/shell/renderer/binding_helpers.h"
+#include "content/shell/renderer/test_runner/mock_credential_manager_client.h"
#include "content/shell/renderer/test_runner/mock_web_push_client.h"
#include "content/shell/renderer/test_runner/mock_web_speech_recognizer.h"
#include "content/shell/renderer/test_runner/notification_presenter.h"
#include "content/shell/renderer/test_runner/test_interfaces.h"
#include "content/shell/renderer/test_runner/web_permissions.h"
+#include "content/shell/renderer/test_runner/web_test_delegate.h"
#include "content/shell/renderer/test_runner/web_test_proxy.h"
#include "gin/arguments.h"
#include "gin/array_buffer.h"
#include "third_party/WebKit/public/platform/WebData.h"
#include "third_party/WebKit/public/platform/WebDeviceMotionData.h"
#include "third_party/WebKit/public/platform/WebDeviceOrientationData.h"
+#include "third_party/WebKit/public/platform/WebLocalCredential.h"
#include "third_party/WebKit/public/platform/WebPoint.h"
#include "third_party/WebKit/public/platform/WebURLResponse.h"
#include "third_party/WebKit/public/web/WebArrayBufferConverter.h"
HostMethodTask(TestRunner* object, CallbackMethodType callback)
: WebMethodTask<TestRunner>(object), callback_(callback) {}
- virtual void runIfValid() OVERRIDE {
- (m_object->*callback_)();
- }
+ virtual void RunIfValid() OVERRIDE { (object_->*callback_)(); }
private:
CallbackMethodType callback_;
callback_(blink::mainThreadIsolate(), callback),
argc_(0) {}
- virtual void runIfValid() OVERRIDE {
+ virtual void RunIfValid() OVERRIDE {
v8::Isolate* isolate = blink::mainThreadIsolate();
v8::HandleScope handle_scope(isolate);
- WebFrame* frame = m_object->web_view_->mainFrame();
+ WebFrame* frame = object_->web_view_->mainFrame();
v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
if (context.IsEmpty())
void SetMockSpeechRecognitionError(const std::string& error,
const std::string& message);
bool WasMockSpeechRecognitionAborted();
+ void AddMockCredentialManagerResponse(const std::string& id,
+ const std::string& name,
+ const std::string& avatar,
+ const std::string& password);
void AddWebPageOverlay();
void RemoveWebPageOverlay();
void DisplayAsync();
void DisplayAsyncThen(v8::Handle<v8::Function> callback);
+ void GetManifestThen(v8::Handle<v8::Function> callback);
void CapturePixelsAsyncThen(v8::Handle<v8::Function> callback);
void CopyImageAtAndCapturePixelsAsyncThen(int x,
int y,
const std::string& registration_id);
void SetMockPushClientError(const std::string& message);
- bool GlobalFlag();
- void SetGlobalFlag(bool value);
std::string PlatformName();
std::string TooltipText();
bool DisableNotifyDone();
// static
void TestRunnerBindings::Install(base::WeakPtr<TestRunner> runner,
WebFrame* frame) {
- v8::Isolate* isolate = blink::mainThreadIsolate();
- v8::HandleScope handle_scope(isolate);
- v8::Handle<v8::Context> context = frame->mainWorldScriptContext();
- if (context.IsEmpty())
- return;
-
- v8::Context::Scope context_scope(context);
-
- gin::Handle<TestRunnerBindings> bindings =
- gin::CreateHandle(isolate, new TestRunnerBindings(runner));
- if (bindings.IsEmpty())
- return;
- v8::Handle<v8::Object> global = context->Global();
- v8::Handle<v8::Value> v8_bindings = bindings.ToV8();
- global->Set(gin::StringToV8(isolate, "testRunner"), v8_bindings);
- global->Set(gin::StringToV8(isolate, "layoutTestController"), v8_bindings);
+ std::vector<std::string> names;
+ names.push_back("testRunner");
+ names.push_back("layoutTestController");
+ return InstallAsWindowProperties(
+ new TestRunnerBindings(runner), frame, names);
}
TestRunnerBindings::TestRunnerBindings(base::WeakPtr<TestRunner> runner)
&TestRunnerBindings::SetMockSpeechRecognitionError)
.SetMethod("wasMockSpeechRecognitionAborted",
&TestRunnerBindings::WasMockSpeechRecognitionAborted)
+ .SetMethod("addMockCredentialManagerResponse",
+ &TestRunnerBindings::AddMockCredentialManagerResponse)
.SetMethod("addWebPageOverlay", &TestRunnerBindings::AddWebPageOverlay)
.SetMethod("removeWebPageOverlay",
&TestRunnerBindings::RemoveWebPageOverlay)
.SetMethod("displayAsync", &TestRunnerBindings::DisplayAsync)
.SetMethod("displayAsyncThen", &TestRunnerBindings::DisplayAsyncThen)
+ .SetMethod("getManifestThen", &TestRunnerBindings::GetManifestThen)
.SetMethod("capturePixelsAsyncThen",
&TestRunnerBindings::CapturePixelsAsyncThen)
.SetMethod("copyImageAtAndCapturePixelsAsyncThen",
&TestRunnerBindings::SetMockPushClientError)
// Properties.
- .SetProperty("globalFlag",
- &TestRunnerBindings::GlobalFlag,
- &TestRunnerBindings::SetGlobalFlag)
.SetProperty("platformName", &TestRunnerBindings::PlatformName)
.SetProperty("tooltipText", &TestRunnerBindings::TooltipText)
.SetProperty("disableNotifyDone", &TestRunnerBindings::DisableNotifyDone)
return false;
}
+void TestRunnerBindings::AddMockCredentialManagerResponse(
+ const std::string& id,
+ const std::string& name,
+ const std::string& avatar,
+ const std::string& password) {
+ if (runner_)
+ runner_->AddMockCredentialManagerResponse(id, name, avatar, password);
+}
+
void TestRunnerBindings::AddWebPageOverlay() {
if (runner_)
runner_->AddWebPageOverlay();
runner_->DisplayAsyncThen(callback);
}
+void TestRunnerBindings::GetManifestThen(v8::Handle<v8::Function> callback) {
+ if (runner_)
+ runner_->GetManifestThen(callback);
+}
+
void TestRunnerBindings::CapturePixelsAsyncThen(
v8::Handle<v8::Function> callback) {
if (runner_)
runner_->SetMockPushClientError(message);
}
-bool TestRunnerBindings::GlobalFlag() {
- if (runner_)
- return runner_->global_flag_;
- return false;
-}
-
-void TestRunnerBindings::SetGlobalFlag(bool value) {
- if (runner_)
- runner_->global_flag_ = value;
-}
-
std::string TestRunnerBindings::PlatformName() {
if (runner_)
return runner_->platform_name_;
if (!queue_.empty()) {
// We delay processing queued work to avoid recursion problems.
- controller_->delegate_->postTask(new WorkQueueTask(this));
+ controller_->delegate_->PostTask(new WorkQueueTask(this));
} else if (!controller_->wait_until_done_) {
- controller_->delegate_->testFinished();
+ controller_->delegate_->TestFinished();
}
}
}
if (!controller_->wait_until_done_ && !controller_->topLoadingFrame())
- controller_->delegate_->testFinished();
+ controller_->delegate_->TestFinished();
}
-void TestRunner::WorkQueue::WorkQueueTask::runIfValid() {
- m_object->ProcessWork();
+void TestRunner::WorkQueue::WorkQueueTask::RunIfValid() {
+ object_->ProcessWork();
}
TestRunner::TestRunner(TestInterfaces* interfaces)
if (delegate_) {
// Reset the default quota for each origin to 5MB
- delegate_->setDatabaseQuota(5 * 1024 * 1024);
- delegate_->setDeviceColorProfile("sRGB");
- delegate_->setDeviceScaleFactor(1);
- delegate_->setAcceptAllCookies(false);
- delegate_->setLocale("");
- delegate_->useUnfortunateSynchronousResizeMode(false);
- delegate_->disableAutoResizeMode(WebSize());
- delegate_->deleteAllCookies();
- delegate_->resetScreenOrientation();
+ delegate_->SetDatabaseQuota(5 * 1024 * 1024);
+ delegate_->SetDeviceColorProfile("reset");
+ delegate_->SetDeviceScaleFactor(1);
+ delegate_->SetAcceptAllCookies(false);
+ delegate_->SetLocale("");
+ delegate_->UseUnfortunateSynchronousResizeMode(false);
+ delegate_->DisableAutoResizeMode(WebSize());
+ delegate_->DeleteAllCookies();
+ delegate_->ResetScreenOrientation();
ResetBatteryStatus();
ResetDeviceLight();
}
http_headers_to_clear_.clear();
- global_flag_ = false;
platform_name_ = "chromium";
tooltip_text_ = std::string();
disable_notify_done_ = false;
pointer_locked_ = false;
pointer_lock_planned_result_ = PointerLockWillSucceed;
- task_list_.revokeAll();
+ task_list_.RevokeAll();
work_queue_.Reset();
if (close_remaining_windows_ && delegate_)
- delegate_->closeRemainingWindows();
+ delegate_->CloseRemainingWindows();
else
close_remaining_windows_ = true;
}
}
void TestRunner::InvokeCallback(scoped_ptr<InvokeCallbackTask> task) {
- delegate_->postTask(task.release());
+ delegate_->PostTask(task.release());
}
bool TestRunner::shouldDumpEditingCallbacks() const {
void TestRunner::policyDelegateDone() {
DCHECK(wait_until_done_);
- delegate_->testFinished();
+ delegate_->TestFinished();
wait_until_done_ = false;
}
bool TestRunner::RequestPointerLock() {
switch (pointer_lock_planned_result_) {
case PointerLockWillSucceed:
- delegate_->postDelayedTask(
+ delegate_->PostDelayedTask(
new HostMethodTask(this, &TestRunner::DidAcquirePointerLockInternal),
0);
return true;
}
void TestRunner::RequestPointerUnlock() {
- delegate_->postDelayedTask(
+ delegate_->PostDelayedTask(
new HostMethodTask(this, &TestRunner::DidLosePointerLockInternal), 0);
}
return midi_accessor_result_;
}
-void TestRunner::clearDevToolsLocalStorage() {
- delegate_->clearDevToolsLocalStorage();
+void TestRunner::ClearDevToolsLocalStorage() {
+ delegate_->ClearDevToolsLocalStorage();
}
-void TestRunner::showDevTools(const std::string& settings,
+void TestRunner::ShowDevTools(const std::string& settings,
const std::string& frontend_url) {
- delegate_->showDevTools(settings, frontend_url);
+ delegate_->ShowDevTools(settings, frontend_url);
}
class WorkItemBackForward : public TestRunner::WorkItem {
WorkItemBackForward(int distance) : distance_(distance) {}
virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
- delegate->goToOffset(distance_);
+ delegate->GoToOffset(distance_);
return true; // FIXME: Did it really start a navigation?
}
return;
// Test didn't timeout. Kill the timeout timer.
- task_list_.revokeAll();
+ task_list_.RevokeAll();
CompleteNotifyDone();
}
class WorkItemReload : public TestRunner::WorkItem {
public:
virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
- delegate->reload();
+ delegate->Reload();
return true;
}
};
: url_(url), target_(target) {}
virtual bool Run(WebTestDelegate* delegate, WebView*) OVERRIDE {
- delegate->loadURLForFrame(url_, target_);
+ delegate->LoadURLForFrame(url_, target_);
return true; // FIXME: Did it really start a navigation?
}
}
void TestRunner::UseUnfortunateSynchronousResizeMode() {
- delegate_->useUnfortunateSynchronousResizeMode(true);
+ delegate_->UseUnfortunateSynchronousResizeMode(true);
}
bool TestRunner::EnableAutoResizeMode(int min_width,
int max_height) {
WebSize min_size(min_width, min_height);
WebSize max_size(max_width, max_height);
- delegate_->enableAutoResizeMode(min_size, max_size);
+ delegate_->EnableAutoResizeMode(min_size, max_size);
return true;
}
bool TestRunner::DisableAutoResizeMode(int new_width, int new_height) {
WebSize new_size(new_width, new_height);
- delegate_->disableAutoResizeMode(new_size);
+ delegate_->DisableAutoResizeMode(new_size);
return true;
}
void TestRunner::SetMockDeviceLight(double value) {
- delegate_->setDeviceLightData(value);
+ delegate_->SetDeviceLightData(value);
}
void TestRunner::ResetDeviceLight() {
- delegate_->setDeviceLightData(-1);
+ delegate_->SetDeviceLightData(-1);
}
void TestRunner::SetMockDeviceMotion(
// interval
motion.interval = interval;
- delegate_->setDeviceMotionData(motion);
+ delegate_->SetDeviceMotionData(motion);
}
void TestRunner::SetMockDeviceOrientation(bool has_alpha, double alpha,
orientation.hasAbsolute = has_absolute;
orientation.absolute = absolute;
- delegate_->setDeviceOrientationData(orientation);
+ delegate_->SetDeviceOrientationData(orientation);
}
void TestRunner::SetMockScreenOrientation(const std::string& orientation_str) {
orientation = WebScreenOrientationLandscapeSecondary;
}
- delegate_->setScreenOrientation(orientation);
+ delegate_->SetScreenOrientation(orientation);
}
void TestRunner::DidChangeBatteryStatus(bool charging,
status.chargingTime = chargingTime;
status.dischargingTime = dischargingTime;
status.level = level;
- delegate_->didChangeBatteryStatus(status);
+ delegate_->DidChangeBatteryStatus(status);
}
void TestRunner::ResetBatteryStatus() {
blink::WebBatteryStatus status;
- delegate_->didChangeBatteryStatus(status);
+ delegate_->DidChangeBatteryStatus(status);
}
void TestRunner::DidAcquirePointerLock() {
}
void TestRunner::SetPopupBlockingEnabled(bool block_popups) {
- delegate_->preferences()->java_script_can_open_windows_automatically =
+ delegate_->Preferences()->java_script_can_open_windows_automatically =
!block_popups;
- delegate_->applyPreferences();
+ delegate_->ApplyPreferences();
}
void TestRunner::SetJavaScriptCanAccessClipboard(bool can_access) {
- delegate_->preferences()->java_script_can_access_clipboard = can_access;
- delegate_->applyPreferences();
+ delegate_->Preferences()->java_script_can_access_clipboard = can_access;
+ delegate_->ApplyPreferences();
}
void TestRunner::SetXSSAuditorEnabled(bool enabled) {
- delegate_->preferences()->xss_auditor_enabled = enabled;
- delegate_->applyPreferences();
+ delegate_->Preferences()->xss_auditor_enabled = enabled;
+ delegate_->ApplyPreferences();
}
void TestRunner::SetAllowUniversalAccessFromFileURLs(bool allow) {
- delegate_->preferences()->allow_universal_access_from_file_urls = allow;
- delegate_->applyPreferences();
+ delegate_->Preferences()->allow_universal_access_from_file_urls = allow;
+ delegate_->ApplyPreferences();
}
void TestRunner::SetAllowFileAccessFromFileURLs(bool allow) {
- delegate_->preferences()->allow_file_access_from_file_urls = allow;
- delegate_->applyPreferences();
+ delegate_->Preferences()->allow_file_access_from_file_urls = allow;
+ delegate_->ApplyPreferences();
}
void TestRunner::OverridePreference(const std::string key,
v8::Handle<v8::Value> value) {
- TestPreferences* prefs = delegate_->preferences();
+ TestPreferences* prefs = delegate_->Preferences();
if (key == "WebKitDefaultFontSize") {
prefs->default_font_size = value->Int32Value();
} else if (key == "WebKitMinimumFontSize") {
prefs->should_respect_image_orientation = value->BooleanValue();
} else if (key == "WebKitWebAudioEnabled") {
DCHECK(value->BooleanValue());
+ } else if (key == "WebKitWebSecurityEnabled") {
+ prefs->web_security_enabled = value->BooleanValue();
} else {
std::string message("Invalid name for preference: ");
message.append(key);
- delegate_->printMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
+ delegate_->PrintMessage(std::string("CONSOLE MESSAGE: ") + message + "\n");
}
- delegate_->applyPreferences();
+ delegate_->ApplyPreferences();
}
void TestRunner::SetAcceptLanguages(const std::string& accept_languages) {
}
void TestRunner::SetPluginsEnabled(bool enabled) {
- delegate_->preferences()->plugins_enabled = enabled;
- delegate_->applyPreferences();
+ delegate_->Preferences()->plugins_enabled = enabled;
+ delegate_->ApplyPreferences();
}
void TestRunner::DumpEditingCallbacks() {
void TestRunner::ShowWebInspector(const std::string& str,
const std::string& frontend_url) {
- showDevTools(str, frontend_url);
+ ShowDevTools(str, frontend_url);
}
void TestRunner::WaitUntilExternalURLLoad() {
}
void TestRunner::CloseWebInspector() {
- delegate_->closeDevTools();
+ delegate_->CloseDevTools();
}
bool TestRunner::IsChooserShown() {
void TestRunner::EvaluateInWebInspector(int call_id,
const std::string& script) {
- delegate_->evaluateInWebInspector(call_id, script);
+ delegate_->EvaluateInWebInspector(call_id, script);
}
void TestRunner::ClearAllDatabases() {
- delegate_->clearAllDatabases();
+ delegate_->ClearAllDatabases();
}
void TestRunner::SetDatabaseQuota(int quota) {
- delegate_->setDatabaseQuota(quota);
+ delegate_->SetDatabaseQuota(quota);
}
void TestRunner::SetAlwaysAcceptCookies(bool accept) {
- delegate_->setAcceptAllCookies(accept);
+ delegate_->SetAcceptAllCookies(accept);
}
void TestRunner::SetWindowIsKey(bool value) {
- delegate_->setFocus(proxy_, value);
+ delegate_->SetFocus(proxy_, value);
}
std::string TestRunner::PathToLocalResource(const std::string& path) {
- return delegate_->pathToLocalResource(path);
+ return delegate_->PathToLocalResource(path);
}
void TestRunner::SetBackingScaleFactor(double value,
v8::Handle<v8::Function> callback) {
- delegate_->setDeviceScaleFactor(value);
- delegate_->postTask(new InvokeCallbackTask(this, callback));
+ delegate_->SetDeviceScaleFactor(value);
+ delegate_->PostTask(new InvokeCallbackTask(this, callback));
}
void TestRunner::SetColorProfile(const std::string& name,
v8::Handle<v8::Function> callback) {
- delegate_->setDeviceColorProfile(name);
- delegate_->postTask(new InvokeCallbackTask(this, callback));
+ delegate_->SetDeviceColorProfile(name);
+ delegate_->PostTask(new InvokeCallbackTask(this, callback));
}
void TestRunner::SetPOSIXLocale(const std::string& locale) {
- delegate_->setLocale(locale);
+ delegate_->SetLocale(locale);
}
void TestRunner::SetMIDIAccessorResult(bool result) {
void TestRunner::GrantWebNotificationPermission(const GURL& origin,
bool permission_granted) {
- delegate_->grantWebNotificationPermission(origin, permission_granted);
+ delegate_->GrantWebNotificationPermission(origin, permission_granted);
}
void TestRunner::ClearWebNotificationPermissions() {
- delegate_->clearWebNotificationPermissions();
+ delegate_->ClearWebNotificationPermissions();
}
bool TestRunner::SimulateWebNotificationClick(const std::string& value) {
return proxy_->GetSpeechRecognizerMock()->WasAborted();
}
+void TestRunner::AddMockCredentialManagerResponse(const std::string& id,
+ const std::string& name,
+ const std::string& avatar,
+ const std::string& password) {
+ proxy_->GetCredentialManagerClientMock()->SetResponse(
+ new WebLocalCredential(WebString::fromUTF8(id),
+ WebString::fromUTF8(name),
+ WebURL(GURL(avatar)),
+ WebString::fromUTF8(password)));
+}
+
void TestRunner::AddWebPageOverlay() {
if (web_view_ && !page_overlay_) {
page_overlay_ = new TestPageOverlay(web_view_);
base::Passed(&task)));
}
+void TestRunner::GetManifestThen(v8::Handle<v8::Function> callback) {
+ scoped_ptr<InvokeCallbackTask> task(
+ new InvokeCallbackTask(this, callback));
+
+ FetchManifest(web_view_, web_view_->mainFrame()->document().manifestURL(),
+ base::Bind(&TestRunner::GetManifestCallback,
+ base::Unretained(this),
+ base::Passed(&task)));
+}
+
void TestRunner::CapturePixelsAsyncThen(v8::Handle<v8::Function> callback) {
scoped_ptr<InvokeCallbackTask> task(
new InvokeCallbackTask(this, callback));
base::Passed(&task)));
}
+void TestRunner::GetManifestCallback(scoped_ptr<InvokeCallbackTask> task,
+ const blink::WebURLResponse& response,
+ const std::string& data) {
+ InvokeCallback(task.Pass());
+}
+
void TestRunner::CapturePixelsCallback(scoped_ptr<InvokeCallbackTask> task,
const SkBitmap& snapshot) {
v8::Isolate* isolate = blink::mainThreadIsolate();
}
void TestRunner::LocationChangeDone() {
- web_history_item_count_ = delegate_->navigationEntryCount();
+ web_history_item_count_ = delegate_->NavigationEntryCount();
// No more new work after the first complete load.
work_queue_.set_frozen(true);
void TestRunner::CompleteNotifyDone() {
if (wait_until_done_ && !topLoadingFrame() && work_queue_.is_empty())
- delegate_->testFinished();
+ delegate_->TestFinished();
wait_until_done_ = false;
}