| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/extensions/platform_app_browsertest_util.h" | 5 #include "chrome/browser/extensions/platform_app_browsertest_util.h" |
| 6 | 6 |
| 7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
| 8 #include "base/stringprintf.h" | 8 #include "base/stringprintf.h" |
| 9 #include "chrome/browser/extensions/api/tabs/tabs.h" | 9 #include "chrome/browser/extensions/api/tabs/tabs.h" |
| 10 #include "chrome/browser/extensions/extension_function_test_utils.h" | 10 #include "chrome/browser/extensions/extension_function_test_utils.h" |
| 11 #include "chrome/browser/extensions/extension_test_message_listener.h" |
| 11 #include "chrome/browser/extensions/shell_window_registry.h" | 12 #include "chrome/browser/extensions/shell_window_registry.h" |
| 12 #include "chrome/browser/ui/browser.h" | 13 #include "chrome/browser/ui/browser.h" |
| 13 #include "chrome/browser/ui/extensions/application_launch.h" | 14 #include "chrome/browser/ui/extensions/application_launch.h" |
| 14 #include "chrome/browser/ui/extensions/shell_window.h" | 15 #include "chrome/browser/ui/extensions/shell_window.h" |
| 16 #include "chrome/common/chrome_notification_types.h" |
| 15 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
| 16 #include "content/public/browser/notification_service.h" | 18 #include "content/public/browser/notification_service.h" |
| 17 #include "content/public/test/test_utils.h" | 19 #include "content/public/test/test_utils.h" |
| 18 | 20 |
| 19 using content::WebContents; | 21 using content::WebContents; |
| 20 | 22 |
| 21 namespace utils = extension_function_test_utils; | 23 namespace utils = extension_function_test_utils; |
| 22 | 24 |
| 23 namespace extensions { | 25 namespace extensions { |
| 24 | 26 |
| 25 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { | 27 void PlatformAppBrowserTest::SetUpCommandLine(CommandLine* command_line) { |
| 26 // Skips ExtensionApiTest::SetUpCommandLine. | 28 // Skips ExtensionApiTest::SetUpCommandLine. |
| 27 ExtensionBrowserTest::SetUpCommandLine(command_line); | 29 ExtensionBrowserTest::SetUpCommandLine(command_line); |
| 30 } |
| 28 | 31 |
| 29 // Make event pages get suspended quicker. | 32 const Extension* PlatformAppBrowserTest::LoadPlatformApp(const char* name) { |
| 30 command_line->AppendSwitchASCII(switches::kEventPageIdleTime, "1"); | 33 const Extension* extension = LoadExtension( |
| 31 command_line->AppendSwitchASCII(switches::kEventPageUnloadingTime, "1"); | 34 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name)); |
| 35 EXPECT_TRUE(extension); |
| 36 |
| 37 return extension; |
| 38 } |
| 39 |
| 40 const Extension* PlatformAppBrowserTest::InstallPlatformApp( |
| 41 const char* name) { |
| 42 const Extension* extension = InstallExtension( |
| 43 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); |
| 44 EXPECT_TRUE(extension); |
| 45 |
| 46 return extension; |
| 32 } | 47 } |
| 33 | 48 |
| 34 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( | 49 const Extension* PlatformAppBrowserTest::LoadAndLaunchPlatformApp( |
| 35 const char* name) { | 50 const char* name) { |
| 36 content::WindowedNotificationObserver app_loaded_observer( | 51 ExtensionTestMessageListener launched_listener("Launched", false); |
| 37 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 38 content::NotificationService::AllSources()); | |
| 39 | 52 |
| 40 const Extension* extension = LoadExtension( | 53 const Extension* extension = LoadPlatformApp(name); |
| 41 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name)); | |
| 42 EXPECT_TRUE(extension); | |
| 43 | |
| 44 application_launch::OpenApplication(application_launch::LaunchParams( | 54 application_launch::OpenApplication(application_launch::LaunchParams( |
| 45 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | 55 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 46 NEW_WINDOW)); | 56 NEW_WINDOW)); |
| 47 | 57 |
| 48 app_loaded_observer.Wait(); | 58 launched_listener.WaitUntilSatisfied(); |
| 49 | 59 |
| 50 return extension; | 60 return extension; |
| 51 } | 61 } |
| 52 | 62 |
| 53 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( | 63 const Extension* PlatformAppBrowserTest::InstallAndLaunchPlatformApp( |
| 54 const char* name) { | 64 const char* name) { |
| 55 content::WindowedNotificationObserver app_loaded_observer( | 65 ExtensionTestMessageListener launched_listener("Launched", false); |
| 56 content::NOTIFICATION_LOAD_COMPLETED_MAIN_FRAME, | |
| 57 content::NotificationService::AllSources()); | |
| 58 | 66 |
| 59 const Extension* extension = InstallExtension( | 67 const Extension* extension = InstallPlatformApp(name); |
| 60 test_data_dir_.AppendASCII("platform_apps").AppendASCII(name), 1); | |
| 61 EXPECT_TRUE(extension); | |
| 62 | |
| 63 application_launch::OpenApplication(application_launch::LaunchParams( | 68 application_launch::OpenApplication(application_launch::LaunchParams( |
| 64 browser()->profile(), extension, extension_misc::LAUNCH_NONE, | 69 browser()->profile(), extension, extension_misc::LAUNCH_NONE, |
| 65 NEW_WINDOW)); | 70 NEW_WINDOW)); |
| 66 | 71 |
| 67 app_loaded_observer.Wait(); | 72 launched_listener.WaitUntilSatisfied(); |
| 68 | 73 |
| 69 return extension; | 74 return extension; |
| 70 } | 75 } |
| 71 | 76 |
| 72 WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() { | 77 WebContents* PlatformAppBrowserTest::GetFirstShellWindowWebContents() { |
| 73 ShellWindow* window = GetFirstShellWindow(); | 78 ShellWindow* window = GetFirstShellWindow(); |
| 74 if (window) | 79 if (window) |
| 75 return window->web_contents(); | 80 return window->web_contents(); |
| 76 | 81 |
| 77 return NULL; | 82 return NULL; |
| 78 } | 83 } |
| 79 | 84 |
| 80 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() { | 85 ShellWindow* PlatformAppBrowserTest::GetFirstShellWindow() { |
| 81 ShellWindowRegistry* app_registry = | 86 ShellWindowRegistry* app_registry = |
| 82 ShellWindowRegistry::Get(browser()->profile()); | 87 ShellWindowRegistry::Get(browser()->profile()); |
| 83 ShellWindowRegistry::const_iterator iter; | 88 ShellWindowRegistry::const_iterator iter; |
| 84 ShellWindowRegistry::ShellWindowSet shell_windows = | 89 ShellWindowRegistry::ShellWindowSet shell_windows = |
| 85 app_registry->shell_windows(); | 90 app_registry->shell_windows(); |
| 86 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) { | 91 for (iter = shell_windows.begin(); iter != shell_windows.end(); ++iter) |
| 87 return *iter; | 92 return *iter; |
| 88 } | |
| 89 | 93 |
| 90 return NULL; | 94 return NULL; |
| 91 } | 95 } |
| 92 | 96 |
| 93 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension( | 97 size_t PlatformAppBrowserTest::RunGetWindowsFunctionForExtension( |
| 94 const Extension* extension) { | 98 const Extension* extension) { |
| 95 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); | 99 scoped_refptr<GetAllWindowsFunction> function = new GetAllWindowsFunction(); |
| 96 function->set_extension(extension); | 100 function->set_extension(extension); |
| 97 scoped_ptr<base::ListValue> result(utils::ToList( | 101 scoped_ptr<base::ListValue> result(utils::ToList( |
| 98 utils::RunFunctionAndReturnSingleResult(function.get(), | 102 utils::RunFunctionAndReturnSingleResult(function.get(), |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 136 command_line->AppendArgPath(test_doc); | 140 command_line->AppendArgPath(test_doc); |
| 137 } | 141 } |
| 138 | 142 |
| 139 ShellWindow* PlatformAppBrowserTest::CreateShellWindow( | 143 ShellWindow* PlatformAppBrowserTest::CreateShellWindow( |
| 140 const Extension* extension) { | 144 const Extension* extension) { |
| 141 ShellWindow::CreateParams params; | 145 ShellWindow::CreateParams params; |
| 142 return ShellWindow::Create( | 146 return ShellWindow::Create( |
| 143 browser()->profile(), extension, GURL(""), params); | 147 browser()->profile(), extension, GURL(""), params); |
| 144 } | 148 } |
| 145 | 149 |
| 146 void PlatformAppBrowserTest::CloseShellWindow(ShellWindow* window) { | |
| 147 content::WindowedNotificationObserver destroyed_observer( | |
| 148 content::NOTIFICATION_WEB_CONTENTS_DESTROYED, | |
| 149 content::NotificationService::AllSources()); | |
| 150 window->GetBaseWindow()->Close(); | |
| 151 destroyed_observer.Wait(); | |
| 152 } | |
| 153 | |
| 154 } // namespace extensions | 150 } // namespace extensions |
| OLD | NEW |