summaryrefslogtreecommitdiffstats
path: root/chrome/test/chromedriver/javascript_dialog_manager.h
blob: a5684c67c8efa71342c848be79d10f55a9f854e9 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
// Copyright (c) 2013 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.

#ifndef CHROME_TEST_CHROMEDRIVER_JAVASCRIPT_DIALOG_MANAGER_H_
#define CHROME_TEST_CHROMEDRIVER_JAVASCRIPT_DIALOG_MANAGER_H_

#include <list>
#include <string>

#include "base/basictypes.h"
#include "base/compiler_specific.h"
#include "chrome/test/chromedriver/devtools_event_listener.h"

namespace base {
class DictionaryValue;
}

class DevToolsClient;
class Status;

// Tracks the opening and closing of JavaScript dialogs (e.g., alerts).
class JavaScriptDialogManager : public DevToolsEventListener {
 public:
  explicit JavaScriptDialogManager(DevToolsClient* client);
  virtual ~JavaScriptDialogManager();

  bool IsDialogOpen();

  Status GetDialogMessage(std::string* message);

  Status HandleDialog(bool accept, const std::string& text);

  // Overridden from DevToolsEventListener:
  virtual Status OnConnected() OVERRIDE;
  virtual void OnEvent(const std::string& method,
                       const base::DictionaryValue& params) OVERRIDE;

 private:
  DevToolsClient* client_;

  // The queue of unhandled dialogs. This may be greater than 1 in rare
  // cases. E.g., if the page shows an alert but before the manager received
  // the event, a script was injected via Inspector that triggered an alert.
  std::list<std::string> unhandled_dialog_queue_;

  DISALLOW_COPY_AND_ASSIGN(JavaScriptDialogManager);
};

#endif  // CHROME_TEST_CHROMEDRIVER_JAVASCRIPT_DIALOG_MANAGER_H_