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 "base/strings/stringprintf.h" | 5 #include "base/strings/stringprintf.h" |
6 #include "base/strings/utf_string_conversions.h" | 6 #include "base/strings/utf_string_conversions.h" |
7 #include "chrome/browser/background/background_contents_service.h" | 7 #include "chrome/browser/background/background_contents_service.h" |
8 #include "chrome/browser/background/background_contents_service_factory.h" | 8 #include "chrome/browser/background/background_contents_service_factory.h" |
9 #include "chrome/browser/background/background_mode_manager.h" | 9 #include "chrome/browser/background/background_mode_manager.h" |
10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
11 #include "chrome/browser/extensions/extension_apitest.h" | 11 #include "chrome/browser/extensions/extension_apitest.h" |
12 #include "chrome/browser/extensions/extension_service.h" | 12 #include "chrome/browser/extensions/extension_service.h" |
13 #include "chrome/browser/profiles/profile.h" | 13 #include "chrome/browser/profiles/profile.h" |
14 #include "chrome/browser/ui/browser.h" | 14 #include "chrome/browser/ui/browser.h" |
15 #include "chrome/browser/ui/browser_window.h" | 15 #include "chrome/browser/ui/browser_window.h" |
16 #include "chrome/common/chrome_notification_types.h" | 16 #include "chrome/common/chrome_notification_types.h" |
17 #include "chrome/common/chrome_switches.h" | 17 #include "chrome/common/chrome_switches.h" |
18 #include "chrome/common/extensions/extension.h" | 18 #include "chrome/common/extensions/extension.h" |
19 #include "content/public/browser/notification_service.h" | 19 #include "content/public/browser/notification_service.h" |
20 #include "content/public/test/test_notification_tracker.h" | 20 #include "content/public/test/test_notification_tracker.h" |
21 #include "content/public/test/test_utils.h" | 21 #include "content/public/test/test_utils.h" |
22 #include "net/dns/mock_host_resolver.h" | 22 #include "net/dns/mock_host_resolver.h" |
| 23 #include "net/test/embedded_test_server/embedded_test_server.h" |
23 | 24 |
24 #if defined(OS_MACOSX) | 25 #if defined(OS_MACOSX) |
25 #include "base/mac/scoped_nsautorelease_pool.h" | 26 #include "base/mac/scoped_nsautorelease_pool.h" |
26 #endif | 27 #endif |
27 | 28 |
28 using extensions::Extension; | 29 using extensions::Extension; |
29 | 30 |
30 class AppBackgroundPageApiTest : public ExtensionApiTest { | 31 class AppBackgroundPageApiTest : public ExtensionApiTest { |
31 public: | 32 public: |
32 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { | 33 virtual void SetUpCommandLine(CommandLine* command_line) OVERRIDE { |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
107 | 108 |
108 // Disable on Mac only. http://crbug.com/95139 | 109 // Disable on Mac only. http://crbug.com/95139 |
109 #if defined(OS_MACOSX) | 110 #if defined(OS_MACOSX) |
110 #define MAYBE_Basic DISABLED_Basic | 111 #define MAYBE_Basic DISABLED_Basic |
111 #else | 112 #else |
112 #define MAYBE_Basic Basic | 113 #define MAYBE_Basic Basic |
113 #endif | 114 #endif |
114 | 115 |
115 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) { | 116 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, MAYBE_Basic) { |
116 host_resolver()->AddRule("a.com", "127.0.0.1"); | 117 host_resolver()->AddRule("a.com", "127.0.0.1"); |
117 ASSERT_TRUE(StartTestServer()); | 118 ASSERT_TRUE(StartEmbeddedTestServer()); |
118 | 119 |
119 std::string app_manifest = base::StringPrintf( | 120 std::string app_manifest = base::StringPrintf( |
120 "{" | 121 "{" |
121 " \"name\": \"App\"," | 122 " \"name\": \"App\"," |
122 " \"version\": \"0.1\"," | 123 " \"version\": \"0.1\"," |
123 " \"manifest_version\": 2," | 124 " \"manifest_version\": 2," |
124 " \"app\": {" | 125 " \"app\": {" |
125 " \"urls\": [" | 126 " \"urls\": [" |
126 " \"http://a.com/\"" | 127 " \"http://a.com/\"" |
127 " ]," | 128 " ]," |
128 " \"launch\": {" | 129 " \"launch\": {" |
129 " \"web_url\": \"http://a.com:%d/\"" | 130 " \"web_url\": \"http://a.com:%d/\"" |
130 " }" | 131 " }" |
131 " }," | 132 " }," |
132 " \"permissions\": [\"background\"]" | 133 " \"permissions\": [\"background\"]" |
133 "}", | 134 "}", |
134 test_server()->host_port_pair().port()); | 135 embedded_test_server()->port()); |
135 | 136 |
136 base::FilePath app_dir; | 137 base::FilePath app_dir; |
137 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 138 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
138 ASSERT_TRUE(LoadExtension(app_dir)); | 139 ASSERT_TRUE(LoadExtension(app_dir)); |
139 // Background mode should not be active until a background page is created. | 140 // Background mode should not be active until a background page is created. |
140 ASSERT_TRUE(WaitForBackgroundMode(false)); | 141 ASSERT_TRUE(WaitForBackgroundMode(false)); |
141 ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_; | 142 ASSERT_TRUE(RunExtensionTest("app_background_page/basic")) << message_; |
142 // The test closes the background contents, so we should fall back to no | 143 // The test closes the background contents, so we should fall back to no |
143 // background mode at the end. | 144 // background mode at the end. |
144 ASSERT_TRUE(WaitForBackgroundMode(false)); | 145 ASSERT_TRUE(WaitForBackgroundMode(false)); |
145 } | 146 } |
146 | 147 |
147 // Crashy, http://crbug.com/69215. | 148 // Crashy, http://crbug.com/69215. |
148 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_LacksPermission) { | 149 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_LacksPermission) { |
149 host_resolver()->AddRule("a.com", "127.0.0.1"); | 150 host_resolver()->AddRule("a.com", "127.0.0.1"); |
150 ASSERT_TRUE(StartTestServer()); | 151 ASSERT_TRUE(StartEmbeddedTestServer()); |
151 | 152 |
152 std::string app_manifest = base::StringPrintf( | 153 std::string app_manifest = base::StringPrintf( |
153 "{" | 154 "{" |
154 " \"name\": \"App\"," | 155 " \"name\": \"App\"," |
155 " \"version\": \"0.1\"," | 156 " \"version\": \"0.1\"," |
156 " \"manifest_version\": 2," | 157 " \"manifest_version\": 2," |
157 " \"app\": {" | 158 " \"app\": {" |
158 " \"urls\": [" | 159 " \"urls\": [" |
159 " \"http://a.com/\"" | 160 " \"http://a.com/\"" |
160 " ]," | 161 " ]," |
161 " \"launch\": {" | 162 " \"launch\": {" |
162 " \"web_url\": \"http://a.com:%d/\"" | 163 " \"web_url\": \"http://a.com:%d/\"" |
163 " }" | 164 " }" |
164 " }" | 165 " }" |
165 "}", | 166 "}", |
166 test_server()->host_port_pair().port()); | 167 embedded_test_server()->port()); |
167 | 168 |
168 base::FilePath app_dir; | 169 base::FilePath app_dir; |
169 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 170 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
170 ASSERT_TRUE(LoadExtension(app_dir)); | 171 ASSERT_TRUE(LoadExtension(app_dir)); |
171 ASSERT_TRUE(RunExtensionTest("app_background_page/lacks_permission")) | 172 ASSERT_TRUE(RunExtensionTest("app_background_page/lacks_permission")) |
172 << message_; | 173 << message_; |
173 ASSERT_TRUE(WaitForBackgroundMode(false)); | 174 ASSERT_TRUE(WaitForBackgroundMode(false)); |
174 } | 175 } |
175 | 176 |
176 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { | 177 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, ManifestBackgroundPage) { |
177 host_resolver()->AddRule("a.com", "127.0.0.1"); | 178 host_resolver()->AddRule("a.com", "127.0.0.1"); |
178 ASSERT_TRUE(StartTestServer()); | 179 ASSERT_TRUE(StartEmbeddedTestServer()); |
179 | 180 |
180 std::string app_manifest = base::StringPrintf( | 181 std::string app_manifest = base::StringPrintf( |
181 "{" | 182 "{" |
182 " \"name\": \"App\"," | 183 " \"name\": \"App\"," |
183 " \"version\": \"0.1\"," | 184 " \"version\": \"0.1\"," |
184 " \"manifest_version\": 2," | 185 " \"manifest_version\": 2," |
185 " \"app\": {" | 186 " \"app\": {" |
186 " \"urls\": [" | 187 " \"urls\": [" |
187 " \"http://a.com/\"" | 188 " \"http://a.com/\"" |
188 " ]," | 189 " ]," |
189 " \"launch\": {" | 190 " \"launch\": {" |
190 " \"web_url\": \"http://a.com:%d/\"" | 191 " \"web_url\": \"http://a.com:%d/\"" |
191 " }" | 192 " }" |
192 " }," | 193 " }," |
193 " \"permissions\": [\"background\"]," | 194 " \"permissions\": [\"background\"]," |
194 " \"background\": {" | 195 " \"background\": {" |
195 " \"page\": \"http://a.com:%d/test.html\"" | 196 " \"page\": \"http://a.com:%d/test.html\"" |
196 " }" | 197 " }" |
197 "}", | 198 "}", |
198 test_server()->host_port_pair().port(), | 199 embedded_test_server()->port(), |
199 test_server()->host_port_pair().port()); | 200 embedded_test_server()->port()); |
200 | 201 |
201 base::FilePath app_dir; | 202 base::FilePath app_dir; |
202 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 203 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
203 // Background mode should not be active now because no background app was | 204 // Background mode should not be active now because no background app was |
204 // loaded. | 205 // loaded. |
205 ASSERT_TRUE(LoadExtension(app_dir)); | 206 ASSERT_TRUE(LoadExtension(app_dir)); |
206 // Background mode be active now because a background page was created when | 207 // Background mode be active now because a background page was created when |
207 // the app was loaded. | 208 // the app was loaded. |
208 ASSERT_TRUE(WaitForBackgroundMode(true)); | 209 ASSERT_TRUE(WaitForBackgroundMode(true)); |
209 | 210 |
210 const Extension* extension = GetSingleLoadedExtension(); | 211 const Extension* extension = GetSingleLoadedExtension(); |
211 ASSERT_TRUE( | 212 ASSERT_TRUE( |
212 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 213 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
213 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 214 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
214 UnloadExtension(extension->id()); | 215 UnloadExtension(extension->id()); |
215 } | 216 } |
216 | 217 |
217 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { | 218 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsBackgroundPage) { |
218 // Make sure that no BackgroundContentses get deleted (a signal that repeated | 219 // Make sure that no BackgroundContentses get deleted (a signal that repeated |
219 // window.open calls recreate instances, instead of being no-ops). | 220 // window.open calls recreate instances, instead of being no-ops). |
220 content::TestNotificationTracker background_deleted_tracker; | 221 content::TestNotificationTracker background_deleted_tracker; |
221 background_deleted_tracker.ListenFor( | 222 background_deleted_tracker.ListenFor( |
222 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, | 223 chrome::NOTIFICATION_BACKGROUND_CONTENTS_DELETED, |
223 content::Source<Profile>(browser()->profile())); | 224 content::Source<Profile>(browser()->profile())); |
224 | 225 |
225 host_resolver()->AddRule("a.com", "127.0.0.1"); | 226 host_resolver()->AddRule("a.com", "127.0.0.1"); |
226 ASSERT_TRUE(StartTestServer()); | 227 ASSERT_TRUE(StartEmbeddedTestServer()); |
227 | 228 |
228 std::string app_manifest = base::StringPrintf( | 229 std::string app_manifest = base::StringPrintf( |
229 "{" | 230 "{" |
230 " \"name\": \"App\"," | 231 " \"name\": \"App\"," |
231 " \"version\": \"0.1\"," | 232 " \"version\": \"0.1\"," |
232 " \"manifest_version\": 2," | 233 " \"manifest_version\": 2," |
233 " \"app\": {" | 234 " \"app\": {" |
234 " \"urls\": [" | 235 " \"urls\": [" |
235 " \"http://a.com/\"" | 236 " \"http://a.com/\"" |
236 " ]," | 237 " ]," |
237 " \"launch\": {" | 238 " \"launch\": {" |
238 " \"web_url\": \"http://a.com:%d/test.html\"" | 239 " \"web_url\": \"http://a.com:%d/test.html\"" |
239 " }" | 240 " }" |
240 " }," | 241 " }," |
241 " \"permissions\": [\"background\"]," | 242 " \"permissions\": [\"background\"]," |
242 " \"background\": {" | 243 " \"background\": {" |
243 " \"allow_js_access\": false" | 244 " \"allow_js_access\": false" |
244 " }" | 245 " }" |
245 "}", | 246 "}", |
246 test_server()->host_port_pair().port()); | 247 embedded_test_server()->port()); |
247 | 248 |
248 base::FilePath app_dir; | 249 base::FilePath app_dir; |
249 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 250 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
250 ASSERT_TRUE(LoadExtension(app_dir)); | 251 ASSERT_TRUE(LoadExtension(app_dir)); |
251 | 252 |
252 // There isn't a background page loaded initially. | 253 // There isn't a background page loaded initially. |
253 const Extension* extension = GetSingleLoadedExtension(); | 254 const Extension* extension = GetSingleLoadedExtension(); |
254 ASSERT_FALSE( | 255 ASSERT_FALSE( |
255 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 256 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
256 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 257 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
257 // The test makes sure that window.open returns null. | 258 // The test makes sure that window.open returns null. |
258 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; | 259 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js")) << message_; |
259 // And after it runs there should be a background page. | 260 // And after it runs there should be a background page. |
260 ASSERT_TRUE( | 261 ASSERT_TRUE( |
261 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 262 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
262 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 263 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
263 | 264 |
264 EXPECT_EQ(0u, background_deleted_tracker.size()); | 265 EXPECT_EQ(0u, background_deleted_tracker.size()); |
265 UnloadExtension(extension->id()); | 266 UnloadExtension(extension->id()); |
266 } | 267 } |
267 | 268 |
268 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { | 269 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, NoJsManifestBackgroundPage) { |
269 host_resolver()->AddRule("a.com", "127.0.0.1"); | 270 host_resolver()->AddRule("a.com", "127.0.0.1"); |
270 ASSERT_TRUE(StartTestServer()); | 271 ASSERT_TRUE(StartEmbeddedTestServer()); |
271 | 272 |
272 std::string app_manifest = base::StringPrintf( | 273 std::string app_manifest = base::StringPrintf( |
273 "{" | 274 "{" |
274 " \"name\": \"App\"," | 275 " \"name\": \"App\"," |
275 " \"version\": \"0.1\"," | 276 " \"version\": \"0.1\"," |
276 " \"manifest_version\": 2," | 277 " \"manifest_version\": 2," |
277 " \"app\": {" | 278 " \"app\": {" |
278 " \"urls\": [" | 279 " \"urls\": [" |
279 " \"http://a.com/\"" | 280 " \"http://a.com/\"" |
280 " ]," | 281 " ]," |
281 " \"launch\": {" | 282 " \"launch\": {" |
282 " \"web_url\": \"http://a.com:%d/\"" | 283 " \"web_url\": \"http://a.com:%d/\"" |
283 " }" | 284 " }" |
284 " }," | 285 " }," |
285 " \"permissions\": [\"background\"]," | 286 " \"permissions\": [\"background\"]," |
286 " \"background\": {" | 287 " \"background\": {" |
287 " \"page\": \"http://a.com:%d/bg.html\"," | 288 " \"page\": \"http://a.com:%d/bg.html\"," |
288 " \"allow_js_access\": false" | 289 " \"allow_js_access\": false" |
289 " }" | 290 " }" |
290 "}", | 291 "}", |
291 test_server()->host_port_pair().port(), | 292 embedded_test_server()->port(), |
292 test_server()->host_port_pair().port()); | 293 embedded_test_server()->port()); |
293 | 294 |
294 base::FilePath app_dir; | 295 base::FilePath app_dir; |
295 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 296 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
296 ASSERT_TRUE(LoadExtension(app_dir)); | 297 ASSERT_TRUE(LoadExtension(app_dir)); |
297 | 298 |
298 // The background page should load, but window.open should return null. | 299 // The background page should load, but window.open should return null. |
299 const Extension* extension = GetSingleLoadedExtension(); | 300 const Extension* extension = GetSingleLoadedExtension(); |
300 ASSERT_TRUE( | 301 ASSERT_TRUE( |
301 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 302 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
302 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 303 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
303 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) << | 304 ASSERT_TRUE(RunExtensionTest("app_background_page/no_js_manifest")) << |
304 message_; | 305 message_; |
305 UnloadExtension(extension->id()); | 306 UnloadExtension(extension->id()); |
306 } | 307 } |
307 | 308 |
308 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { | 309 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoBackgroundPages) { |
309 host_resolver()->AddRule("a.com", "127.0.0.1"); | 310 host_resolver()->AddRule("a.com", "127.0.0.1"); |
310 ASSERT_TRUE(StartTestServer()); | 311 ASSERT_TRUE(StartEmbeddedTestServer()); |
311 | 312 |
312 std::string app_manifest = base::StringPrintf( | 313 std::string app_manifest = base::StringPrintf( |
313 "{" | 314 "{" |
314 " \"name\": \"App\"," | 315 " \"name\": \"App\"," |
315 " \"version\": \"0.1\"," | 316 " \"version\": \"0.1\"," |
316 " \"manifest_version\": 2," | 317 " \"manifest_version\": 2," |
317 " \"app\": {" | 318 " \"app\": {" |
318 " \"urls\": [" | 319 " \"urls\": [" |
319 " \"http://a.com/\"" | 320 " \"http://a.com/\"" |
320 " ]," | 321 " ]," |
321 " \"launch\": {" | 322 " \"launch\": {" |
322 " \"web_url\": \"http://a.com:%d/\"" | 323 " \"web_url\": \"http://a.com:%d/\"" |
323 " }" | 324 " }" |
324 " }," | 325 " }," |
325 " \"permissions\": [\"background\"]" | 326 " \"permissions\": [\"background\"]" |
326 "}", | 327 "}", |
327 test_server()->host_port_pair().port()); | 328 embedded_test_server()->port()); |
328 | 329 |
329 base::FilePath app_dir; | 330 base::FilePath app_dir; |
330 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 331 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
331 ASSERT_TRUE(LoadExtension(app_dir)); | 332 ASSERT_TRUE(LoadExtension(app_dir)); |
332 const Extension* extension = GetSingleLoadedExtension(); | 333 const Extension* extension = GetSingleLoadedExtension(); |
333 ASSERT_TRUE(RunExtensionTest("app_background_page/two_pages")) << message_; | 334 ASSERT_TRUE(RunExtensionTest("app_background_page/two_pages")) << message_; |
334 UnloadExtension(extension->id()); | 335 UnloadExtension(extension->id()); |
335 } | 336 } |
336 | 337 |
337 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) { | 338 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, OpenTwoPagesWithManifest) { |
338 host_resolver()->AddRule("a.com", "127.0.0.1"); | 339 host_resolver()->AddRule("a.com", "127.0.0.1"); |
339 ASSERT_TRUE(StartTestServer()); | 340 ASSERT_TRUE(StartEmbeddedTestServer()); |
340 | 341 |
341 std::string app_manifest = base::StringPrintf( | 342 std::string app_manifest = base::StringPrintf( |
342 "{" | 343 "{" |
343 " \"name\": \"App\"," | 344 " \"name\": \"App\"," |
344 " \"version\": \"0.1\"," | 345 " \"version\": \"0.1\"," |
345 " \"manifest_version\": 2," | 346 " \"manifest_version\": 2," |
346 " \"app\": {" | 347 " \"app\": {" |
347 " \"urls\": [" | 348 " \"urls\": [" |
348 " \"http://a.com/\"" | 349 " \"http://a.com/\"" |
349 " ]," | 350 " ]," |
350 " \"launch\": {" | 351 " \"launch\": {" |
351 " \"web_url\": \"http://a.com:%d/\"" | 352 " \"web_url\": \"http://a.com:%d/\"" |
352 " }" | 353 " }" |
353 " }," | 354 " }," |
354 " \"background\": {" | 355 " \"background\": {" |
355 " \"page\": \"http://a.com:%d/bg.html\"" | 356 " \"page\": \"http://a.com:%d/bg.html\"" |
356 " }," | 357 " }," |
357 " \"permissions\": [\"background\"]" | 358 " \"permissions\": [\"background\"]" |
358 "}", | 359 "}", |
359 test_server()->host_port_pair().port(), | 360 embedded_test_server()->port(), |
360 test_server()->host_port_pair().port()); | 361 embedded_test_server()->port()); |
361 | 362 |
362 base::FilePath app_dir; | 363 base::FilePath app_dir; |
363 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 364 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
364 ASSERT_TRUE(LoadExtension(app_dir)); | 365 ASSERT_TRUE(LoadExtension(app_dir)); |
365 const Extension* extension = GetSingleLoadedExtension(); | 366 const Extension* extension = GetSingleLoadedExtension(); |
366 ASSERT_TRUE(RunExtensionTest("app_background_page/two_with_manifest")) << | 367 ASSERT_TRUE(RunExtensionTest("app_background_page/two_with_manifest")) << |
367 message_; | 368 message_; |
368 UnloadExtension(extension->id()); | 369 UnloadExtension(extension->id()); |
369 } | 370 } |
370 | 371 |
371 // Times out occasionally -- see crbug.com/108493 | 372 // Times out occasionally -- see crbug.com/108493 |
372 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) { | 373 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenPopupFromBGPage) { |
373 host_resolver()->AddRule("a.com", "127.0.0.1"); | 374 host_resolver()->AddRule("a.com", "127.0.0.1"); |
374 ASSERT_TRUE(StartTestServer()); | 375 ASSERT_TRUE(StartEmbeddedTestServer()); |
375 | 376 |
376 std::string app_manifest = base::StringPrintf( | 377 std::string app_manifest = base::StringPrintf( |
377 "{" | 378 "{" |
378 " \"name\": \"App\"," | 379 " \"name\": \"App\"," |
379 " \"version\": \"0.1\"," | 380 " \"version\": \"0.1\"," |
380 " \"manifest_version\": 2," | 381 " \"manifest_version\": 2," |
381 " \"app\": {" | 382 " \"app\": {" |
382 " \"urls\": [" | 383 " \"urls\": [" |
383 " \"http://a.com/\"" | 384 " \"http://a.com/\"" |
384 " ]," | 385 " ]," |
385 " \"launch\": {" | 386 " \"launch\": {" |
386 " \"web_url\": \"http://a.com:%d/\"" | 387 " \"web_url\": \"http://a.com:%d/\"" |
387 " }" | 388 " }" |
388 " }," | 389 " }," |
389 " \"background\": { \"page\": \"http://a.com:%d/files/extensions/api_test
/" | 390 " \"background\": { \"page\": \"http://a.com:%d/extensions/api_test/" |
390 "app_background_page/bg_open/bg_open_bg.html\" }," | 391 "app_background_page/bg_open/bg_open_bg.html\" }," |
391 " \"permissions\": [\"background\"]" | 392 " \"permissions\": [\"background\"]" |
392 "}", | 393 "}", |
393 test_server()->host_port_pair().port(), | 394 embedded_test_server()->port(), |
394 test_server()->host_port_pair().port()); | 395 embedded_test_server()->port()); |
395 | 396 |
396 base::FilePath app_dir; | 397 base::FilePath app_dir; |
397 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 398 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
398 ASSERT_TRUE(LoadExtension(app_dir)); | 399 ASSERT_TRUE(LoadExtension(app_dir)); |
399 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; | 400 ASSERT_TRUE(RunExtensionTest("app_background_page/bg_open")) << message_; |
400 } | 401 } |
401 | 402 |
402 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) { | 403 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, DISABLED_OpenThenClose) { |
403 host_resolver()->AddRule("a.com", "127.0.0.1"); | 404 host_resolver()->AddRule("a.com", "127.0.0.1"); |
404 ASSERT_TRUE(StartTestServer()); | 405 ASSERT_TRUE(StartEmbeddedTestServer()); |
405 | 406 |
406 std::string app_manifest = base::StringPrintf( | 407 std::string app_manifest = base::StringPrintf( |
407 "{" | 408 "{" |
408 " \"name\": \"App\"," | 409 " \"name\": \"App\"," |
409 " \"version\": \"0.1\"," | 410 " \"version\": \"0.1\"," |
410 " \"manifest_version\": 2," | 411 " \"manifest_version\": 2," |
411 " \"app\": {" | 412 " \"app\": {" |
412 " \"urls\": [" | 413 " \"urls\": [" |
413 " \"http://a.com/\"" | 414 " \"http://a.com/\"" |
414 " ]," | 415 " ]," |
415 " \"launch\": {" | 416 " \"launch\": {" |
416 " \"web_url\": \"http://a.com:%d/\"" | 417 " \"web_url\": \"http://a.com:%d/\"" |
417 " }" | 418 " }" |
418 " }," | 419 " }," |
419 " \"permissions\": [\"background\"]" | 420 " \"permissions\": [\"background\"]" |
420 "}", | 421 "}", |
421 test_server()->host_port_pair().port()); | 422 embedded_test_server()->port()); |
422 | 423 |
423 base::FilePath app_dir; | 424 base::FilePath app_dir; |
424 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 425 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
425 ASSERT_TRUE(LoadExtension(app_dir)); | 426 ASSERT_TRUE(LoadExtension(app_dir)); |
426 // There isn't a background page loaded initially. | 427 // There isn't a background page loaded initially. |
427 const Extension* extension = GetSingleLoadedExtension(); | 428 const Extension* extension = GetSingleLoadedExtension(); |
428 ASSERT_FALSE( | 429 ASSERT_FALSE( |
429 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 430 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
430 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 431 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
431 // Background mode should not be active until a background page is created. | 432 // Background mode should not be active until a background page is created. |
432 ASSERT_TRUE(WaitForBackgroundMode(false)); | 433 ASSERT_TRUE(WaitForBackgroundMode(false)); |
433 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_open")) << message_; | 434 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_open")) << message_; |
434 // Background mode should be active now because a background page was created. | 435 // Background mode should be active now because a background page was created. |
435 ASSERT_TRUE(WaitForBackgroundMode(true)); | 436 ASSERT_TRUE(WaitForBackgroundMode(true)); |
436 ASSERT_TRUE( | 437 ASSERT_TRUE( |
437 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 438 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
438 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 439 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
439 // Now close the BackgroundContents. | 440 // Now close the BackgroundContents. |
440 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_; | 441 ASSERT_TRUE(RunExtensionTest("app_background_page/basic_close")) << message_; |
441 // Background mode should no longer be active. | 442 // Background mode should no longer be active. |
442 ASSERT_TRUE(WaitForBackgroundMode(false)); | 443 ASSERT_TRUE(WaitForBackgroundMode(false)); |
443 ASSERT_FALSE( | 444 ASSERT_FALSE( |
444 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 445 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
445 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 446 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
446 } | 447 } |
447 | 448 |
448 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, UnloadExtensionWhileHidden) { | 449 IN_PROC_BROWSER_TEST_F(AppBackgroundPageApiTest, UnloadExtensionWhileHidden) { |
449 host_resolver()->AddRule("a.com", "127.0.0.1"); | 450 host_resolver()->AddRule("a.com", "127.0.0.1"); |
450 ASSERT_TRUE(StartTestServer()); | 451 ASSERT_TRUE(StartEmbeddedTestServer()); |
451 | 452 |
452 std::string app_manifest = base::StringPrintf( | 453 std::string app_manifest = base::StringPrintf( |
453 "{" | 454 "{" |
454 " \"name\": \"App\"," | 455 " \"name\": \"App\"," |
455 " \"version\": \"0.1\"," | 456 " \"version\": \"0.1\"," |
456 " \"manifest_version\": 2," | 457 " \"manifest_version\": 2," |
457 " \"app\": {" | 458 " \"app\": {" |
458 " \"urls\": [" | 459 " \"urls\": [" |
459 " \"http://a.com/\"" | 460 " \"http://a.com/\"" |
460 " ]," | 461 " ]," |
461 " \"launch\": {" | 462 " \"launch\": {" |
462 " \"web_url\": \"http://a.com:%d/\"" | 463 " \"web_url\": \"http://a.com:%d/\"" |
463 " }" | 464 " }" |
464 " }," | 465 " }," |
465 " \"permissions\": [\"background\"]," | 466 " \"permissions\": [\"background\"]," |
466 " \"background\": {" | 467 " \"background\": {" |
467 " \"page\": \"http://a.com:%d/test.html\"" | 468 " \"page\": \"http://a.com:%d/test.html\"" |
468 " }" | 469 " }" |
469 "}", | 470 "}", |
470 test_server()->host_port_pair().port(), | 471 embedded_test_server()->port(), |
471 test_server()->host_port_pair().port()); | 472 embedded_test_server()->port()); |
472 | 473 |
473 base::FilePath app_dir; | 474 base::FilePath app_dir; |
474 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); | 475 ASSERT_TRUE(CreateApp(app_manifest, &app_dir)); |
475 // Background mode should not be active now because no background app was | 476 // Background mode should not be active now because no background app was |
476 // loaded. | 477 // loaded. |
477 ASSERT_TRUE(LoadExtension(app_dir)); | 478 ASSERT_TRUE(LoadExtension(app_dir)); |
478 // Background mode be active now because a background page was created when | 479 // Background mode be active now because a background page was created when |
479 // the app was loaded. | 480 // the app was loaded. |
480 ASSERT_TRUE(WaitForBackgroundMode(true)); | 481 ASSERT_TRUE(WaitForBackgroundMode(true)); |
481 | 482 |
482 const Extension* extension = GetSingleLoadedExtension(); | 483 const Extension* extension = GetSingleLoadedExtension(); |
483 ASSERT_TRUE( | 484 ASSERT_TRUE( |
484 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> | 485 BackgroundContentsServiceFactory::GetForProfile(browser()->profile())-> |
485 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); | 486 GetAppBackgroundContents(ASCIIToUTF16(extension->id()))); |
486 | 487 |
487 // Close all browsers - app should continue running. | 488 // Close all browsers - app should continue running. |
488 set_exit_when_last_browser_closes(false); | 489 set_exit_when_last_browser_closes(false); |
489 CloseBrowser(browser()); | 490 CloseBrowser(browser()); |
490 | 491 |
491 // Post a task to unload the extension - this should cause Chrome to exit | 492 // Post a task to unload the extension - this should cause Chrome to exit |
492 // cleanly (not crash). | 493 // cleanly (not crash). |
493 UnloadExtensionViaTask(extension->id()); | 494 UnloadExtensionViaTask(extension->id()); |
494 content::RunAllPendingInMessageLoop(); | 495 content::RunAllPendingInMessageLoop(); |
495 ASSERT_TRUE(WaitForBackgroundMode(false)); | 496 ASSERT_TRUE(WaitForBackgroundMode(false)); |
496 } | 497 } |
OLD | NEW |