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

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

Issue 8342048: Make NotificationService an interface in the content namespace, and switch callers to use it. Mov... (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: '' Created 9 years, 2 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/reliability/page_load_test.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) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 #include <vector> 7 #include <vector>
8 8
9 #include "base/bind.h" 9 #include "base/bind.h"
10 #include "base/bind_helpers.h" 10 #include "base/bind_helpers.h"
(...skipping 28 matching lines...) Expand all
39 #include "chrome/test/automation/javascript_execution_controller.h" 39 #include "chrome/test/automation/javascript_execution_controller.h"
40 #include "chrome/test/base/bookmark_load_observer.h" 40 #include "chrome/test/base/bookmark_load_observer.h"
41 #include "chrome/test/test_navigation_observer.h" 41 #include "chrome/test/test_navigation_observer.h"
42 #include "content/browser/download/download_item.h" 42 #include "content/browser/download/download_item.h"
43 #include "content/browser/download/download_manager.h" 43 #include "content/browser/download/download_manager.h"
44 #include "content/browser/renderer_host/render_process_host.h" 44 #include "content/browser/renderer_host/render_process_host.h"
45 #include "content/browser/renderer_host/render_view_host.h" 45 #include "content/browser/renderer_host/render_view_host.h"
46 #include "content/browser/tab_contents/navigation_controller.h" 46 #include "content/browser/tab_contents/navigation_controller.h"
47 #include "content/browser/tab_contents/navigation_entry.h" 47 #include "content/browser/tab_contents/navigation_entry.h"
48 #include "content/browser/tab_contents/tab_contents.h" 48 #include "content/browser/tab_contents/tab_contents.h"
49 #include "content/public/browser/notification_service.h"
49 #include "googleurl/src/gurl.h" 50 #include "googleurl/src/gurl.h"
50 #include "net/base/net_util.h" 51 #include "net/base/net_util.h"
51 #include "testing/gtest/include/gtest/gtest.h" 52 #include "testing/gtest/include/gtest/gtest.h"
52 #include "third_party/skia/include/core/SkBitmap.h" 53 #include "third_party/skia/include/core/SkBitmap.h"
53 #include "third_party/skia/include/core/SkColor.h" 54 #include "third_party/skia/include/core/SkColor.h"
54 #include "ui/gfx/size.h" 55 #include "ui/gfx/size.h"
55 56
56 #if defined(TOOLKIT_VIEWS) 57 #if defined(TOOLKIT_VIEWS)
57 #include "views/focus/accelerator_handler.h" 58 #include "views/focus/accelerator_handler.h"
58 #endif 59 #endif
(...skipping 225 matching lines...) Expand 10 before | Expand all | Expand 10 after
284 !tab->render_manager_for_testing()->pending_render_view_host()) 285 !tab->render_manager_for_testing()->pending_render_view_host())
285 return; 286 return;
286 TestNotificationObserver observer; 287 TestNotificationObserver observer;
287 RegisterAndWait(&observer, content::NOTIFICATION_LOAD_STOP, 288 RegisterAndWait(&observer, content::NOTIFICATION_LOAD_STOP,
288 content::Source<NavigationController>(&tab->controller())); 289 content::Source<NavigationController>(&tab->controller()));
289 } 290 }
290 291
291 Browser* WaitForNewBrowser() { 292 Browser* WaitForNewBrowser() {
292 TestNotificationObserver observer; 293 TestNotificationObserver observer;
293 RegisterAndWait(&observer, chrome::NOTIFICATION_BROWSER_WINDOW_READY, 294 RegisterAndWait(&observer, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
294 NotificationService::AllSources()); 295 content::NotificationService::AllSources());
295 return content::Source<Browser>(observer.source()).ptr(); 296 return content::Source<Browser>(observer.source()).ptr();
296 } 297 }
297 298
298 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { 299 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
299 TestNotificationObserver observer; 300 TestNotificationObserver observer;
300 Browser* new_browser = GetBrowserNotInSet(excluded_browsers); 301 Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
301 if (new_browser == NULL) { 302 if (new_browser == NULL) {
302 new_browser = WaitForNewBrowser(); 303 new_browser = WaitForNewBrowser();
303 // The new browser should never be in |excluded_browsers|. 304 // The new browser should never be in |excluded_browsers|.
304 DCHECK(!ContainsKey(excluded_browsers, new_browser)); 305 DCHECK(!ContainsKey(excluded_browsers, new_browser));
305 } 306 }
306 return new_browser; 307 return new_browser;
307 } 308 }
308 309
309 void OpenURLOffTheRecord(Profile* profile, const GURL& url) { 310 void OpenURLOffTheRecord(Profile* profile, const GURL& url) {
310 Browser::OpenURLOffTheRecord(profile, url); 311 Browser::OpenURLOffTheRecord(profile, url);
311 Browser* browser = BrowserList::FindTabbedBrowser( 312 Browser* browser = BrowserList::FindTabbedBrowser(
312 profile->GetOffTheRecordProfile(), false); 313 profile->GetOffTheRecordProfile(), false);
313 WaitForNavigations(&browser->GetSelectedTabContents()->controller(), 1); 314 WaitForNavigations(&browser->GetSelectedTabContents()->controller(), 1);
314 } 315 }
315 316
316 void NavigateToURL(browser::NavigateParams* params) { 317 void NavigateToURL(browser::NavigateParams* params) {
317 TestNavigationObserver observer(NotificationService::AllSources(), NULL, 1); 318 TestNavigationObserver observer(
319 content::NotificationService::AllSources(), NULL, 1);
318 browser::Navigate(params); 320 browser::Navigate(params);
319 observer.WaitForObservation(); 321 observer.WaitForObservation();
320 } 322 }
321 323
322 void NavigateToURL(Browser* browser, const GURL& url) { 324 void NavigateToURL(Browser* browser, const GURL& url) {
323 NavigateToURLWithDisposition(browser, url, CURRENT_TAB, 325 NavigateToURLWithDisposition(browser, url, CURRENT_TAB,
324 BROWSER_TEST_WAIT_FOR_NAVIGATION); 326 BROWSER_TEST_WAIT_FOR_NAVIGATION);
325 } 327 }
326 328
327 // Navigates the specified tab (via |disposition|) of |browser| to |url|, 329 // Navigates the specified tab (via |disposition|) of |browser| to |url|,
(...skipping 14 matching lines...) Expand all
342 344
343 std::set<Browser*> initial_browsers; 345 std::set<Browser*> initial_browsers;
344 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); 346 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
345 iter != BrowserList::end(); 347 iter != BrowserList::end();
346 ++iter) { 348 ++iter) {
347 initial_browsers.insert(*iter); 349 initial_browsers.insert(*iter);
348 } 350 }
349 351
350 WindowedNotificationObserver tab_added_observer( 352 WindowedNotificationObserver tab_added_observer(
351 content::NOTIFICATION_TAB_ADDED, 353 content::NOTIFICATION_TAB_ADDED,
352 NotificationService::AllSources()); 354 content::NotificationService::AllSources());
353 355
354 browser->OpenURL(url, GURL(), disposition, content::PAGE_TRANSITION_TYPED); 356 browser->OpenURL(url, GURL(), disposition, content::PAGE_TRANSITION_TYPED);
355 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) 357 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
356 browser = WaitForBrowserNotInSet(initial_browsers); 358 browser = WaitForBrowserNotInSet(initial_browsers);
357 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) 359 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
358 tab_added_observer.Wait(); 360 tab_added_observer.Wait();
359 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { 361 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) {
360 // Some other flag caused the wait prior to this. 362 // Some other flag caused the wait prior to this.
361 return; 363 return;
362 } 364 }
(...skipping 120 matching lines...) Expand 10 before | Expand all | Expand 10 after
483 GURL::Replacements replacements; 485 GURL::Replacements replacements;
484 replacements.SetQueryStr(query_string); 486 replacements.SetQueryStr(query_string);
485 return url.ReplaceComponents(replacements); 487 return url.ReplaceComponents(replacements);
486 } 488 }
487 return url; 489 return url;
488 } 490 }
489 491
490 AppModalDialog* WaitForAppModalDialog() { 492 AppModalDialog* WaitForAppModalDialog() {
491 TestNotificationObserver observer; 493 TestNotificationObserver observer;
492 RegisterAndWait(&observer, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, 494 RegisterAndWait(&observer, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
493 NotificationService::AllSources()); 495 content::NotificationService::AllSources());
494 return content::Source<AppModalDialog>(observer.source()).ptr(); 496 return content::Source<AppModalDialog>(observer.source()).ptr();
495 } 497 }
496 498
497 void CrashTab(TabContents* tab) { 499 void CrashTab(TabContents* tab) {
498 RenderProcessHost* rph = tab->render_view_host()->process(); 500 RenderProcessHost* rph = tab->render_view_host()->process();
499 base::KillProcess(rph->GetHandle(), 0, false); 501 base::KillProcess(rph->GetHandle(), 0, false);
500 TestNotificationObserver observer; 502 TestNotificationObserver observer;
501 RegisterAndWait(&observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED, 503 RegisterAndWait(&observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
502 content::Source<RenderProcessHost>(rph)); 504 content::Source<RenderProcessHost>(rph));
503 } 505 }
(...skipping 44 matching lines...) Expand 10 before | Expand all | Expand 10 after
548 service->Load(); 550 service->Load();
549 TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests(); 551 TemplateURLServiceTestUtil::BlockTillServiceProcessesRequests();
550 ASSERT_TRUE(service->loaded()); 552 ASSERT_TRUE(service->loaded());
551 } 553 }
552 554
553 void WaitForHistoryToLoad(Browser* browser) { 555 void WaitForHistoryToLoad(Browser* browser) {
554 HistoryService* history_service = 556 HistoryService* history_service =
555 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 557 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
556 WindowedNotificationObserver history_loaded_observer( 558 WindowedNotificationObserver history_loaded_observer(
557 chrome::NOTIFICATION_HISTORY_LOADED, 559 chrome::NOTIFICATION_HISTORY_LOADED,
558 NotificationService::AllSources()); 560 content::NotificationService::AllSources());
559 if (!history_service->BackendLoaded()) 561 if (!history_service->BackendLoaded())
560 history_loaded_observer.Wait(); 562 history_loaded_observer.Wait();
561 } 563 }
562 564
563 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { 565 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
564 BrowserWindow* window = browser->window(); 566 BrowserWindow* window = browser->window();
565 if (!window) 567 if (!window)
566 return false; 568 return false;
567 569
568 *native_window = window->GetNativeHandle(); 570 *native_window = window->GetNativeHandle();
(...skipping 193 matching lines...) Expand 10 before | Expand all | Expand 10 after
762 cmd_line->AppendArg("--server=stop"); 764 cmd_line->AppendArg("--server=stop");
763 cmd_line->AppendArg("--chromium"); 765 cmd_line->AppendArg("--chromium");
764 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") + 766 cmd_line->AppendArgNative(FILE_PATH_LITERAL("--pidfile=") +
765 websocket_pid_file_.value()); 767 websocket_pid_file_.value());
766 base::LaunchOptions options; 768 base::LaunchOptions options;
767 options.wait = true; 769 options.wait = true;
768 base::LaunchProcess(*cmd_line.get(), options, NULL); 770 base::LaunchProcess(*cmd_line.get(), options, NULL);
769 } 771 }
770 772
771 TestNotificationObserver::TestNotificationObserver() 773 TestNotificationObserver::TestNotificationObserver()
772 : source_(NotificationService::AllSources()) { 774 : source_(content::NotificationService::AllSources()) {
773 } 775 }
774 776
775 TestNotificationObserver::~TestNotificationObserver() {} 777 TestNotificationObserver::~TestNotificationObserver() {}
776 778
777 void TestNotificationObserver::Observe( 779 void TestNotificationObserver::Observe(
778 int type, 780 int type,
779 const content::NotificationSource& source, 781 const content::NotificationSource& source,
780 const content::NotificationDetails& details) { 782 const content::NotificationDetails& details) {
781 source_ = source; 783 source_ = source;
782 details_ = details; 784 details_ = details;
783 MessageLoopForUI::current()->Quit(); 785 MessageLoopForUI::current()->Quit();
784 } 786 }
785 787
786 WindowedNotificationObserver::WindowedNotificationObserver( 788 WindowedNotificationObserver::WindowedNotificationObserver(
787 int notification_type, 789 int notification_type,
788 const content::NotificationSource& source) 790 const content::NotificationSource& source)
789 : seen_(false), 791 : seen_(false),
790 running_(false), 792 running_(false),
791 waiting_for_(source) { 793 waiting_for_(source) {
792 registrar_.Add(this, notification_type, waiting_for_); 794 registrar_.Add(this, notification_type, waiting_for_);
793 } 795 }
794 796
795 WindowedNotificationObserver::~WindowedNotificationObserver() {} 797 WindowedNotificationObserver::~WindowedNotificationObserver() {}
796 798
797 void WindowedNotificationObserver::Wait() { 799 void WindowedNotificationObserver::Wait() {
798 if (seen_ || (waiting_for_ == NotificationService::AllSources() && 800 if (seen_ || (waiting_for_ == content::NotificationService::AllSources() &&
799 !sources_seen_.empty())) { 801 !sources_seen_.empty())) {
800 return; 802 return;
801 } 803 }
802 804
803 running_ = true; 805 running_ = true;
804 ui_test_utils::RunMessageLoop(); 806 ui_test_utils::RunMessageLoop();
805 } 807 }
806 808
807 void WindowedNotificationObserver::Observe( 809 void WindowedNotificationObserver::Observe(
808 int type, 810 int type,
809 const content::NotificationSource& source, 811 const content::NotificationSource& source,
810 const content::NotificationDetails& details) { 812 const content::NotificationDetails& details) {
811 if (waiting_for_ == source || 813 if (waiting_for_ == source ||
812 (running_ && waiting_for_ == NotificationService::AllSources())) { 814 (running_ && waiting_for_ == content::NotificationService::AllSources())) {
813 seen_ = true; 815 seen_ = true;
814 if (running_) 816 if (running_)
815 MessageLoopForUI::current()->Quit(); 817 MessageLoopForUI::current()->Quit();
816 } else { 818 } else {
817 sources_seen_.insert(source.map_key()); 819 sources_seen_.insert(source.map_key());
818 } 820 }
819 } 821 }
820 822
821 TitleWatcher::TitleWatcher(TabContents* tab_contents, 823 TitleWatcher::TitleWatcher(TabContents* tab_contents,
822 const string16& expected_title) 824 const string16& expected_title)
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after
876 if (it == expected_titles_.end()) 878 if (it == expected_titles_.end())
877 return; 879 return;
878 observed_title_ = *it; 880 observed_title_ = *it;
879 expected_title_observed_ = true; 881 expected_title_observed_ = true;
880 if (quit_loop_on_observation_) 882 if (quit_loop_on_observation_)
881 MessageLoopForUI::current()->Quit(); 883 MessageLoopForUI::current()->Quit();
882 } 884 }
883 885
884 DOMMessageQueue::DOMMessageQueue() { 886 DOMMessageQueue::DOMMessageQueue() {
885 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE, 887 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
886 NotificationService::AllSources()); 888 content::NotificationService::AllSources());
887 } 889 }
888 890
889 DOMMessageQueue::~DOMMessageQueue() {} 891 DOMMessageQueue::~DOMMessageQueue() {}
890 892
891 void DOMMessageQueue::Observe(int type, 893 void DOMMessageQueue::Observe(int type,
892 const content::NotificationSource& source, 894 const content::NotificationSource& source,
893 const content::NotificationDetails& details) { 895 const content::NotificationDetails& details) {
894 content::Details<DomOperationNotificationDetails> dom_op_details(details); 896 content::Details<DomOperationNotificationDetails> dom_op_details(details);
895 content::Source<RenderViewHost> sender(source); 897 content::Source<RenderViewHost> sender(source);
896 message_queue_.push(dom_op_details->json()); 898 message_queue_.push(dom_op_details->json());
(...skipping 89 matching lines...) Expand 10 before | Expand all | Expand 10 after
986 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 988 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
987 } 989 }
988 990
989 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 991 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
990 DCHECK(bitmap); 992 DCHECK(bitmap);
991 SnapshotTaker taker; 993 SnapshotTaker taker;
992 return taker.TakeEntirePageSnapshot(rvh, bitmap); 994 return taker.TakeEntirePageSnapshot(rvh, bitmap);
993 } 995 }
994 996
995 } // namespace ui_test_utils 997 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/reliability/page_load_test.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698