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