| OLD | NEW |
| 1 // Copyright (c) 2009 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2009 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/json/json_reader.h" | 9 #include "base/json/json_reader.h" |
| 10 #include "base/message_loop.h" | 10 #include "base/message_loop.h" |
| (...skipping 236 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 247 const NotificationDetails& details) { | 247 const NotificationDetails& details) { |
| 248 MessageLoopForUI::current()->Quit(); | 248 MessageLoopForUI::current()->Quit(); |
| 249 } | 249 } |
| 250 | 250 |
| 251 private: | 251 private: |
| 252 NotificationRegistrar registrar_; | 252 NotificationRegistrar registrar_; |
| 253 | 253 |
| 254 DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); | 254 DISALLOW_COPY_AND_ASSIGN(SimpleNotificationObserver); |
| 255 }; | 255 }; |
| 256 | 256 |
| 257 class LanguageDetectionNotificationObserver : public NotificationObserver { | |
| 258 public: | |
| 259 explicit LanguageDetectionNotificationObserver( | |
| 260 RenderViewHost* render_view_host) { | |
| 261 registrar_.Add(this, NotificationType::TAB_LANGUAGE_DETERMINED, | |
| 262 Source<RenderViewHost>(render_view_host)); | |
| 263 ui_test_utils::RunMessageLoop(); | |
| 264 } | |
| 265 | |
| 266 virtual void Observe(NotificationType type, | |
| 267 const NotificationSource& source, | |
| 268 const NotificationDetails& details) { | |
| 269 language_ = *(Details<std::string>(details).ptr()); | |
| 270 MessageLoopForUI::current()->Quit(); | |
| 271 } | |
| 272 | |
| 273 std::string language() const { | |
| 274 return language_; | |
| 275 } | |
| 276 | |
| 277 private: | |
| 278 NotificationRegistrar registrar_; | |
| 279 std::string language_; | |
| 280 | |
| 281 DISALLOW_COPY_AND_ASSIGN(LanguageDetectionNotificationObserver); | |
| 282 }; | |
| 283 | |
| 284 class FindInPageNotificationObserver : public NotificationObserver { | 257 class FindInPageNotificationObserver : public NotificationObserver { |
| 285 public: | 258 public: |
| 286 explicit FindInPageNotificationObserver(TabContents* parent_tab) | 259 explicit FindInPageNotificationObserver(TabContents* parent_tab) |
| 287 : parent_tab_(parent_tab), | 260 : parent_tab_(parent_tab), |
| 288 active_match_ordinal_(-1), | 261 active_match_ordinal_(-1), |
| 289 number_of_matches_(0) { | 262 number_of_matches_(0) { |
| 290 current_find_request_id_ = parent_tab->current_find_request_id(); | 263 current_find_request_id_ = parent_tab->current_find_request_id(); |
| 291 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, | 264 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, |
| 292 Source<TabContents>(parent_tab_)); | 265 Source<TabContents>(parent_tab_)); |
| 293 ui_test_utils::RunMessageLoop(); | 266 ui_test_utils::RunMessageLoop(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 504 SimpleNotificationObserver<RenderViewHost> | 477 SimpleNotificationObserver<RenderViewHost> |
| 505 focus_observer(NotificationType::FOCUS_CHANGED_IN_PAGE, rvh); | 478 focus_observer(NotificationType::FOCUS_CHANGED_IN_PAGE, rvh); |
| 506 } | 479 } |
| 507 | 480 |
| 508 void WaitForFocusInBrowser(Browser* browser) { | 481 void WaitForFocusInBrowser(Browser* browser) { |
| 509 SimpleNotificationObserver<Browser> | 482 SimpleNotificationObserver<Browser> |
| 510 focus_observer(NotificationType::FOCUS_RETURNED_TO_BROWSER, | 483 focus_observer(NotificationType::FOCUS_RETURNED_TO_BROWSER, |
| 511 browser); | 484 browser); |
| 512 } | 485 } |
| 513 | 486 |
| 514 std::string WaitForLanguageDetection(TabContents* tab) { | |
| 515 LanguageDetectionNotificationObserver observer(tab->render_view_host()); | |
| 516 return observer.language(); | |
| 517 } | |
| 518 | |
| 519 int FindInPage(TabContents* tab_contents, const string16& search_string, | 487 int FindInPage(TabContents* tab_contents, const string16& search_string, |
| 520 bool forward, bool match_case, int* ordinal) { | 488 bool forward, bool match_case, int* ordinal) { |
| 521 tab_contents->StartFinding(search_string, forward, match_case); | 489 tab_contents->StartFinding(search_string, forward, match_case); |
| 522 FindInPageNotificationObserver observer(tab_contents); | 490 FindInPageNotificationObserver observer(tab_contents); |
| 523 if (ordinal) | 491 if (ordinal) |
| 524 *ordinal = observer.active_match_ordinal(); | 492 *ordinal = observer.active_match_ordinal(); |
| 525 return observer.number_of_matches(); | 493 return observer.number_of_matches(); |
| 526 } | 494 } |
| 527 | 495 |
| 528 void RegisterAndWait(NotificationType::Type type, | 496 void RegisterAndWait(NotificationType::Type type, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 556 quit_loop_invoked_ = true; | 524 quit_loop_invoked_ = true; |
| 557 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 525 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 558 } | 526 } |
| 559 | 527 |
| 560 void TimedMessageLoopRunner::QuitAfter(int ms) { | 528 void TimedMessageLoopRunner::QuitAfter(int ms) { |
| 561 quit_loop_invoked_ = true; | 529 quit_loop_invoked_ = true; |
| 562 loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, ms); | 530 loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, ms); |
| 563 } | 531 } |
| 564 | 532 |
| 565 } // namespace ui_test_utils | 533 } // namespace ui_test_utils |
| OLD | NEW |