Upstream version 5.34.92.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
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   // Launch the given platform app.
45   void LaunchPlatformApp(const Extension* extension);
46
47   // Gets the WebContents associated with the first shell window that is found
48   // (most tests only deal with one platform app window, so this is good
49   // enough).
50   content::WebContents* GetFirstShellWindowWebContents();
51
52   // Gets the first shell window that is found (most tests only deal with one
53   // platform app window, so this is good enough).
54   apps::ShellWindow* GetFirstShellWindow();
55
56   // Gets the first shell window for an app.
57   apps::ShellWindow* GetFirstShellWindowForApp(const std::string& app_id);
58
59   // Runs chrome.windows.getAll for the given extension and returns the number
60   // of windows that the function returns.
61   size_t RunGetWindowsFunctionForExtension(const Extension* extension);
62
63   // Runs chrome.windows.get(|window_id|) for the the given extension and
64   // returns whether or not a window was found.
65   bool RunGetWindowFunctionForExtension(int window_id,
66                                         const Extension* extension);
67
68   // Returns the number of shell windows.
69   size_t GetShellWindowCount();
70
71   // Returns the number of shell windows for a specific app.
72   size_t GetShellWindowCountForApp(const std::string& app_id);
73
74   // The command line already has an argument on it - about:blank, which
75   // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app
76   // launch tests we need to clear this.
77   void ClearCommandLineArgs();
78
79   // Sets up the command line for running platform apps.
80   void SetCommandLineArg(const std::string& test_file);
81
82   // Creates an empty shell window for |extension|.
83   apps::ShellWindow* CreateShellWindow(const Extension* extension);
84
85   apps::ShellWindow* CreateShellWindowFromParams(
86       const Extension* extension,
87       const apps::ShellWindow::CreateParams& params);
88
89   // Closes |window| and waits until it's gone.
90   void CloseShellWindow(apps::ShellWindow* window);
91
92   // Call AdjustBoundsToBeVisibleOnScreen of |window|.
93   void CallAdjustBoundsToBeVisibleOnScreenForShellWindow(
94       apps::ShellWindow* window,
95       const gfx::Rect& cached_bounds,
96       const gfx::Rect& cached_screen_bounds,
97       const gfx::Rect& current_screen_bounds,
98       const gfx::Size& minimum_size,
99       gfx::Rect* bounds);
100 };
101
102 class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest {
103  public:
104   virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE;
105 };
106
107 }  // namespace extensions
108
109 #endif  // CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_