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 CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_
6 #define CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_
8 #include "chrome/browser/extensions/extension_apitest.h"
9 #include "extensions/browser/app_window/app_window.h"
20 class ExtensionTestMessageListener;
22 namespace extensions {
25 class PlatformAppBrowserTest : public ExtensionApiTest {
27 PlatformAppBrowserTest();
29 void SetUpCommandLine(base::CommandLine* command_line) override;
31 // Gets the first app window that is found for a given browser.
32 static AppWindow* GetFirstAppWindowForBrowser(Browser* browser);
35 // Runs the app named |name| out of the platform_apps subdirectory. Waits
36 // for the provided listener to be satisifed.
37 const Extension* LoadAndLaunchPlatformApp(
39 ExtensionTestMessageListener* listener);
41 // Runs the app named |name| out of the platform_apps subdirectory. Waits
42 // until the given message is received from the app.
43 const Extension* LoadAndLaunchPlatformApp(const char* name,
44 const std::string& message);
46 // Installs the app named |name| out of the platform_apps subdirectory.
47 const Extension* InstallPlatformApp(const char* name);
49 // Installs and runs the app named |name| out of the platform_apps
50 // subdirectory. Waits until it is launched.
51 const Extension* InstallAndLaunchPlatformApp(const char* name);
53 // Launch the given platform app.
54 virtual void LaunchPlatformApp(const Extension* extension);
56 // Gets the WebContents associated with the first app window that is found
57 // (most tests only deal with one platform app window, so this is good
59 content::WebContents* GetFirstAppWindowWebContents();
61 // Gets the first app window that is found (most tests only deal with one
62 // platform app window, so this is good enough).
63 AppWindow* GetFirstAppWindow();
65 // Gets the first app window for an app.
66 AppWindow* GetFirstAppWindowForApp(const std::string& app_id);
68 // Runs chrome.windows.getAll for the given extension and returns the number
69 // of windows that the function returns.
70 size_t RunGetWindowsFunctionForExtension(const Extension* extension);
72 // Runs chrome.windows.get(|window_id|) for the the given extension and
73 // returns whether or not a window was found.
74 bool RunGetWindowFunctionForExtension(int window_id,
75 const Extension* extension);
77 // Returns the number of app windows.
78 size_t GetAppWindowCount();
80 // Returns the number of app windows for a specific app.
81 size_t GetAppWindowCountForApp(const std::string& app_id);
83 // The command line already has an argument on it - about:blank, which
84 // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app
85 // launch tests we need to clear this.
86 void ClearCommandLineArgs();
88 // Sets up the command line for running platform apps.
89 void SetCommandLineArg(const std::string& test_file);
91 // Creates an empty app window for |extension|.
92 AppWindow* CreateAppWindow(const Extension* extension);
94 AppWindow* CreateAppWindowFromParams(const Extension* extension,
95 const AppWindow::CreateParams& params);
97 // Closes |window| and waits until it's gone.
98 void CloseAppWindow(AppWindow* window);
100 // Call AdjustBoundsToBeVisibleOnScreen of |window|.
101 void CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
103 const gfx::Rect& cached_bounds,
104 const gfx::Rect& cached_screen_bounds,
105 const gfx::Rect& current_screen_bounds,
106 const gfx::Size& minimum_size,
109 // Load a simple test app and create a window. The window must be closed by
110 // the caller in order to terminate the test - use CloseAppWindow().
111 // |window_create_options| are the options that will be passed to
112 // chrome.app.window.create() in the test app.
113 AppWindow* CreateTestAppWindow(const std::string& window_create_options);
116 DISALLOW_COPY_AND_ASSIGN(PlatformAppBrowserTest);
119 class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest {
121 void SetUpCommandLine(base::CommandLine* command_line) override;
124 } // namespace extensions
126 #endif // CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_