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.
5 #include "content/public/test/javascript_test_observer.h"
7 #include "content/public/browser/dom_operation_notification_details.h"
8 #include "content/public/browser/notification_types.h"
9 #include "content/public/browser/render_view_host.h"
10 #include "content/public/browser/web_contents.h"
11 #include "content/public/test/test_utils.h"
15 TestMessageHandler::TestMessageHandler() : ok_(true) {
18 TestMessageHandler::~TestMessageHandler() {
21 void TestMessageHandler::SetError(const std::string
& message
) {
23 error_message_
= message
;
26 void TestMessageHandler::Reset() {
28 error_message_
.clear();
31 JavascriptTestObserver::JavascriptTestObserver(
32 WebContents
* web_contents
, TestMessageHandler
* handler
)
38 NOTIFICATION_DOM_OPERATION_RESPONSE
,
39 Source
<WebContents
>(web_contents
));
42 JavascriptTestObserver::~JavascriptTestObserver() {
45 bool JavascriptTestObserver::Run() {
46 // Messages may have arrived before Run was called.
53 return handler_
->ok();
56 void JavascriptTestObserver::Reset() {
63 void JavascriptTestObserver::Observe(
65 const NotificationSource
& source
,
66 const NotificationDetails
& details
) {
67 CHECK(type
== NOTIFICATION_DOM_OPERATION_RESPONSE
);
68 Details
<DomOperationNotificationDetails
> dom_op_details(details
);
69 // We might receive responses for other script execution, but we only
70 // care about the test finished message.
71 TestMessageHandler::MessageResponse response
=
72 handler_
->HandleMessage(dom_op_details
->json
);
74 if (response
== TestMessageHandler::DONE
) {
81 void JavascriptTestObserver::Continue() {
84 void JavascriptTestObserver::EndTest() {
88 base::MessageLoopForUI::current()->Quit();
92 } // namespace content