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 <stdio.h> | 5 #include <stdio.h> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/scoped_observer.h" | 8 #include "base/scoped_observer.h" |
9 #include "base/strings/string16.h" | 9 #include "base/strings/string16.h" |
10 #include "base/strings/string_util.h" | 10 #include "base/strings/string_util.h" |
(...skipping 123 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
134 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; | 134 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; |
135 #else | 135 #else |
136 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; | 136 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; |
137 #endif | 137 #endif |
138 | 138 |
139 } // namespace | 139 } // namespace |
140 | 140 |
141 class OmniboxViewTest : public InProcessBrowserTest, | 141 class OmniboxViewTest : public InProcessBrowserTest, |
142 public content::NotificationObserver, | 142 public content::NotificationObserver, |
143 public history::HistoryServiceObserver { | 143 public history::HistoryServiceObserver { |
| 144 public: |
| 145 OmniboxViewTest() : observer_(this) {} |
| 146 |
| 147 // history::HisoryServiceObserver |
| 148 void OnHistoryServiceLoaded(HistoryService* history_service) override { |
| 149 base::MessageLoop::current()->Quit(); |
| 150 } |
| 151 |
144 protected: | 152 protected: |
145 void SetUpOnMainThread() override { | 153 void SetUpOnMainThread() override { |
146 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); | 154 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); |
147 ASSERT_NO_FATAL_FAILURE(SetupComponents()); | 155 ASSERT_NO_FATAL_FAILURE(SetupComponents()); |
148 chrome::FocusLocationBar(browser()); | 156 chrome::FocusLocationBar(browser()); |
149 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); | 157 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); |
150 } | 158 } |
151 | 159 |
152 static void GetOmniboxViewForBrowser( | 160 static void GetOmniboxViewForBrowser( |
153 const Browser* browser, | 161 const Browser* browser, |
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
278 } | 286 } |
279 } | 287 } |
280 | 288 |
281 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { | 289 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { |
282 Profile* profile = browser()->profile(); | 290 Profile* profile = browser()->profile(); |
283 HistoryService* history_service = HistoryServiceFactory::GetForProfile( | 291 HistoryService* history_service = HistoryServiceFactory::GetForProfile( |
284 profile, Profile::EXPLICIT_ACCESS); | 292 profile, Profile::EXPLICIT_ACCESS); |
285 ASSERT_TRUE(history_service); | 293 ASSERT_TRUE(history_service); |
286 | 294 |
287 if (!history_service->BackendLoaded()) { | 295 if (!history_service->BackendLoaded()) { |
288 content::NotificationRegistrar registrar; | 296 observer_.Add(history_service); |
289 registrar.Add(this, chrome::NOTIFICATION_HISTORY_LOADED, | |
290 content::Source<Profile>(profile)); | |
291 content::RunMessageLoop(); | 297 content::RunMessageLoop(); |
292 } | 298 } |
293 | 299 |
294 BookmarkModel* bookmark_model = | 300 BookmarkModel* bookmark_model = |
295 BookmarkModelFactory::GetForProfile(profile); | 301 BookmarkModelFactory::GetForProfile(profile); |
296 ASSERT_TRUE(bookmark_model); | 302 ASSERT_TRUE(bookmark_model); |
297 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); | 303 bookmarks::test::WaitForBookmarkModelToLoad(bookmark_model); |
298 | 304 |
299 GURL url(entry.url); | 305 GURL url(entry.url); |
300 // Add everything in order of time. We don't want to have a time that | 306 // Add everything in order of time. We don't want to have a time that |
(...skipping 41 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
342 ASSERT_NO_FATAL_FAILURE(SetupHistory()); | 348 ASSERT_NO_FATAL_FAILURE(SetupHistory()); |
343 } | 349 } |
344 | 350 |
345 void Observe(int type, | 351 void Observe(int type, |
346 const content::NotificationSource& source, | 352 const content::NotificationSource& source, |
347 const content::NotificationDetails& details) override { | 353 const content::NotificationDetails& details) override { |
348 switch (type) { | 354 switch (type) { |
349 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: | 355 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: |
350 case chrome::NOTIFICATION_TAB_PARENTED: | 356 case chrome::NOTIFICATION_TAB_PARENTED: |
351 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY: | 357 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY: |
352 case chrome::NOTIFICATION_HISTORY_LOADED: | |
353 break; | 358 break; |
354 default: | 359 default: |
355 FAIL() << "Unexpected notification type"; | 360 FAIL() << "Unexpected notification type"; |
356 } | 361 } |
357 base::MessageLoop::current()->Quit(); | 362 base::MessageLoop::current()->Quit(); |
358 } | 363 } |
359 | 364 |
360 void OnURLsModified(HistoryService* history_service, | 365 void OnURLsModified(HistoryService* history_service, |
361 const history::URLRows& changed_urls) override { | 366 const history::URLRows& changed_urls) override { |
362 base::MessageLoop::current()->Quit(); | 367 base::MessageLoop::current()->Quit(); |
363 } | 368 } |
| 369 |
| 370 private: |
| 371 ScopedObserver<HistoryService, OmniboxViewTest> observer_; |
| 372 |
| 373 DISALLOW_COPY_AND_ASSIGN(OmniboxViewTest); |
364 }; | 374 }; |
365 | 375 |
366 // Test if ctrl-* accelerators are workable in omnibox. | 376 // Test if ctrl-* accelerators are workable in omnibox. |
367 // See http://crbug.com/19193: omnibox blocks ctrl-* commands | 377 // See http://crbug.com/19193: omnibox blocks ctrl-* commands |
368 // | 378 // |
369 // Flaky on interactive tests (dbg), http://crbug.com/69433 | 379 // Flaky on interactive tests (dbg), http://crbug.com/69433 |
370 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { | 380 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, DISABLED_BrowserAccelerators) { |
371 OmniboxView* omnibox_view = NULL; | 381 OmniboxView* omnibox_view = NULL; |
372 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); | 382 ASSERT_NO_FATAL_FAILURE(GetOmniboxView(&omnibox_view)); |
373 | 383 |
(...skipping 1432 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
1806 omnibox_view->Update(); | 1816 omnibox_view->Update(); |
1807 EXPECT_EQ(url_c, omnibox_view->GetText()); | 1817 EXPECT_EQ(url_c, omnibox_view->GetText()); |
1808 } | 1818 } |
1809 | 1819 |
1810 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { | 1820 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { |
1811 browser()->toolbar_model()->set_url_replacement_enabled(true); | 1821 browser()->toolbar_model()->set_url_replacement_enabled(true); |
1812 chrome::FocusLocationBar(browser()); | 1822 chrome::FocusLocationBar(browser()); |
1813 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); | 1823 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); |
1814 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); | 1824 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); |
1815 } | 1825 } |
OLD | NEW |