| 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 "ash/ash_switches.h" | 7 #include "ash/ash_switches.h" |
| 8 #include "base/auto_reset.h" | 8 #include "base/auto_reset.h" |
| 9 #include "base/bind.h" | 9 #include "base/bind.h" |
| 10 #include "base/command_line.h" | 10 #include "base/command_line.h" |
| (...skipping 75 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 86 | 86 |
| 87 #if defined(USE_ASH) | 87 #if defined(USE_ASH) |
| 88 #include "chrome/test/base/default_ash_event_generator_delegate.h" | 88 #include "chrome/test/base/default_ash_event_generator_delegate.h" |
| 89 #endif | 89 #endif |
| 90 | 90 |
| 91 namespace { | 91 namespace { |
| 92 | 92 |
| 93 // Passed as value of kTestType. | 93 // Passed as value of kTestType. |
| 94 const char kBrowserTestType[] = "browser"; | 94 const char kBrowserTestType[] = "browser"; |
| 95 | 95 |
| 96 // A BrowserListObserver that makes sure that all browsers created are on the | |
| 97 // |allowed_desktop_|. | |
| 98 class SingleDesktopTestObserver : public chrome::BrowserListObserver, | |
| 99 public base::NonThreadSafe { | |
| 100 public: | |
| 101 explicit SingleDesktopTestObserver(chrome::HostDesktopType allowed_desktop); | |
| 102 ~SingleDesktopTestObserver() override; | |
| 103 | |
| 104 // chrome::BrowserListObserver: | |
| 105 void OnBrowserAdded(Browser* browser) override; | |
| 106 | |
| 107 private: | |
| 108 chrome::HostDesktopType allowed_desktop_; | |
| 109 | |
| 110 DISALLOW_COPY_AND_ASSIGN(SingleDesktopTestObserver); | |
| 111 }; | |
| 112 | |
| 113 SingleDesktopTestObserver::SingleDesktopTestObserver( | |
| 114 chrome::HostDesktopType allowed_desktop) | |
| 115 : allowed_desktop_(allowed_desktop) { | |
| 116 BrowserList::AddObserver(this); | |
| 117 } | |
| 118 | |
| 119 SingleDesktopTestObserver::~SingleDesktopTestObserver() { | |
| 120 BrowserList::RemoveObserver(this); | |
| 121 } | |
| 122 | |
| 123 void SingleDesktopTestObserver::OnBrowserAdded(Browser* browser) { | |
| 124 CHECK(CalledOnValidThread()); | |
| 125 CHECK_EQ(browser->host_desktop_type(), allowed_desktop_); | |
| 126 } | |
| 127 | |
| 128 } // namespace | 96 } // namespace |
| 129 | 97 |
| 130 // Library used for testing accessibility. | 98 // Library used for testing accessibility. |
| 131 const base::FilePath::CharType kAXSTesting[] = | 99 const base::FilePath::CharType kAXSTesting[] = |
| 132 FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js"); | 100 FILE_PATH_LITERAL("third_party/accessibility-audit/axs_testing.js"); |
| 133 // JavaScript snippet to configure and run the accessibility audit. | 101 // JavaScript snippet to configure and run the accessibility audit. |
| 134 const char kAccessibilityTestString[] = | 102 const char kAccessibilityTestString[] = |
| 135 "var config = new axs.AuditConfiguration();" | 103 "var config = new axs.AuditConfiguration();" |
| 136 "/* Disable warning about rules that cannot be checked. */" | 104 "/* Disable warning about rules that cannot be checked. */" |
| 137 "config.showUnsupportedRulesWarning = false;" | 105 "config.showUnsupportedRulesWarning = false;" |
| (...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 543 return new_command_line; | 511 return new_command_line; |
| 544 } | 512 } |
| 545 #endif | 513 #endif |
| 546 | 514 |
| 547 void InProcessBrowserTest::RunTestOnMainThreadLoop() { | 515 void InProcessBrowserTest::RunTestOnMainThreadLoop() { |
| 548 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); | 516 AfterStartupTaskUtils::SetBrowserStartupIsCompleteForTesting(); |
| 549 | 517 |
| 550 // Pump startup related events. | 518 // Pump startup related events. |
| 551 content::RunAllPendingInMessageLoop(); | 519 content::RunAllPendingInMessageLoop(); |
| 552 | 520 |
| 553 chrome::HostDesktopType active_desktop = chrome::GetActiveDesktop(); | 521 const BrowserList* active_browser_list = BrowserList::GetInstance(); |
| 554 // Self-adds/removes itself from the BrowserList observers. | |
| 555 scoped_ptr<SingleDesktopTestObserver> single_desktop_test_observer; | |
| 556 if (!multi_desktop_test_) { | |
| 557 single_desktop_test_observer.reset( | |
| 558 new SingleDesktopTestObserver(active_desktop)); | |
| 559 } | |
| 560 | |
| 561 const BrowserList* active_browser_list = | |
| 562 BrowserList::GetInstance(active_desktop); | |
| 563 if (!active_browser_list->empty()) { | 522 if (!active_browser_list->empty()) { |
| 564 browser_ = active_browser_list->get(0); | 523 browser_ = active_browser_list->get(0); |
| 565 #if defined(USE_ASH) | 524 #if defined(USE_ASH) |
| 566 // There are cases where windows get created maximized by default. | 525 // There are cases where windows get created maximized by default. |
| 567 if (browser_->window()->IsMaximized()) | 526 if (browser_->window()->IsMaximized()) |
| 568 browser_->window()->Restore(); | 527 browser_->window()->Restore(); |
| 569 #endif | 528 #endif |
| 570 content::WaitForLoadStop( | 529 content::WaitForLoadStop( |
| 571 browser_->tab_strip_model()->GetActiveWebContents()); | 530 browser_->tab_strip_model()->GetActiveWebContents()); |
| 572 } | 531 } |
| (...skipping 48 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 621 autorelease_pool_->Recycle(); | 580 autorelease_pool_->Recycle(); |
| 622 #endif | 581 #endif |
| 623 | 582 |
| 624 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's | 583 // Sometimes tests leave Quit tasks in the MessageLoop (for shame), so let's |
| 625 // run all pending messages here to avoid preempting the QuitBrowsers tasks. | 584 // run all pending messages here to avoid preempting the QuitBrowsers tasks. |
| 626 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it | 585 // TODO(jbates) Once crbug.com/134753 is fixed, this can be removed because it |
| 627 // will not be possible to post Quit tasks. | 586 // will not be possible to post Quit tasks. |
| 628 content::RunAllPendingInMessageLoop(); | 587 content::RunAllPendingInMessageLoop(); |
| 629 | 588 |
| 630 QuitBrowsers(); | 589 QuitBrowsers(); |
| 631 // All BrowserLists should be empty at this point. | 590 // BrowserList should be empty at this point. |
| 632 for (chrome::HostDesktopType t = chrome::HOST_DESKTOP_TYPE_FIRST; | 591 CHECK(BrowserList::GetInstance()->empty()); |
| 633 t < chrome::HOST_DESKTOP_TYPE_COUNT; | |
| 634 t = static_cast<chrome::HostDesktopType>(t + 1)) { | |
| 635 CHECK(BrowserList::GetInstance(t)->empty()) << t; | |
| 636 } | |
| 637 } | 592 } |
| 638 | 593 |
| 639 void InProcessBrowserTest::QuitBrowsers() { | 594 void InProcessBrowserTest::QuitBrowsers() { |
| 640 if (chrome::GetTotalBrowserCount() == 0) { | 595 if (chrome::GetTotalBrowserCount() == 0) { |
| 641 chrome::NotifyAppTerminating(); | 596 chrome::NotifyAppTerminating(); |
| 642 return; | 597 return; |
| 643 } | 598 } |
| 644 | 599 |
| 645 // Invoke AttemptExit on a running message loop. | 600 // Invoke AttemptExit on a running message loop. |
| 646 // AttemptExit exits the message loop after everything has been | 601 // AttemptExit exits the message loop after everything has been |
| (...skipping 10 matching lines...) Expand all Loading... |
| 657 // On the Mac, this eventually reaches | 612 // On the Mac, this eventually reaches |
| 658 // -[BrowserWindowController windowWillClose:], which will post a deferred | 613 // -[BrowserWindowController windowWillClose:], which will post a deferred |
| 659 // -autorelease on itself to ultimately destroy the Browser object. The line | 614 // -autorelease on itself to ultimately destroy the Browser object. The line |
| 660 // below is necessary to pump these pending messages to ensure all Browsers | 615 // below is necessary to pump these pending messages to ensure all Browsers |
| 661 // get deleted. | 616 // get deleted. |
| 662 content::RunAllPendingInMessageLoop(); | 617 content::RunAllPendingInMessageLoop(); |
| 663 delete autorelease_pool_; | 618 delete autorelease_pool_; |
| 664 autorelease_pool_ = NULL; | 619 autorelease_pool_ = NULL; |
| 665 #endif | 620 #endif |
| 666 } | 621 } |
| OLD | NEW |