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

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

Issue 829263004: Add WaitForInterstitialReady to browser_test_utils. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: mattm comments, fix test Created 5 years, 11 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 "base/bind.h" 7 #include "base/bind.h"
8 #include "base/command_line.h" 8 #include "base/command_line.h"
9 #include "base/json/json_reader.h" 9 #include "base/json/json_reader.h"
10 #include "base/process/kill.h" 10 #include "base/process/kill.h"
11 #include "base/rand_util.h" 11 #include "base/rand_util.h"
12 #include "base/strings/string_number_conversions.h" 12 #include "base/strings/string_number_conversions.h"
13 #include "base/strings/utf_string_conversions.h" 13 #include "base/strings/utf_string_conversions.h"
14 #include "base/synchronization/waitable_event.h" 14 #include "base/synchronization/waitable_event.h"
15 #include "base/test/test_timeouts.h" 15 #include "base/test/test_timeouts.h"
16 #include "base/values.h" 16 #include "base/values.h"
17 #include "content/browser/renderer_host/render_widget_host_impl.h" 17 #include "content/browser/renderer_host/render_widget_host_impl.h"
18 #include "content/browser/web_contents/web_contents_impl.h" 18 #include "content/browser/web_contents/web_contents_impl.h"
19 #include "content/browser/web_contents/web_contents_view.h" 19 #include "content/browser/web_contents/web_contents_view.h"
20 #include "content/common/input/synthetic_web_input_event_builders.h" 20 #include "content/common/input/synthetic_web_input_event_builders.h"
21 #include "content/public/browser/browser_context.h" 21 #include "content/public/browser/browser_context.h"
22 #include "content/public/browser/dom_operation_notification_details.h" 22 #include "content/public/browser/dom_operation_notification_details.h"
23 #include "content/public/browser/histogram_fetcher.h" 23 #include "content/public/browser/histogram_fetcher.h"
24 #include "content/public/browser/interstitial_page.h"
mattm 2015/01/22 04:51:27 no longer needed
meacer 2015/01/22 18:31:37 Done.
24 #include "content/public/browser/navigation_entry.h" 25 #include "content/public/browser/navigation_entry.h"
25 #include "content/public/browser/notification_service.h" 26 #include "content/public/browser/notification_service.h"
26 #include "content/public/browser/notification_types.h" 27 #include "content/public/browser/notification_types.h"
27 #include "content/public/browser/render_frame_host.h" 28 #include "content/public/browser/render_frame_host.h"
28 #include "content/public/browser/render_process_host.h" 29 #include "content/public/browser/render_process_host.h"
29 #include "content/public/browser/render_view_host.h" 30 #include "content/public/browser/render_view_host.h"
30 #include "content/public/browser/web_contents.h" 31 #include "content/public/browser/web_contents.h"
31 #include "content/public/browser/web_contents_observer.h" 32 #include "content/public/browser/web_contents_observer.h"
32 #include "content/public/test/test_utils.h" 33 #include "content/public/test/test_utils.h"
33 #include "net/base/filename_util.h" 34 #include "net/base/filename_util.h"
(...skipping 682 matching lines...) Expand 10 before | Expand all | Expand 10 after
716 new content::MessageLoopRunner); 717 new content::MessageLoopRunner);
717 InterstitialObserver observer(web_contents, 718 InterstitialObserver observer(web_contents,
718 base::Closure(), 719 base::Closure(),
719 loop_runner->QuitClosure()); 720 loop_runner->QuitClosure());
720 if (!task.is_null()) 721 if (!task.is_null())
721 task.Run(); 722 task.Run();
722 // At this point, web_contents may have been deleted. 723 // At this point, web_contents may have been deleted.
723 loop_runner->Run(); 724 loop_runner->Run();
724 } 725 }
725 726
727 bool WaitForRenderFrameReady(RenderFrameHost* rfh) {
728 if (!rfh)
729 return false;
730 std::string result;
731 EXPECT_TRUE(
732 content::ExecuteScriptAndExtractString(
733 rfh,
734 "(function() {"
735 " var done = false;"
736 " function checkState() {"
737 " if (!done && document.readyState == 'complete') {"
738 " done = true;"
739 " window.domAutomationController.send('pageLoadComplete');"
740 " }"
741 " }"
742 " checkState();"
743 " document.addEventListener('readystatechange', checkState);"
Paweł Hajdan Jr. 2015/01/22 15:43:10 I might be wrong (not a JS/DOM expert), but should
mmenke 2015/01/22 15:53:25 Javascript and the DOM are essentially single-thre
mmenke 2015/01/22 15:55:00 That is, they can't change except as a result of a
744 "})();",
745 &result));
746 return result == "pageLoadComplete";
747 }
748
726 TitleWatcher::TitleWatcher(WebContents* web_contents, 749 TitleWatcher::TitleWatcher(WebContents* web_contents,
727 const base::string16& expected_title) 750 const base::string16& expected_title)
728 : WebContentsObserver(web_contents), 751 : WebContentsObserver(web_contents),
729 message_loop_runner_(new MessageLoopRunner) { 752 message_loop_runner_(new MessageLoopRunner) {
730 EXPECT_TRUE(web_contents != NULL); 753 EXPECT_TRUE(web_contents != NULL);
731 expected_titles_.push_back(expected_title); 754 expected_titles_.push_back(expected_title);
732 } 755 }
733 756
734 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) { 757 void TitleWatcher::AlsoWaitForTitle(const base::string16& expected_title) {
735 expected_titles_.push_back(expected_title); 758 expected_titles_.push_back(expected_title);
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
917 940
918 bool WebContentsAddedObserver::RenderViewCreatedCalled() { 941 bool WebContentsAddedObserver::RenderViewCreatedCalled() {
919 if (child_observer_) { 942 if (child_observer_) {
920 return child_observer_->render_view_created_called_ && 943 return child_observer_->render_view_created_called_ &&
921 child_observer_->main_frame_created_called_; 944 child_observer_->main_frame_created_called_;
922 } 945 }
923 return false; 946 return false;
924 } 947 }
925 948
926 } // namespace content 949 } // namespace content
OLDNEW
« content/public/test/browser_test_utils.h ('K') | « content/public/test/browser_test_utils.h ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698