OLD | NEW |
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2011 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/utf_string_conversions.h" | 5 #include "base/utf_string_conversions.h" |
6 #include "chrome/browser/extensions/extension_apitest.h" | 6 #include "chrome/browser/extensions/extension_apitest.h" |
7 #include "chrome/browser/extensions/extension_host.h" | 7 #include "chrome/browser/extensions/extension_host.h" |
8 #include "chrome/browser/extensions/extension_process_manager.h" | 8 #include "chrome/browser/extensions/extension_process_manager.h" |
9 #include "chrome/browser/profiles/profile.h" | 9 #include "chrome/browser/profiles/profile.h" |
10 #include "chrome/browser/ui/browser.h" | 10 #include "chrome/browser/ui/browser.h" |
11 #include "chrome/browser/ui/browser_list.h" | 11 #include "chrome/browser/ui/browser_list.h" |
| 12 #include "chrome/browser/ui/browser_window.h" |
12 #include "chrome/common/chrome_switches.h" | 13 #include "chrome/common/chrome_switches.h" |
13 #include "chrome/common/extensions/extension.h" | 14 #include "chrome/common/extensions/extension.h" |
14 #include "chrome/test/base/ui_test_utils.h" | 15 #include "chrome/test/base/ui_test_utils.h" |
15 #include "content/browser/renderer_host/render_view_host.h" | 16 #include "content/browser/renderer_host/render_view_host.h" |
16 #include "content/browser/tab_contents/tab_contents.h" | 17 #include "content/browser/tab_contents/tab_contents.h" |
17 #include "net/base/mock_host_resolver.h" | 18 #include "net/base/mock_host_resolver.h" |
18 | 19 |
19 class AppApiTest : public ExtensionApiTest { | 20 class AppApiTest : public ExtensionApiTest { |
20 protected: | 21 protected: |
21 // Gets the base URL for files for a specific test, making sure that it uses | 22 // Gets the base URL for files for a specific test, making sure that it uses |
(...skipping 311 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
333 EXPECT_TRUE(newtab); | 334 EXPECT_TRUE(newtab); |
334 if (!newtab->controller().GetLastCommittedEntry() || | 335 if (!newtab->controller().GetLastCommittedEntry() || |
335 newtab->controller().GetLastCommittedEntry()->url() != app_url) | 336 newtab->controller().GetLastCommittedEntry()->url() != app_url) |
336 ui_test_utils::WaitForNavigation(&newtab->controller()); | 337 ui_test_utils::WaitForNavigation(&newtab->controller()); |
337 | 338 |
338 // Popup window should be in the app's process. | 339 // Popup window should be in the app's process. |
339 EXPECT_TRUE(last_active_browser->GetTabContentsAt(0)->render_view_host()-> | 340 EXPECT_TRUE(last_active_browser->GetTabContentsAt(0)->render_view_host()-> |
340 process()->is_extension_process()); | 341 process()->is_extension_process()); |
341 } | 342 } |
342 | 343 |
| 344 // Tests that if we have an app process (path1/container.html) with a non-app |
| 345 // iframe (path3/iframe.html), then opening a link from that iframe to a new |
| 346 // window to a same-origin non-app URL (path3/empty.html) should keep the window |
| 347 // in the app process. |
| 348 // This is in contrast to OpenAppFromIframe, since here the popup will not be |
| 349 // missing special permissions and should be scriptable from the iframe. |
| 350 // See http://crbug.com/92669 for more details. |
| 351 IN_PROC_BROWSER_TEST_F(AppApiTest, OpenWebPopupFromWebIframe) { |
| 352 CommandLine::ForCurrentProcess()->AppendSwitch( |
| 353 switches::kDisablePopupBlocking); |
| 354 |
| 355 host_resolver()->AddRule("*", "127.0.0.1"); |
| 356 ASSERT_TRUE(test_server()->Start()); |
| 357 |
| 358 GURL base_url = GetTestBaseURL("app_process"); |
| 359 |
| 360 // Load app and start URL (in the app). |
| 361 const Extension* app = |
| 362 LoadExtension(test_data_dir_.AppendASCII("app_process")); |
| 363 ASSERT_TRUE(app); |
| 364 ui_test_utils::NavigateToURLWithDisposition( |
| 365 browser(), |
| 366 base_url.Resolve("path1/container.html"), |
| 367 CURRENT_TAB, |
| 368 ui_test_utils::BROWSER_TEST_WAIT_FOR_NAVIGATION | |
| 369 ui_test_utils::BROWSER_TEST_WAIT_FOR_BROWSER); |
| 370 RenderProcessHost* process = |
| 371 browser()->GetTabContentsAt(0)->render_view_host()->process(); |
| 372 EXPECT_TRUE(process->is_extension_process()); |
| 373 |
| 374 // Wait for popup window to appear. The new Browser may not have been |
| 375 // added with SetLastActive, in which case we need to show it first. |
| 376 // This is necessary for popup windows without a cross-site transition. |
| 377 if (browser() == BrowserList::GetLastActive()) { |
| 378 // Grab the second window and show it. |
| 379 ASSERT_TRUE(BrowserList::size() == 2); |
| 380 Browser* popup_browser = *(++BrowserList::begin()); |
| 381 popup_browser->window()->Show(); |
| 382 } |
| 383 Browser* last_active_browser = BrowserList::GetLastActive(); |
| 384 EXPECT_TRUE(last_active_browser); |
| 385 ASSERT_NE(browser(), last_active_browser); |
| 386 TabContents* newtab = last_active_browser->GetSelectedTabContents(); |
| 387 EXPECT_TRUE(newtab); |
| 388 GURL non_app_url = base_url.Resolve("path3/empty.html"); |
| 389 if (!newtab->controller().GetLastCommittedEntry() || |
| 390 newtab->controller().GetLastCommittedEntry()->url() != non_app_url) |
| 391 ui_test_utils::WaitForNavigation(&newtab->controller()); |
| 392 |
| 393 // Popup window should be in the app's process. |
| 394 RenderProcessHost* popup_process = |
| 395 last_active_browser->GetTabContentsAt(0)->render_view_host()->process(); |
| 396 EXPECT_EQ(process, popup_process); |
| 397 } |
| 398 |
343 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) { | 399 IN_PROC_BROWSER_TEST_F(AppApiTest, ReloadAppAfterCrash) { |
344 host_resolver()->AddRule("*", "127.0.0.1"); | 400 host_resolver()->AddRule("*", "127.0.0.1"); |
345 ASSERT_TRUE(test_server()->Start()); | 401 ASSERT_TRUE(test_server()->Start()); |
346 | 402 |
347 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); | 403 ASSERT_TRUE(LoadExtension(test_data_dir_.AppendASCII("app_process"))); |
348 | 404 |
349 GURL base_url = GetTestBaseURL("app_process"); | 405 GURL base_url = GetTestBaseURL("app_process"); |
350 | 406 |
351 // Load the app, chrome.app.isInstalled should be true. | 407 // Load the app, chrome.app.isInstalled should be true. |
352 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); | 408 ui_test_utils::NavigateToURL(browser(), base_url.Resolve("path1/empty.html")); |
353 TabContents* contents = browser()->GetTabContentsAt(0); | 409 TabContents* contents = browser()->GetTabContentsAt(0); |
354 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); | 410 EXPECT_TRUE(contents->render_view_host()->process()->is_extension_process()); |
355 bool is_installed = false; | 411 bool is_installed = false; |
356 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 412 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
357 contents->render_view_host(), L"", | 413 contents->render_view_host(), L"", |
358 L"window.domAutomationController.send(chrome.app.isInstalled)", | 414 L"window.domAutomationController.send(chrome.app.isInstalled)", |
359 &is_installed)); | 415 &is_installed)); |
360 ASSERT_TRUE(is_installed); | 416 ASSERT_TRUE(is_installed); |
361 | 417 |
362 // Crash the tab and reload it, chrome.app.isInstalled should still be true. | 418 // Crash the tab and reload it, chrome.app.isInstalled should still be true. |
363 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); | 419 ui_test_utils::CrashTab(browser()->GetSelectedTabContents()); |
364 browser()->Reload(CURRENT_TAB); | 420 browser()->Reload(CURRENT_TAB); |
365 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); | 421 ASSERT_TRUE(ui_test_utils::WaitForNavigationInCurrentTab(browser())); |
366 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( | 422 ASSERT_TRUE(ui_test_utils::ExecuteJavaScriptAndExtractBool( |
367 contents->render_view_host(), L"", | 423 contents->render_view_host(), L"", |
368 L"window.domAutomationController.send(chrome.app.isInstalled)", | 424 L"window.domAutomationController.send(chrome.app.isInstalled)", |
369 &is_installed)); | 425 &is_installed)); |
370 ASSERT_TRUE(is_installed); | 426 ASSERT_TRUE(is_installed); |
371 } | 427 } |
OLD | NEW |