Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / chrome / browser / apps / app_browsertest_util.cc
index 69479e1..f8d804e 100644 (file)
@@ -4,31 +4,38 @@
 
 #include "chrome/browser/apps/app_browsertest_util.h"
 
-#include "apps/app_window_contents.h"
-#include "apps/app_window_registry.h"
-#include "apps/ui/native_app_window.h"
 #include "base/command_line.h"
 #include "base/strings/stringprintf.h"
+#include "chrome/browser/apps/scoped_keep_alive.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/apps/chrome_app_delegate.h"
 #include "chrome/browser/ui/browser.h"
 #include "chrome/browser/ui/extensions/application_launch.h"
 #include "content/public/browser/notification_service.h"
 #include "content/public/test/browser_test_utils.h"
 #include "content/public/test/test_utils.h"
+#include "extensions/browser/app_window/app_window_contents.h"
+#include "extensions/browser/app_window/app_window_registry.h"
+#include "extensions/browser/app_window/native_app_window.h"
+#include "extensions/browser/process_manager.h"
 #include "extensions/common/switches.h"
+#include "extensions/test/extension_test_message_listener.h"
 
-using apps::AppWindow;
-using apps::AppWindowRegistry;
 using content::WebContents;
 
+namespace {
+
+const char kAppWindowTestApp[] = "app_window/generic";
+
+}  // namespace
+
 namespace utils = extension_function_test_utils;
 
 namespace extensions {
 
 PlatformAppBrowserTest::PlatformAppBrowserTest() {
-  ChromeShellWindowDelegate::DisableExternalOpenForTesting();
+  ChromeAppDelegate::DisableExternalOpenForTesting();
 }
 
 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
@@ -36,8 +43,8 @@ void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) {
   ExtensionBrowserTest::SetUpCommandLine(command_line);
 
   // Make event pages get suspended quicker.
-  command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1000");
-  command_line->AppendSwitchASCII(switches::kEventPageSuspendingTime, "1000");
+  ProcessManager::SetEventPageIdleTimeForTesting(1000);
+  ProcessManager::SetEventPageSuspendingTimeForTesting(1000);
 }
 
 // static
@@ -55,18 +62,27 @@ AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForBrowser(
 }
 
 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp(
-    const char* name) {
-  content::WindowedNotificationObserver app_loaded_observer(
-      content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME,
-      content::NotificationService::AllSources());
-
+    const char* name,
+    ExtensionTestMessageListener* listener) {
+  DCHECK(listener);
   const Extension* extension = LoadExtension(
       test_data_dir_.AppendASCII("platform_apps").AppendASCII(name));
   EXPECT_TRUE(extension);
 
   LaunchPlatformApp(extension);
 
-  app_loaded_observer.Wait();
+  EXPECT_TRUE(listener->WaitUntilSatisfied()) << "'" << listener->message()
+                                              << "' message was not receieved";
+
+  return extension;
+}
+
+const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp(
+    const char* name,
+    const std::string& message) {
+  ExtensionTestMessageListener launched_listener(message, false);
+  const Extension* extension =
+      LoadAndLaunchPlatformApp(name, &launched_listener);
 
   return extension;
 }
@@ -112,7 +128,7 @@ AppWindow* PlatformAppBrowserTest::GetFirstAppWindow() {
   return GetFirstAppWindowForBrowser(browser());
 }
 
-apps::AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForApp(
+AppWindow* PlatformAppBrowserTest::GetFirstAppWindowForApp(
     const std::string& app_id) {
   AppWindowRegistry* app_registry =
       AppWindowRegistry::Get(browser()->profile());
@@ -185,10 +201,11 @@ AppWindow* PlatformAppBrowserTest::CreateAppWindow(const Extension* extension) {
 AppWindow* PlatformAppBrowserTest::CreateAppWindowFromParams(
     const Extension* extension,
     const AppWindow::CreateParams& params) {
-  AppWindow* window = new AppWindow(
-      browser()->profile(), new ChromeShellWindowDelegate(), extension);
-  window->Init(
-      GURL(std::string()), new apps::AppWindowContentsImpl(window), params);
+  AppWindow* window =
+      new AppWindow(browser()->profile(),
+                    new ChromeAppDelegate(make_scoped_ptr(new ScopedKeepAlive)),
+                    extension);
+  window->Init(GURL(std::string()), new AppWindowContentsImpl(window), params);
   return window;
 }
 
@@ -213,6 +230,28 @@ void PlatformAppBrowserTest::CallAdjustBoundsToBeVisibleOnScreenForAppWindow(
                                           bounds);
 }
 
+AppWindow* PlatformAppBrowserTest::CreateTestAppWindow(
+    const std::string& window_create_options) {
+  ExtensionTestMessageListener launched_listener("launched", true);
+  ExtensionTestMessageListener loaded_listener("window_loaded", false);
+
+  // Load and launch the test app.
+  const Extension* extension =
+      LoadAndLaunchPlatformApp(kAppWindowTestApp, &launched_listener);
+  EXPECT_TRUE(extension);
+  EXPECT_TRUE(launched_listener.WaitUntilSatisfied());
+
+  // Send the options for window creation.
+  launched_listener.Reply(window_create_options);
+
+  // Wait for the window to be opened and loaded.
+  EXPECT_TRUE(loaded_listener.WaitUntilSatisfied());
+
+  EXPECT_EQ(1U, GetAppWindowCount());
+  AppWindow* app_window = GetFirstAppWindow();
+  return app_window;
+}
+
 void ExperimentalPlatformAppBrowserTest::SetUpCommandLine(
     CommandLine* command_line) {
   PlatformAppBrowserTest::SetUpCommandLine(command_line);