summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjyasskin <jyasskin@chromium.org>2015-09-22 09:20:26 -0700
committerCommit bot <commit-bot@chromium.org>2015-09-22 16:21:06 +0000
commita5cef8fe03eba361467c63ab38db5d759fa6eedb (patch)
treec870c04b8ba23af9ac4b84983896d4c904fe1452
parent716fe641702c915b637d08676fd4cc47af07c890 (diff)
downloadchromium_src-a5cef8fe03eba361467c63ab38db5d759fa6eedb.zip
chromium_src-a5cef8fe03eba361467c63ab38db5d759fa6eedb.tar.gz
chromium_src-a5cef8fe03eba361467c63ab38db5d759fa6eedb.tar.bz2
Make getBluetoothManualChooserEvents() asynchronous.
This fixes the Windows tests, where synchronous, unpumped messages to the UI thread are forbidden: https://codereview.chromium.org/1304353004/ BUG=500989 Review URL: https://codereview.chromium.org/1351393002 Cr-Commit-Position: refs/heads/master@{#350167}
-rw-r--r--components/html_viewer/web_test_delegate_impl.cc5
-rw-r--r--components/html_viewer/web_test_delegate_impl.h4
-rw-r--r--components/test_runner/test_runner.cc38
-rw-r--r--components/test_runner/test_runner.h8
-rw-r--r--components/test_runner/web_test_delegate.h4
-rw-r--r--content/shell/browser/blink_test_controller.cc7
-rw-r--r--content/shell/browser/blink_test_controller.h2
-rw-r--r--content/shell/common/shell_messages.h5
-rw-r--r--content/shell/renderer/layout_test/blink_test_runner.cc22
-rw-r--r--content/shell/renderer/layout_test/blink_test_runner.h11
10 files changed, 81 insertions, 25 deletions
diff --git a/components/html_viewer/web_test_delegate_impl.cc b/components/html_viewer/web_test_delegate_impl.cc
index 6a62f97..4e958fd 100644
--- a/components/html_viewer/web_test_delegate_impl.cc
+++ b/components/html_viewer/web_test_delegate_impl.cc
@@ -201,10 +201,9 @@ void WebTestDelegateImpl::SetBluetoothManualChooser() {
NOTIMPLEMENTED();
}
-std::vector<std::string>
-WebTestDelegateImpl::GetBluetoothManualChooserEvents() {
+void WebTestDelegateImpl::GetBluetoothManualChooserEvents(
+ const base::Callback<void(const std::vector<std::string>&)>& callback) {
NOTIMPLEMENTED();
- return std::vector<std::string>();
}
void WebTestDelegateImpl::SendBluetoothManualChooserEvent(
diff --git a/components/html_viewer/web_test_delegate_impl.h b/components/html_viewer/web_test_delegate_impl.h
index 933a76e..b3ae0e8 100644
--- a/components/html_viewer/web_test_delegate_impl.h
+++ b/components/html_viewer/web_test_delegate_impl.h
@@ -75,7 +75,9 @@ class WebTestDelegateImpl : public test_runner::WebTestDelegate {
void SetDeviceColorProfile(const std::string& name) override;
void SetBluetoothMockDataSet(const std::string& data_set) override;
void SetBluetoothManualChooser() override;
- std::vector<std::string> GetBluetoothManualChooserEvents() override;
+ void GetBluetoothManualChooserEvents(
+ const base::Callback<void(const std::vector<std::string>&)>& callback)
+ override;
void SendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument) override;
void SetGeofencingMockProvider(bool service_available) override;
diff --git a/components/test_runner/test_runner.cc b/components/test_runner/test_runner.cc
index 0d13157..00dc145 100644
--- a/components/test_runner/test_runner.cc
+++ b/components/test_runner/test_runner.cc
@@ -296,7 +296,7 @@ class TestRunnerBindings : public gin::Wrappable<TestRunnerBindings> {
void SetViewSourceForFrame(const std::string& name, bool enabled);
void SetBluetoothMockDataSet(const std::string& dataset_name);
void SetBluetoothManualChooser();
- std::vector<std::string> GetBluetoothManualChooserEvents();
+ void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
void SendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument);
void SetGeofencingMockProvider(bool service_available);
@@ -1350,10 +1350,10 @@ void TestRunnerBindings::SetBluetoothManualChooser() {
runner_->SetBluetoothManualChooser();
}
-std::vector<std::string> TestRunnerBindings::GetBluetoothManualChooserEvents() {
+void TestRunnerBindings::GetBluetoothManualChooserEvents(
+ v8::Local<v8::Function> callback) {
if (runner_)
- return runner_->GetBluetoothManualChooserEvents();
- return std::vector<std::string>(1, "No Test Runner");
+ return runner_->GetBluetoothManualChooserEvents(callback);
}
void TestRunnerBindings::SendBluetoothManualChooserEvent(
@@ -2846,8 +2846,12 @@ void TestRunner::SetBluetoothManualChooser() {
delegate_->SetBluetoothManualChooser();
}
-std::vector<std::string> TestRunner::GetBluetoothManualChooserEvents() {
- return delegate_->GetBluetoothManualChooserEvents();
+void TestRunner::GetBluetoothManualChooserEvents(
+ v8::Local<v8::Function> callback) {
+ scoped_ptr<InvokeCallbackTask> task(new InvokeCallbackTask(this, callback));
+ return delegate_->GetBluetoothManualChooserEvents(
+ base::Bind(&TestRunner::GetBluetoothManualChooserEventsCallback,
+ weak_factory_.GetWeakPtr(), base::Passed(&task)));
}
void TestRunner::SendBluetoothManualChooserEvent(const std::string& event,
@@ -3062,6 +3066,28 @@ void TestRunner::DispatchBeforeInstallPromptCallback(
InvokeCallback(task.Pass());
}
+void TestRunner::GetBluetoothManualChooserEventsCallback(
+ scoped_ptr<InvokeCallbackTask> task,
+ const std::vector<std::string>& events) {
+ // Build the V8 context.
+ v8::Isolate* isolate = blink::mainThreadIsolate();
+ v8::HandleScope handle_scope(isolate);
+ v8::Local<v8::Context> context =
+ web_view_->mainFrame()->mainWorldScriptContext();
+ if (context.IsEmpty())
+ return;
+ v8::Context::Scope context_scope(context);
+
+ // Convert the argument.
+ v8::Local<v8::Value> arg[1];
+ if (!gin::TryConvertToV8(isolate, events, &arg[0]))
+ return;
+
+ // Call the callback.
+ task->SetArguments(1, arg);
+ InvokeCallback(task.Pass());
+}
+
void TestRunner::LocationChangeDone() {
web_history_item_count_ = delegate_->NavigationEntryCount();
diff --git a/components/test_runner/test_runner.h b/components/test_runner/test_runner.h
index b8f6284..4ea4ade 100644
--- a/components/test_runner/test_runner.h
+++ b/components/test_runner/test_runner.h
@@ -529,8 +529,9 @@ class TestRunner : public WebTestRunner,
// the test program on how to proceed.
void SetBluetoothManualChooser();
- // Returns the events recorded since the last call to this function.
- std::vector<std::string> GetBluetoothManualChooserEvents();
+ // Calls |callback| with a DOMString[] representing the events recorded since
+ // the last call to this function.
+ void GetBluetoothManualChooserEvents(v8::Local<v8::Function> callback);
// Calls the BluetoothChooser::EventHandler with the arguments here. Valid
// event strings are:
@@ -623,6 +624,9 @@ class TestRunner : public WebTestRunner,
const SkBitmap& snapshot);
void DispatchBeforeInstallPromptCallback(scoped_ptr<InvokeCallbackTask> task,
bool canceled);
+ void GetBluetoothManualChooserEventsCallback(
+ scoped_ptr<InvokeCallbackTask> task,
+ const std::vector<std::string>& events);
void CheckResponseMimeType();
void CompleteNotifyDone();
diff --git a/components/test_runner/web_test_delegate.h b/components/test_runner/web_test_delegate.h
index 1906180..26b135a 100644
--- a/components/test_runner/web_test_delegate.h
+++ b/components/test_runner/web_test_delegate.h
@@ -166,7 +166,9 @@ class WebTestDelegate {
virtual void SetBluetoothManualChooser() = 0;
// Returns the events recorded since the last call to this function.
- virtual std::vector<std::string> GetBluetoothManualChooserEvents() = 0;
+ virtual void GetBluetoothManualChooserEvents(
+ const base::Callback<void(const std::vector<std::string>& events)>&
+ callback) = 0;
// Calls the BluetoothChooser::EventHandler with the arguments here. Valid
// event strings are:
diff --git a/content/shell/browser/blink_test_controller.cc b/content/shell/browser/blink_test_controller.cc
index 97c5337..eb15b2d 100644
--- a/content/shell/browser/blink_test_controller.cc
+++ b/content/shell/browser/blink_test_controller.cc
@@ -727,15 +727,16 @@ void BlinkTestController::OnSetBluetoothManualChooser(bool enable) {
}
}
-void BlinkTestController::OnGetBluetoothManualChooserEvents(
- std::vector<std::string>* events) {
+void BlinkTestController::OnGetBluetoothManualChooserEvents() {
if (!bluetooth_chooser_factory_) {
printer_->AddErrorMessage(
"FAIL: Must call setBluetoothManualChooser before "
"getBluetoothManualChooserEvents.");
return;
}
- *events = bluetooth_chooser_factory_->GetAndResetEvents();
+ Send(new ShellViewMsg_ReplyBluetoothManualChooserEvents(
+ main_window_->web_contents()->GetRoutingID(),
+ bluetooth_chooser_factory_->GetAndResetEvents()));
}
void BlinkTestController::OnSendBluetoothManualChooserEvent(
diff --git a/content/shell/browser/blink_test_controller.h b/content/shell/browser/blink_test_controller.h
index a955df0..4f36c03 100644
--- a/content/shell/browser/blink_test_controller.h
+++ b/content/shell/browser/blink_test_controller.h
@@ -183,7 +183,7 @@ class BlinkTestController : public base::NonThreadSafe,
void OnResetDone();
void OnLeakDetectionDone(const content::LeakDetectionResult& result);
void OnSetBluetoothManualChooser(bool enable);
- void OnGetBluetoothManualChooserEvents(std::vector<std::string>* events);
+ void OnGetBluetoothManualChooserEvents();
void OnSendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument);
diff --git a/content/shell/common/shell_messages.h b/content/shell/common/shell_messages.h
index fa7c63e..9baf871 100644
--- a/content/shell/common/shell_messages.h
+++ b/content/shell/common/shell_messages.h
@@ -112,8 +112,9 @@ IPC_MESSAGE_ROUTED1(ShellViewHostMsg_LeakDetectionDone,
IPC_MESSAGE_ROUTED1(ShellViewHostMsg_SetBluetoothManualChooser,
bool /* enable */)
-IPC_SYNC_MESSAGE_ROUTED0_1(ShellViewHostMsg_GetBluetoothManualChooserEvents,
- std::vector<std::string> /* events */)
+IPC_MESSAGE_ROUTED0(ShellViewHostMsg_GetBluetoothManualChooserEvents)
+IPC_MESSAGE_ROUTED1(ShellViewMsg_ReplyBluetoothManualChooserEvents,
+ std::vector<std::string> /* events */)
IPC_MESSAGE_ROUTED2(ShellViewHostMsg_SendBluetoothManualChooserEvent,
std::string /* event */,
std::string /* argument */)
diff --git a/content/shell/renderer/layout_test/blink_test_runner.cc b/content/shell/renderer/layout_test/blink_test_runner.cc
index bc52f3e..2233563 100644
--- a/content/shell/renderer/layout_test/blink_test_runner.cc
+++ b/content/shell/renderer/layout_test/blink_test_runner.cc
@@ -484,12 +484,13 @@ void BlinkTestRunner::SetBluetoothMockDataSet(const std::string& name) {
void BlinkTestRunner::SetBluetoothManualChooser() {
Send(new ShellViewHostMsg_SetBluetoothManualChooser(routing_id(), true));
}
-std::vector<std::string> BlinkTestRunner::GetBluetoothManualChooserEvents() {
- std::vector<std::string> result;
- Send(new ShellViewHostMsg_GetBluetoothManualChooserEvents(routing_id(),
- &result));
- return result;
+
+void BlinkTestRunner::GetBluetoothManualChooserEvents(
+ const base::Callback<void(const std::vector<std::string>&)>& callback) {
+ get_bluetooth_events_callbacks_.push_back(callback);
+ Send(new ShellViewHostMsg_GetBluetoothManualChooserEvents(routing_id()));
}
+
void BlinkTestRunner::SendBluetoothManualChooserEvent(
const std::string& event,
const std::string& argument) {
@@ -732,6 +733,8 @@ bool BlinkTestRunner::OnMessageReceived(const IPC::Message& message) {
IPC_MESSAGE_HANDLER(ShellViewMsg_Reset, OnReset)
IPC_MESSAGE_HANDLER(ShellViewMsg_NotifyDone, OnNotifyDone)
IPC_MESSAGE_HANDLER(ShellViewMsg_TryLeakDetection, OnTryLeakDetection)
+ IPC_MESSAGE_HANDLER(ShellViewMsg_ReplyBluetoothManualChooserEvents,
+ OnReplyBluetoothManualChooserEvents)
IPC_MESSAGE_UNHANDLED(handled = false)
IPC_END_MESSAGE_MAP()
@@ -911,6 +914,15 @@ void BlinkTestRunner::OnTryLeakDetection() {
leak_detector_->TryLeakDetection(main_frame);
}
+void BlinkTestRunner::OnReplyBluetoothManualChooserEvents(
+ const std::vector<std::string>& events) {
+ DCHECK(!get_bluetooth_events_callbacks_.empty());
+ base::Callback<void(const std::vector<std::string>&)> callback =
+ get_bluetooth_events_callbacks_.front();
+ get_bluetooth_events_callbacks_.pop_front();
+ callback.Run(events);
+}
+
void BlinkTestRunner::ReportLeakDetectionResult(
const LeakDetectionResult& report) {
Send(new ShellViewHostMsg_LeakDetectionDone(routing_id(), report));
diff --git a/content/shell/renderer/layout_test/blink_test_runner.h b/content/shell/renderer/layout_test/blink_test_runner.h
index a4b07ce..6739bed 100644
--- a/content/shell/renderer/layout_test/blink_test_runner.h
+++ b/content/shell/renderer/layout_test/blink_test_runner.h
@@ -5,8 +5,10 @@
#ifndef CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_
#define CONTENT_SHELL_RENDERER_LAYOUT_TEST_BLINK_TEST_RUNNER_H_
+#include <deque>
#include <vector>
+#include "base/callback.h"
#include "base/files/file_path.h"
#include "base/memory/scoped_ptr.h"
#include "components/test_runner/test_preferences.h"
@@ -97,7 +99,9 @@ class BlinkTestRunner : public RenderViewObserver,
void SetDeviceColorProfile(const std::string& name) override;
void SetBluetoothMockDataSet(const std::string& name) override;
void SetBluetoothManualChooser() override;
- std::vector<std::string> GetBluetoothManualChooserEvents() override;
+ void GetBluetoothManualChooserEvents(
+ const base::Callback<void(const std::vector<std::string>&)>& callback)
+ override;
void SendBluetoothManualChooserEvent(const std::string& event,
const std::string& argument) override;
void SetGeofencingMockProvider(bool service_available) override;
@@ -158,6 +162,8 @@ class BlinkTestRunner : public RenderViewObserver,
void OnReset();
void OnNotifyDone();
void OnTryLeakDetection();
+ void OnReplyBluetoothManualChooserEvents(
+ const std::vector<std::string>& events);
// After finishing the test, retrieves the audio, text, and pixel dumps from
// the TestRunner library and sends them to the browser process.
@@ -177,6 +183,9 @@ class BlinkTestRunner : public RenderViewObserver,
std::vector<std::vector<PageState> > session_histories_;
std::vector<unsigned> current_entry_indexes_;
+ std::deque<base::Callback<void(const std::vector<std::string>&)>>
+ get_bluetooth_events_callbacks_;
+
bool is_main_window_;
bool focus_on_next_commit_;