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

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

Issue 7327007: Moving notification types which are chrome specific to a new header file chrome_notification_type... (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/
Patch Set: '' Created 9 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
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/ui_test_utils.h" 5 #include "chrome/test/ui_test_utils.h"
6 6
7 #include <vector> 7 #include <vector>
8 8
9 #include "base/callback.h" 9 #include "base/callback.h"
10 #include "base/command_line.h" 10 #include "base/command_line.h"
(...skipping 12 matching lines...) Expand all
23 #include "chrome/browser/download/download_item.h" 23 #include "chrome/browser/download/download_item.h"
24 #include "chrome/browser/download/download_manager.h" 24 #include "chrome/browser/download/download_manager.h"
25 #include "chrome/browser/profiles/profile.h" 25 #include "chrome/browser/profiles/profile.h"
26 #include "chrome/browser/tab_contents/thumbnail_generator.h" 26 #include "chrome/browser/tab_contents/thumbnail_generator.h"
27 #include "chrome/browser/ui/browser.h" 27 #include "chrome/browser/ui/browser.h"
28 #include "chrome/browser/ui/browser_list.h" 28 #include "chrome/browser/ui/browser_list.h"
29 #include "chrome/browser/ui/browser_window.h" 29 #include "chrome/browser/ui/browser_window.h"
30 #include "chrome/browser/ui/find_bar/find_notification_details.h" 30 #include "chrome/browser/ui/find_bar/find_notification_details.h"
31 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 31 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h" 32 #include "chrome/browser/ui/tab_contents/tab_contents_wrapper.h"
33 #include "chrome/common/chrome_notification_types.h"
33 #include "chrome/common/chrome_paths.h" 34 #include "chrome/common/chrome_paths.h"
34 #include "chrome/common/extensions/extension_action.h" 35 #include "chrome/common/extensions/extension_action.h"
35 #include "chrome/test/automation/javascript_execution_controller.h" 36 #include "chrome/test/automation/javascript_execution_controller.h"
36 #include "chrome/test/bookmark_load_observer.h" 37 #include "chrome/test/bookmark_load_observer.h"
37 #include "content/browser/renderer_host/render_process_host.h" 38 #include "content/browser/renderer_host/render_process_host.h"
38 #include "content/browser/renderer_host/render_view_host.h" 39 #include "content/browser/renderer_host/render_view_host.h"
39 #include "content/browser/tab_contents/navigation_controller.h" 40 #include "content/browser/tab_contents/navigation_controller.h"
40 #include "content/browser/tab_contents/navigation_entry.h" 41 #include "content/browser/tab_contents/navigation_entry.h"
41 #include "content/browser/tab_contents/tab_contents.h" 42 #include "content/browser/tab_contents/tab_contents.h"
42 #include "content/common/notification_type.h"
43 #include "googleurl/src/gurl.h" 43 #include "googleurl/src/gurl.h"
44 #include "net/base/net_util.h" 44 #include "net/base/net_util.h"
45 #include "testing/gtest/include/gtest/gtest.h" 45 #include "testing/gtest/include/gtest/gtest.h"
46 #include "third_party/skia/include/core/SkBitmap.h" 46 #include "third_party/skia/include/core/SkBitmap.h"
47 #include "third_party/skia/include/core/SkColor.h" 47 #include "third_party/skia/include/core/SkColor.h"
48 #include "ui/gfx/size.h" 48 #include "ui/gfx/size.h"
49 49
50 #if defined(TOOLKIT_VIEWS) 50 #if defined(TOOLKIT_VIEWS)
51 #include "views/focus/accelerator_handler.h" 51 #include "views/focus/accelerator_handler.h"
52 #endif 52 #endif
53 53
54 namespace ui_test_utils { 54 namespace ui_test_utils {
55 55
56 namespace { 56 namespace {
57 57
58 // Used to block until a navigation completes. 58 // Used to block until a navigation completes.
59 class NavigationNotificationObserver : public NotificationObserver { 59 class NavigationNotificationObserver : public NotificationObserver {
60 public: 60 public:
61 NavigationNotificationObserver(NavigationController* controller, 61 NavigationNotificationObserver(NavigationController* controller,
62 int number_of_navigations) 62 int number_of_navigations)
63 : navigation_started_(false), 63 : navigation_started_(false),
64 navigations_completed_(0), 64 navigations_completed_(0),
65 number_of_navigations_(number_of_navigations), 65 number_of_navigations_(number_of_navigations),
66 running_(false), 66 running_(false),
67 done_(false) { 67 done_(false) {
68 registrar_.Add(this, NotificationType::NAV_ENTRY_COMMITTED, 68 registrar_.Add(this, content::NOTIFICATION_NAV_ENTRY_COMMITTED,
69 Source<NavigationController>(controller)); 69 Source<NavigationController>(controller));
70 registrar_.Add(this, NotificationType::LOAD_START, 70 registrar_.Add(this, content::NOTIFICATION_LOAD_START,
71 Source<NavigationController>(controller)); 71 Source<NavigationController>(controller));
72 registrar_.Add(this, NotificationType::LOAD_STOP, 72 registrar_.Add(this, content::NOTIFICATION_LOAD_STOP,
73 Source<NavigationController>(controller)); 73 Source<NavigationController>(controller));
74 } 74 }
75 75
76 void Run() { 76 void Run() {
77 if (!done_) { 77 if (!done_) {
78 running_ = true; 78 running_ = true;
79 RunMessageLoop(); 79 RunMessageLoop();
80 } 80 }
81 } 81 }
82 82
83 virtual void Observe(NotificationType type, 83 virtual void Observe(int type,
84 const NotificationSource& source, 84 const NotificationSource& source,
85 const NotificationDetails& details) { 85 const NotificationDetails& details) {
86 if (type == NotificationType::NAV_ENTRY_COMMITTED || 86 if (type == content::NOTIFICATION_NAV_ENTRY_COMMITTED ||
87 type == NotificationType::LOAD_START) { 87 type == content::NOTIFICATION_LOAD_START) {
88 navigation_started_ = true; 88 navigation_started_ = true;
89 } else if (type == NotificationType::LOAD_STOP) { 89 } else if (type == content::NOTIFICATION_LOAD_STOP) {
90 if (navigation_started_ && 90 if (navigation_started_ &&
91 ++navigations_completed_ == number_of_navigations_) { 91 ++navigations_completed_ == number_of_navigations_) {
92 navigation_started_ = false; 92 navigation_started_ = false;
93 done_ = true; 93 done_ = true;
94 if (running_) 94 if (running_)
95 MessageLoopForUI::current()->Quit(); 95 MessageLoopForUI::current()->Quit();
96 } 96 }
97 } 97 }
98 } 98 }
99 99
(...skipping 16 matching lines...) Expand all
116 // done if we never had to start an event loop. 116 // done if we never had to start an event loop.
117 bool running_; 117 bool running_;
118 bool done_; 118 bool done_;
119 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver); 119 DISALLOW_COPY_AND_ASSIGN(NavigationNotificationObserver);
120 }; 120 };
121 121
122 class DOMOperationObserver : public NotificationObserver { 122 class DOMOperationObserver : public NotificationObserver {
123 public: 123 public:
124 explicit DOMOperationObserver(RenderViewHost* render_view_host) 124 explicit DOMOperationObserver(RenderViewHost* render_view_host)
125 : did_respond_(false) { 125 : did_respond_(false) {
126 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, 126 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
127 Source<RenderViewHost>(render_view_host)); 127 Source<RenderViewHost>(render_view_host));
128 ui_test_utils::RunMessageLoop(); 128 ui_test_utils::RunMessageLoop();
129 } 129 }
130 130
131 virtual void Observe(NotificationType type, 131 virtual void Observe(int type,
132 const NotificationSource& source, 132 const NotificationSource& source,
133 const NotificationDetails& details) { 133 const NotificationDetails& details) {
134 DCHECK(type == NotificationType::DOM_OPERATION_RESPONSE); 134 DCHECK(type == chrome::NOTIFICATION_DOM_OPERATION_RESPONSE);
135 Details<DomOperationNotificationDetails> dom_op_details(details); 135 Details<DomOperationNotificationDetails> dom_op_details(details);
136 response_ = dom_op_details->json(); 136 response_ = dom_op_details->json();
137 did_respond_ = true; 137 did_respond_ = true;
138 MessageLoopForUI::current()->Quit(); 138 MessageLoopForUI::current()->Quit();
139 } 139 }
140 140
141 bool GetResponse(std::string* response) WARN_UNUSED_RESULT { 141 bool GetResponse(std::string* response) WARN_UNUSED_RESULT {
142 *response = response_; 142 *response = response_;
143 return did_respond_; 143 return did_respond_;
144 } 144 }
145 145
146 private: 146 private:
147 NotificationRegistrar registrar_; 147 NotificationRegistrar registrar_;
148 std::string response_; 148 std::string response_;
149 bool did_respond_; 149 bool did_respond_;
150 150
151 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver); 151 DISALLOW_COPY_AND_ASSIGN(DOMOperationObserver);
152 }; 152 };
153 153
154 class FindInPageNotificationObserver : public NotificationObserver { 154 class FindInPageNotificationObserver : public NotificationObserver {
155 public: 155 public:
156 explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab) 156 explicit FindInPageNotificationObserver(TabContentsWrapper* parent_tab)
157 : parent_tab_(parent_tab), 157 : parent_tab_(parent_tab),
158 active_match_ordinal_(-1), 158 active_match_ordinal_(-1),
159 number_of_matches_(0) { 159 number_of_matches_(0) {
160 current_find_request_id_ = 160 current_find_request_id_ =
161 parent_tab->find_tab_helper()->current_find_request_id(); 161 parent_tab->find_tab_helper()->current_find_request_id();
162 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, 162 registrar_.Add(this, chrome::NOTIFICATION_FIND_RESULT_AVAILABLE,
163 Source<TabContents>(parent_tab_->tab_contents())); 163 Source<TabContents>(parent_tab_->tab_contents()));
164 ui_test_utils::RunMessageLoop(); 164 ui_test_utils::RunMessageLoop();
165 } 165 }
166 166
167 int active_match_ordinal() const { return active_match_ordinal_; } 167 int active_match_ordinal() const { return active_match_ordinal_; }
168 168
169 int number_of_matches() const { return number_of_matches_; } 169 int number_of_matches() const { return number_of_matches_; }
170 170
171 virtual void Observe(NotificationType type, const NotificationSource& source, 171 virtual void Observe(int type, const NotificationSource& source,
172 const NotificationDetails& details) { 172 const NotificationDetails& details) {
173 if (type == NotificationType::FIND_RESULT_AVAILABLE) { 173 if (type == chrome::NOTIFICATION_FIND_RESULT_AVAILABLE) {
174 Details<FindNotificationDetails> find_details(details); 174 Details<FindNotificationDetails> find_details(details);
175 if (find_details->request_id() == current_find_request_id_) { 175 if (find_details->request_id() == current_find_request_id_) {
176 // We get multiple responses and one of those will contain the ordinal. 176 // We get multiple responses and one of those will contain the ordinal.
177 // This message comes to us before the final update is sent. 177 // This message comes to us before the final update is sent.
178 if (find_details->active_match_ordinal() > -1) 178 if (find_details->active_match_ordinal() > -1)
179 active_match_ordinal_ = find_details->active_match_ordinal(); 179 active_match_ordinal_ = find_details->active_match_ordinal();
180 if (find_details->final_update()) { 180 if (find_details->final_update()) {
181 number_of_matches_ = find_details->number_of_matches(); 181 number_of_matches_ = find_details->number_of_matches();
182 MessageLoopForUI::current()->Quit(); 182 MessageLoopForUI::current()->Quit();
183 } else { 183 } else {
(...skipping 152 matching lines...) Expand 10 before | Expand all | Expand 10 after
336 } 336 }
337 337
338 void WaitForNavigations(NavigationController* controller, 338 void WaitForNavigations(NavigationController* controller,
339 int number_of_navigations) { 339 int number_of_navigations) {
340 NavigationNotificationObserver observer(controller, number_of_navigations); 340 NavigationNotificationObserver observer(controller, number_of_navigations);
341 observer.Run(); 341 observer.Run();
342 } 342 }
343 343
344 void WaitForNewTab(Browser* browser) { 344 void WaitForNewTab(Browser* browser) {
345 TestNotificationObserver observer; 345 TestNotificationObserver observer;
346 RegisterAndWait(&observer, NotificationType::TAB_ADDED, 346 RegisterAndWait(&observer, content::NOTIFICATION_TAB_ADDED,
347 Source<Browser>(browser)); 347 Source<Browser>(browser));
348 } 348 }
349 349
350 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) { 350 void WaitForBrowserActionUpdated(ExtensionAction* browser_action) {
351 TestNotificationObserver observer; 351 TestNotificationObserver observer;
352 RegisterAndWait(&observer, NotificationType::EXTENSION_BROWSER_ACTION_UPDATED, 352 RegisterAndWait(&observer,
353 chrome::NOTIFICATION_EXTENSION_BROWSER_ACTION_UPDATED,
353 Source<ExtensionAction>(browser_action)); 354 Source<ExtensionAction>(browser_action));
354 } 355 }
355 356
356 void WaitForLoadStop(TabContents* tab) { 357 void WaitForLoadStop(TabContents* tab) {
357 // In many cases, the load may have finished before we get here. Only wait if 358 // In many cases, the load may have finished before we get here. Only wait if
358 // the tab still has a pending navigation. 359 // the tab still has a pending navigation.
359 if (!tab->is_loading() && !tab->render_manager()->pending_render_view_host()) 360 if (!tab->is_loading() && !tab->render_manager()->pending_render_view_host())
360 return; 361 return;
361 TestNotificationObserver observer; 362 TestNotificationObserver observer;
362 RegisterAndWait(&observer, NotificationType::LOAD_STOP, 363 RegisterAndWait(&observer, content::NOTIFICATION_LOAD_STOP,
363 Source<NavigationController>(&tab->controller())); 364 Source<NavigationController>(&tab->controller()));
364 } 365 }
365 366
366 Browser* WaitForNewBrowser() { 367 Browser* WaitForNewBrowser() {
367 TestNotificationObserver observer; 368 TestNotificationObserver observer;
368 RegisterAndWait(&observer, NotificationType::BROWSER_WINDOW_READY, 369 RegisterAndWait(&observer, chrome::NOTIFICATION_BROWSER_WINDOW_READY,
369 NotificationService::AllSources()); 370 NotificationService::AllSources());
370 return Source<Browser>(observer.source()).ptr(); 371 return Source<Browser>(observer.source()).ptr();
371 } 372 }
372 373
373 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { 374 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
374 TestNotificationObserver observer; 375 TestNotificationObserver observer;
375 Browser* new_browser = GetBrowserNotInSet(excluded_browsers); 376 Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
376 if (new_browser == NULL) { 377 if (new_browser == NULL) {
377 new_browser = WaitForNewBrowser(); 378 new_browser = WaitForNewBrowser();
378 // The new browser should never be in |excluded_browsers|. 379 // The new browser should never be in |excluded_browsers|.
(...skipping 31 matching lines...) Expand 10 before | Expand all | Expand 10 after
410 std::set<Browser*> initial_browsers; 411 std::set<Browser*> initial_browsers;
411 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin(); 412 for (std::vector<Browser*>::const_iterator iter = BrowserList::begin();
412 iter != BrowserList::end(); 413 iter != BrowserList::end();
413 ++iter) { 414 ++iter) {
414 initial_browsers.insert(*iter); 415 initial_browsers.insert(*iter);
415 } 416 }
416 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED); 417 browser->OpenURL(url, GURL(), disposition, PageTransition::TYPED);
417 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER) 418 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
418 browser = WaitForBrowserNotInSet(initial_browsers); 419 browser = WaitForBrowserNotInSet(initial_browsers);
419 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB) 420 if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
420 WaitForNotification(NotificationType::TAB_ADDED); 421 WaitForNotification(content::NOTIFICATION_TAB_ADDED);
421 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) { 422 if (!(browser_test_flags & BROWSER_TEST_WAIT_FOR_NAVIGATION)) {
422 // Some other flag caused the wait prior to this. 423 // Some other flag caused the wait prior to this.
423 return; 424 return;
424 } 425 }
425 TabContents* tab_contents = NULL; 426 TabContents* tab_contents = NULL;
426 if (disposition == NEW_BACKGROUND_TAB) { 427 if (disposition == NEW_BACKGROUND_TAB) {
427 // We've opened up a new tab, but not selected it. 428 // We've opened up a new tab, but not selected it.
428 tab_contents = browser->GetTabContentsAt(browser->active_index() + 1); 429 tab_contents = browser->GetTabContentsAt(browser->active_index() + 1);
429 EXPECT_TRUE(tab_contents != NULL) 430 EXPECT_TRUE(tab_contents != NULL)
430 << " Unable to wait for navigation to \"" << url.spec() 431 << " Unable to wait for navigation to \"" << url.spec()
(...skipping 113 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 if (!query_string.empty()) { 545 if (!query_string.empty()) {
545 GURL::Replacements replacements; 546 GURL::Replacements replacements;
546 replacements.SetQueryStr(query_string); 547 replacements.SetQueryStr(query_string);
547 return url.ReplaceComponents(replacements); 548 return url.ReplaceComponents(replacements);
548 } 549 }
549 return url; 550 return url;
550 } 551 }
551 552
552 AppModalDialog* WaitForAppModalDialog() { 553 AppModalDialog* WaitForAppModalDialog() {
553 TestNotificationObserver observer; 554 TestNotificationObserver observer;
554 RegisterAndWait(&observer, NotificationType::APP_MODAL_DIALOG_SHOWN, 555 RegisterAndWait(&observer, chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
555 NotificationService::AllSources()); 556 NotificationService::AllSources());
556 return Source<AppModalDialog>(observer.source()).ptr(); 557 return Source<AppModalDialog>(observer.source()).ptr();
557 } 558 }
558 559
559 void CrashTab(TabContents* tab) { 560 void CrashTab(TabContents* tab) {
560 RenderProcessHost* rph = tab->render_view_host()->process(); 561 RenderProcessHost* rph = tab->render_view_host()->process();
561 base::KillProcess(rph->GetHandle(), 0, false); 562 base::KillProcess(rph->GetHandle(), 0, false);
562 TestNotificationObserver observer; 563 TestNotificationObserver observer;
563 RegisterAndWait(&observer, NotificationType::RENDERER_PROCESS_CLOSED, 564 RegisterAndWait(&observer, content::NOTIFICATION_RENDERER_PROCESS_CLOSED,
564 Source<RenderProcessHost>(rph)); 565 Source<RenderProcessHost>(rph));
565 } 566 }
566 567
567 void WaitForFocusChange(TabContents* tab_contents) { 568 void WaitForFocusChange(TabContents* tab_contents) {
568 TestNotificationObserver observer; 569 TestNotificationObserver observer;
569 RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE, 570 RegisterAndWait(&observer, content::NOTIFICATION_FOCUS_CHANGED_IN_PAGE,
570 Source<TabContents>(tab_contents)); 571 Source<TabContents>(tab_contents));
571 } 572 }
572 573
573 void WaitForFocusInBrowser(Browser* browser) { 574 void WaitForFocusInBrowser(Browser* browser) {
574 TestNotificationObserver observer; 575 TestNotificationObserver observer;
575 RegisterAndWait(&observer, NotificationType::FOCUS_RETURNED_TO_BROWSER, 576 RegisterAndWait(&observer, chrome::NOTIFICATION_FOCUS_RETURNED_TO_BROWSER,
576 Source<Browser>(browser)); 577 Source<Browser>(browser));
577 } 578 }
578 579
579 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string, 580 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string,
580 bool forward, bool match_case, int* ordinal) { 581 bool forward, bool match_case, int* ordinal) {
581 tab_contents-> 582 tab_contents->
582 find_tab_helper()->StartFinding(search_string, forward, match_case); 583 find_tab_helper()->StartFinding(search_string, forward, match_case);
583 FindInPageNotificationObserver observer(tab_contents); 584 FindInPageNotificationObserver observer(tab_contents);
584 if (ordinal) 585 if (ordinal)
585 *ordinal = observer.active_match_ordinal(); 586 *ordinal = observer.active_match_ordinal();
586 return observer.number_of_matches(); 587 return observer.number_of_matches();
587 } 588 }
588 589
589 void WaitForNotification(NotificationType type) { 590 void WaitForNotification(int type) {
590 TestNotificationObserver observer; 591 TestNotificationObserver observer;
591 RegisterAndWait(&observer, type, NotificationService::AllSources()); 592 RegisterAndWait(&observer, type, NotificationService::AllSources());
592 } 593 }
593 594
594 void WaitForNotificationFrom(NotificationType type, 595 void WaitForNotificationFrom(int type,
595 const NotificationSource& source) { 596 const NotificationSource& source) {
596 TestNotificationObserver observer; 597 TestNotificationObserver observer;
597 RegisterAndWait(&observer, type, source); 598 RegisterAndWait(&observer, type, source);
598 } 599 }
599 600
600 void RegisterAndWait(NotificationObserver* observer, 601 void RegisterAndWait(NotificationObserver* observer,
601 NotificationType type, 602 int type,
602 const NotificationSource& source) { 603 const NotificationSource& source) {
603 NotificationRegistrar registrar; 604 NotificationRegistrar registrar;
604 registrar.Add(observer, type, source); 605 registrar.Add(observer, type, source);
605 RunMessageLoop(); 606 RunMessageLoop();
606 } 607 }
607 608
608 void WaitForBookmarkModelToLoad(BookmarkModel* model) { 609 void WaitForBookmarkModelToLoad(BookmarkModel* model) {
609 if (model->IsLoaded()) 610 if (model->IsLoaded())
610 return; 611 return;
611 BookmarkLoadObserver observer; 612 BookmarkLoadObserver observer;
612 model->AddObserver(&observer); 613 model->AddObserver(&observer);
613 RunMessageLoop(); 614 RunMessageLoop();
614 model->RemoveObserver(&observer); 615 model->RemoveObserver(&observer);
615 ASSERT_TRUE(model->IsLoaded()); 616 ASSERT_TRUE(model->IsLoaded());
616 } 617 }
617 618
618 void WaitForHistoryToLoad(Browser* browser) { 619 void WaitForHistoryToLoad(Browser* browser) {
619 HistoryService* history_service = 620 HistoryService* history_service =
620 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); 621 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS);
621 if (!history_service->BackendLoaded()) 622 if (!history_service->BackendLoaded())
622 WaitForNotification(NotificationType::HISTORY_LOADED); 623 WaitForNotification(chrome::NOTIFICATION_HISTORY_LOADED);
623 } 624 }
624 625
625 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { 626 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
626 BrowserWindow* window = browser->window(); 627 BrowserWindow* window = browser->window();
627 if (!window) 628 if (!window)
628 return false; 629 return false;
629 630
630 *native_window = window->GetNativeHandle(); 631 *native_window = window->GetNativeHandle();
631 return *native_window; 632 return *native_window;
632 } 633 }
(...skipping 40 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 RunMessageLoop(); 674 RunMessageLoop();
674 return !testing::Test::HasFatalFailure(); 675 return !testing::Test::HasFatalFailure();
675 } 676 }
676 677
677 bool SendKeyPressAndWait(const Browser* browser, 678 bool SendKeyPressAndWait(const Browser* browser,
678 ui::KeyboardCode key, 679 ui::KeyboardCode key,
679 bool control, 680 bool control,
680 bool shift, 681 bool shift,
681 bool alt, 682 bool alt,
682 bool command, 683 bool command,
683 NotificationType type, 684 int type,
684 const NotificationSource& source) { 685 const NotificationSource& source) {
685 WindowedNotificationObserver observer(type, source); 686 WindowedNotificationObserver observer(type, source);
686 687
687 if (!SendKeyPressSync(browser, key, control, shift, alt, command)) 688 if (!SendKeyPressSync(browser, key, control, shift, alt, command))
688 return false; 689 return false;
689 690
690 observer.Wait(); 691 observer.Wait();
691 return !testing::Test::HasFatalFailure(); 692 return !testing::Test::HasFatalFailure();
692 } 693 }
693 694
(...skipping 131 matching lines...) Expand 10 before | Expand all | Expand 10 after
825 websocket_pid_file_.value()); 826 websocket_pid_file_.value());
826 base::LaunchApp(*cmd_line.get(), true, false, NULL); 827 base::LaunchApp(*cmd_line.get(), true, false, NULL);
827 } 828 }
828 829
829 TestNotificationObserver::TestNotificationObserver() 830 TestNotificationObserver::TestNotificationObserver()
830 : source_(NotificationService::AllSources()) { 831 : source_(NotificationService::AllSources()) {
831 } 832 }
832 833
833 TestNotificationObserver::~TestNotificationObserver() {} 834 TestNotificationObserver::~TestNotificationObserver() {}
834 835
835 void TestNotificationObserver::Observe(NotificationType type, 836 void TestNotificationObserver::Observe(int type,
836 const NotificationSource& source, 837 const NotificationSource& source,
837 const NotificationDetails& details) { 838 const NotificationDetails& details) {
838 source_ = source; 839 source_ = source;
839 details_ = details; 840 details_ = details;
840 MessageLoopForUI::current()->Quit(); 841 MessageLoopForUI::current()->Quit();
841 } 842 }
842 843
843 WindowedNotificationObserver::WindowedNotificationObserver( 844 WindowedNotificationObserver::WindowedNotificationObserver(
844 NotificationType notification_type, 845 int notification_type,
845 const NotificationSource& source) 846 const NotificationSource& source)
846 : seen_(false), 847 : seen_(false),
847 running_(false), 848 running_(false),
848 waiting_for_(source) { 849 waiting_for_(source) {
849 registrar_.Add(this, notification_type, waiting_for_); 850 registrar_.Add(this, notification_type, waiting_for_);
850 } 851 }
851 852
852 WindowedNotificationObserver::~WindowedNotificationObserver() {} 853 WindowedNotificationObserver::~WindowedNotificationObserver() {}
853 854
854 void WindowedNotificationObserver::Wait() { 855 void WindowedNotificationObserver::Wait() {
(...skipping 13 matching lines...) Expand all
868 } 869 }
869 870
870 waiting_for_ = source; 871 waiting_for_ = source;
871 if (sources_seen_.count(waiting_for_.map_key()) > 0) 872 if (sources_seen_.count(waiting_for_.map_key()) > 0)
872 return; 873 return;
873 874
874 running_ = true; 875 running_ = true;
875 ui_test_utils::RunMessageLoop(); 876 ui_test_utils::RunMessageLoop();
876 } 877 }
877 878
878 void WindowedNotificationObserver::Observe(NotificationType type, 879 void WindowedNotificationObserver::Observe(int type,
879 const NotificationSource& source, 880 const NotificationSource& source,
880 const NotificationDetails& details) { 881 const NotificationDetails& details) {
881 if (waiting_for_ == source || 882 if (waiting_for_ == source ||
882 (running_ && waiting_for_ == NotificationService::AllSources())) { 883 (running_ && waiting_for_ == NotificationService::AllSources())) {
883 seen_ = true; 884 seen_ = true;
884 if (running_) 885 if (running_)
885 MessageLoopForUI::current()->Quit(); 886 MessageLoopForUI::current()->Quit();
886 } else { 887 } else {
887 sources_seen_.insert(source.map_key()); 888 sources_seen_.insert(source.map_key());
888 } 889 }
889 } 890 }
890 891
891 TitleWatcher::TitleWatcher(TabContents* tab_contents, 892 TitleWatcher::TitleWatcher(TabContents* tab_contents,
892 const string16& expected_title) 893 const string16& expected_title)
893 : expected_tab_(tab_contents), 894 : expected_tab_(tab_contents),
894 expected_title_(expected_title), 895 expected_title_(expected_title),
895 title_observed_(false), 896 title_observed_(false),
896 quit_loop_on_observation_(false) { 897 quit_loop_on_observation_(false) {
897 EXPECT_TRUE(tab_contents != NULL); 898 EXPECT_TRUE(tab_contents != NULL);
898 notification_registrar_.Add(this, 899 notification_registrar_.Add(this,
899 NotificationType::TAB_CONTENTS_TITLE_UPDATED, 900 content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED,
900 Source<TabContents>(tab_contents)); 901 Source<TabContents>(tab_contents));
901 } 902 }
902 903
903 TitleWatcher::~TitleWatcher() { 904 TitleWatcher::~TitleWatcher() {
904 } 905 }
905 906
906 bool TitleWatcher::Wait() { 907 bool TitleWatcher::Wait() {
907 if (title_observed_) 908 if (title_observed_)
908 return true; 909 return true;
909 quit_loop_on_observation_ = true; 910 quit_loop_on_observation_ = true;
910 ui_test_utils::RunMessageLoop(); 911 ui_test_utils::RunMessageLoop();
911 return title_observed_; 912 return title_observed_;
912 } 913 }
913 914
914 void TitleWatcher::Observe(NotificationType type, 915 void TitleWatcher::Observe(int type,
915 const NotificationSource& source, 916 const NotificationSource& source,
916 const NotificationDetails& details) { 917 const NotificationDetails& details) {
917 if (type != NotificationType::TAB_CONTENTS_TITLE_UPDATED) 918 if (type != content::NOTIFICATION_TAB_CONTENTS_TITLE_UPDATED)
918 return; 919 return;
919 920
920 TabContents* source_contents = Source<TabContents>(source).ptr(); 921 TabContents* source_contents = Source<TabContents>(source).ptr();
921 ASSERT_EQ(expected_tab_, source_contents); 922 ASSERT_EQ(expected_tab_, source_contents);
922 if (source_contents->GetTitle() != expected_title_) 923 if (source_contents->GetTitle() != expected_title_)
923 return; 924 return;
924 925
925 title_observed_ = true; 926 title_observed_ = true;
926 if (quit_loop_on_observation_) 927 if (quit_loop_on_observation_)
927 MessageLoopForUI::current()->Quit(); 928 MessageLoopForUI::current()->Quit();
928 } 929 }
929 930
930 DOMMessageQueue::DOMMessageQueue() { 931 DOMMessageQueue::DOMMessageQueue() {
931 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, 932 registrar_.Add(this, chrome::NOTIFICATION_DOM_OPERATION_RESPONSE,
932 NotificationService::AllSources()); 933 NotificationService::AllSources());
933 } 934 }
934 935
935 DOMMessageQueue::~DOMMessageQueue() {} 936 DOMMessageQueue::~DOMMessageQueue() {}
936 937
937 void DOMMessageQueue::Observe(NotificationType type, 938 void DOMMessageQueue::Observe(int type,
938 const NotificationSource& source, 939 const NotificationSource& source,
939 const NotificationDetails& details) { 940 const NotificationDetails& details) {
940 Details<DomOperationNotificationDetails> dom_op_details(details); 941 Details<DomOperationNotificationDetails> dom_op_details(details);
941 Source<RenderViewHost> sender(source); 942 Source<RenderViewHost> sender(source);
942 message_queue_.push(dom_op_details->json()); 943 message_queue_.push(dom_op_details->json());
943 if (waiting_for_message_) { 944 if (waiting_for_message_) {
944 waiting_for_message_ = false; 945 waiting_for_message_ = false;
945 MessageLoopForUI::current()->Quit(); 946 MessageLoopForUI::current()->Quit();
946 } 947 }
947 } 948 }
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
1032 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); 1033 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap);
1033 } 1034 }
1034 1035
1035 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { 1036 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) {
1036 DCHECK(bitmap); 1037 DCHECK(bitmap);
1037 SnapshotTaker taker; 1038 SnapshotTaker taker;
1038 return taker.TakeEntirePageSnapshot(rvh, bitmap); 1039 return taker.TakeEntirePageSnapshot(rvh, bitmap);
1039 } 1040 }
1040 1041
1041 } // namespace ui_test_utils 1042 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/ui_test_utils.h ('k') | content/browser/accessibility/browser_accessibility_manager.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698