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

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 10807047: Create content\public\test\test_utils.h to hold common test classes that are used by unit and brows… (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/perf/rendering/throughput_tests.cc » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "chrome/test/base/ui_test_utils.h" 5 #include "chrome/test/base/ui_test_utils.h"
6 6
7 #if defined(OS_WIN) 7 #if defined(OS_WIN)
8 #include <windows.h> 8 #include <windows.h>
9 #endif 9 #endif
10 10
(...skipping 47 matching lines...) Expand 10 before | Expand all | Expand 10 after
58 #include "content/public/browser/navigation_entry.h" 58 #include "content/public/browser/navigation_entry.h"
59 #include "content/public/browser/notification_service.h" 59 #include "content/public/browser/notification_service.h"
60 #include "content/public/browser/render_process_host.h" 60 #include "content/public/browser/render_process_host.h"
61 #include "content/public/browser/render_view_host.h" 61 #include "content/public/browser/render_view_host.h"
62 #include "content/public/browser/web_contents.h" 62 #include "content/public/browser/web_contents.h"
63 #include "content/public/browser/web_contents_observer.h" 63 #include "content/public/browser/web_contents_observer.h"
64 #include "content/public/browser/web_contents_view.h" 64 #include "content/public/browser/web_contents_view.h"
65 #include "content/public/common/geoposition.h" 65 #include "content/public/common/geoposition.h"
66 #include "content/public/test/browser_test_utils.h" 66 #include "content/public/test/browser_test_utils.h"
67 #include "content/public/test/test_navigation_observer.h" 67 #include "content/public/test/test_navigation_observer.h"
68 #include "content/public/test/test_utils.h"
68 #include "googleurl/src/gurl.h" 69 #include "googleurl/src/gurl.h"
69 #include "net/base/net_util.h" 70 #include "net/base/net_util.h"
70 #include "net/test/python_utils.h" 71 #include "net/test/python_utils.h"
71 #include "testing/gtest/include/gtest/gtest.h" 72 #include "testing/gtest/include/gtest/gtest.h"
72 #include "third_party/skia/include/core/SkBitmap.h" 73 #include "third_party/skia/include/core/SkBitmap.h"
73 #include "third_party/skia/include/core/SkColor.h" 74 #include "third_party/skia/include/core/SkColor.h"
74 #include "ui/gfx/size.h" 75 #include "ui/gfx/size.h"
75 #include "ui/ui_controls/ui_controls.h" 76 #include "ui/ui_controls/ui_controls.h"
76 77
77 #if defined(USE_AURA) 78 #if defined(USE_AURA)
(...skipping 19 matching lines...) Expand all
97 98
98 class DOMOperationObserver : public content::NotificationObserver, 99 class DOMOperationObserver : public content::NotificationObserver,
99 public content::WebContentsObserver { 100 public content::WebContentsObserver {
100 public: 101 public:
101 explicit DOMOperationObserver(RenderViewHost* render_view_host) 102 explicit DOMOperationObserver(RenderViewHost* render_view_host)
102 : content::WebContentsObserver( 103 : content::WebContentsObserver(
103 WebContents::FromRenderViewHost(render_view_host)), 104 WebContents::FromRenderViewHost(render_view_host)),
104 did_respond_(false) { 105 did_respond_(false) {
105 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE, 106 registrar_.Add(this, content::NOTIFICATION_DOM_OPERATION_RESPONSE,
106 content::Source<RenderViewHost>(render_view_host)); 107 content::Source<RenderViewHost>(render_view_host));
107 message_loop_runner_ = new MessageLoopRunner; 108 message_loop_runner_ = new content::MessageLoopRunner;
108 } 109 }
109 110
110 virtual void Observe(int type, 111 virtual void Observe(int type,
111 const content::NotificationSource& source, 112 const content::NotificationSource& source,
112 const content::NotificationDetails& details) OVERRIDE { 113 const content::NotificationDetails& details) OVERRIDE {
113 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE); 114 DCHECK(type == content::NOTIFICATION_DOM_OPERATION_RESPONSE);
114 content::Details<DomOperationNotificationDetails> dom_op_details(details); 115 content::Details<DomOperationNotificationDetails> dom_op_details(details);
115 response_ = dom_op_details->json; 116 response_ = dom_op_details->json;
116 did_respond_ = true; 117 did_respond_ = true;
117 message_loop_runner_->Quit(); 118 message_loop_runner_->Quit();
118 } 119 }
119 120
120 // Overridden from content::WebContentsObserver: 121 // Overridden from content::WebContentsObserver:
121 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE { 122 virtual void RenderViewGone(base::TerminationStatus status) OVERRIDE {
122 message_loop_runner_->Quit(); 123 message_loop_runner_->Quit();
123 } 124 }
124 125
125 bool WaitAndGetResponse(std::string* response) WARN_UNUSED_RESULT { 126 bool WaitAndGetResponse(std::string* response) WARN_UNUSED_RESULT {
126 message_loop_runner_->Run(); 127 message_loop_runner_->Run();
127 *response = response_; 128 *response = response_;
128 return did_respond_; 129 return did_respond_;
129 } 130 }
130 131
131 private: 132 private:
132 content::NotificationRegistrar registrar_; 133 content::NotificationRegistrar registrar_;
133 std::string response_; 134 std::string response_;
134 bool did_respond_; 135 bool did_respond_;
135 scoped_refptr<MessageLoopRunner> message_loop_runner_; 136 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
136 137
137 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); 138 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
138 }; 139 };
139 140
140 class FindInPageNotificationObserver : public content::NotificationObserver { 141 class FindInPageNotificationObserver : public content::NotificationObserver {
141 public: 142 public:
142 explicit FindInPageNotificationObserver(TabContents* parent_tab) 143 explicit FindInPageNotificationObserver(TabContents* parent_tab)
143 : parent_tab_(parent_tab), 144 : parent_tab_(parent_tab),
144 active_match_ordinal_(-1), 145 active_match_ordinal_(-1),
145 number_of_matches_(0) { 146 number_of_matches_(0) {
146 current_find_request_id_ = 147 current_find_request_id_ =
147 parent_tab->find_tab_helper()->current_find_request_id(); 148 parent_tab->find_tab_helper()->current_find_request_id();
148 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE, 149 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE,
149 content::Source<WebContents>(parent_tab_->web_contents())); 150 content::Source<WebContents>(parent_tab_->web_contents()));
150 message_loop_runner_ = new MessageLoopRunner; 151 message_loop_runner_ = new content::MessageLoopRunner;
151 message_loop_runner_->Run(); 152 message_loop_runner_->Run();
152 } 153 }
153 154
154 int active_match_ordinal() const { return active_match_ordinal_; } 155 int active_match_ordinal() const { return active_match_ordinal_; }
155 156
156 int number_of_matches() const { return number_of_matches_; } 157 int number_of_matches() const { return number_of_matches_; }
157 158
158 virtual void Observe(int type, const content::NotificationSource& source, 159 virtual void Observe(int type, const content::NotificationSource& source,
159 const content::NotificationDetails& details) { 160 const content::NotificationDetails& details) {
160 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) { 161 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) {
(...skipping 18 matching lines...) Expand all
179 private: 180 private:
180 content::NotificationRegistrar registrar_; 181 content::NotificationRegistrar registrar_;
181 TabContents* parent_tab_; 182 TabContents* parent_tab_;
182 // We will at some point (before final update) be notified of the ordinal and 183 // We will at some point (before final update) be notified of the ordinal and
183 // we need to preserve it so we can send it later. 184 // we need to preserve it so we can send it later.
184 int active_match_ordinal_; 185 int active_match_ordinal_;
185 int number_of_matches_; 186 int number_of_matches_;
186 // The id of the current find request, obtained from WebContents. Allows us 187 // The id of the current find request, obtained from WebContents. Allows us
187 // to monitor when the search completes. 188 // to monitor when the search completes.
188 int current_find_request_id_; 189 int current_find_request_id_;
189 scoped_refptr<MessageLoopRunner> message_loop_runner_; 190 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
190 191
191 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver); 192 DISALLOW_COPY_AND_ASSIGN(FindInPageNotificationObserver);
192 }; 193 };
193 194
194 class InProcessJavaScriptExecutionController 195 class InProcessJavaScriptExecutionController
195 : public base::RefCounted<InProcessJavaScriptExecutionController>, 196 : public base::RefCounted<InProcessJavaScriptExecutionController>,
196 public JavaScriptExecutionController { 197 public JavaScriptExecutionController {
197 public: 198 public:
198 explicit InProcessJavaScriptExecutionController( 199 explicit InProcessJavaScriptExecutionController(
199 RenderViewHost* render_view_host) 200 RenderViewHost* render_view_host)
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
320 content::TestNavigationObserver observer( 321 content::TestNavigationObserver observer(
321 content::Source<NavigationController>(controller), NULL, 322 content::Source<NavigationController>(controller), NULL,
322 number_of_navigations); 323 number_of_navigations);
323 base::RunLoop run_loop; 324 base::RunLoop run_loop;
324 observer.WaitForObservation( 325 observer.WaitForObservation(
325 base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)), 326 base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)),
326 content::GetQuitTaskForRunLoop(&run_loop)); 327 content::GetQuitTaskForRunLoop(&run_loop));
327 } 328 }
328 329
329 void WaitForNewTab(Browser* browser) { 330 void WaitForNewTab(Browser* browser) {
330 WindowedNotificationObserver observer( 331 content::WindowedNotificationObserver observer(
331 chrome::NOTIFICATION_TAB_ADDED, 332 chrome::NOTIFICATION_TAB_ADDED,
332 content::Source<content::WebContentsDelegate>(browser)); 333 content::Source<content::WebContentsDelegate>(browser));
333 observer.Wait(); 334 observer.Wait();
334 } 335 }
335 336
336 void WaitForLoadStop(WebContents* tab) { 337 void WaitForLoadStop(WebContents* tab) {
337 WindowedNotificationObserver load_stop_observer( 338 content::WindowedNotificationObserver load_stop_observer(
338 content::NOTIFICATION_LOAD_STOP, 339 content::NOTIFICATION_LOAD_STOP,
339 content::Source<NavigationController>(&tab->GetController())); 340 content::Source<NavigationController>(&tab->GetController()));
340 // In many cases, the load may have finished before we get here. Only wait if 341 // In many cases, the load may have finished before we get here. Only wait if
341 // the tab still has a pending navigation. 342 // the tab still has a pending navigation.
342 if (!tab->IsLoading()) 343 if (!tab->IsLoading())
343 return; 344 return;
344 load_stop_observer.Wait(); 345 load_stop_observer.Wait();
345 } 346 }
346 347
347 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { 348 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after
399 NULL, 400 NULL,
400 number_of_navigations); 401 number_of_navigations);
401 402
402 std::set<Browser*> initial_browsers; 403 std::set<Browser*> initial_browsers;
403 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); 404 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
404 iter != BrowserList::end(); 405 iter != BrowserList::end();
405 ++iter) { 406 ++iter) {
406 initial_browsers.insert(*iter); 407 initial_browsers.insert(*iter);
407 } 408 }
408 409
409 WindowedNotificationObserver tab_added_observer( 410 content::WindowedNotificationObserver tab_added_observer(
410 chrome::NOTIFICATION_TAB_ADDED, 411 chrome::NOTIFICATION_TAB_ADDED,
411 content::NotificationService::AllSources()); 412 content::NotificationService::AllSources());
412 413
413 WindowedNotificationObserver auth_observer( 414 content::WindowedNotificationObserver auth_observer(
414 chrome::NOTIFICATION_AUTH_NEEDED, 415 chrome::NOTIFICATION_AUTH_NEEDED,
415 content::NotificationService::AllSources()); 416 content::NotificationService::AllSources());
416 417
417 browser->OpenURL(OpenURLParams( 418 browser->OpenURL(OpenURLParams(
418 url, Referrer(), disposition, content::PAGE_TRANSITION_TYPED, false)); 419 url, Referrer(), disposition, content::PAGE_TRANSITION_TYPED, false));
419 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) 420 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
420 browser = WaitForBrowserNotInSet(initial_browsers); 421 browser = WaitForBrowserNotInSet(initial_browsers);
421 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) 422 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
422 tab_added_observer.Wait(); 423 tab_added_observer.Wait();
423 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_AUTH) 424 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_AUTH)
(...skipping 127 matching lines...) Expand 10 before | Expand all | Expand 10 after
551 GURL url = net::FilePathToFileURL(path); 552 GURL url = net::FilePathToFileURL(path);
552 if (!query_string.empty()) { 553 if (!query_string.empty()) {
553 GURL::Replacements replacements; 554 GURL::Replacements replacements;
554 replacements.SetQueryStr(query_string); 555 replacements.SetQueryStr(query_string);
555 return url.ReplaceComponents(replacements); 556 return url.ReplaceComponents(replacements);
556 } 557 }
557 return url; 558 return url;
558 } 559 }
559 560
560 AppModalDialog* WaitForAppModalDialog() { 561 AppModalDialog* WaitForAppModalDialog() {
561 WindowedNotificationObserver observer( 562 content::WindowedNotificationObserver observer(
562 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 563 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
563 content::NotificationService::AllSources()); 564 content::NotificationService::AllSources());
564 observer.Wait(); 565 observer.Wait();
565 return content::Source<AppModalDialog>(observer.source()).ptr(); 566 return content::Source<AppModalDialog>(observer.source()).ptr();
566 } 567 }
567 568
568 void WaitForAppModalDialogAndCloseIt() { 569 void WaitForAppModalDialogAndCloseIt() {
569 AppModalDialog* dialog = WaitForAppModalDialog(); 570 AppModalDialog* dialog = WaitForAppModalDialog();
570 dialog->CloseModalDialog(); 571 dialog->CloseModalDialog();
571 } 572 }
572 573
573 void CrashTab(WebContents* tab) { 574 void CrashTab(WebContents* tab) {
574 content::RenderProcessHost* rph = tab->GetRenderProcessHost(); 575 content::RenderProcessHost* rph = tab->GetRenderProcessHost();
575 WindowedNotificationObserver observer( 576 content::WindowedNotificationObserver observer(
576 content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 577 content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
577 content::Source<content::RenderProcessHost>(rph)); 578 content::Source<content::RenderProcessHost>(rph));
578 base::KillProcess(rph->GetHandle(), 0, false); 579 base::KillProcess(rph->GetHandle(), 0, false);
579 observer.Wait(); 580 observer.Wait();
580 } 581 }
581 582
582 int FindInPage(TabContents* tab_contents, const string16& search_string, 583 int FindInPage(TabContents* tab_contents, const string16& search_string,
583 bool forward, bool match_case, int* ordinal) { 584 bool forward, bool match_case, int* ordinal) {
584 tab_contents-> 585 tab_contents->
585 find_tab_helper()->StartFinding(search_string, forward, match_case); 586 find_tab_helper()->StartFinding(search_string, forward, match_case);
(...skipping 119 matching lines...) Expand 10 before | Expand all | Expand 10 after
705 706
706 void WaitForTemplateURLServiceToLoad(TemplateURLService* service) { 707 void WaitForTemplateURLServiceToLoad(TemplateURLService* service) {
707 if (service->loaded()) 708 if (service->loaded())
708 return; 709 return;
709 service->Load(); 710 service->Load();
710 TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests(); 711 TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
711 ASSERT_TRUE(service->loaded()); 712 ASSERT_TRUE(service->loaded());
712 } 713 }
713 714
714 void WaitForHistoryToLoad(HistoryService* history_service) { 715 void WaitForHistoryToLoad(HistoryService* history_service) {
715 WindowedNotificationObserver history_loaded_observer( 716 content::WindowedNotificationObserver history_loaded_observer(
716 chrome::NOTIFICATION_HISTORY_LOADED, 717 chrome::NOTIFICATION_HISTORY_LOADED,
717 content::NotificationService::AllSources()); 718 content::NotificationService::AllSources());
718 if (!history_service->BackendLoaded()) 719 if (!history_service->BackendLoaded())
719 history_loaded_observer.Wait(); 720 history_loaded_observer.Wait();
720 } 721 }
721 722
722 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { 723 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
723 BrowserWindow* window = browser->window(); 724 BrowserWindow* window = browser->window();
724 if (!window) 725 if (!window)
725 return false; 726 return false;
(...skipping 23 matching lines...) Expand all
749 750
750 bool SendKeyPressSync(const Browser* browser, 751 bool SendKeyPressSync(const Browser* browser,
751 ui::KeyboardCode key, 752 ui::KeyboardCode key,
752 bool control, 753 bool control,
753 bool shift, 754 bool shift,
754 bool alt, 755 bool alt,
755 bool command) { 756 bool command) {
756 gfx::NativeWindow window = NULL; 757 gfx::NativeWindow window = NULL;
757 if (!GetNativeWindow(browser, &window)) 758 if (!GetNativeWindow(browser, &window))
758 return false; 759 return false;
759 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; 760 scoped_refptr<content::MessageLoopRunner> runner =
761 new content::MessageLoopRunner;
760 bool result; 762 bool result;
761 result = ui_controls::SendKeyPressNotifyWhenDone( 763 result = ui_controls::SendKeyPressNotifyWhenDone(
762 window, key, control, shift, alt, command, runner->QuitClosure()); 764 window, key, control, shift, alt, command, runner->QuitClosure());
763 #if defined(OS_WIN) 765 #if defined(OS_WIN)
764 if (!result && BringBrowserWindowToFront(browser)) { 766 if (!result && BringBrowserWindowToFront(browser)) {
765 result = ui_controls::SendKeyPressNotifyWhenDone( 767 result = ui_controls::SendKeyPressNotifyWhenDone(
766 window, key, control, shift, alt, command, runner->QuitClosure()); 768 window, key, control, shift, alt, command, runner->QuitClosure());
767 } 769 }
768 #endif 770 #endif
769 if (!result) { 771 if (!result) {
770 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed"; 772 LOG(ERROR) << "ui_controls::SendKeyPressNotifyWhenDone failed";
771 return false; 773 return false;
772 } 774 }
773 775
774 // Run the message loop. It'll stop running when either the key was received 776 // Run the message loop. It'll stop running when either the key was received
775 // or the test timed out (in which case testing::Test::HasFatalFailure should 777 // or the test timed out (in which case testing::Test::HasFatalFailure should
776 // be set). 778 // be set).
777 runner->Run(); 779 runner->Run();
778 return !testing::Test::HasFatalFailure(); 780 return !testing::Test::HasFatalFailure();
779 } 781 }
780 782
781 bool SendKeyPressAndWait(const Browser* browser, 783 bool SendKeyPressAndWait(const Browser* browser,
782 ui::KeyboardCode key, 784 ui::KeyboardCode key,
783 bool control, 785 bool control,
784 bool shift, 786 bool shift,
785 bool alt, 787 bool alt,
786 bool command, 788 bool command,
787 int type, 789 int type,
788 const content::NotificationSource& source) { 790 const content::NotificationSource& source) {
789 WindowedNotificationObserver observer(type, source); 791 content::WindowedNotificationObserver observer(type, source);
790 792
791 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) 793 if (!SendKeyPressSync(browser, key, control, shift, alt, command))
792 return false; 794 return false;
793 795
794 observer.Wait(); 796 observer.Wait();
795 return !testing::Test::HasFatalFailure(); 797 return !testing::Test::HasFatalFailure();
796 } 798 }
797 799
798 bool SendMouseMoveSync(const gfx::Point& location) { 800 bool SendMouseMoveSync(const gfx::Point& location) {
799 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; 801 scoped_refptr<content::MessageLoopRunner> runner =
802 new content::MessageLoopRunner;
800 if (!ui_controls::SendMouseMoveNotifyWhenDone( 803 if (!ui_controls::SendMouseMoveNotifyWhenDone(
801 location.x(), location.y(), runner->QuitClosure())) { 804 location.x(), location.y(), runner->QuitClosure())) {
802 return false; 805 return false;
803 } 806 }
804 runner->Run(); 807 runner->Run();
805 return !testing::Test::HasFatalFailure(); 808 return !testing::Test::HasFatalFailure();
806 } 809 }
807 810
808 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) { 811 bool SendMouseEventsSync(ui_controls::MouseButton type, int state) {
809 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; 812 scoped_refptr<content::MessageLoopRunner> runner =
813 new content::MessageLoopRunner;
810 if (!ui_controls::SendMouseEventsNotifyWhenDone( 814 if (!ui_controls::SendMouseEventsNotifyWhenDone(
811 type, state, runner->QuitClosure())) { 815 type, state, runner->QuitClosure())) {
812 return false; 816 return false;
813 } 817 }
814 runner->Run(); 818 runner->Run();
815 return !testing::Test::HasFatalFailure(); 819 return !testing::Test::HasFatalFailure();
816 } 820 }
817 821
818 MessageLoopRunner::MessageLoopRunner() {
819 }
820
821 MessageLoopRunner::~MessageLoopRunner() {
822 }
823
824 void MessageLoopRunner::Run() {
825 content::RunThisRunLoop(&run_loop_);
826 }
827
828 base::Closure MessageLoopRunner::QuitClosure() {
829 return base::Bind(&MessageLoopRunner::Quit, this);
830 }
831
832 void MessageLoopRunner::Quit() {
833 content::GetQuitTaskForRunLoop(&run_loop_).Run();
834 }
835
836 TestWebSocketServer::TestWebSocketServer() 822 TestWebSocketServer::TestWebSocketServer()
837 : started_(false), 823 : started_(false),
838 port_(kDefaultWsPort), 824 port_(kDefaultWsPort),
839 secure_(false) { 825 secure_(false) {
840 #if defined(OS_POSIX) 826 #if defined(OS_POSIX)
841 process_group_id_ = base::kNullProcessHandle; 827 process_group_id_ = base::kNullProcessHandle;
842 #endif 828 #endif
843 } 829 }
844 830
845 int TestWebSocketServer::UseRandomPort() { 831 int TestWebSocketServer::UseRandomPort() {
(...skipping 126 matching lines...) Expand 10 before | Expand all | Expand 10 after
972 options.wait = true; 958 options.wait = true;
973 base::LaunchProcess(*cmd_line.get(), options, NULL); 959 base::LaunchProcess(*cmd_line.get(), options, NULL);
974 960
975 #if defined(OS_POSIX) 961 #if defined(OS_POSIX)
976 // Just to make sure that the server process terminates certainly. 962 // Just to make sure that the server process terminates certainly.
977 if (process_group_id_ != base::kNullProcessHandle) 963 if (process_group_id_ != base::kNullProcessHandle)
978 base::KillProcessGroup(process_group_id_); 964 base::KillProcessGroup(process_group_id_);
979 #endif 965 #endif
980 } 966 }
981 967
982 WindowedNotificationObserver::WindowedNotificationObserver(
983 int notification_type,
984 const content::NotificationSource& source)
985 : seen_(false),
986 running_(false),
987 source_(content::NotificationService::AllSources()) {
988 registrar_.Add(this, notification_type, source);
989 }
990
991 WindowedNotificationObserver::~WindowedNotificationObserver() {}
992
993 void WindowedNotificationObserver::Wait() {
994 if (seen_)
995 return;
996
997 running_ = true;
998 message_loop_runner_ = new MessageLoopRunner;
999 message_loop_runner_->Run();
1000 EXPECT_TRUE(seen_);
1001 }
1002
1003 void WindowedNotificationObserver::Observe(
1004 int type,
1005 const content::NotificationSource& source,
1006 const content::NotificationDetails& details) {
1007 source_ = source;
1008 details_ = details;
1009 seen_ = true;
1010 if (!running_)
1011 return;
1012
1013 message_loop_runner_->Quit();
1014 running_ = false;
1015 }
1016
1017 WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver( 968 WindowedTabAddedNotificationObserver::WindowedTabAddedNotificationObserver(
1018 const content::NotificationSource& source) 969 const content::NotificationSource& source)
1019 : WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source), 970 : WindowedNotificationObserver(chrome::NOTIFICATION_TAB_ADDED, source),
1020 added_tab_(NULL) { 971 added_tab_(NULL) {
1021 } 972 }
1022 973
1023 void WindowedTabAddedNotificationObserver::Observe( 974 void WindowedTabAddedNotificationObserver::Observe(
1024 int type, 975 int type,
1025 const content::NotificationSource& source, 976 const content::NotificationSource& source,
1026 const content::NotificationDetails& details) { 977 const content::NotificationDetails& details) {
1027 added_tab_ = content::Details<content::WebContents>(details).ptr(); 978 added_tab_ = content::Details<WebContents>(details).ptr();
1028 WindowedNotificationObserver::Observe(type, source, details); 979 content::WindowedNotificationObserver::Observe(type, source, details);
1029 } 980 }
1030 981
1031 TitleWatcher::TitleWatcher(WebContents* web_contents, 982 TitleWatcher::TitleWatcher(WebContents* web_contents,
1032 const string16& expected_title) 983 const string16& expected_title)
1033 : web_contents_(web_contents), 984 : web_contents_(web_contents),
1034 expected_title_observed_(false), 985 expected_title_observed_(false),
1035 quit_loop_on_observation_(false) { 986 quit_loop_on_observation_(false) {
1036 EXPECT_TRUE(web_contents != NULL); 987 EXPECT_TRUE(web_contents != NULL);
1037 expected_titles_.push_back(expected_title); 988 expected_titles_.push_back(expected_title);
1038 notification_registrar_.Add(this, 989 notification_registrar_.Add(this,
(...skipping 15 matching lines...) Expand all
1054 expected_titles_.push_back(expected_title); 1005 expected_titles_.push_back(expected_title);
1055 } 1006 }
1056 1007
1057 TitleWatcher::~TitleWatcher() { 1008 TitleWatcher::~TitleWatcher() {
1058 } 1009 }
1059 1010
1060 const string16& TitleWatcher::WaitAndGetTitle() { 1011 const string16& TitleWatcher::WaitAndGetTitle() {
1061 if (expected_title_observed_) 1012 if (expected_title_observed_)
1062 return observed_title_; 1013 return observed_title_;
1063 quit_loop_on_observation_ = true; 1014 quit_loop_on_observation_ = true;
1064 message_loop_runner_ = new MessageLoopRunner; 1015 message_loop_runner_ = new content::MessageLoopRunner;
1065 message_loop_runner_->Run(); 1016 message_loop_runner_->Run();
1066 return observed_title_; 1017 return observed_title_;
1067 } 1018 }
1068 1019
1069 void TitleWatcher::Observe(int type, 1020 void TitleWatcher::Observe(int type,
1070 const content::NotificationSource& source, 1021 const content::NotificationSource& source,
1071 const content::NotificationDetails& details) { 1022 const content::NotificationDetails& details) {
1072 if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { 1023 if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) {
1073 WebContents* source_contents = content::Source<WebContents>(source).ptr(); 1024 WebContents* source_contents = content::Source<WebContents>(source).ptr();
1074 ASSERT_EQ(web_contents_, source_contents); 1025 ASSERT_EQ(web_contents_, source_contents);
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
1132 } 1083 }
1133 1084
1134 void DOMMessageQueue::ClearQueue() { 1085 void DOMMessageQueue::ClearQueue() {
1135 message_queue_ = std::queue<std::string>(); 1086 message_queue_ = std::queue<std::string>();
1136 } 1087 }
1137 1088
1138 bool DOMMessageQueue::WaitForMessage(std::string* message) { 1089 bool DOMMessageQueue::WaitForMessage(std::string* message) {
1139 if (message_queue_.empty()) { 1090 if (message_queue_.empty()) {
1140 waiting_for_message_ = true; 1091 waiting_for_message_ = true;
1141 // This will be quit when a new message comes in. 1092 // This will be quit when a new message comes in.
1142 message_loop_runner_ = new MessageLoopRunner; 1093 message_loop_runner_ = new content::MessageLoopRunner;
1143 message_loop_runner_->Run(); 1094 message_loop_runner_->Run();
1144 } 1095 }
1145 // The queue should not be empty, unless we were quit because of a timeout. 1096 // The queue should not be empty, unless we were quit because of a timeout.
1146 if (message_queue_.empty()) 1097 if (message_queue_.empty())
1147 return false; 1098 return false;
1148 if (message) 1099 if (message)
1149 *message = message_queue_.front(); 1100 *message = message_queue_.front();
1150 return true; 1101 return true;
1151 } 1102 }
1152 1103
1153 // Coordinates taking snapshots of a |RenderWidget|. 1104 // Coordinates taking snapshots of a |RenderWidget|.
1154 class SnapshotTaker { 1105 class SnapshotTaker {
1155 public: 1106 public:
1156 SnapshotTaker() : bitmap_(NULL) {} 1107 SnapshotTaker() : bitmap_(NULL) {}
1157 1108
1158 bool TakeRenderWidgetSnapshot(RenderWidgetHost* rwh, 1109 bool TakeRenderWidgetSnapshot(RenderWidgetHost* rwh,
1159 const gfx::Size& page_size, 1110 const gfx::Size& page_size,
1160 const gfx::Size& desired_size, 1111 const gfx::Size& desired_size,
1161 SkBitmap* bitmap) WARN_UNUSED_RESULT { 1112 SkBitmap* bitmap) WARN_UNUSED_RESULT {
1162 bitmap_ = bitmap; 1113 bitmap_ = bitmap;
1163 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator(); 1114 ThumbnailGenerator* generator = g_browser_process->GetThumbnailGenerator();
1164 generator->MonitorRenderer(rwh, true); 1115 generator->MonitorRenderer(rwh, true);
1165 snapshot_taken_ = false; 1116 snapshot_taken_ = false;
1166 generator->AskForSnapshot( 1117 generator->AskForSnapshot(
1167 rwh, 1118 rwh,
1168 base::Bind(&SnapshotTaker::OnSnapshotTaken, base::Unretained(this)), 1119 base::Bind(&SnapshotTaker::OnSnapshotTaken, base::Unretained(this)),
1169 page_size, 1120 page_size,
1170 desired_size); 1121 desired_size);
1171 message_loop_runner_ = new MessageLoopRunner; 1122 message_loop_runner_ = new content::MessageLoopRunner;
1172 message_loop_runner_->Run(); 1123 message_loop_runner_->Run();
1173 return snapshot_taken_; 1124 return snapshot_taken_;
1174 } 1125 }
1175 1126
1176 bool TakeEntirePageSnapshot(RenderViewHost* rvh, 1127 bool TakeEntirePageSnapshot(RenderViewHost* rvh,
1177 SkBitmap* bitmap) WARN_UNUSED_RESULT { 1128 SkBitmap* bitmap) WARN_UNUSED_RESULT {
1178 const wchar_t* script = 1129 const wchar_t* script =
1179 L"window.domAutomationController.send(" 1130 L"window.domAutomationController.send("
1180 L" JSON.stringify([document.width, document.height]))"; 1131 L" JSON.stringify([document.width, document.height]))";
1181 std::string json; 1132 std::string json;
(...skipping 22 matching lines...) Expand all
1204 void OnSnapshotTaken(const SkBitmap& bitmap) { 1155 void OnSnapshotTaken(const SkBitmap& bitmap) {
1205 *bitmap_ = bitmap; 1156 *bitmap_ = bitmap;
1206 snapshot_taken_ = true; 1157 snapshot_taken_ = true;
1207 message_loop_runner_->Quit(); 1158 message_loop_runner_->Quit();
1208 } 1159 }
1209 1160
1210 SkBitmap* bitmap_; 1161 SkBitmap* bitmap_;
1211 // Whether the snapshot was actually taken and received by this SnapshotTaker. 1162 // Whether the snapshot was actually taken and received by this SnapshotTaker.
1212 // This will be false if the test times out. 1163 // This will be false if the test times out.
1213 bool snapshot_taken_; 1164 bool snapshot_taken_;
1214 scoped_refptr<MessageLoopRunner> message_loop_runner_; 1165 scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
1215 1166
1216 DISALLOW_COPY_AND_ASSIGN(SnapshotTaker); 1167 DISALLOW_COPY_AND_ASSIGN(SnapshotTaker);
1217 }; 1168 };
1218 1169
1219 bool TakeRenderWidgetSnapshot(RenderWidgetHost* rwh, 1170 bool TakeRenderWidgetSnapshot(RenderWidgetHost* rwh,
1220 const gfx::Size& page_size, 1171 const gfx::Size& page_size,
1221 SkBitmap* bitmap) { 1172 SkBitmap* bitmap) {
1222 DCHECK(bitmap); 1173 DCHECK(bitmap);
1223 SnapshotTaker taker; 1174 SnapshotTaker taker;
1224 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 1175 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
1225 } 1176 }
1226 1177
1227 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 1178 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
1228 DCHECK(bitmap); 1179 DCHECK(bitmap);
1229 SnapshotTaker taker; 1180 SnapshotTaker taker;
1230 return taker.TakeEntirePageSnapshot(rvh, bitmap); 1181 return taker.TakeEntirePageSnapshot(rvh, bitmap);
1231 } 1182 }
1232 1183
1233 void OverrideGeolocation(double latitude, double longitude) { 1184 void OverrideGeolocation(double latitude, double longitude) {
1234 content::Geoposition position; 1185 content::Geoposition position;
1235 position.latitude = latitude; 1186 position.latitude = latitude;
1236 position.longitude = longitude; 1187 position.longitude = longitude;
1237 position.altitude = 0.; 1188 position.altitude = 0.;
1238 position.accuracy = 0.; 1189 position.accuracy = 0.;
1239 position.timestamp = base::Time::Now(); 1190 position.timestamp = base::Time::Now();
1240 scoped_refptr<MessageLoopRunner> runner = new MessageLoopRunner; 1191 scoped_refptr<content::MessageLoopRunner> runner =
1192 new content::MessageLoopRunner;
1241 content::OverrideLocationForTesting(position, runner->QuitClosure()); 1193 content::OverrideLocationForTesting(position, runner->QuitClosure());
1242 runner->Run(); 1194 runner->Run();
1243 } 1195 }
1244 1196
1245 namespace internal { 1197 namespace internal {
1246 1198
1247 void ClickTask(ui_controls::MouseButton button, 1199 void ClickTask(ui_controls::MouseButton button,
1248 int state, 1200 int state,
1249 const base::Closure& followup) { 1201 const base::Closure& followup) {
1250 if (!followup.is_null()) 1202 if (!followup.is_null())
1251 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 1203 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
1252 else 1204 else
1253 ui_controls::SendMouseEvents(button, state); 1205 ui_controls::SendMouseEvents(button, state);
1254 } 1206 }
1255 1207
1256 } // namespace internal 1208 } // namespace internal
1257 } // namespace ui_test_utils 1209 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/perf/rendering/throughput_tests.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698