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