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

Side by Side Diff: chrome/test/base/javascript_test_observer.cc

Issue 286243003: Move JavascriptTestObserver from chrome to content. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Remove unnecessary content prefixes Created 6 years, 7 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/javascript_test_observer.h ('k') | chrome/test/nacl/nacl_browsertest_util.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
(Empty)
1 // Copyright (c) 2011 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 "chrome/test/base/javascript_test_observer.h"
6
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"
12
13 TestMessageHandler::TestMessageHandler() : ok_(true) {
14 }
15
16 TestMessageHandler::~TestMessageHandler() {
17 }
18
19 void TestMessageHandler::SetError(const std::string& message) {
20 ok_ = false;
21 error_message_ = message;
22 }
23
24 void TestMessageHandler::Reset() {
25 ok_ = true;
26 error_message_.clear();
27 }
28
29 JavascriptTestObserver::JavascriptTestObserver(
30 content::WebContents* web_contents,
31 TestMessageHandler* handler)
32 : handler_(handler),
33 running_(false),
34 finished_(false) {
35 Reset();
36 registrar_.Add(this,
37 content::NOTIFICATION_DOM_OPERATION_RESPONSE,
38 content::Source<content::WebContents>(web_contents));
39 }
40
41 JavascriptTestObserver::~JavascriptTestObserver() {
42 }
43
44 bool JavascriptTestObserver::Run() {
45 // Messages may have arrived before Run was called.
46 if (!finished_) {
47 CHECK(!running_);
48 running_ = true;
49 content::RunMessageLoop();
50 running_ = false;
51 }
52 return handler_->ok();
53 }
54
55 void JavascriptTestObserver::Reset() {
56 CHECK(!running_);
57 running_ = false;
58 finished_ = false;
59 handler_->Reset();
60 }
61
62 void JavascriptTestObserver::Observe(
63 int type,
64 const content::NotificationSource& source,
65 const content::NotificationDetails& details) {
66 CHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE);
67 content::Details<content::DomOperationNotificationDetails> dom_op_details(
68 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);
73
74 if (response == TestMessageHandler::DONE) {
75 EndTest();
76 } else {
77 Continue();
78 }
79 }
80
81 void JavascriptTestObserver::Continue() {
82 }
83
84 void JavascriptTestObserver::EndTest() {
85 finished_ = true;
86 if (running_) {
87 running_ = false;
88 base::MessageLoopForUI::current()->Quit();
89 }
90 }
OLDNEW
« no previous file with comments | « chrome/test/base/javascript_test_observer.h ('k') | chrome/test/nacl/nacl_browsertest_util.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698