| 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..8ac15077bbd9972ea157de3ab6f07d37b2aff120 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"
|
|
|
| @@ -50,7 +52,7 @@ bool GetLocalSession(int index, const sync_sessions::SyncedSession** session) {
|
| ->GetLocalSession(session);
|
| }
|
|
|
| -bool ModelAssociatorHasTabWithUrl(int index, const GURL& url) {
|
| +bool SessionsSyncManagerHasTabWithURL(int index, const GURL& url) {
|
| content::RunAllPendingInMessageLoop();
|
| const sync_sessions::SyncedSession* local_session;
|
| if (!GetLocalSession(index, &local_session)) {
|
| @@ -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 = SessionsSyncManagerHasTabWithURL(index, url);
|
| + 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;
|
| @@ -224,7 +223,7 @@ bool WaitForTabsToLoad(int index, const std::vector<GURL>& urls) {
|
|
|
| bool GetLocalWindows(int index, ScopedWindowMap* local_windows) {
|
| // The local session provided by GetLocalSession is owned, and has lifetime
|
| - // controlled, by the model associator, so we must make our own copy.
|
| + // controlled, by the sessions sync manager, so we must make our own copy.
|
| const sync_sessions::SyncedSession* local_session;
|
| if (!GetLocalSession(index, &local_session)) {
|
| return false;
|
|
|