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. 4 5 #ifndef CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_ 6 #define CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_ 7 8 9 #include "apps/shell_window.h" 10 #include "chrome/browser/extensions/extension_apitest.h" 11 #include "content/public/common/page_transition_types.h" 12 13 namespace content { 14 class WebContents; 15 } 16 17 class Browser; 18 class CommandLine; 19 20 namespace extensions { 21 class Extension; 22 23 class PlatformAppBrowserTest : public ExtensionApiTest { 24 public: 25 PlatformAppBrowserTest(); 26 27 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 28 29 // Gets the first shell window that is found for a given browser. 30 static apps::ShellWindow* GetFirstShellWindowForBrowser(Browser* browser); 31 32 protected: 33 // Runs the app named |name| out of the platform_apps subdirectory. Waits 34 // until it is launched. 35 const Extension* LoadAndLaunchPlatformApp(const char* name); 36 37 // Installs the app named |name| out of the platform_apps subdirectory. 38 const Extension* InstallPlatformApp(const char* name); 39 40 // Installs and runs the app named |name| out of the platform_apps 41 // subdirectory. Waits until it is launched. 42 const Extension* InstallAndLaunchPlatformApp(const char* name); 43 44 // Gets the WebContents associated with the first shell window that is found 45 // (most tests only deal with one platform app window, so this is good 46 // enough). 47 content::WebContents* GetFirstShellWindowWebContents(); 48 49 // Gets the first shell window that is found (most tests only deal with one 50 // platform app window, so this is good enough). 51 apps::ShellWindow* GetFirstShellWindow(); 52 53 // Runs chrome.windows.getAll for the given extension and returns the number 54 // of windows that the function returns. 55 size_t RunGetWindowsFunctionForExtension(const Extension* extension); 56 57 // Runs chrome.windows.get(|window_id|) for the the given extension and 58 // returns whether or not a window was found. 59 bool RunGetWindowFunctionForExtension(int window_id, 60 const Extension* extension); 61 62 // Returns the number of shell windows. 63 size_t GetShellWindowCount(); 64 65 // The command line already has an argument on it - about:blank, which 66 // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app 67 // launch tests we need to clear this. 68 void ClearCommandLineArgs(); 69 70 // Sets up the command line for running platform apps. 71 void SetCommandLineArg(const std::string& test_file); 72 73 // Creates an empty shell window for |extension|. 74 apps::ShellWindow* CreateShellWindow(const Extension* extension); 75 76 apps::ShellWindow* CreateShellWindowFromParams( 77 const Extension* extension, 78 const apps::ShellWindow::CreateParams& params); 79 80 // Closes |window| and waits until it's gone. 81 void CloseShellWindow(apps::ShellWindow* window); 82 83 // Call AdjustBoundsToBeVisibleOnScreen of |window|. 84 void CallAdjustBoundsToBeVisibleOnScreenForShellWindow( 85 apps::ShellWindow* window, 86 const gfx::Rect& cached_bounds, 87 const gfx::Rect& cached_screen_bounds, 88 const gfx::Rect& current_screen_bounds, 89 const gfx::Size& minimum_size, 90 gfx::Rect* bounds); 91 }; 92 93 class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest { 94 public: 95 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE; 96 }; 97 98 } // namespace extensions 99 100 #endif // CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_ 101