| 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 |
| 257 class FindInPageNotificationObserver : public NotificationObserver { | 284 class FindInPageNotificationObserver : public NotificationObserver { |
| 258 public: | 285 public: |
| 259 explicit FindInPageNotificationObserver(TabContents* parent_tab) | 286 explicit FindInPageNotificationObserver(TabContents* parent_tab) |
| 260 : parent_tab_(parent_tab), | 287 : parent_tab_(parent_tab), |
| 261 active_match_ordinal_(-1), | 288 active_match_ordinal_(-1), |
| 262 number_of_matches_(0) { | 289 number_of_matches_(0) { |
| 263 current_find_request_id_ = parent_tab->current_find_request_id(); | 290 current_find_request_id_ = parent_tab->current_find_request_id(); |
| 264 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, | 291 registrar_.Add(this, NotificationType::FIND_RESULT_AVAILABLE, |
| 265 Source<TabContents>(parent_tab_)); | 292 Source<TabContents>(parent_tab_)); |
| 266 ui_test_utils::RunMessageLoop(); | 293 ui_test_utils::RunMessageLoop(); |
| (...skipping 210 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 477 SimpleNotificationObserver<RenderViewHost> | 504 SimpleNotificationObserver<RenderViewHost> |
| 478 focus_observer(NotificationType::FOCUS_CHANGED_IN_PAGE, rvh); | 505 focus_observer(NotificationType::FOCUS_CHANGED_IN_PAGE, rvh); |
| 479 } | 506 } |
| 480 | 507 |
| 481 void WaitForFocusInBrowser(Browser* browser) { | 508 void WaitForFocusInBrowser(Browser* browser) { |
| 482 SimpleNotificationObserver<Browser> | 509 SimpleNotificationObserver<Browser> |
| 483 focus_observer(NotificationType::FOCUS_RETURNED_TO_BROWSER, | 510 focus_observer(NotificationType::FOCUS_RETURNED_TO_BROWSER, |
| 484 browser); | 511 browser); |
| 485 } | 512 } |
| 486 | 513 |
| 514 std::string WaitForLanguageDetection(TabContents* tab) { |
| 515 LanguageDetectionNotificationObserver observer(tab->render_view_host()); |
| 516 return observer.language(); |
| 517 } |
| 518 |
| 487 int FindInPage(TabContents* tab_contents, const string16& search_string, | 519 int FindInPage(TabContents* tab_contents, const string16& search_string, |
| 488 bool forward, bool match_case, int* ordinal) { | 520 bool forward, bool match_case, int* ordinal) { |
| 489 tab_contents->StartFinding(search_string, forward, match_case); | 521 tab_contents->StartFinding(search_string, forward, match_case); |
| 490 FindInPageNotificationObserver observer(tab_contents); | 522 FindInPageNotificationObserver observer(tab_contents); |
| 491 if (ordinal) | 523 if (ordinal) |
| 492 *ordinal = observer.active_match_ordinal(); | 524 *ordinal = observer.active_match_ordinal(); |
| 493 return observer.number_of_matches(); | 525 return observer.number_of_matches(); |
| 494 } | 526 } |
| 495 | 527 |
| 496 void RegisterAndWait(NotificationType::Type type, | 528 void RegisterAndWait(NotificationType::Type type, |
| (...skipping 27 matching lines...) Expand all Loading... |
| 524 quit_loop_invoked_ = true; | 556 quit_loop_invoked_ = true; |
| 525 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask); | 557 loop_->PostTask(FROM_HERE, new MessageLoop::QuitTask); |
| 526 } | 558 } |
| 527 | 559 |
| 528 void TimedMessageLoopRunner::QuitAfter(int ms) { | 560 void TimedMessageLoopRunner::QuitAfter(int ms) { |
| 529 quit_loop_invoked_ = true; | 561 quit_loop_invoked_ = true; |
| 530 loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, ms); | 562 loop_->PostDelayedTask(FROM_HERE, new MessageLoop::QuitTask, ms); |
| 531 } | 563 } |
| 532 | 564 |
| 533 } // namespace ui_test_utils | 565 } // namespace ui_test_utils |
| OLD | NEW |