Implement nacl_irt_memory for non-sfi mode.
[chromium-blink-merge.git] / chrome / test / base / javascript_test_observer.h
blob835cc721ddb6aa4362a83e70384ad533ebfdaf0c
1 // Copyright (c) 2012 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 #ifndef CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_
6 #define CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_
8 #include <string>
10 #include "base/compiler_specific.h"
11 #include "content/public/browser/notification_observer.h"
12 #include "content/public/browser/notification_registrar.h"
14 namespace base {
15 class DictionaryValue;
18 namespace content {
19 class RenderViewHost;
22 // Base class for handling a stream of automation messages produced by a
23 // JavascriptTestObserver.
24 class TestMessageHandler {
25 public:
26 enum MessageResponse {
27 // Reset the timeout and keep running.
28 CONTINUE,
29 // Stop runnning.
30 DONE
33 TestMessageHandler();
34 virtual ~TestMessageHandler();
36 // Called when a message is received from the DOM automation controller.
37 virtual MessageResponse HandleMessage(const std::string& json) = 0;
39 void SetError(const std::string& message);
41 bool ok() const {
42 return ok_;
45 const std::string& error_message() const {
46 return error_message_;
49 // Prepare the handler to be used or reused.
50 virtual void Reset();
52 private:
53 bool ok_;
54 std::string error_message_;
57 // This class captures a stream of automation messages coming from a Javascript
58 // test and dispatches them to a message handler.
59 class JavascriptTestObserver : public content::NotificationObserver {
60 public:
61 // The observer does not own any arguments passed to it. It is assumed that
62 // the arguments will outlive all uses of the observer.
63 JavascriptTestObserver(
64 content::RenderViewHost* render_view_host,
65 TestMessageHandler* handler);
67 virtual ~JavascriptTestObserver();
69 // Pump the message loop until the message handler indicates the Javascript
70 // test is done running. Return true if the test jig functioned correctly and
71 // nothing timed out.
72 bool Run();
74 // Prepare the observer to be used again. This method should NOT be called
75 // while Run() is pumping the message loop.
76 void Reset();
78 virtual void Observe(
79 int type,
80 const content::NotificationSource& source,
81 const content::NotificationDetails& details) OVERRIDE;
83 private:
84 // This message did not signal the end of a test, keep going.
85 void Continue();
87 // This was the last message we care about, stop listening for more messages.
88 void EndTest();
90 TestMessageHandler* handler_;
91 bool running_;
92 bool finished_;
93 content::NotificationRegistrar registrar_;
95 DISALLOW_COPY_AND_ASSIGN(JavascriptTestObserver);
98 #endif // CHROME_TEST_BASE_JAVASCRIPT_TEST_OBSERVER_H_