| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/base/ui_test_utils.h" | 5 #include "chrome/test/base/ui_test_utils.h" |
| 6 | 6 |
| 7 #if defined(OS_WIN) | 7 #if defined(OS_WIN) |
| 8 #include <windows.h> | 8 #include <windows.h> |
| 9 #endif | 9 #endif |
| 10 | 10 |
| (...skipping 961 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 972 } | 972 } |
| 973 | 973 |
| 974 void WindowedTabAddedNotificationObserver::Observe( | 974 void WindowedTabAddedNotificationObserver::Observe( |
| 975 int type, | 975 int type, |
| 976 const content::NotificationSource& source, | 976 const content::NotificationSource& source, |
| 977 const content::NotificationDetails& details) { | 977 const content::NotificationDetails& details) { |
| 978 added_tab_ = content::Details<WebContents>(details).ptr(); | 978 added_tab_ = content::Details<WebContents>(details).ptr(); |
| 979 content::WindowedNotificationObserver::Observe(type, source, details); | 979 content::WindowedNotificationObserver::Observe(type, source, details); |
| 980 } | 980 } |
| 981 | 981 |
| 982 TitleWatcher::TitleWatcher(WebContents* web_contents, | |
| 983 const string16& expected_title) | |
| 984 : web_contents_(web_contents), | |
| 985 expected_title_observed_(false), | |
| 986 quit_loop_on_observation_(false) { | |
| 987 EXPECT_TRUE(web_contents != NULL); | |
| 988 expected_titles_.push_back(expected_title); | |
| 989 notification_registrar_.Add(this, | |
| 990 content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED, | |
| 991 content::Source<WebContents>(web_contents)); | |
| 992 | |
| 993 // When navigating through the history, the restored NavigationEntry's title | |
| 994 // will be used. If the entry ends up having the same title after we return | |
| 995 // to it, as will usually be the case, the | |
| 996 // NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED will then be suppressed, since the | |
| 997 // NavigationEntry's title hasn't changed. | |
| 998 notification_registrar_.Add( | |
| 999 this, | |
| 1000 content::NOTIFICATION_LOAD_STOP, | |
| 1001 content::Source<NavigationController>(&web_contents->GetController())); | |
| 1002 } | |
| 1003 | |
| 1004 void TitleWatcher::AlsoWaitForTitle(const string16& expected_title) { | |
| 1005 expected_titles_.push_back(expected_title); | |
| 1006 } | |
| 1007 | |
| 1008 TitleWatcher::~TitleWatcher() { | |
| 1009 } | |
| 1010 | |
| 1011 const string16& TitleWatcher::WaitAndGetTitle() { | |
| 1012 if (expected_title_observed_) | |
| 1013 return observed_title_; | |
| 1014 quit_loop_on_observation_ = true; | |
| 1015 message_loop_runner_ = new content::MessageLoopRunner; | |
| 1016 message_loop_runner_->Run(); | |
| 1017 return observed_title_; | |
| 1018 } | |
| 1019 | |
| 1020 void TitleWatcher::Observe(int type, | |
| 1021 const content::NotificationSource& source, | |
| 1022 const content::NotificationDetails& details) { | |
| 1023 if (type == content::NOTIFICATION_WEB_CONTENTS_TITLE_UPDATED) { | |
| 1024 WebContents* source_contents = content::Source<WebContents>(source).ptr(); | |
| 1025 ASSERT_EQ(web_contents_, source_contents); | |
| 1026 } else if (type == content::NOTIFICATION_LOAD_STOP) { | |
| 1027 NavigationController* controller = | |
| 1028 content::Source<NavigationController>(source).ptr(); | |
| 1029 ASSERT_EQ(&web_contents_->GetController(), controller); | |
| 1030 } else { | |
| 1031 FAIL() << "Unexpected notification received."; | |
| 1032 } | |
| 1033 | |
| 1034 std::vector<string16>::const_iterator it = | |
| 1035 std::find(expected_titles_.begin(), | |
| 1036 expected_titles_.end(), | |
| 1037 web_contents_->GetTitle()); | |
| 1038 if (it == expected_titles_.end()) | |
| 1039 return; | |
| 1040 observed_title_ = *it; | |
| 1041 expected_title_observed_ = true; | |
| 1042 if (quit_loop_on_observation_) { | |
| 1043 // Only call Quit once, on first Observe: | |
| 1044 quit_loop_on_observation_ = false; | |
| 1045 message_loop_runner_->Quit(); | |
| 1046 } | |
| 1047 } | |
| 1048 | |
| 1049 BrowserAddedObserver::BrowserAddedObserver() | 982 BrowserAddedObserver::BrowserAddedObserver() |
| 1050 : notification_observer_( | 983 : notification_observer_( |
| 1051 chrome::NOTIFICATION_BROWSER_OPENED, | 984 chrome::NOTIFICATION_BROWSER_OPENED, |
| 1052 content::NotificationService::AllSources()) { | 985 content::NotificationService::AllSources()) { |
| 1053 original_browsers_.insert(BrowserList::begin(), BrowserList::end()); | 986 original_browsers_.insert(BrowserList::begin(), BrowserList::end()); |
| 1054 } | 987 } |
| 1055 | 988 |
| 1056 BrowserAddedObserver::~BrowserAddedObserver() { | 989 BrowserAddedObserver::~BrowserAddedObserver() { |
| 1057 } | 990 } |
| 1058 | 991 |
| (...skipping 141 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1200 int state, | 1133 int state, |
| 1201 const base::Closure& followup) { | 1134 const base::Closure& followup) { |
| 1202 if (!followup.is_null()) | 1135 if (!followup.is_null()) |
| 1203 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 1136 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
| 1204 else | 1137 else |
| 1205 ui_controls::SendMouseEvents(button, state); | 1138 ui_controls::SendMouseEvents(button, state); |
| 1206 } | 1139 } |
| 1207 | 1140 |
| 1208 } // namespace internal | 1141 } // namespace internal |
| 1209 } // namespace ui_test_utils | 1142 } // namespace ui_test_utils |
| OLD | NEW |