Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(264)

Side by Side Diff: chrome/browser/ui/search/instant_test_utils.cc

Issue 14130012: InstantExtendedManualTests should fail and not hang (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: Fix bug number Created 7 years, 8 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright 2013 The Chromium Authors. All rights reserved. 1 // Copyright 2013 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/browser/ui/search/instant_test_utils.h" 5 #include "chrome/browser/ui/search/instant_test_utils.h"
6 6
7 #include "base/command_line.h" 7 #include "base/command_line.h"
8 #include "base/prefs/pref_service.h" 8 #include "base/prefs/pref_service.h"
9 #include "chrome/browser/profiles/profile.h" 9 #include "chrome/browser/profiles/profile.h"
10 #include "chrome/browser/search_engines/template_url_service.h" 10 #include "chrome/browser/search_engines/template_url_service.h"
(...skipping 15 matching lines...) Expand all
26 std::string WrapScript(const std::string& script) { 26 std::string WrapScript(const std::string& script) {
27 return "domAutomationController.send(" + script + ")"; 27 return "domAutomationController.send(" + script + ")";
28 } 28 }
29 29
30 } // namespace 30 } // namespace
31 31
32 // InstantTestModelObserver -------------------------------------------------- 32 // InstantTestModelObserver --------------------------------------------------
33 33
34 InstantTestModelObserver::InstantTestModelObserver( 34 InstantTestModelObserver::InstantTestModelObserver(
35 InstantOverlayModel* model, 35 InstantOverlayModel* model,
36 SearchMode::Type desired_mode_type) 36 SearchMode::Type expected_mode_type)
37 : model_(model), 37 : model_(model),
38 desired_mode_type_(desired_mode_type) { 38 expected_mode_type_(expected_mode_type),
39 observed_mode_type_(static_cast<SearchMode::Type>(-1)) {
39 model_->AddObserver(this); 40 model_->AddObserver(this);
40 } 41 }
41 42
42 InstantTestModelObserver::~InstantTestModelObserver() { 43 InstantTestModelObserver::~InstantTestModelObserver() {
43 model_->RemoveObserver(this); 44 model_->RemoveObserver(this);
44 } 45 }
45 46
46 void InstantTestModelObserver::WaitForDesiredOverlayState() { 47 bool InstantTestModelObserver::WaitForExpectedOverlayState() {
47 run_loop_.Run(); 48 run_loop_.Run();
49 return observed_mode_type_ == expected_mode_type_;
48 } 50 }
49 51
50 void InstantTestModelObserver::OverlayStateChanged( 52 void InstantTestModelObserver::OverlayStateChanged(
51 const InstantOverlayModel& model) { 53 const InstantOverlayModel& model) {
52 if (model.mode().mode == desired_mode_type_) 54 observed_mode_type_ = model.mode().mode;
Jered 2013/04/16 22:35:57 I'm worried that this might break some tests which
dhollowa 2013/04/16 22:50:51 Yes, I verified. No problems with this.
53 run_loop_.Quit(); 55 EXPECT_EQ(expected_mode_type_, observed_mode_type_);
56 run_loop_.Quit();
54 } 57 }
55 58
56 // InstantTestBase ----------------------------------------------------------- 59 // InstantTestBase -----------------------------------------------------------
57 60
58 void InstantTestBase::SetupInstant(Browser* browser) { 61 void InstantTestBase::SetupInstant(Browser* browser) {
59 browser_ = browser; 62 browser_ = browser;
60 TemplateURLService* service = 63 TemplateURLService* service =
61 TemplateURLServiceFactory::GetForProfile(browser_->profile()); 64 TemplateURLServiceFactory::GetForProfile(browser_->profile());
62 ui_test_utils::WaitForTemplateURLServiceToLoad(service); 65 ui_test_utils::WaitForTemplateURLServiceToLoad(service);
63 66
(...skipping 69 matching lines...) Expand 10 before | Expand all | Expand 10 after
133 FocusOmnibox(); 136 FocusOmnibox();
134 ntp_observer.Wait(); 137 ntp_observer.Wait();
135 overlay_observer.Wait(); 138 overlay_observer.Wait();
136 } 139 }
137 140
138 void InstantTestBase::SetOmniboxText(const std::string& text) { 141 void InstantTestBase::SetOmniboxText(const std::string& text) {
139 FocusOmnibox(); 142 FocusOmnibox();
140 omnibox()->SetUserText(UTF8ToUTF16(text)); 143 omnibox()->SetUserText(UTF8ToUTF16(text));
141 } 144 }
142 145
143 void InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow( 146 bool InstantTestBase::SetOmniboxTextAndWaitForOverlayToShow(
144 const std::string& text) { 147 const std::string& text) {
145 InstantTestModelObserver observer( 148 InstantTestModelObserver observer(
146 instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS); 149 instant()->model(), SearchMode::MODE_SEARCH_SUGGESTIONS);
147 SetOmniboxText(text); 150 SetOmniboxText(text);
148 observer.WaitForDesiredOverlayState(); 151 return observer.WaitForExpectedOverlayState();
149 } 152 }
150 153
151 void InstantTestBase::SetOmniboxTextAndWaitForSuggestion( 154 void InstantTestBase::SetOmniboxTextAndWaitForSuggestion(
152 const std::string& text) { 155 const std::string& text) {
153 content::WindowedNotificationObserver observer( 156 content::WindowedNotificationObserver observer(
154 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION, 157 chrome::NOTIFICATION_INSTANT_SET_SUGGESTION,
155 content::NotificationService::AllSources()); 158 content::NotificationService::AllSources());
156 SetOmniboxText(text); 159 SetOmniboxText(text);
157 observer.Wait(); 160 observer.Wait();
158 } 161 }
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after
214 size_t start = 0, end = 0; 217 size_t start = 0, end = 0;
215 omnibox()->GetSelectionBounds(&start, &end); 218 omnibox()->GetSelectionBounds(&start, &end);
216 if (start > end) 219 if (start > end)
217 std::swap(start, end); 220 std::swap(start, end);
218 return omnibox()->GetText().substr(start, end - start); 221 return omnibox()->GetText().substr(start, end - start);
219 } 222 }
220 223
221 string16 InstantTestBase::GetGrayText() { 224 string16 InstantTestBase::GetGrayText() {
222 return omnibox()->GetInstantSuggestion(); 225 return omnibox()->GetInstantSuggestion();
223 } 226 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698