blob: ac7d405d99a232d8fb278bd66959a7cd5d2344db [file] [log] [blame]
[email protected]2a28e0b22011-02-03 21:49:031// 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#ifndef CHROME_TEST_WEBDRIVER_AUTOMATION_H_
6#define CHROME_TEST_WEBDRIVER_AUTOMATION_H_
7
8#include <string>
9
10#include "base/task.h"
11#include "base/ref_counted.h"
12#include "base/scoped_temp_dir.h"
[email protected]7cc2c912011-02-13 03:11:2113#include "chrome/common/automation_constants.h"
[email protected]2a28e0b22011-02-03 21:49:0314#include "chrome/test/ui/ui_test.h"
[email protected]7cc2c912011-02-13 03:11:2115#include "ui/base/keycodes/keyboard_codes.h"
[email protected]2a28e0b22011-02-03 21:49:0316
17namespace webdriver {
18
[email protected]7cc2c912011-02-13 03:11:2119struct WebKeyEvent {
20 WebKeyEvent(automation::KeyEventTypes type,
21 ui::KeyboardCode key_code,
22 const std::string& unmodified_text,
23 const std::string& modified_text,
24 int modifiers)
25 : type(type),
26 key_code(key_code),
27 unmodified_text(unmodified_text),
28 modified_text(modified_text),
29 modifiers(modifiers) {}
30
31 automation::KeyEventTypes type;
32 ui::KeyboardCode key_code;
33 std::string unmodified_text;
34 std::string modified_text;
35 int modifiers;
36};
37
[email protected]2a28e0b22011-02-03 21:49:0338// Creates and controls the Chrome instance.
39// This class should be created and accessed on a single thread.
40// TODO(phajdan.jr): Abstract UITestBase classes, see:
41// http://code.google.com/p/chromium/issues/detail?id=56865
42class Automation : private UITestBase {
43 public:
[email protected]808d1032011-02-09 20:16:5544 Automation();
45 virtual ~Automation();
[email protected]2a28e0b22011-02-03 21:49:0346
47 // Creates a browser.
48 void Init(bool* success);
49
50 // Terminates this session and disconnects its automation proxy. After
51 // invoking this method, the Automation can safely be deleted.
52 void Terminate();
53
54 // Executes the given |script| in the specified frame of the current
55 // tab. |result| will be set to the JSON result. Returns true on success.
56 void ExecuteScript(const std::string& frame_xpath,
57 const std::string& script,
58 std::string* result,
59 bool* success);
60
[email protected]7cc2c912011-02-13 03:11:2161 // Sends a key event to the current browser. Waits until the key has
62 // been processed by the web page.
63 void SendWebKeyEvent(const WebKeyEvent& key_event, bool* success);
64
[email protected]2a28e0b22011-02-03 21:49:0365 void NavigateToURL(const std::string& url, bool* success);
66 void GoForward(bool* success);
67 void GoBack(bool* success);
68 void Reload(bool* success);
69 void GetURL(std::string* url, bool* success);
70 void GetTabTitle(std::string* tab_title, bool* success);
71
72 private:
73 scoped_refptr<BrowserProxy> browser_;
74 scoped_refptr<TabProxy> tab_;
75
76 ScopedTempDir profile_dir_;
77
78 DISALLOW_COPY_AND_ASSIGN(Automation);
79};
80
81} // namespace webdriver
82
83DISABLE_RUNNABLE_METHOD_REFCOUNT(webdriver::Automation);
84
85#endif // CHROME_TEST_WEBDRIVER_AUTOMATION_H_