Chromium Code Reviews| Index: chrome/browser/sync/test/integration/sessions_helper.cc |
| diff --git a/chrome/browser/sync/test/integration/sessions_helper.cc b/chrome/browser/sync/test/integration/sessions_helper.cc |
| index 84a843a6cb158548faada77eba53021283a0ce51..c33335d482eb58683f635e234dfbdc85af128b8b 100644 |
| --- a/chrome/browser/sync/test/integration/sessions_helper.cc |
| +++ b/chrome/browser/sync/test/integration/sessions_helper.cc |
| @@ -20,7 +20,6 @@ |
| #include "base/time/time.h" |
| #include "chrome/browser/profiles/profile.h" |
| #include "chrome/browser/sync/profile_sync_service_factory.h" |
| -#include "chrome/browser/sync/sessions/notification_service_sessions_router.h" |
| #include "chrome/browser/sync/test/integration/profile_sync_service_harness.h" |
| #include "chrome/browser/sync/test/integration/sync_datatype_helper.h" |
| #include "chrome/browser/ui/browser.h" |
| @@ -35,7 +34,10 @@ |
| #include "components/sync/test/fake_server/sessions_hierarchy.h" |
| #include "components/sync_sessions/open_tabs_ui_delegate.h" |
| #include "content/public/browser/navigation_entry.h" |
| +#include "content/public/browser/render_frame_host.h" |
| +#include "content/public/browser/render_process_host.h" |
| #include "content/public/browser/web_contents.h" |
| +#include "content/public/test/browser_test_utils.cc" |
| #include "content/public/test/test_utils.h" |
| #include "url/gurl.h" |
| @@ -101,7 +103,10 @@ bool OpenTab(int index, const GURL& url) { |
| bool OpenTabAtIndex(int index, int tab_index, const GURL& url) { |
| chrome::AddTabAt(test()->GetBrowser(index), url, tab_index, true); |
| - return WaitForTabsToLoad(index, {url}); |
| + return WaitForTabToLoad( |
| + index, url, |
| + test()->GetBrowser(index)->tab_strip_model()->GetWebContentsAt( |
| + tab_index)); |
| } |
| bool OpenMultipleTabs(int index, const std::vector<GURL>& urls) { |
| @@ -115,6 +120,31 @@ bool OpenMultipleTabs(int index, const std::vector<GURL>& urls) { |
| return WaitForTabsToLoad(index, urls); |
| } |
| +bool OpenTabFromSourceIndex(int index, |
| + int index_of_source_tab, |
| + const GURL& url, |
| + WindowOpenDisposition disposition) { |
| + content::WebContents* source_contents = |
| + test()->GetBrowser(index)->tab_strip_model()->GetWebContentsAt( |
| + index_of_source_tab); |
| + |
| + content::OpenURLParams open_url_params(url, content::Referrer(), disposition, |
| + ui::PAGE_TRANSITION_LINK, false, |
| + false); |
| + open_url_params.source_render_frame_id = |
| + source_contents->GetMainFrame()->GetRoutingID(); |
| + open_url_params.source_render_process_id = |
| + source_contents->GetRenderProcessHost()->GetID(); |
| + |
| + content::WebContents* new_contents = |
| + source_contents->OpenURL(open_url_params); |
| + if (!new_contents) { |
| + return false; |
| + } |
| + |
| + return WaitForTabToLoad(index, url, new_contents); |
| +} |
| + |
| void MoveTab(int from_index, int to_index, int tab_index) { |
| content::WebContents* detached_contents = |
| test() |
| @@ -133,7 +163,7 @@ bool NavigateTab(int index, const GURL& url) { |
| params.disposition = WindowOpenDisposition::CURRENT_TAB; |
| ui_test_utils::NavigateToURL(¶ms); |
| - return WaitForTabsToLoad(index, {url}); |
| + return WaitForTabToLoad(index, url, params.target_contents); |
| } |
| void NavigateTabBack(int index) { |
| @@ -154,69 +184,38 @@ void NavigateTabForward(int index) { |
| .GoForward(); |
| } |
| -namespace { |
| - |
| -class TabEventHandler : public sync_sessions::LocalSessionEventHandler { |
| - public: |
| - TabEventHandler() : weak_factory_(this) { |
| - base::ThreadTaskRunnerHandle::Get()->PostDelayedTask( |
| - FROM_HERE, |
| - base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr()), |
| - TestTimeouts::action_max_timeout()); |
| - } |
| - |
| - void OnLocalTabModified( |
| - sync_sessions::SyncedTabDelegate* modified_tab) override { |
| - // Unwind to ensure SessionsSyncManager has processed the event. |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr())); |
| - } |
| - |
| - void OnFaviconsChanged(const std::set<GURL>& /* page_urls */, |
| - const GURL& /* icon_url */) override { |
| - // Unwind to ensure SessionsSyncManager has processed the event. |
| - base::ThreadTaskRunnerHandle::Get()->PostTask( |
| - FROM_HERE, |
| - base::Bind(&TabEventHandler::QuitLoop, weak_factory_.GetWeakPtr())); |
| +bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) { |
| + int tab_index = 0; |
| + for (const auto& url : urls) { |
| + bool success = WaitForTabToLoad( |
| + index, url, |
| + test()->GetBrowser(index)->tab_strip_model()->GetWebContentsAt( |
| + tab_index)); |
| + if (!success) { |
| + return false; |
| + } |
| + tab_index++; |
| } |
| + return true; |
| +} |
| - private: |
| - void QuitLoop() { base::MessageLoop::current()->QuitWhenIdle(); } |
| - |
| - base::WeakPtrFactory<TabEventHandler> weak_factory_; |
| -}; |
| - |
| -} // namespace |
| - |
| -bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) { |
| +bool WaitForTabToLoad(int index, |
| + const GURL& url, |
| + content::WebContents* web_contents) { |
| DVLOG(1) << "Waiting for session to propagate to associator."; |
| base::TimeTicks start_time = base::TimeTicks::Now(); |
| base::TimeTicks end_time = start_time + TestTimeouts::action_max_timeout(); |
| - bool found; |
| - for (std::vector<GURL>::const_iterator it = urls.begin(); |
| - it != urls.end(); ++it) { |
| - found = false; |
| - while (!found) { |
| - found = ModelAssociatorHasTabWithUrl(index, *it); |
| - if (base::TimeTicks::Now() >= end_time) { |
| - LOG(ERROR) << "Failed to find all tabs after " |
| - << TestTimeouts::action_max_timeout().InSecondsF() |
| - << " seconds."; |
| - return false; |
| - } |
| - if (!found) { |
| - TabEventHandler handler; |
| - sync_sessions::NotificationServiceSessionsRouter router( |
| - test()->GetProfile(index), |
| - ProfileSyncServiceFactory::GetInstance() |
| - ->GetForProfile(test()->GetProfile(index)) |
| - ->GetSyncClient() |
| - ->GetSyncSessionsClient(), |
| - syncer::SyncableService::StartSyncFlare()); |
| - router.StartRoutingTo(&handler); |
| - content::RunMessageLoop(); |
| - } |
| + bool found = false; |
| + while (!found) { |
| + found = ModelAssociatorHasTabWithUrl(index, url); |
|
Nicolas Zea
2017/03/20 18:14:50
nit: SyncableServiceHasTabWithURL (or perhaps Sync
Patrick Noland
2017/03/21 22:54:31
Done.
|
| + if (base::TimeTicks::Now() >= end_time) { |
| + LOG(ERROR) << "Failed to find url " << url.spec() << " in tab after " |
| + << TestTimeouts::action_max_timeout().InSecondsF() |
| + << " seconds."; |
| + return false; |
| + } |
| + if (!found) { |
| + content::WaitForLoadStop(web_contents); |
| } |
| } |
| return true; |