Chromium Code Reviews| Index: content/browser/frame_host/interstitial_page_impl_browsertest.cc |
| diff --git a/content/browser/frame_host/interstitial_page_impl_browsertest.cc b/content/browser/frame_host/interstitial_page_impl_browsertest.cc |
| index 2fbdda35c986c6b0713dec2372b10bcd0c633447..6bb649c1eabdee609b3c9176115bbe2b7a6e9a21 100644 |
| --- a/content/browser/frame_host/interstitial_page_impl_browsertest.cc |
| +++ b/content/browser/frame_host/interstitial_page_impl_browsertest.cc |
| @@ -181,6 +181,53 @@ class ClipboardMessageWatcher : public IPC::MessageFilter { |
| DISALLOW_COPY_AND_ASSIGN(ClipboardMessageWatcher); |
| }; |
| +// An observer of the interstitial page WebContents that makes sure any title |
| +// changes made by the interstitial page are emitted to the WebContentsObservers |
| +// as WebContentsObserver::TitleWasSet() events. |
| +class WebContentsTitleWatcher : public WebContentsObserver { |
|
ncarter (slow)
2016/07/13 18:56:02
There's a public util class TitleWatcher -- I thin
afakhry
2016/07/13 22:10:27
Cool, thanks! Done.
|
| + public: |
| + WebContentsTitleWatcher(WebContents* contents) |
| + : WebContentsObserver(contents) {} |
| + ~WebContentsTitleWatcher() override {} |
| + |
| + // WebContentsObserver: |
| + void TitleWasSet(NavigationEntry* entry, bool explicit_set) override { |
| + if (!run_loop_) |
| + return; |
| + |
| + if (expected_title_ == web_contents()->GetTitle()) { |
| + if (run_loop_->running()) |
| + run_loop_->Quit(); |
| + else |
| + title_was_set_already_ = true; |
| + } |
| + } |
| + |
| + void InitWait(const std::string& expected_title) { |
| + DCHECK(!run_loop_); |
| + expected_title_ = base::UTF8ToUTF16(expected_title); |
| + run_loop_.reset(new base::RunLoop()); |
| + } |
| + |
| + void WaitForTitleWasSetEvent() { |
| + DCHECK(run_loop_); |
| + |
| + if (!title_was_set_already_) |
| + run_loop_->Run(); |
| + else |
| + title_was_set_already_ = false; |
| + |
| + run_loop_.reset(); |
| + } |
| + |
| + private: |
| + std::unique_ptr<base::RunLoop> run_loop_; |
| + base::string16 expected_title_; |
| + bool title_was_set_already_ = false; |
| + |
| + DISALLOW_COPY_AND_ASSIGN(WebContentsTitleWatcher); |
| +}; |
| + |
| } // namespace |
| class InterstitialPageImplTest : public ContentBrowserTest { |
| @@ -234,6 +281,9 @@ class InterstitialPageImplTest : public ContentBrowserTest { |
| WebContentsImpl* web_contents = |
| static_cast<WebContentsImpl*>(shell()->web_contents()); |
| + web_contents_title_watcher_.reset( |
| + new WebContentsTitleWatcher(web_contents)); |
| + |
| // Create the interstitial page. |
| TestInterstitialPageDelegate* interstitial_delegate = |
| new TestInterstitialPageDelegate; |
| @@ -293,11 +343,13 @@ class InterstitialPageImplTest : public ContentBrowserTest { |
| std::string PerformCut() { |
| clipboard_message_watcher_->InitWait(); |
| title_update_watcher_->InitWait("TEXT_CHANGED"); |
| + web_contents_title_watcher_->InitWait("TEXT_CHANGED"); |
| RenderFrameHostImpl* rfh = |
| static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| rfh->GetRenderWidgetHost()->delegate()->Cut(); |
| clipboard_message_watcher_->WaitForWriteCommit(); |
| title_update_watcher_->Wait(); |
| + web_contents_title_watcher_->WaitForTitleWasSetEvent(); |
| return clipboard_message_watcher_->last_text(); |
| } |
| @@ -312,18 +364,22 @@ class InterstitialPageImplTest : public ContentBrowserTest { |
| void PerformPaste() { |
| title_update_watcher_->InitWait("TEXT_CHANGED"); |
| + web_contents_title_watcher_->InitWait("TEXT_CHANGED"); |
| RenderFrameHostImpl* rfh = |
| static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| rfh->GetRenderWidgetHost()->delegate()->Paste(); |
| title_update_watcher_->Wait(); |
| + web_contents_title_watcher_->WaitForTitleWasSetEvent(); |
| } |
| void PerformSelectAll() { |
| title_update_watcher_->InitWait("SELECTION_CHANGED"); |
| + web_contents_title_watcher_->InitWait("SELECTION_CHANGED"); |
| RenderFrameHostImpl* rfh = |
| static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); |
| rfh->GetRenderWidgetHost()->delegate()->SelectAll(); |
| title_update_watcher_->Wait(); |
| + web_contents_title_watcher_->WaitForTitleWasSetEvent(); |
| } |
| private: |
| @@ -345,6 +401,7 @@ class InterstitialPageImplTest : public ContentBrowserTest { |
| std::unique_ptr<InterstitialPageImpl> interstitial_; |
| scoped_refptr<ClipboardMessageWatcher> clipboard_message_watcher_; |
| scoped_refptr<InterstitialTitleUpdateWatcher> title_update_watcher_; |
| + std::unique_ptr<WebContentsTitleWatcher> web_contents_title_watcher_; |
| DISALLOW_COPY_AND_ASSIGN(InterstitialPageImplTest); |
| }; |