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