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

Side by Side Diff: content/browser/frame_host/interstitial_page_impl_browsertest.cc

Issue 2086423005: Using WebContents::UpdateTitleForEntry() instead of NavigationEntry::SetTitle() (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: DidFinishNavigation is received when RenderFrameHostImpl is destroyed!! Created 4 years, 5 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 2015 The Chromium Authors. All rights reserved. 1 // Copyright 2015 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/browser/frame_host/interstitial_page_impl.h" 5 #include "content/browser/frame_host/interstitial_page_impl.h"
6 6
7 #include <tuple> 7 #include <tuple>
8 8
9 #include "base/macros.h" 9 #include "base/macros.h"
10 #include "base/strings/utf_string_conversions.h" 10 #include "base/strings/utf_string_conversions.h"
(...skipping 163 matching lines...) Expand 10 before | Expand all | Expand 10 after
174 } 174 }
175 return false; 175 return false;
176 } 176 }
177 177
178 std::unique_ptr<base::RunLoop> run_loop_; 178 std::unique_ptr<base::RunLoop> run_loop_;
179 std::string last_text_; 179 std::string last_text_;
180 180
181 DISALLOW_COPY_AND_ASSIGN(ClipboardMessageWatcher); 181 DISALLOW_COPY_AND_ASSIGN(ClipboardMessageWatcher);
182 }; 182 };
183 183
184 // An observer of the interstitial page WebContents that makes sure any title
185 // changes made by the interstitial page is emitted to the WebContentsObservers
Charlie Reis 2016/06/24 22:21:17 nit: s/is/are/
afakhry 2016/06/27 14:29:18 Done.
186 // as WebContentsObserver::TitleWasSet() event.
187 class WebContentsTitleWatcher : public WebContentsObserver {
188 public:
189 WebContentsTitleWatcher(WebContents* contents)
190 : WebContentsObserver(contents) {}
191 ~WebContentsTitleWatcher() override {}
192
193 // WebContentsObserver:
194 void TitleWasSet(NavigationEntry* entry, bool explicit_set) override {
195 if (!run_loop_)
196 return;
197
198 if (expected_title_ == web_contents()->GetTitle()) {
199 if (run_loop_->running())
200 run_loop_->Quit();
201 else
202 title_was_set_already_ = true;
203 }
204 }
205
206 void InitWait(const std::string& expected_title) {
207 DCHECK(!run_loop_);
208 expected_title_ = base::UTF8ToUTF16(expected_title);
209 run_loop_.reset(new base::RunLoop());
210 }
211
212 void WaitForTitleWasSetEvent() {
213 DCHECK(run_loop_);
214
215 if (!title_was_set_already_)
216 run_loop_->Run();
217 else
218 title_was_set_already_ = false;
219
220 run_loop_.reset();
221 }
222
223 private:
224 std::unique_ptr<base::RunLoop> run_loop_;
225 base::string16 expected_title_;
226 bool title_was_set_already_ = false;
227
228 DISALLOW_COPY_AND_ASSIGN(WebContentsTitleWatcher);
229 };
230
184 } // namespace 231 } // namespace
185 232
186 class InterstitialPageImplTest : public ContentBrowserTest { 233 class InterstitialPageImplTest : public ContentBrowserTest {
187 public: 234 public:
188 InterstitialPageImplTest() {} 235 InterstitialPageImplTest() {}
189 236
190 ~InterstitialPageImplTest() override {} 237 ~InterstitialPageImplTest() override {}
191 238
192 protected: 239 protected:
193 void SetUpTestClipboard() { 240 void SetUpTestClipboard() {
(...skipping 33 matching lines...) Expand 10 before | Expand all | Expand 10 after
227 } 274 }
228 #endif 275 #endif
229 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE); 276 ui::ScopedClipboardWriter clipboard_writer(ui::CLIPBOARD_TYPE_COPY_PASTE);
230 clipboard_writer.WriteText(base::ASCIIToUTF16(text)); 277 clipboard_writer.WriteText(base::ASCIIToUTF16(text));
231 } 278 }
232 279
233 void SetUpInterstitialPage() { 280 void SetUpInterstitialPage() {
234 WebContentsImpl* web_contents = 281 WebContentsImpl* web_contents =
235 static_cast<WebContentsImpl*>(shell()->web_contents()); 282 static_cast<WebContentsImpl*>(shell()->web_contents());
236 283
284 web_contents_title_watcher_.reset(
285 new WebContentsTitleWatcher(web_contents));
286
237 // Create the interstitial page. 287 // Create the interstitial page.
238 TestInterstitialPageDelegate* interstitial_delegate = 288 TestInterstitialPageDelegate* interstitial_delegate =
239 new TestInterstitialPageDelegate; 289 new TestInterstitialPageDelegate;
240 GURL url("http://interstitial"); 290 GURL url("http://interstitial");
241 interstitial_.reset(new InterstitialPageImpl( 291 interstitial_.reset(new InterstitialPageImpl(
242 web_contents, static_cast<RenderWidgetHostDelegate*>(web_contents), 292 web_contents, static_cast<RenderWidgetHostDelegate*>(web_contents),
243 true, url, interstitial_delegate)); 293 true, url, interstitial_delegate));
244 interstitial_->Show(); 294 interstitial_->Show();
245 WaitForInterstitialAttach(web_contents); 295 WaitForInterstitialAttach(web_contents);
246 296
(...skipping 39 matching lines...) Expand 10 before | Expand all | Expand 10 after
286 } 336 }
287 337
288 bool SetSelectionChangeListener() { 338 bool SetSelectionChangeListener() {
289 return ExecuteScript(interstitial_->GetMainFrame(), 339 return ExecuteScript(interstitial_->GetMainFrame(),
290 "set_selection_change_listener()"); 340 "set_selection_change_listener()");
291 } 341 }
292 342
293 std::string PerformCut() { 343 std::string PerformCut() {
294 clipboard_message_watcher_->InitWait(); 344 clipboard_message_watcher_->InitWait();
295 title_update_watcher_->InitWait("TEXT_CHANGED"); 345 title_update_watcher_->InitWait("TEXT_CHANGED");
346 web_contents_title_watcher_->InitWait("TEXT_CHANGED");
296 RenderFrameHostImpl* rfh = 347 RenderFrameHostImpl* rfh =
297 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 348 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
298 rfh->GetRenderWidgetHost()->delegate()->Cut(); 349 rfh->GetRenderWidgetHost()->delegate()->Cut();
299 clipboard_message_watcher_->WaitForWriteCommit(); 350 clipboard_message_watcher_->WaitForWriteCommit();
300 title_update_watcher_->Wait(); 351 title_update_watcher_->Wait();
352 web_contents_title_watcher_->WaitForTitleWasSetEvent();
301 return clipboard_message_watcher_->last_text(); 353 return clipboard_message_watcher_->last_text();
302 } 354 }
303 355
304 std::string PerformCopy() { 356 std::string PerformCopy() {
305 clipboard_message_watcher_->InitWait(); 357 clipboard_message_watcher_->InitWait();
306 RenderFrameHostImpl* rfh = 358 RenderFrameHostImpl* rfh =
307 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 359 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
308 rfh->GetRenderWidgetHost()->delegate()->Copy(); 360 rfh->GetRenderWidgetHost()->delegate()->Copy();
309 clipboard_message_watcher_->WaitForWriteCommit(); 361 clipboard_message_watcher_->WaitForWriteCommit();
310 return clipboard_message_watcher_->last_text(); 362 return clipboard_message_watcher_->last_text();
311 } 363 }
312 364
313 void PerformPaste() { 365 void PerformPaste() {
314 title_update_watcher_->InitWait("TEXT_CHANGED"); 366 title_update_watcher_->InitWait("TEXT_CHANGED");
367 web_contents_title_watcher_->InitWait("TEXT_CHANGED");
315 RenderFrameHostImpl* rfh = 368 RenderFrameHostImpl* rfh =
316 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 369 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
317 rfh->GetRenderWidgetHost()->delegate()->Paste(); 370 rfh->GetRenderWidgetHost()->delegate()->Paste();
318 title_update_watcher_->Wait(); 371 title_update_watcher_->Wait();
372 web_contents_title_watcher_->WaitForTitleWasSetEvent();
319 } 373 }
320 374
321 void PerformSelectAll() { 375 void PerformSelectAll() {
322 title_update_watcher_->InitWait("SELECTION_CHANGED"); 376 title_update_watcher_->InitWait("SELECTION_CHANGED");
377 web_contents_title_watcher_->InitWait("SELECTION_CHANGED");
323 RenderFrameHostImpl* rfh = 378 RenderFrameHostImpl* rfh =
324 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame()); 379 static_cast<RenderFrameHostImpl*>(interstitial_->GetMainFrame());
325 rfh->GetRenderWidgetHost()->delegate()->SelectAll(); 380 rfh->GetRenderWidgetHost()->delegate()->SelectAll();
326 title_update_watcher_->Wait(); 381 title_update_watcher_->Wait();
382 web_contents_title_watcher_->WaitForTitleWasSetEvent();
327 } 383 }
328 384
329 private: 385 private:
330 void RunTaskOnIOThreadAndWait(const base::Closure& task) { 386 void RunTaskOnIOThreadAndWait(const base::Closure& task) {
331 base::WaitableEvent completion( 387 base::WaitableEvent completion(
332 base::WaitableEvent::ResetPolicy::AUTOMATIC, 388 base::WaitableEvent::ResetPolicy::AUTOMATIC,
333 base::WaitableEvent::InitialState::NOT_SIGNALED); 389 base::WaitableEvent::InitialState::NOT_SIGNALED);
334 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE, 390 BrowserThread::PostTask(BrowserThread::IO, FROM_HERE,
335 base::Bind(&InterstitialPageImplTest::RunTask, this, 391 base::Bind(&InterstitialPageImplTest::RunTask, this,
336 task, &completion)); 392 task, &completion));
337 completion.Wait(); 393 completion.Wait();
338 } 394 }
339 395
340 void RunTask(const base::Closure& task, base::WaitableEvent* completion) { 396 void RunTask(const base::Closure& task, base::WaitableEvent* completion) {
341 task.Run(); 397 task.Run();
342 completion->Signal(); 398 completion->Signal();
343 } 399 }
344 400
345 std::unique_ptr<InterstitialPageImpl> interstitial_; 401 std::unique_ptr<InterstitialPageImpl> interstitial_;
346 scoped_refptr<ClipboardMessageWatcher> clipboard_message_watcher_; 402 scoped_refptr<ClipboardMessageWatcher> clipboard_message_watcher_;
347 scoped_refptr<InterstitialTitleUpdateWatcher> title_update_watcher_; 403 scoped_refptr<InterstitialTitleUpdateWatcher> title_update_watcher_;
404 std::unique_ptr<WebContentsTitleWatcher> web_contents_title_watcher_;
348 405
349 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImplTest); 406 DISALLOW_COPY_AND_ASSIGN(InterstitialPageImplTest);
350 }; 407 };
351 408
352 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, Cut) { 409 IN_PROC_BROWSER_TEST_F(InterstitialPageImplTest, Cut) {
353 SetUpInterstitialPage(); 410 SetUpInterstitialPage();
354 411
355 ASSERT_TRUE(CreateInputAndSetText("text-to-cut")); 412 ASSERT_TRUE(CreateInputAndSetText("text-to-cut"));
356 ASSERT_TRUE(FocusInputAndSelectText()); 413 ASSERT_TRUE(FocusInputAndSelectText());
357 414
(...skipping 52 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 467
411 PerformSelectAll(); 468 PerformSelectAll();
412 469
413 ASSERT_TRUE(GetSelection(&input_text)); 470 ASSERT_TRUE(GetSelection(&input_text));
414 EXPECT_EQ("original body text", input_text); 471 EXPECT_EQ("original body text", input_text);
415 472
416 TearDownInterstitialPage(); 473 TearDownInterstitialPage();
417 } 474 }
418 475
419 } // namespace content 476 } // namespace content
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698