13551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Copyright 2013 The Chromium Authors. All rights reserved. 23551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Use of this source code is governed by a BSD-style license that can be 33551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// found in the LICENSE file. 43551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 54e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#ifndef CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ 64e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#define CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ 73551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 8116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch#include "base/debug/stack_trace.h" 98bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)#include "chrome/browser/apps/app_browsertest_util.h" 103551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/chrome_notification_types.h" 113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/browser/ui/tabs/tab_strip_model.h" 123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "chrome/test/base/ui_test_utils.h" 133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/browser/notification_service.h" 143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "content/public/test/browser_test_utils.h" 153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)#include "net/dns/mock_host_resolver.h" 163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace { 183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)// Command line arguments specific to the chromoting browser tests. 193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kOverrideUserDataDir[] = "override-user-data-dir"; 203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kNoCleanup[] = "no-cleanup"; 213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kNoInstall[] = "no-install"; 223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kWebAppCrx[] = "webapp-crx"; 238bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)const char kWebAppUnpacked[] = "webapp-unpacked"; 243551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kUsername[] = "username"; 253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)const char kkPassword[] = "password"; 26424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)const char kMe2MePin[] = "me2me-pin"; 274e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)const char kRemoteHostName[] = "remote-host-name"; 285d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles)const char kExtensionName[] = "extension-name"; 29c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdochconst char kHttpServer[] = "http-server"; 303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 31424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// ASSERT_TRUE can only be used in void returning functions. This version 32424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)// should be used in non-void-returning functions. 33424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles)inline void _ASSERT_TRUE(bool condition) { 34116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch if (!condition) { 35116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // ASSERT_TRUE only prints the first call frame in the error message. 36116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // In our case, this is the _ASSERT_TRUE wrapper function, which is not 37116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch // useful. To help with debugging, we will dump the full callstack. 38116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch LOG(ERROR) << "Assertion failed."; 39116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch LOG(ERROR) << base::debug::StackTrace().ToString(); 40116680a4aac90f2aa7413d9095a592090648e557Ben Murdoch } 413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) ASSERT_TRUE(condition); 423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return; 433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} 443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 454e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)} // namespace 463551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)using extensions::Extension; 488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 493551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)namespace remoting { 503551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles)class RemoteDesktopBrowserTest : public extensions::PlatformAppBrowserTest { 523551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) public: 533551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) RemoteDesktopBrowserTest(); 543551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual ~RemoteDesktopBrowserTest(); 553551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 563551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // InProcessBrowserTest Overrides 573551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void SetUp() OVERRIDE; 584e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) virtual void SetUpOnMainThread() OVERRIDE; 593551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 603551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) protected: 613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // InProcessBrowserTest Overrides 623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void SetUpInProcessBrowserTestFixture() OVERRIDE; 633551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // InProcessBrowserTest Overrides 653551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) virtual void TearDownInProcessBrowserTestFixture() OVERRIDE; 663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 67d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The following helpers each perform a simple task. 683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Verify the test has access to the internet (specifically google.com) 703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void VerifyInternetAccess(); 713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 72c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Open the client page for the browser test to get status of host actions 73c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch void OpenClientBrowserPage(); 74c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Install the chromoting extension from a crx file. 768bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void InstallChromotingAppCrx(); 778bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 788bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Install the unpacked chromoting extension. 798bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) void InstallChromotingAppUnpacked(); 803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Uninstall the chromoting extension. 823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void UninstallChromotingApp(); 833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 843551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Test whether the chromoting extension is installed. 853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void VerifyChromotingLoaded(bool expected); 863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Launch the chromoting app. 883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void LaunchChromotingApp(); 893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 903551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Authorize: grant extended access permission to the user's computer. 913551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Authorize(); 923551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 933551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Authenticate: sign in to google using the credentials provided. 943551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Authenticate(); 953551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 963551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Approve: grant the chromoting app necessary permissions. 973551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Approve(); 983551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 99424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Click on "Get Started" in the Me2Me section and show the host list. 1001e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ExpandMe2Me(); 101424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1024e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Disconnect the active Me2Me session. 1034e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) void DisconnectMe2Me(); 1044e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 10558537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) // Simulate a key event. 10658537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void SimulateKeyPressWithCode(ui::KeyboardCode keyCode, const char* code); 10758537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 10858537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) void SimulateKeyPressWithCode(ui::KeyboardCode keyCode, 10958537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) const char* code, 11058537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool control, 11158537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool shift, 11258537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool alt, 11358537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) bool command); 11458537e28ecd584eab876aee8be7156509866d23aTorne (Richard Coles) 11568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Simulate typing a character 11668043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void SimulateCharInput(char c); 11768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 11868043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Simulate typing a string 11968043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void SimulateStringInput(const std::string& input); 12068043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12168043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Helper to simulate a left button mouse click. 12268043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void SimulateMouseLeftClickAt(int x, int y); 12368043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 12468043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) // Helper to simulate a mouse click. 12568043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) void SimulateMouseClickAt( 126f2477e01787aa58f445919b809d89e252beef54fTorne (Richard Coles) int modifiers, blink::WebMouseEvent::Button button, int x, int y); 12768043e1e95eeb07d5cae7aca370b26518b0867d6Torne (Richard Coles) 128d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // The following helpers each perform a composite task. 1293551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Install the chromoting extension 1313551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Install(); 1323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 133cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Perform all necessary steps (installation, authorization, authentication, 134cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // expanding the me2me section) so that the app is ready for a me2me 135cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // connection. 136cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) void SetUpTestForMe2Me(); 137cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) 1383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Clean up after the test. 1393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Cleanup(); 1403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 141cedac228d2dd51db4b79ea1e72c7f249408ee061Torne (Richard Coles) // Perform all the auth steps: authorization, authentication, etc. 1423551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // It starts from the chromoting main page unauthenticated and ends up back 1433551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // on the chromoting main page authenticated and ready to go. 1443551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void Auth(); 1453551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1465f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Ensures that the host is started locally with |me2me_pin()|. 1475f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) // Browser_test.js must be loaded before calling this function. 1485f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) void EnsureRemoteConnectionEnabled(); 1495f1c94371a64b3196d4be9466099bb892df9b88eTorne (Richard Coles) 150424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Connect to the local host through Me2Me. 1511e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ConnectToLocalHost(bool remember_pin); 152424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1534e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Connect to a remote host through Me2Me. 1541e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void ConnectToRemoteHost(const std::string& host_name, bool remember_pin); 1554e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 156424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Enter the pin number and connect. 1571e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void EnterPin(const std::string& name, bool remember_pin); 158424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 159424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Helper to get the pin number used for me2me authentication. 160424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::string me2me_pin() { return me2me_pin_; } 161424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 1624e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Helper to get the name of the remote host to connect to. 1634e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string remote_host_name() { return remote_host_name_; } 1644e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 165c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Helper to get the test controller URL. 166c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch std::string http_server() { return http_server_; } 167c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 1683551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Change behavior of the default host resolver to allow DNS lookup 1693551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // to proceed instead of being blocked by the test infrastructure. 1703551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void EnableDNSLookupForThisTest( 1713551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) net::RuleBasedHostResolverProc* host_resolver); 1723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // We need to reset the DNS lookup when we finish, or the test will fail. 1743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void DisableDNSLookupForThisTest(); 1753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1763551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void ParseCommandLine(); 1773551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 178d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Accessor methods. 1793551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1803551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Helper to get the path to the crx file of the webapp to be tested. 1813551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::FilePath WebAppCrxPath() { return webapp_crx_; } 1823551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 1833551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Helper to get the extension ID of the installed chromoting webapp. 1848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::string ChromotingID() { return extension_->id(); } 1858bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1868bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Is this a appsv2 web app? 1878bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool is_platform_app() { 1888bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return extension_->GetType() == extensions::Manifest::TYPE_PLATFORM_APP; 1898bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Are we testing an unpacked extension? 1928bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool is_unpacked() { 1938bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return !webapp_unpacked_.empty(); 1948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 1958bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 1968bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The "active" WebContents instance the test needs to interact with. 1978bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::WebContents* active_web_contents() { 1988bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) DCHECK(!web_contents_stack_.empty()); 1998bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return web_contents_stack_.back(); 2008bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2013551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 202c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // The client WebContents instance the test needs to interact with. 203c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content::WebContents* client_web_content() { 204c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch return client_web_content_; 205c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch } 206c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 207010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::WebContents* app_web_content() { 208010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) return app_web_content_; 209010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) } 210010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2113551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Whether to perform the cleanup tasks (uninstalling chromoting, etc). 2123551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This is useful for diagnostic purposes. 2133551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool NoCleanup() { return no_cleanup_; } 2143551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2153551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Whether to install the chromoting extension before running the test cases. 2163551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This is useful for diagnostic purposes. 2173551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool NoInstall() { return no_install_; } 2183551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2193551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // Helper to construct the starting URL of the installed chromoting webapp. 2203551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GURL Chromoting_Main_URL() { 2213551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return GURL("chrome-extension://" + ChromotingID() + "/main.html"); 2223551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2233551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2248bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Helper to retrieve the current URL in the active WebContents. 2253551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) GURL GetCurrentURL() { 2268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return active_web_contents()->GetURL(); 2273551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2283551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 229010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helpers to execute JavaScript code on a web page. 2303551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 231010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet in the active WebContents. 2323551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) void ExecuteScript(const std::string& script); 2333551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 234010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet in the active WebContents 2358bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and wait for page load to complete. 236d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) void ExecuteScriptAndWaitForAnyPageLoad(const std::string& script); 2373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 238010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet in the active WebContents 2398bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and extract the boolean result. 2404e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) bool ExecuteScriptAndExtractBool(const std::string& script) { 2418bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return ExecuteScriptAndExtractBool(active_web_contents(), script); 2424e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) } 2434e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 244010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet and extract the boolean result. 2458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static bool ExecuteScriptAndExtractBool(content::WebContents* web_contents, 2464e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) const std::string& script); 2473551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 248010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet in the active WebContents 2498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and extract the int result. 2508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) int ExecuteScriptAndExtractInt(const std::string& script) { 2518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return ExecuteScriptAndExtractInt(active_web_contents(), script); 2528bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 2538bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) 254010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet and extract the int result. 2558bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static int ExecuteScriptAndExtractInt(content::WebContents* web_contents, 2568bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const std::string& script); 257424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 258010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet in the active WebContents 2598bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // and extract the string result. 2608bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::string ExecuteScriptAndExtractString(const std::string& script) { 2618bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return ExecuteScriptAndExtractString(active_web_contents(), script); 2628bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 263424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 264010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript code snippet and extract the string result. 2658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static std::string ExecuteScriptAndExtractString( 2668bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) content::WebContents* web_contents, const std::string& script); 2673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 268010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to load a JavaScript file from |path| and inject it to 269010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // current web_content. The variable |path| is relative to the directory of 270010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // the |browsertest| executable. 271010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) static bool LoadScript(content::WebContents* web_contents, 272010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const base::FilePath::StringType& path); 273010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 274010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // Helper to execute a JavaScript browser test. It creates an object using 275010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // the |browserTest.testName| ctor and calls |run| on the created object with 276010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // |testData|, which can be any arbitrary object literal. The script 277010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // browser_test.js must be loaded (using LoadScript) before calling this 278010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // function. 279010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) void RunJavaScriptTest(content::WebContents* web_contents, 280010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const std::string& testName, 281010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) const std::string& testData); 282010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 2838bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Helper to check whether an html element with the given name exists in 2848bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // the active WebContents. 2853551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool HtmlElementExists(const std::string& name) { 2863551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) return ExecuteScriptAndExtractBool( 2873551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) "document.getElementById(\"" + name + "\") != null"); 2883551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) } 2893551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 2908bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Helper to check whether a html element with the given name is visible in 2918bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // the active WebContents. 292424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) bool HtmlElementVisible(const std::string& name); 293424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 2948bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Click on the named HTML control in the active WebContents. 295424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void ClickOnControl(const std::string& name); 296424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 297424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) // Wait for the me2me connection to be established. 298424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) void WaitForConnection(); 299424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) 300d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Checking whether the localHost has been initialized. 301d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool IsLocalHostReady(); 302d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 303d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Callback used by EnterPin to check whether the pin form is visible 304d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // and to dismiss the host-needs-update dialog. 305d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool IsPinFormVisible(); 3063551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 307d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Callback used by WaitForConnection to check whether the connection 308d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // has been established. 309d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) bool IsSessionConnected(); 310d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 3118bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Callback used by Approve to check whether the chromoting app has 3128bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // successfully authenticated with the Google services. 3138bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) bool IsAuthenticated() { 3148bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) return IsAuthenticatedInWindow(active_web_contents()); 3158bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) } 316d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 3171320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // Callback used by Approve to check whether the Accept button is enabled 3181320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci // and ready to receive a click. 3191320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci static bool IsEnabled( 3201320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci content::WebContents* web_contents, const std::string& name); 3211320f92c476a1ad9d19dba2a48c72b75566198e9Primiano Tucci 3221e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) // If the "Host version out-of-date" form is visible, dismiss it. 3231e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) void DismissHostVersionWarningIfVisible(); 3241e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) 3254e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) // Callback used by Approve to check whether the chromoting app has 3268bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // successfully authenticated with the Google services. 3278bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) static bool IsAuthenticatedInWindow(content::WebContents* web_contents); 328d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) 329c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Callback used to check whether a host action is completed. 330c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // Used by browser tests while conditionally waiting for host actions. 331c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch static bool IsHostActionComplete( 332c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content::WebContents* client_web_content, std::string host_action_var); 333c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 3341e9bf3e0803691d0a228da41fc608347b6db4340Torne (Richard Coles) private: 335d0247b1b59f9c528cb6df88b4f2b9afaf80d181eTorne (Richard Coles) // Fields 3363551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3373551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // This test needs to make live DNS requests for access to 3383551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // GAIA and sync server URLs under google.com. We use a scoped version 3393551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) // to override the default resolver while the test is active. 3403551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) scoped_ptr<net::ScopedDefaultHostResolverProc> mock_host_resolver_override_; 3413551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3428bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Stores all the WebContents instance in a stack so that we can easily 3438bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // return to the previous instance. 3448bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // The active WebContents instance is always stored at the top of the stack. 3458bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Initially the stack contains the WebContents instance created by 3468bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // InProcessBrowserTest as the initial context to run test in. 3478bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // Whenever a WebContents instance is spawned and needs attention we 3488bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // push it onto the stack and that becomes the active instance. 3498bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // And once we are done with the current WebContents instance 3508bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) // we pop it off the stack, returning to the previous instance. 3518bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) std::vector<content::WebContents*> web_contents_stack_; 3524e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) 353c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // WebContent of the client page that facilitates communication with 354c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // the HTTP server. This is how the remoting browser tests 355c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch // will get acknowledgments of actions completed on the host. 356c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch content::WebContents* client_web_content_; 357c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch 358010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) // WebContent of the landing page in the chromoting app. 359010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) content::WebContents* app_web_content_; 360010d83a9304c5a91596085d917d248abff47903aTorne (Richard Coles) 3613551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool no_cleanup_; 3623551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) bool no_install_; 3638bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) const Extension* extension_; 3643551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) base::FilePath webapp_crx_; 3658bcbed890bc3ce4d7a057a8f32cab53fa534672eTorne (Richard Coles) base::FilePath webapp_unpacked_; 3663551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::string username_; 3673551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) std::string password_; 368424c4d7b64af9d0d8fd9624f381f469654d5e3d2Torne (Richard Coles) std::string me2me_pin_; 3694e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles) std::string remote_host_name_; 3705d1f7b1de12d16ceb2c938c56701a3e8bfa558f7Torne (Richard Coles) std::string extension_name_; 371c5cede9ae108bb15f6b7a8aea21c7e1fefa2834cBen Murdoch std::string http_server_; 3723551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)}; 3733551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3743551c9c881056c480085172ff9840cab31610854Torne (Richard Coles)} // namespace remoting 3753551c9c881056c480085172ff9840cab31610854Torne (Richard Coles) 3764e180b6a0b4720a9b8e9e959a882386f690f08ffTorne (Richard Coles)#endif // CHROME_TEST_REMOTING_REMOTE_DESKTOP_BROWSERTEST_H_ 377