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