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" |
(...skipping 74 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
85 namespace { | 85 namespace { |
86 | 86 |
87 // Passed as value of kTestType. | 87 // Passed as value of kTestType. |
88 const char kBrowserTestType[] = "browser"; | 88 const char kBrowserTestType[] = "browser"; |
89 | 89 |
90 // A BrowserListObserver that makes sure that all browsers created are on the | 90 // A BrowserListObserver that makes sure that all browsers created are on the |
91 // |allowed_desktop_|. | 91 // |allowed_desktop_|. |
92 class SingleDesktopTestObserver : public chrome::BrowserListObserver, | 92 class SingleDesktopTestObserver : public chrome::BrowserListObserver, |
93 public base::NonThreadSafe { | 93 public base::NonThreadSafe { |
94 public: | 94 public: |
95 explicit SingleDesktopTestObserver(chrome::HostDesktopType allowed_desktop); | 95 explicit SingleDesktopTestObserver(ui::HostDesktopType allowed_desktop); |
96 ~SingleDesktopTestObserver() override; | 96 ~SingleDesktopTestObserver() override; |
97 | 97 |
98 // chrome::BrowserListObserver: | 98 // chrome::BrowserListObserver: |
99 void OnBrowserAdded(Browser* browser) override; | 99 void OnBrowserAdded(Browser* browser) override; |
100 | 100 |
101 private: | 101 private: |
102 chrome::HostDesktopType allowed_desktop_; | 102 ui::HostDesktopType allowed_desktop_; |
103 | 103 |
104 DISALLOW_COPY_AND_ASSIGN(SingleDesktopTestObserver); | 104 DISALLOW_COPY_AND_ASSIGN(SingleDesktopTestObserver); |
105 }; | 105 }; |
106 | 106 |
107 SingleDesktopTestObserver::SingleDesktopTestObserver( | 107 SingleDesktopTestObserver::SingleDesktopTestObserver( |
108 chrome::HostDesktopType allowed_desktop) | 108 ui::HostDesktopType allowed_desktop) |
109 : allowed_desktop_(allowed_desktop) { | 109 : allowed_desktop_(allowed_desktop) { |
110 BrowserList::AddObserver(this); | 110 BrowserList::AddObserver(this); |
111 } | 111 } |
112 | 112 |
113 SingleDesktopTestObserver::~SingleDesktopTestObserver() { | 113 SingleDesktopTestObserver::~SingleDesktopTestObserver() { |
114 BrowserList::RemoveObserver(this); | 114 BrowserList::RemoveObserver(this); |
115 } | 115 } |
116 | 116 |
117 void SingleDesktopTestObserver::OnBrowserAdded(Browser* browser) { | 117 void SingleDesktopTestObserver::OnBrowserAdded(Browser* browser) { |
118 CHECK(CalledOnValidThread()); | 118 CHECK(CalledOnValidThread()); |
119 CHECK_EQ(browser->host_desktop_type(), allowed_desktop_); | 119 CHECK_EQ(browser->host_desktop_type(), allowed_desktop_); |
(...skipping 327 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
447 #if !defined(OS_MACOSX) | 447 #if !defined(OS_MACOSX) |
448 void InProcessBrowserTest::OpenDevToolsWindow( | 448 void InProcessBrowserTest::OpenDevToolsWindow( |
449 content::WebContents* web_contents) { | 449 content::WebContents* web_contents) { |
450 ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents)); | 450 ASSERT_FALSE(content::DevToolsAgentHost::HasFor(web_contents)); |
451 DevToolsWindow::OpenDevToolsWindow(web_contents); | 451 DevToolsWindow::OpenDevToolsWindow(web_contents); |
452 ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents)); | 452 ASSERT_TRUE(content::DevToolsAgentHost::HasFor(web_contents)); |
453 } | 453 } |
454 | 454 |
455 Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile, | 455 Browser* InProcessBrowserTest::OpenURLOffTheRecord(Profile* profile, |
456 const GURL& url) { | 456 const GURL& url) { |
457 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | 457 ui::HostDesktopType active_desktop = chrome::GetActiveDesktop(); |
458 chrome::OpenURLOffTheRecord(profile, url, active_desktop); | 458 chrome::OpenURLOffTheRecord(profile, url, active_desktop); |
459 Browser* browser = chrome::FindTabbedBrowser( | 459 Browser* browser = chrome::FindTabbedBrowser( |
460 profile->GetOffTheRecordProfile(), false, active_desktop); | 460 profile->GetOffTheRecordProfile(), false, active_desktop); |
461 content::TestNavigationObserver observer( | 461 content::TestNavigationObserver observer( |
462 browser->tab_strip_model()->GetActiveWebContents()); | 462 browser->tab_strip_model()->GetActiveWebContents()); |
463 observer.Wait(); | 463 observer.Wait(); |
464 return browser; | 464 return browser; |
465 } | 465 } |
466 | 466 |
467 // Creates a browser with a single tab (about:blank), waits for the tab to | 467 // Creates a browser with a single tab (about:blank), waits for the tab to |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
536 return new_command_line; | 536 return new_command_line; |
537 } | 537 } |
538 #endif | 538 #endif |
539 | 539 |
540 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 540 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
541 AfterStartupTaskUtils::SetBrowserStartupIsComplete(); | 541 AfterStartupTaskUtils::SetBrowserStartupIsComplete(); |
542 | 542 |
543 // Pump startup related events. | 543 // Pump startup related events. |
544 content::RunAllPendingInMessageLoop(); | 544 content::RunAllPendingInMessageLoop(); |
545 | 545 |
546 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | 546 ui::HostDesktopType active_desktop = chrome::GetActiveDesktop(); |
547 // Self-adds/removes itself from the BrowserList observers. | 547 // Self-adds/removes itself from the BrowserList observers. |
548 scoped_ptr<SingleDesktopTestObserver> single_desktop_test_observer; | 548 scoped_ptr<SingleDesktopTestObserver> single_desktop_test_observer; |
549 if (!multi_desktop_test_) { | 549 if (!multi_desktop_test_) { |
550 single_desktop_test_observer.reset( | 550 single_desktop_test_observer.reset( |
551 new SingleDesktopTestObserver(active_desktop)); | 551 new SingleDesktopTestObserver(active_desktop)); |
552 } | 552 } |
553 | 553 |
554 const BrowserList* active_browser_list = | 554 const BrowserList* active_browser_list = |
555 BrowserList::GetInstance(active_desktop); | 555 BrowserList::GetInstance(active_desktop); |
556 if (!active_browser_list->empty()) { | 556 if (!active_browser_list->empty()) { |
(...skipping 58 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
615 #endif | 615 #endif |
616 | 616 |
617 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's | 617 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's |
618 // run all pending messages here to avoid preempting the QuitBrowsers tasks. | 618 // run all pending messages here to avoid preempting the QuitBrowsers tasks. |
619 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it | 619 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it |
620 // will not be possible to post Quit tasks. | 620 // will not be possible to post Quit tasks. |
621 content::RunAllPendingInMessageLoop(); | 621 content::RunAllPendingInMessageLoop(); |
622 | 622 |
623 QuitBrowsers(); | 623 QuitBrowsers(); |
624 // All BrowserLists should be empty at this point. | 624 // All BrowserLists should be empty at this point. |
625 for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST; | 625 for (ui::HostDesktopType t = ui::HOST_DESKTOP_TYPE_FIRST; |
626 t < chrome::HOST_DESKTOP_TYPE_COUNT; | 626 t < ui::HOST_DESKTOP_TYPE_COUNT; |
627 t = static_cast<chrome::HostDesktopType>(t + 1)) { | 627 t = static_cast<ui::HostDesktopType>(t + 1)) { |
628 CHECK(BrowserList::GetInstance(t)->empty()) << t; | 628 CHECK(BrowserList::GetInstance(t)->empty()) << t; |
629 } | 629 } |
630 } | 630 } |
631 | 631 |
632 void InProcessBrowserTest::QuitBrowsers() { | 632 void InProcessBrowserTest::QuitBrowsers() { |
633 if (chrome::GetTotalBrowserCount() == 0) { | 633 if (chrome::GetTotalBrowserCount() == 0) { |
634 chrome::NotifyAppTerminating(); | 634 chrome::NotifyAppTerminating(); |
635 return; | 635 return; |
636 } | 636 } |
637 | 637 |
(...skipping 12 matching lines...) Expand all Loading... |
650 // On the Mac, this eventually reaches | 650 // On the Mac, this eventually reaches |
651 // -[BrowserWindowController windowWillClose:], which will post a deferred | 651 // -[BrowserWindowController windowWillClose:], which will post a deferred |
652 // -autorelease on itself to ultimately destroy the Browser object. The line | 652 // -autorelease on itself to ultimately destroy the Browser object. The line |
653 // below is necessary to pump these pending messages to ensure all Browsers | 653 // below is necessary to pump these pending messages to ensure all Browsers |
654 // get deleted. | 654 // get deleted. |
655 content::RunAllPendingInMessageLoop(); | 655 content::RunAllPendingInMessageLoop(); |
656 delete autorelease_pool_; | 656 delete autorelease_pool_; |
657 autorelease_pool_ = NULL; | 657 autorelease_pool_ = NULL; |
658 #endif | 658 #endif |
659 } | 659 } |
OLD | NEW |