Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(219)

Side by Side Diff: content/public/test/browser_test_utils.cc

Issue 2397893002: Revert the merge of CrossSiteResourceHandler and NavigationResourceThrottle. (Closed)
Patch Set: Add back initialization of started_from_context_menu_. Created 4 years, 2 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
OLDNEW
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 "content/public/test/browser_test_utils.h" 5 #include "content/public/test/browser_test_utils.h"
6 6
7 #include <stddef.h> 7 #include <stddef.h>
8 #include <tuple> 8 #include <tuple>
9 #include <utility> 9 #include <utility>
10 10
(...skipping 343 matching lines...) Expand 10 before | Expand all | Expand 10 after
354 return std::move(http_response); 354 return std::move(http_response);
355 } 355 }
356 356
357 // Helper class used by the TestNavigationManager to pause navigations. 357 // Helper class used by the TestNavigationManager to pause navigations.
358 // Note: the throttle should be added to the *end* of the list of throttles, 358 // Note: the throttle should be added to the *end* of the list of throttles,
359 // so all NavigationThrottles that should be attached observe the 359 // so all NavigationThrottles that should be attached observe the
360 // WillStartRequest callback. RegisterThrottleForTesting has this behavior. 360 // WillStartRequest callback. RegisterThrottleForTesting has this behavior.
361 class TestNavigationManagerThrottle : public NavigationThrottle { 361 class TestNavigationManagerThrottle : public NavigationThrottle {
362 public: 362 public:
363 TestNavigationManagerThrottle(NavigationHandle* handle, 363 TestNavigationManagerThrottle(NavigationHandle* handle,
364 base::Closure on_will_start_request_closure, 364 base::Closure on_will_start_request_closure)
365 base::Closure on_will_process_response_closure)
366 : NavigationThrottle(handle), 365 : NavigationThrottle(handle),
367 on_will_start_request_closure_(on_will_start_request_closure), 366 on_will_start_request_closure_(on_will_start_request_closure) {}
368 on_will_process_response_closure_(on_will_process_response_closure) {}
369 ~TestNavigationManagerThrottle() override {} 367 ~TestNavigationManagerThrottle() override {}
370 368
371 private: 369 private:
372 // NavigationThrottle: 370 // NavigationThrottle:
373 NavigationThrottle::ThrottleCheckResult WillStartRequest() override { 371 NavigationThrottle::ThrottleCheckResult WillStartRequest() override {
374 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE, 372 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
375 on_will_start_request_closure_); 373 on_will_start_request_closure_);
376 return NavigationThrottle::DEFER; 374 return NavigationThrottle::DEFER;
377 } 375 }
378 376
379 NavigationThrottle::ThrottleCheckResult WillProcessResponse() override {
380 BrowserThread::PostTask(BrowserThread::UI, FROM_HERE,
381 on_will_process_response_closure_);
382 return NavigationThrottle::DEFER;
383 }
384
385 base::Closure on_will_start_request_closure_; 377 base::Closure on_will_start_request_closure_;
386 base::Closure on_will_process_response_closure_;
387 }; 378 };
388 379
389 bool HasGzipHeader(const base::RefCountedMemory& maybe_gzipped) { 380 bool HasGzipHeader(const base::RefCountedMemory& maybe_gzipped) {
390 net::GZipHeader header; 381 net::GZipHeader header;
391 net::GZipHeader::Status header_status = net::GZipHeader::INCOMPLETE_HEADER; 382 net::GZipHeader::Status header_status = net::GZipHeader::INCOMPLETE_HEADER;
392 const char* header_end = nullptr; 383 const char* header_end = nullptr;
393 while (header_status == net::GZipHeader::INCOMPLETE_HEADER) { 384 while (header_status == net::GZipHeader::INCOMPLETE_HEADER) {
394 header_status = header.ReadMore(maybe_gzipped.front_as<char>(), 385 header_status = header.ReadMore(maybe_gzipped.front_as<char>(),
395 maybe_gzipped.size(), 386 maybe_gzipped.size(),
396 &header_end); 387 &header_end);
(...skipping 1241 matching lines...) Expand 10 before | Expand all | Expand 10 after
1638 FrameFocusedObserver::~FrameFocusedObserver() {} 1629 FrameFocusedObserver::~FrameFocusedObserver() {}
1639 1630
1640 void FrameFocusedObserver::Wait() { 1631 void FrameFocusedObserver::Wait() {
1641 impl_->Run(); 1632 impl_->Run();
1642 } 1633 }
1643 1634
1644 TestNavigationManager::TestNavigationManager(WebContents* web_contents, 1635 TestNavigationManager::TestNavigationManager(WebContents* web_contents,
1645 const GURL& url) 1636 const GURL& url)
1646 : WebContentsObserver(web_contents), 1637 : WebContentsObserver(web_contents),
1647 url_(url), 1638 url_(url),
1648 navigation_paused_in_will_start_(false), 1639 navigation_paused_(false),
1649 navigation_paused_in_will_process_response_(false),
1650 handle_(nullptr), 1640 handle_(nullptr),
1651 handled_navigation_(false), 1641 handled_navigation_(false),
1652 weak_factory_(this) {} 1642 weak_factory_(this) {}
1653 1643
1654 TestNavigationManager::~TestNavigationManager() { 1644 TestNavigationManager::~TestNavigationManager() {
1655 ResumeNavigation(); 1645 ResumeNavigation();
1656 } 1646 }
1657 1647
1658 bool TestNavigationManager::WaitForWillStartRequest() { 1648 bool TestNavigationManager::WaitForWillStartRequest() {
1659 DCHECK(!did_finish_loop_runner_); 1649 DCHECK(!did_finish_loop_runner_);
1660 if (!handle_ && handled_navigation_) 1650 if (!handle_ && handled_navigation_)
1661 return true; 1651 return true;
1662 if (navigation_paused_in_will_start_) 1652 if (navigation_paused_)
1663 return true; 1653 return true;
1664 DCHECK(!navigation_paused_in_will_process_response_);
1665 will_start_loop_runner_ = new MessageLoopRunner(); 1654 will_start_loop_runner_ = new MessageLoopRunner();
1666 will_start_loop_runner_->Run(); 1655 will_start_loop_runner_->Run();
1667 will_start_loop_runner_ = nullptr; 1656 will_start_loop_runner_ = nullptr;
1668 1657
1669 // This will only be false if DidFinishNavigation is called before 1658 // This will only be false if DidFinishNavigation is called before
1670 // OnWillStartRequest, which could occur if a throttle cancels the navigation 1659 // OnWillStartRequest, which could occur if a throttle cancels the navigation
1671 // before the TestNavigationManagerThrottle's method is called. 1660 // before the TestNavigationManagerThrottle's method is called.
1672 return !handled_navigation_; 1661 return !handled_navigation_;
1673 } 1662 }
1674 1663
1675 bool TestNavigationManager::WaitForWillProcessResponse() {
1676 DCHECK(!did_finish_loop_runner_);
1677 if (!handle_ && handled_navigation_)
1678 return true;
1679 if (navigation_paused_in_will_process_response_)
1680 return true;
1681 // Ensure the navigation is resumed if the manager paused it previously.
1682 if (navigation_paused_in_will_start_)
1683 ResumeNavigation();
1684 will_process_response_loop_runner_ = new MessageLoopRunner();
1685 will_process_response_loop_runner_->Run();
1686 will_process_response_loop_runner_ = nullptr;
1687
1688 // This will only be false if DidFinishNavigation is called before
1689 // OnWillProcessResponse.
1690 return !handled_navigation_;
1691 }
1692
1693 void TestNavigationManager::WaitForNavigationFinished() { 1664 void TestNavigationManager::WaitForNavigationFinished() {
1694 DCHECK(!will_start_loop_runner_); 1665 DCHECK(!will_start_loop_runner_);
1695 if (!handle_ && handled_navigation_) 1666 if (!handle_ && handled_navigation_)
1696 return; 1667 return;
1697 // Ensure the navigation is resumed if the manager paused it previously. 1668 // Ensure the navigation is resumed if the manager paused it previously.
1698 if (navigation_paused_in_will_start_ || 1669 if (navigation_paused_)
1699 navigation_paused_in_will_process_response_) {
1700 ResumeNavigation(); 1670 ResumeNavigation();
1701 }
1702 did_finish_loop_runner_ = new MessageLoopRunner(); 1671 did_finish_loop_runner_ = new MessageLoopRunner();
1703 did_finish_loop_runner_->Run(); 1672 did_finish_loop_runner_->Run();
1704 did_finish_loop_runner_ = nullptr; 1673 did_finish_loop_runner_ = nullptr;
1705 } 1674 }
1706 1675
1707 void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) { 1676 void TestNavigationManager::DidStartNavigation(NavigationHandle* handle) {
1708 if (!ShouldMonitorNavigation(handle)) 1677 if (!ShouldMonitorNavigation(handle))
1709 return; 1678 return;
1710 1679
1711 handle_ = handle; 1680 handle_ = handle;
1712 std::unique_ptr<NavigationThrottle> throttle( 1681 std::unique_ptr<NavigationThrottle> throttle(
1713 new TestNavigationManagerThrottle( 1682 new TestNavigationManagerThrottle(
1714 handle_, base::Bind(&TestNavigationManager::OnWillStartRequest, 1683 handle_, base::Bind(&TestNavigationManager::OnWillStartRequest,
1715 weak_factory_.GetWeakPtr()), 1684 weak_factory_.GetWeakPtr())));
1716 base::Bind(&TestNavigationManager::OnWillProcessResponse,
1717 weak_factory_.GetWeakPtr())));
1718 handle_->RegisterThrottleForTesting(std::move(throttle)); 1685 handle_->RegisterThrottleForTesting(std::move(throttle));
1719 } 1686 }
1720 1687
1721 void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) { 1688 void TestNavigationManager::DidFinishNavigation(NavigationHandle* handle) {
1722 if (handle != handle_) 1689 if (handle != handle_)
1723 return; 1690 return;
1724 handle_ = nullptr; 1691 handle_ = nullptr;
1725 handled_navigation_ = true; 1692 handled_navigation_ = true;
1726 navigation_paused_in_will_start_ = false; 1693 navigation_paused_ = false;
1727 navigation_paused_in_will_process_response_ = false;
1728 1694
1729 // Resume any clients that are waiting for the end of the navigation. Note 1695 // Resume any clients that are waiting for the end of the navigation. Note
1730 // that |will_start_loop_runner_| can be running if the navigation was 1696 // that |will_start_loop_runner_| can be running if the navigation was
1731 // cancelled while it was deferred. 1697 // cancelled while it was deferred.
1732 if (did_finish_loop_runner_) 1698 if (did_finish_loop_runner_)
1733 did_finish_loop_runner_->Quit(); 1699 did_finish_loop_runner_->Quit();
1734 if (will_start_loop_runner_) 1700 if (will_start_loop_runner_)
1735 will_start_loop_runner_->Quit(); 1701 will_start_loop_runner_->Quit();
1736 if (will_process_response_loop_runner_)
1737 will_process_response_loop_runner_->Quit();
1738 } 1702 }
1739 1703
1740 void TestNavigationManager::OnWillStartRequest() { 1704 void TestNavigationManager::OnWillStartRequest() {
1741 navigation_paused_in_will_start_ = true; 1705 navigation_paused_ = true;
1742 if (will_start_loop_runner_) 1706 if (will_start_loop_runner_)
1743 will_start_loop_runner_->Quit(); 1707 will_start_loop_runner_->Quit();
1744 1708
1745 // If waiting for further events in the navigation, resume the navigation. 1709 // If waiting for the navigation to finish, resume the navigation.
1746 if (did_finish_loop_runner_ || will_process_response_loop_runner_)
1747 ResumeNavigation();
1748 }
1749
1750 void TestNavigationManager::OnWillProcessResponse() {
1751 navigation_paused_in_will_process_response_ = true;
1752 DCHECK(!will_start_loop_runner_);
1753 if (will_process_response_loop_runner_)
1754 will_process_response_loop_runner_->Quit();
1755
1756 // If waiting for further events in the navigation, resume the navigation.
1757 if (did_finish_loop_runner_) 1710 if (did_finish_loop_runner_)
1758 ResumeNavigation(); 1711 ResumeNavigation();
1759 } 1712 }
1760 1713
1761 void TestNavigationManager::ResumeNavigation() { 1714 void TestNavigationManager::ResumeNavigation() {
1762 if (!(navigation_paused_in_will_start_ || 1715 if (!navigation_paused_ || !handle_)
1763 navigation_paused_in_will_process_response_) ||
1764 !handle_) {
1765 return; 1716 return;
1766 } 1717 navigation_paused_ = false;
1767 navigation_paused_in_will_start_ = false;
1768 navigation_paused_in_will_process_response_ = false;
1769 handle_->Resume(); 1718 handle_->Resume();
1770 } 1719 }
1771 1720
1772 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) { 1721 bool TestNavigationManager::ShouldMonitorNavigation(NavigationHandle* handle) {
1773 if (handle_ || handle->GetURL() != url_) 1722 if (handle_ || handle->GetURL() != url_)
1774 return false; 1723 return false;
1775 if (handled_navigation_) 1724 if (handled_navigation_)
1776 return false; 1725 return false;
1777 return true; 1726 return true;
1778 } 1727 }
1779 1728
1780 } // namespace content 1729 } // namespace content
OLDNEW
« no previous file with comments | « content/public/test/browser_test_utils.h ('k') | content/shell/browser/shell_content_browser_client.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698