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/test/base/in_process_browser_test.h" | 5 #include "chrome/test/base/in_process_browser_test.h" |
6 | 6 |
7 #include "base/auto_reset.h" | 7 #include "base/auto_reset.h" |
8 #include "base/basictypes.h" | 8 #include "base/basictypes.h" |
9 #include "base/bind.h" | 9 #include "base/bind.h" |
10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
11 #include "base/files/file_path.h" | 11 #include "base/files/file_path.h" |
12 #include "base/files/file_util.h" | 12 #include "base/files/file_util.h" |
13 #include "base/lazy_instance.h" | 13 #include "base/lazy_instance.h" |
14 #include "base/location.h" | 14 #include "base/location.h" |
15 #include "base/path_service.h" | 15 #include "base/path_service.h" |
16 #include "base/single_thread_task_runner.h" | 16 #include "base/single_thread_task_runner.h" |
17 #include "base/strings/string_number_conversions.h" | 17 #include "base/strings/string_number_conversions.h" |
18 #include "base/test/test_file_util.h" | 18 #include "base/test/test_file_util.h" |
19 #include "base/thread_task_runner_handle.h" | 19 #include "base/thread_task_runner_handle.h" |
20 #include "base/threading/non_thread_safe.h" | 20 #include "base/threading/non_thread_safe.h" |
21 #include "chrome/browser/browser_process.h" | 21 #include "chrome/browser/browser_process.h" |
22 #include "chrome/browser/chrome_notification_types.h" | 22 #include "chrome/browser/chrome_notification_types.h" |
23 #include "chrome/browser/devtools/devtools_window.h" | |
23 #include "chrome/browser/lifetime/application_lifetime.h" | 24 #include "chrome/browser/lifetime/application_lifetime.h" |
24 #include "chrome/browser/net/net_error_tab_helper.h" | 25 #include "chrome/browser/net/net_error_tab_helper.h" |
25 #include "chrome/browser/profiles/profile.h" | 26 #include "chrome/browser/profiles/profile.h" |
26 #include "chrome/browser/profiles/profile_manager.h" | 27 #include "chrome/browser/profiles/profile_manager.h" |
27 #include "chrome/browser/ui/browser.h" | 28 #include "chrome/browser/ui/browser.h" |
28 #include "chrome/browser/ui/browser_finder.h" | 29 #include "chrome/browser/ui/browser_finder.h" |
29 #include "chrome/browser/ui/browser_list.h" | 30 #include "chrome/browser/ui/browser_list.h" |
30 #include "chrome/browser/ui/browser_list_observer.h" | 31 #include "chrome/browser/ui/browser_list_observer.h" |
31 #include "chrome/browser/ui/browser_navigator.h" | 32 #include "chrome/browser/ui/browser_navigator.h" |
32 #include "chrome/browser/ui/browser_tabstrip.h" | 33 #include "chrome/browser/ui/browser_tabstrip.h" |
33 #include "chrome/browser/ui/browser_window.h" | 34 #include "chrome/browser/ui/browser_window.h" |
34 #include "chrome/browser/ui/host_desktop.h" | 35 #include "chrome/browser/ui/host_desktop.h" |
35 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 36 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
36 #include "chrome/common/chrome_constants.h" | 37 #include "chrome/common/chrome_constants.h" |
37 #include "chrome/common/chrome_paths.h" | 38 #include "chrome/common/chrome_paths.h" |
38 #include "chrome/common/chrome_switches.h" | 39 #include "chrome/common/chrome_switches.h" |
39 #include "chrome/common/logging_chrome.h" | 40 #include "chrome/common/logging_chrome.h" |
40 #include "chrome/common/url_constants.h" | 41 #include "chrome/common/url_constants.h" |
41 #include "chrome/renderer/chrome_content_renderer_client.h" | 42 #include "chrome/renderer/chrome_content_renderer_client.h" |
42 #include "chrome/test/base/chrome_test_suite.h" | 43 #include "chrome/test/base/chrome_test_suite.h" |
43 #include "chrome/test/base/test_launcher_utils.h" | 44 #include "chrome/test/base/test_launcher_utils.h" |
44 #include "chrome/test/base/test_switches.h" | 45 #include "chrome/test/base/test_switches.h" |
45 #include "chrome/test/base/testing_browser_process.h" | 46 #include "chrome/test/base/testing_browser_process.h" |
47 #include "chrome/test/base/ui_test_utils.h" | |
46 #include "components/google/core/browser/google_util.h" | 48 #include "components/google/core/browser/google_util.h" |
47 #include "components/os_crypt/os_crypt.h" | 49 #include "components/os_crypt/os_crypt.h" |
50 #include "content/public/browser/devtools_agent_host.h" | |
48 #include "content/public/browser/notification_service.h" | 51 #include "content/public/browser/notification_service.h" |
49 #include "content/public/browser/notification_types.h" | 52 #include "content/public/browser/notification_types.h" |
50 #include "content/public/test/browser_test_utils.h" | 53 #include "content/public/test/browser_test_utils.h" |
51 #include "content/public/test/test_launcher.h" | 54 #include "content/public/test/test_launcher.h" |
52 #include "content/public/test/test_navigation_observer.h" | 55 #include "content/public/test/test_navigation_observer.h" |
53 #include "net/test/embedded_test_server/embedded_test_server.h" | 56 #include "net/test/embedded_test_server/embedded_test_server.h" |
54 #include "net/test/spawned_test_server/spawned_test_server.h" | 57 #include "net/test/spawned_test_server/spawned_test_server.h" |
55 | 58 |
56 #if defined(OS_MACOSX) | 59 #if defined(OS_MACOSX) |
57 #include "base/mac/scoped_nsautorelease_pool.h" | 60 #include "base/mac/scoped_nsautorelease_pool.h" |
(...skipping 344 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
402 | 405 |
403 void InProcessBrowserTest::CloseAllBrowsers() { | 406 void InProcessBrowserTest::CloseAllBrowsers() { |
404 chrome::CloseAllBrowsers(); | 407 chrome::CloseAllBrowsers(); |
405 #if defined(OS_MACOSX) | 408 #if defined(OS_MACOSX) |
406 // BrowserWindowController depends on the auto release pool being recycled | 409 // BrowserWindowController depends on the auto release pool being recycled |
407 // in the message loop to delete itself. | 410 // in the message loop to delete itself. |
408 AutoreleasePool()->Recycle(); | 411 AutoreleasePool()->Recycle(); |
409 #endif | 412 #endif |
410 } | 413 } |
411 | 414 |
415 void InProcessBrowserTest::OpenDevToolsWindow( | |
416 content::WebContents* web_contents) { | |
417 #if defined(OS_MACOSX) | |
418 // Opening a Devtools Window can cause AppKit to throw objects into the | |
419 // autorelease pool. Flush the pool when this function returns. | |
420 base::mac::ScopedNSAutoreleasePool pool; | |
421 #endif // OS_MACOSX | |
422 ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents)); | |
423 DevToolsWindow::OpenDevToolsWindow(web_contents); | |
424 ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents)); | |
425 } | |
426 | |
427 Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile, | |
428 const GURL& url) { | |
429 #if defined(OS_MACOSX) | |
430 // Opening an incognito window can cause AppKit to throw objects into the | |
431 // autorelease pool. Flush the pool when this function returns. | |
432 base::mac::ScopedNSAutoreleasePool pool; | |
433 #endif | |
434 return ui_test_utils::OpenURLOffTheRecord(profile, url); | |
Robert Sesek
2015/07/09 15:11:46
For this case, how will callers know to choose the
erikchen
2015/07/10 00:14:41
I removed the UTU version and migrated all calls t
| |
435 } | |
436 | |
412 // TODO(alexmos): This function should expose success of the underlying | 437 // TODO(alexmos): This function should expose success of the underlying |
413 // navigation to tests, which should make sure navigations succeed when | 438 // navigation to tests, which should make sure navigations succeed when |
414 // appropriate. See https://crbug.com/425335 | 439 // appropriate. See https://crbug.com/425335 |
415 void InProcessBrowserTest::AddTabAtIndexToBrowser( | 440 void InProcessBrowserTest::AddTabAtIndexToBrowser( |
416 Browser* browser, | 441 Browser* browser, |
417 int index, | 442 int index, |
418 const GURL& url, | 443 const GURL& url, |
419 ui::PageTransition transition, | 444 ui::PageTransition transition, |
420 bool check_navigation_success) { | 445 bool check_navigation_success) { |
421 chrome::NavigateParams params(browser, url, transition); | 446 chrome::NavigateParams params(browser, url, transition); |
(...skipping 14 matching lines...) Expand all Loading... | |
436 AddTabAtIndexToBrowser(browser(), index, url, transition, true); | 461 AddTabAtIndexToBrowser(browser(), index, url, transition, true); |
437 } | 462 } |
438 | 463 |
439 bool InProcessBrowserTest::SetUpUserDataDirectory() { | 464 bool InProcessBrowserTest::SetUpUserDataDirectory() { |
440 return true; | 465 return true; |
441 } | 466 } |
442 | 467 |
443 // Creates a browser with a single tab (about:blank), waits for the tab to | 468 // Creates a browser with a single tab (about:blank), waits for the tab to |
444 // finish loading and shows the browser. | 469 // finish loading and shows the browser. |
445 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { | 470 Browser* InProcessBrowserTest::CreateBrowser(Profile* profile) { |
471 #if defined(OS_MACOSX) | |
472 // Making a browser window can cause AppKit to throw objects into the | |
473 // autorelease pool. Flush the pool when this function returns. | |
474 base::mac::ScopedNSAutoreleasePool pool; | |
475 #endif | |
446 Browser* browser = new Browser( | 476 Browser* browser = new Browser( |
447 Browser::CreateParams(profile, chrome::GetActiveDesktop())); | 477 Browser::CreateParams(profile, chrome::GetActiveDesktop())); |
448 AddBlankTabAndShow(browser); | 478 AddBlankTabAndShow(browser); |
449 return browser; | 479 return browser; |
450 } | 480 } |
451 | 481 |
452 Browser* InProcessBrowserTest::CreateIncognitoBrowser() { | 482 Browser* InProcessBrowserTest::CreateIncognitoBrowser() { |
483 #if defined(OS_MACOSX) | |
484 // Making a browser window can cause AppKit to throw objects into the | |
485 // autorelease pool. Flush the pool when this function returns. | |
486 base::mac::ScopedNSAutoreleasePool pool; | |
487 #endif | |
453 // Create a new browser with using the incognito profile. | 488 // Create a new browser with using the incognito profile. |
454 Browser* incognito = new Browser( | 489 Browser* incognito = new Browser( |
455 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(), | 490 Browser::CreateParams(browser()->profile()->GetOffTheRecordProfile(), |
456 chrome::GetActiveDesktop())); | 491 chrome::GetActiveDesktop())); |
457 AddBlankTabAndShow(incognito); | 492 AddBlankTabAndShow(incognito); |
458 return incognito; | 493 return incognito; |
459 } | 494 } |
460 | 495 |
461 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) { | 496 Browser* InProcessBrowserTest::CreateBrowserForPopup(Profile* profile) { |
497 #if defined(OS_MACOSX) | |
498 // Making a browser window can cause AppKit to throw objects into the | |
499 // autorelease pool. Flush the pool when this function returns. | |
500 base::mac::ScopedNSAutoreleasePool pool; | |
501 #endif | |
462 Browser* browser = | 502 Browser* browser = |
463 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, | 503 new Browser(Browser::CreateParams(Browser::TYPE_POPUP, profile, |
464 chrome::GetActiveDesktop())); | 504 chrome::GetActiveDesktop())); |
465 AddBlankTabAndShow(browser); | 505 AddBlankTabAndShow(browser); |
466 return browser; | 506 return browser; |
467 } | 507 } |
468 | 508 |
469 Browser* InProcessBrowserTest::CreateBrowserForApp( | 509 Browser* InProcessBrowserTest::CreateBrowserForApp( |
470 const std::string& app_name, | 510 const std::string& app_name, |
471 Profile* profile) { | 511 Profile* profile) { |
512 #if defined(OS_MACOSX) | |
513 // Making a browser window can cause AppKit to throw objects into the | |
514 // autorelease pool. Flush the pool when this function returns. | |
515 base::mac::ScopedNSAutoreleasePool pool; | |
516 #endif | |
472 Browser* browser = new Browser( | 517 Browser* browser = new Browser( |
473 Browser::CreateParams::CreateForApp( | 518 Browser::CreateParams::CreateForApp( |
474 app_name, false /* trusted_source */, gfx::Rect(), profile, | 519 app_name, false /* trusted_source */, gfx::Rect(), profile, |
475 chrome::GetActiveDesktop())); | 520 chrome::GetActiveDesktop())); |
476 AddBlankTabAndShow(browser); | 521 AddBlankTabAndShow(browser); |
477 return browser; | 522 return browser; |
478 } | 523 } |
479 | 524 |
480 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) { | 525 void InProcessBrowserTest::AddBlankTabAndShow(Browser* browser) { |
481 content::WindowedNotificationObserver observer( | 526 content::WindowedNotificationObserver observer( |
(...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
623 // On the Mac, this eventually reaches | 668 // On the Mac, this eventually reaches |
624 // -[BrowserWindowController windowWillClose:], which will post a deferred | 669 // -[BrowserWindowController windowWillClose:], which will post a deferred |
625 // -autorelease on itself to ultimately destroy the Browser object. The line | 670 // -autorelease on itself to ultimately destroy the Browser object. The line |
626 // below is necessary to pump these pending messages to ensure all Browsers | 671 // below is necessary to pump these pending messages to ensure all Browsers |
627 // get deleted. | 672 // get deleted. |
628 content::RunAllPendingInMessageLoop(); | 673 content::RunAllPendingInMessageLoop(); |
629 delete autorelease_pool_; | 674 delete autorelease_pool_; |
630 autorelease_pool_ = NULL; | 675 autorelease_pool_ = NULL; |
631 #endif | 676 #endif |
632 } | 677 } |
OLD | NEW |