• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
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 base {
13 class CommandLine;
14 }
15 
16 namespace content {
17 class WebContents;
18 }
19 
20 class Browser;
21 class ExtensionTestMessageListener;
22 
23 namespace extensions {
24 class Extension;
25 
26 class PlatformAppBrowserTest : public ExtensionApiTest {
27  public:
28   PlatformAppBrowserTest();
29 
30   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
31 
32   // Gets the first app window that is found for a given browser.
33   static apps::AppWindow* GetFirstAppWindowForBrowser(Browser* browser);
34 
35  protected:
36   // Runs the app named |name| out of the platform_apps subdirectory. Waits
37   // for the provided listener to be satisifed.
38   const Extension* LoadAndLaunchPlatformApp(
39       const char* name,
40       ExtensionTestMessageListener* listener);
41 
42   // Runs the app named |name| out of the platform_apps subdirectory. Waits
43   // until the given message is received from the app.
44   const Extension* LoadAndLaunchPlatformApp(const char* name,
45                                             const std::string& message);
46 
47   // Installs the app named |name| out of the platform_apps subdirectory.
48   const Extension* InstallPlatformApp(const char* name);
49 
50   // Installs and runs the app named |name| out of the platform_apps
51   // subdirectory. Waits until it is launched.
52   const Extension* InstallAndLaunchPlatformApp(const char* name);
53 
54   // Launch the given platform app.
55   void LaunchPlatformApp(const Extension* extension);
56 
57   // Gets the WebContents associated with the first app window that is found
58   // (most tests only deal with one platform app window, so this is good
59   // enough).
60   content::WebContents* GetFirstAppWindowWebContents();
61 
62   // Gets the first app window that is found (most tests only deal with one
63   // platform app window, so this is good enough).
64   apps::AppWindow* GetFirstAppWindow();
65 
66   // Gets the first app window for an app.
67   apps::AppWindow* GetFirstAppWindowForApp(const std::string& app_id);
68 
69   // Runs chrome.windows.getAll for the given extension and returns the number
70   // of windows that the function returns.
71   size_t RunGetWindowsFunctionForExtension(const Extension* extension);
72 
73   // Runs chrome.windows.get(|window_id|) for the the given extension and
74   // returns whether or not a window was found.
75   bool RunGetWindowFunctionForExtension(int window_id,
76                                         const Extension* extension);
77 
78   // Returns the number of app windows.
79   size_t GetAppWindowCount();
80 
81   // Returns the number of app windows for a specific app.
82   size_t GetAppWindowCountForApp(const std::string& app_id);
83 
84   // The command line already has an argument on it - about:blank, which
85   // is set by InProcessBrowserTest::PrepareTestCommandLine. For platform app
86   // launch tests we need to clear this.
87   void ClearCommandLineArgs();
88 
89   // Sets up the command line for running platform apps.
90   void SetCommandLineArg(const std::string& test_file);
91 
92   // Creates an empty app window for |extension|.
93   apps::AppWindow* CreateAppWindow(const Extension* extension);
94 
95   apps::AppWindow* CreateAppWindowFromParams(
96       const Extension* extension,
97       const apps::AppWindow::CreateParams& params);
98 
99   // Closes |window| and waits until it's gone.
100   void CloseAppWindow(apps::AppWindow* window);
101 
102   // Call AdjustBoundsToBeVisibleOnScreen of |window|.
103   void CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
104       apps::AppWindow* window,
105       const gfx::Rect& cached_bounds,
106       const gfx::Rect& cached_screen_bounds,
107       const gfx::Rect& current_screen_bounds,
108       const gfx::Size& minimum_size,
109       gfx::Rect* bounds);
110 
111   // Load a simple test app and create a window. The window must be closed by
112   // the caller in order to terminate the test - use CloseAppWindow().
113   // |window_create_options| are the options that will be passed to
114   // chrome.app.window.create() in the test app.
115   apps::AppWindow* CreateTestAppWindow(
116       const std::string& window_create_options);
117 };
118 
119 class ExperimentalPlatformAppBrowserTest : public PlatformAppBrowserTest {
120  public:
121   virtual void SetUpCommandLine(base::CommandLine* command_line) OVERRIDE;
122 };
123 
124 }  // namespace extensions
125 
126 #endif  // CHROME_BROWSER_APPS_APP_BROWSERTEST_UTIL_H_
127