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 |
(...skipping 63 matching lines...) Expand 10 before | Expand all | Expand 10 after 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::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(NotificationType 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::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::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(NotificationType type, const NotificationSource& source, |
171 const NotificationDetails& details) { | 171 const NotificationDetails& details) { |
172 if (type == NotificationType::FIND_RESULT_AVAILABLE) { | 172 if (type == chrome::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 158 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
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, NotificationType::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, chrome::EXTENSION_BROWSER_ACTION_UPDATED, |
352 Source<ExtensionAction>(browser_action)); | 352 Source<ExtensionAction>(browser_action)); |
353 } | 353 } |
354 | 354 |
355 void WaitForLoadStop(TabContents* tab) { | 355 void WaitForLoadStop(TabContents* tab) { |
356 // In many cases, the load may have finished before we get here. Only wait if | 356 // In many cases, the load may have finished before we get here. Only wait if |
357 // the tab still has a pending navigation. | 357 // the tab still has a pending navigation. |
358 if (!tab->is_loading() && !tab->render_manager()->pending_render_view_host()) | 358 if (!tab->is_loading() && !tab->render_manager()->pending_render_view_host()) |
359 return; | 359 return; |
360 TestNotificationObserver observer; | 360 TestNotificationObserver observer; |
361 RegisterAndWait(&observer, NotificationType::LOAD_STOP, | 361 RegisterAndWait(&observer, NotificationType::LOAD_STOP, |
362 Source<NavigationController>(&tab->controller())); | 362 Source<NavigationController>(&tab->controller())); |
363 } | 363 } |
364 | 364 |
365 Browser* WaitForNewBrowser() { | 365 Browser* WaitForNewBrowser() { |
366 TestNotificationObserver observer; | 366 TestNotificationObserver observer; |
367 RegisterAndWait(&observer, NotificationType::BROWSER_WINDOW_READY, | 367 RegisterAndWait(&observer, chrome::BROWSER_WINDOW_READY, |
368 NotificationService::AllSources()); | 368 NotificationService::AllSources()); |
369 return Source<Browser>(observer.source()).ptr(); | 369 return Source<Browser>(observer.source()).ptr(); |
370 } | 370 } |
371 | 371 |
372 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { | 372 Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) { |
373 TestNotificationObserver observer; | 373 TestNotificationObserver observer; |
374 Browser* new_browser = GetBrowserNotInSet(excluded_browsers); | 374 Browser* new_browser = GetBrowserNotInSet(excluded_browsers); |
375 if (new_browser == NULL) { | 375 if (new_browser == NULL) { |
376 new_browser = WaitForNewBrowser(); | 376 new_browser = WaitForNewBrowser(); |
377 // The new browser should never be in |excluded_browsers|. | 377 // The new browser should never be in |excluded_browsers|. |
(...skipping 165 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
543 if (!query_string.empty()) { | 543 if (!query_string.empty()) { |
544 GURL::Replacements replacements; | 544 GURL::Replacements replacements; |
545 replacements.SetQueryStr(query_string); | 545 replacements.SetQueryStr(query_string); |
546 return url.ReplaceComponents(replacements); | 546 return url.ReplaceComponents(replacements); |
547 } | 547 } |
548 return url; | 548 return url; |
549 } | 549 } |
550 | 550 |
551 AppModalDialog* WaitForAppModalDialog() { | 551 AppModalDialog* WaitForAppModalDialog() { |
552 TestNotificationObserver observer; | 552 TestNotificationObserver observer; |
553 RegisterAndWait(&observer, NotificationType::APP_MODAL_DIALOG_SHOWN, | 553 RegisterAndWait(&observer, chrome::APP_MODAL_DIALOG_SHOWN, |
554 NotificationService::AllSources()); | 554 NotificationService::AllSources()); |
555 return Source<AppModalDialog>(observer.source()).ptr(); | 555 return Source<AppModalDialog>(observer.source()).ptr(); |
556 } | 556 } |
557 | 557 |
558 void CrashTab(TabContents* tab) { | 558 void CrashTab(TabContents* tab) { |
559 RenderProcessHost* rph = tab->render_view_host()->process(); | 559 RenderProcessHost* rph = tab->render_view_host()->process(); |
560 base::KillProcess(rph->GetHandle(), 0, false); | 560 base::KillProcess(rph->GetHandle(), 0, false); |
561 TestNotificationObserver observer; | 561 TestNotificationObserver observer; |
562 RegisterAndWait(&observer, NotificationType::RENDERER_PROCESS_CLOSED, | 562 RegisterAndWait(&observer, NotificationType::RENDERER_PROCESS_CLOSED, |
563 Source<RenderProcessHost>(rph)); | 563 Source<RenderProcessHost>(rph)); |
564 } | 564 } |
565 | 565 |
566 void WaitForFocusChange(TabContents* tab_contents) { | 566 void WaitForFocusChange(TabContents* tab_contents) { |
567 TestNotificationObserver observer; | 567 TestNotificationObserver observer; |
568 RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE, | 568 RegisterAndWait(&observer, NotificationType::FOCUS_CHANGED_IN_PAGE, |
569 Source<TabContents>(tab_contents)); | 569 Source<TabContents>(tab_contents)); |
570 } | 570 } |
571 | 571 |
572 void WaitForFocusInBrowser(Browser* browser) { | 572 void WaitForFocusInBrowser(Browser* browser) { |
573 TestNotificationObserver observer; | 573 TestNotificationObserver observer; |
574 RegisterAndWait(&observer, NotificationType::FOCUS_RETURNED_TO_BROWSER, | 574 RegisterAndWait(&observer, chrome::FOCUS_RETURNED_TO_BROWSER, |
575 Source<Browser>(browser)); | 575 Source<Browser>(browser)); |
576 } | 576 } |
577 | 577 |
578 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string, | 578 int FindInPage(TabContentsWrapper* tab_contents, const string16& search_string, |
579 bool forward, bool match_case, int* ordinal) { | 579 bool forward, bool match_case, int* ordinal) { |
580 tab_contents-> | 580 tab_contents-> |
581 find_tab_helper()->StartFinding(search_string, forward, match_case); | 581 find_tab_helper()->StartFinding(search_string, forward, match_case); |
582 FindInPageNotificationObserver observer(tab_contents); | 582 FindInPageNotificationObserver observer(tab_contents); |
583 if (ordinal) | 583 if (ordinal) |
584 *ordinal = observer.active_match_ordinal(); | 584 *ordinal = observer.active_match_ordinal(); |
(...skipping 26 matching lines...) Expand all Loading... |
611 model->AddObserver(&observer); | 611 model->AddObserver(&observer); |
612 RunMessageLoop(); | 612 RunMessageLoop(); |
613 model->RemoveObserver(&observer); | 613 model->RemoveObserver(&observer); |
614 ASSERT_TRUE(model->IsLoaded()); | 614 ASSERT_TRUE(model->IsLoaded()); |
615 } | 615 } |
616 | 616 |
617 void WaitForHistoryToLoad(Browser* browser) { | 617 void WaitForHistoryToLoad(Browser* browser) { |
618 HistoryService* history_service = | 618 HistoryService* history_service = |
619 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); | 619 browser->profile()->GetHistoryService(Profile::EXPLICIT_ACCESS); |
620 if (!history_service->BackendLoaded()) | 620 if (!history_service->BackendLoaded()) |
621 WaitForNotification(NotificationType::HISTORY_LOADED); | 621 WaitForNotification(chrome::HISTORY_LOADED); |
622 } | 622 } |
623 | 623 |
624 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { | 624 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { |
625 BrowserWindow* window = browser->window(); | 625 BrowserWindow* window = browser->window(); |
626 if (!window) | 626 if (!window) |
627 return false; | 627 return false; |
628 | 628 |
629 *native_window = window->GetNativeHandle(); | 629 *native_window = window->GetNativeHandle(); |
630 return *native_window; | 630 return *native_window; |
631 } | 631 } |
(...skipping 288 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
920 ASSERT_EQ(expected_tab_, source_contents); | 920 ASSERT_EQ(expected_tab_, source_contents); |
921 if (source_contents->GetTitle() != expected_title_) | 921 if (source_contents->GetTitle() != expected_title_) |
922 return; | 922 return; |
923 | 923 |
924 title_observed_ = true; | 924 title_observed_ = true; |
925 if (quit_loop_on_observation_) | 925 if (quit_loop_on_observation_) |
926 MessageLoopForUI::current()->Quit(); | 926 MessageLoopForUI::current()->Quit(); |
927 } | 927 } |
928 | 928 |
929 DOMMessageQueue::DOMMessageQueue() { | 929 DOMMessageQueue::DOMMessageQueue() { |
930 registrar_.Add(this, NotificationType::DOM_OPERATION_RESPONSE, | 930 registrar_.Add(this, chrome::DOM_OPERATION_RESPONSE, |
931 NotificationService::AllSources()); | 931 NotificationService::AllSources()); |
932 } | 932 } |
933 | 933 |
934 DOMMessageQueue::~DOMMessageQueue() {} | 934 DOMMessageQueue::~DOMMessageQueue() {} |
935 | 935 |
936 void DOMMessageQueue::Observe(NotificationType type, | 936 void DOMMessageQueue::Observe(NotificationType type, |
937 const NotificationSource& source, | 937 const NotificationSource& source, |
938 const NotificationDetails& details) { | 938 const NotificationDetails& details) { |
939 Details<DomOperationNotificationDetails> dom_op_details(details); | 939 Details<DomOperationNotificationDetails> dom_op_details(details); |
940 Source<RenderViewHost> sender(source); | 940 Source<RenderViewHost> sender(source); |
(...skipping 90 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1031 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); | 1031 return taker.TakeRenderWidgetSnapshot(rwh, page_size, page_size, bitmap); |
1032 } | 1032 } |
1033 | 1033 |
1034 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { | 1034 bool TakeEntirePageSnapshot(RenderViewHost* rvh, SkBitmap* bitmap) { |
1035 DCHECK(bitmap); | 1035 DCHECK(bitmap); |
1036 SnapshotTaker taker; | 1036 SnapshotTaker taker; |
1037 return taker.TakeEntirePageSnapshot(rvh, bitmap); | 1037 return taker.TakeEntirePageSnapshot(rvh, bitmap); |
1038 } | 1038 } |
1039 | 1039 |
1040 } // namespace ui_test_utils | 1040 } // namespace ui_test_utils |
OLD | NEW |