summaryrefslogtreecommitdiffstats
path: root/chrome/browser/apps/app_browsertest_util.cc
diff options
context:
space:
mode:
authorbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 11:26:58 +0000
committerbenwells@chromium.org <benwells@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2013-08-15 11:26:58 +0000
commitbb4bec003c8f8a417f55068b34362860389c28cd (patch)
tree32e9c5a43661a66c7e53856662c50ecd33c76694 /chrome/browser/apps/app_browsertest_util.cc
parenta1a5c407f567e89556da15d1a7e4d1c13a9c256d (diff)
downloadchromium_src-bb4bec003c8f8a417f55068b34362860389c28cd.zip
chromium_src-bb4bec003c8f8a417f55068b34362860389c28cd.tar.gz
chromium_src-bb4bec003c8f8a417f55068b34362860389c28cd.tar.bz2
Move apps tests from c/b/extensions to c/b/apps and refine DEPS.
TBR=sky BUG=159366 Review URL: https://chromiumcodereview.appspot.com/23003004 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@217780 0039d316-1c4b-4281-b951-d872f2087c98
Diffstat (limited to 'chrome/browser/apps/app_browsertest_util.cc')
-rw-r--r--chrome/browser/apps/app_browsertest_util.cc194
1 files changed, 194 insertions, 0 deletions
diff --git a/chrome/browser/apps/app_browsertest_util.cc b/chrome/browser/apps/app_browsertest_util.cc
new file mode 100644
index 0000000..7a2f9ce
--- /dev/null
+++ b/chrome/browser/apps/app_browsertest_util.cc
@@ -0,0 +1,194 @@
+// Copyright 2013 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "chrome/browser/apps/app_browsertest_util.h"
+
+#include "apps/app_window_contents.h"
+#include "apps/native_app_window.h"
+#include "apps/shell_window_registry.h"
+#include "base/command_line.h"
+#include "base/strings/stringprintf.h"
+#include "chrome/browser/extensions/api/tabs/tabs_api.h"
+#include "chrome/browser/extensions/extension_function_test_utils.h"
+#include "chrome/browser/ui/apps/chrome_shell_window_delegate.h"
+#include "chrome/browser/ui/browser.h"
+#include "chrome/browser/ui/extensions/application_launch.h"
+#include "chrome/common/chrome_switches.h"
+#include "content/public/browser/notification_service.h"
+#include "content/public/test/test_utils.h"
+#include "extensions/common/switches.h"
+
+using apps::ShellWindow;
+using apps::ShellWindowRegistry;
+using content::WebContents;
+
+namespace utils = extension_function_test_utils;
+
+namespace extensions {
+
+PlatformAppBrowserTest::PlatformAppBrowserTest() {
+ ChromeShellWindowDelegate::DisableExternalOpenForTesting();
+}
+
+void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
+ // Skips ExtensionApiTest::SetUpCommandLine.
+ ExtensionBrowserTest::SetUpCommandLine(command_line);
+
+ // Make event pages get suspended quicker.
+ command_line->AppendSwitchASCII(::switches::kEventPageIdleTime, "1");
+ command_line->AppendSwitchASCII(::switches::kEventPageSuspendingTime, "1");
+}
+
+const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp(
+ const char* name) {
+ content::WindowedNotificationObserver app_loaded_observer(
+ content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+
+ const Extension* extension = LoadExtension(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII(name));
+ EXPECT_TRUE(extension);
+
+ chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(),
+ extension,
+ extension_misc::LAUNCH_NONE,
+ NEW_WINDOW));
+
+ app_loaded_observer.Wait();
+
+ return extension;
+}
+
+const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp(
+ const char* name) {
+ content::WindowedNotificationObserver app_loaded_observer(
+ content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
+ content::NotificationService::AllSources());
+
+ const Extension* extension = InstallExtension(
+ test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1);
+ EXPECT_TRUE(extension);
+
+ chrome::OpenApplication(chrome::AppLaunchParams(browser()->profile(),
+ extension,
+ extension_misc::LAUNCH_NONE,
+ NEW_WINDOW));
+
+ app_loaded_observer.Wait();
+
+ return extension;
+}
+
+WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() {
+ ShellWindow* window = GetFirstShellWindow();
+ if (window)
+ return window->web_contents();
+
+ return NULL;
+}
+
+ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() {
+ ShellWindowRegistry* app_registry =
+ ShellWindowRegistry::Get(browser()->profile());
+ const ShellWindowRegistry::ShellWindowList& shell_windows =
+ app_registry->shell_windows();
+
+ ShellWindowRegistry::const_iterator iter = shell_windows.begin();
+ if (iter != shell_windows.end())
+ return *iter;
+
+ return NULL;
+}
+
+size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension(
+ const Extension* extension) {
+ scoped_refptr<WindowsGetAllFunction> function = new WindowsGetAllFunction();
+ function->set_extension(extension);
+ scoped_ptr<base::ListValue> result(utils::ToList(
+ utils::RunFunctionAndReturnSingleResult(function.get(),
+ "[]",
+ browser())));
+ return result->GetSize();
+}
+
+bool PlatformAppBrowserTest::RunGetWindowFunctionForExtension(
+ int window_id,
+ const Extension* extension) {
+ scoped_refptr<WindowsGetFunction> function = new WindowsGetFunction();
+ function->set_extension(extension);
+ utils::RunFunction(
+ function.get(),
+ base::StringPrintf("[%u]", window_id),
+ browser(),
+ utils::NONE);
+ return function->GetResultList() != NULL;
+}
+
+size_t PlatformAppBrowserTest::GetShellWindowCount() {
+ return ShellWindowRegistry::Get(browser()->profile())->
+ shell_windows().size();
+}
+
+void PlatformAppBrowserTest::ClearCommandLineArgs() {
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ CommandLine::StringVector args = command_line->GetArgs();
+ CommandLine::StringVector argv = command_line->argv();
+ for (size_t i = 0; i < args.size(); i++)
+ argv.pop_back();
+ command_line->InitFromArgv(argv);
+}
+
+void PlatformAppBrowserTest::SetCommandLineArg(const std::string& test_file) {
+ ClearCommandLineArgs();
+ CommandLine* command_line = CommandLine::ForCurrentProcess();
+ base::FilePath test_doc(test_data_dir_.AppendASCII(test_file));
+ test_doc = test_doc.NormalizePathSeparators();
+ command_line->AppendArgPath(test_doc);
+}
+
+ShellWindow* PlatformAppBrowserTest::CreateShellWindow(
+ const Extension* extension) {
+ return CreateShellWindowFromParams(extension, ShellWindow::CreateParams());
+}
+
+ShellWindow* PlatformAppBrowserTest::CreateShellWindowFromParams(
+ const Extension* extension, const ShellWindow::CreateParams& params) {
+ ShellWindow* window = new ShellWindow(browser()->profile(),
+ new ChromeShellWindowDelegate(),
+ extension);
+ window->Init(GURL(std::string()),
+ new apps::AppWindowContents(window),
+ params);
+ return window;
+}
+
+void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) {
+ content::WindowedNotificationObserver destroyed_observer(
+ content::NOTIFICATION_WEB_CONTENTS_DESTROYED,
+ content::NotificationService::AllSources());
+ window->GetBaseWindow()->Close();
+ destroyed_observer.Wait();
+}
+
+void PlatformAppBrowserTest::CallAdjustBoundsToBeVisibleOnScreenForShellWindow(
+ ShellWindow* window,
+ const gfx::Rect& cached_bounds,
+ const gfx::Rect& cached_screen_bounds,
+ const gfx::Rect& current_screen_bounds,
+ const gfx::Size& minimum_size,
+ gfx::Rect* bounds) {
+ window->AdjustBoundsToBeVisibleOnScreen(cached_bounds,
+ cached_screen_bounds,
+ current_screen_bounds,
+ minimum_size,
+ bounds);
+}
+
+void ExperimentalPlatformAppBrowserTest::SetUpCommandLine(
+ CommandLine* command_line) {
+ PlatformAppBrowserTest::SetUpCommandLine(command_line);
+ command_line->AppendSwitch(switches::kEnableExperimentalExtensionApis);
+}
+
+} // namespace extensions