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