Returns Downloads mount point from getMountPoints.
[chromium-blink-merge.git] / remoting / test / remote_desktop_browsertest.h
blobbab191f7cc31e4a28f53fe6ea780f7e3e40f14b7
1 // Copyright 2013 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 REMOTE_DESKTOP_BROWSER_TEST_H_
6 #define REMOTE_DESKTOP_BROWSER_TEST_H_
8 #include "chrome/browser/chrome_notification_types.h"
9 #include "chrome/browser/extensions/extension_browsertest.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/ui_test_utils.h"
12 #include "content/public/browser/notification_service.h"
13 #include "content/public/test/browser_test_utils.h"
14 #include "net/dns/mock_host_resolver.h"
16 namespace {
17 // Command line arguments specific to the chromoting browser tests.
18 const char kOverrideUserDataDir[] = "override-user-data-dir";
19 const char kNoCleanup[] = "no-cleanup";
20 const char kNoInstall[] = "no-install";
21 const char kWebAppCrx[] = "webapp-crx";
22 const char kUsername[] = "username";
23 const char kkPassword[] = "password";
24 const char kMe2MePin[] = "me2me-pin";
26 // ASSERT_TRUE can only be used in void returning functions. This version
27 // should be used in non-void-returning functions.
28 inline void _ASSERT_TRUE(bool condition) {
29 ASSERT_TRUE(condition);
30 return;
35 namespace remoting {
37 class RemoteDesktopBrowserTest : public ExtensionBrowserTest {
38 public:
39 RemoteDesktopBrowserTest();
40 virtual ~RemoteDesktopBrowserTest();
42 // InProcessBrowserTest Overrides
43 virtual void SetUp() OVERRIDE;
45 protected:
46 // InProcessBrowserTest Overrides
47 virtual void SetUpInProcessBrowserTestFixture() OVERRIDE;
49 // InProcessBrowserTest Overrides
50 virtual void TearDownInProcessBrowserTestFixture() OVERRIDE;
53 /* */
54 /* The following helpers each perform a simple task. */
55 /* */
57 // Verify the test has access to the internet (specifically google.com)
58 void VerifyInternetAccess();
60 // Install the chromoting extension from a crx file.
61 void InstallChromotingApp();
63 // Uninstall the chromoting extension.
64 void UninstallChromotingApp();
66 // Test whether the chromoting extension is installed.
67 void VerifyChromotingLoaded(bool expected);
69 // Launch the chromoting app.
70 void LaunchChromotingApp();
72 // Authorize: grant extended access permission to the user's computer.
73 void Authorize();
75 // Authenticate: sign in to google using the credentials provided.
76 void Authenticate();
78 // Approve: grant the chromoting app necessary permissions.
79 void Approve();
81 // Click on "Get Started" in the Me2Me section and show the host list.
82 void StartMe2Me();
85 /* */
86 /* The following helpers each perform a composite task. */
87 /* */
89 // Install the chromoting extension
90 void Install();
92 // Clean up after the test.
93 void Cleanup();
95 // Perform all the auth steps: authorization, authenticattion, etc.
96 // It starts from the chromoting main page unauthenticated and ends up back
97 // on the chromoting main page authenticated and ready to go.
98 void Auth();
100 // Connect to the local host through Me2Me.
101 void ConnectToLocalHost();
103 // Enter the pin number and connect.
104 void EnterPin(const std::string& name);
106 // Helper to get the pin number used for me2me authentication.
107 std::string me2me_pin() { return me2me_pin_; }
109 private:
110 // Change behavior of the default host resolver to allow DNS lookup
111 // to proceed instead of being blocked by the test infrastructure.
112 void EnableDNSLookupForThisTest(
113 net::RuleBasedHostResolverProc* host_resolver);
115 // We need to reset the DNS lookup when we finish, or the test will fail.
116 void DisableDNSLookupForThisTest();
118 void ParseCommandLine();
121 /* */
122 /* Accessor methods. */
123 /* */
125 // Helper to get the path to the crx file of the webapp to be tested.
126 base::FilePath WebAppCrxPath() { return webapp_crx_; }
128 // Helper to get the extension ID of the installed chromoting webapp.
129 std::string ChromotingID() { return chromoting_id_; }
131 // Whether to perform the cleanup tasks (uninstalling chromoting, etc).
132 // This is useful for diagnostic purposes.
133 bool NoCleanup() { return no_cleanup_; }
135 // Whether to install the chromoting extension before running the test cases.
136 // This is useful for diagnostic purposes.
137 bool NoInstall() { return no_install_; }
139 // Helper to construct the starting URL of the installed chromoting webapp.
140 GURL Chromoting_Main_URL() {
141 return GURL("chrome-extension://" + ChromotingID() + "/main.html");
144 // Helper to retrieve the current URL of the active tab in the browser.
145 GURL GetCurrentURL() {
146 return browser()->tab_strip_model()->GetActiveWebContents()->GetURL();
150 /* */
151 /* Helpers to execute javascript code on a web page. */
152 /* */
154 // Helper to execute a javascript code snippet on the current page.
155 void ExecuteScript(const std::string& script);
157 // Helper to execute a javascript code snippet on the current page and
158 // wait for page load to complete.
159 void ExecuteScriptAndWait(const std::string& script);
161 // Helper to execute a javascript code snippet on the current page and
162 // wait until the target url is loaded. This is used when the target page
163 // is loaded after multiple redirections.
164 void ExecuteScriptAndWaitUntil(const std::string& script, const GURL& target);
166 // Helper to execute a javascript code snippet on the current page and
167 // extract the boolean result.
168 bool ExecuteScriptAndExtractBool(const std::string& script);
170 // Helper to execute a javascript code snippet on the current page and
171 // extract the int result.
172 int ExecuteScriptAndExtractInt(const std::string& script);
174 // Helper to execute a javascript code snippet on the current page and
175 // extract the string result.
176 std::string ExecuteScriptAndExtractString(const std::string& script);
178 // Helper to navigate to a given url.
179 void NavigateToURLAndWait(const GURL& url);
181 // Helper to check whether an html element with the given name exists on
182 // the current page.
183 bool HtmlElementExists(const std::string& name) {
184 return ExecuteScriptAndExtractBool(
185 "document.getElementById(\"" + name + "\") != null");
188 // Helper to check whether a html element with the given name is visible.
189 bool HtmlElementVisible(const std::string& name);
191 // Click on the named HTML control.
192 void ClickOnControl(const std::string& name);
194 // Wait for the me2me connection to be established.
195 void WaitForConnection();
198 /* */
199 /* Fields */
200 /* */
202 // This test needs to make live DNS requests for access to
203 // GAIA and sync server URLs under google.com. We use a scoped version
204 // to override the default resolver while the test is active.
205 scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_;
207 bool no_cleanup_;
208 bool no_install_;
209 std::string chromoting_id_;
210 base::FilePath webapp_crx_;
211 std::string username_;
212 std::string password_;
213 std::string me2me_pin_;
216 } // namespace remoting
218 #endif // REMOTE_DESKTOP_BROWSER_TEST_H_