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

Side by Side Diff: chrome/browser/ui/omnibox/omnibox_view_browsertest.cc

Issue 573553004: Eliminate NOTIFICATION_HISTORY_LOADED notification (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 3 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
OLDNEW
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 16 matching lines...) Expand all
27 #include "chrome/browser/ui/toolbar/test_toolbar_model.h" 27 #include "chrome/browser/ui/toolbar/test_toolbar_model.h"
28 #include "chrome/common/chrome_paths.h" 28 #include "chrome/common/chrome_paths.h"
29 #include "chrome/common/chrome_switches.h" 29 #include "chrome/common/chrome_switches.h"
30 #include "chrome/common/url_constants.h" 30 #include "chrome/common/url_constants.h"
31 #include "chrome/test/base/in_process_browser_test.h" 31 #include "chrome/test/base/in_process_browser_test.h"
32 #include "chrome/test/base/interactive_test_utils.h" 32 #include "chrome/test/base/interactive_test_utils.h"
33 #include "chrome/test/base/ui_test_utils.h" 33 #include "chrome/test/base/ui_test_utils.h"
34 #include "components/bookmarks/browser/bookmark_model.h" 34 #include "components/bookmarks/browser/bookmark_model.h"
35 #include "components/bookmarks/browser/bookmark_utils.h" 35 #include "components/bookmarks/browser/bookmark_utils.h"
36 #include "components/bookmarks/test/bookmark_test_helpers.h" 36 #include "components/bookmarks/test/bookmark_test_helpers.h"
37 #include "components/history/core/browser/history_service_observer.h"
37 #include "components/omnibox/autocomplete_input.h" 38 #include "components/omnibox/autocomplete_input.h"
38 #include "components/omnibox/autocomplete_match.h" 39 #include "components/omnibox/autocomplete_match.h"
39 #include "components/search_engines/template_url.h" 40 #include "components/search_engines/template_url.h"
40 #include "components/search_engines/template_url_service.h" 41 #include "components/search_engines/template_url_service.h"
41 #include "content/public/browser/notification_service.h" 42 #include "content/public/browser/notification_service.h"
42 #include "content/public/browser/web_contents.h" 43 #include "content/public/browser/web_contents.h"
43 #include "net/dns/mock_host_resolver.h" 44 #include "net/dns/mock_host_resolver.h"
44 #include "ui/base/clipboard/clipboard.h" 45 #include "ui/base/clipboard/clipboard.h"
45 #include "ui/base/clipboard/scoped_clipboard_writer.h" 46 #include "ui/base/clipboard/scoped_clipboard_writer.h"
46 #include "ui/events/event_constants.h" 47 #include "ui/events/event_constants.h"
(...skipping 84 matching lines...) Expand 10 before | Expand all | Expand 10 after
131 132
132 #if defined(OS_MACOSX) 133 #if defined(OS_MACOSX)
133 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN; 134 const int kCtrlOrCmdMask = ui::EF_COMMAND_DOWN;
134 #else 135 #else
135 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN; 136 const int kCtrlOrCmdMask = ui::EF_CONTROL_DOWN;
136 #endif 137 #endif
137 138
138 } // namespace 139 } // namespace
139 140
140 class OmniboxViewTest : public InProcessBrowserTest, 141 class OmniboxViewTest : public InProcessBrowserTest,
141 public content::NotificationObserver { 142 public content::NotificationObserver,
143 public history::HistoryServiceObserver {
144 public:
145 virtual void HistoryServiceLoaded(HistoryService* history_service) OVERRIDE {
146 history_service->RemoveHistoryServiceObserver(this);
sdefresne 2014/10/20 13:15:42 Use ScopedObserver<>
nshaik 2014/10/29 08:43:39 Done.
147 base::MessageLoop::current()->Quit();
148 }
149
150 virtual ~OmniboxViewTest() {
151 Profile* profile = browser()->profile();
sdefresne 2014/10/20 13:15:42 You can remove this if you use ScopedObserver<>
nshaik 2014/10/29 08:43:39 Done.
152 HistoryService* history_service =
153 HistoryServiceFactory::GetForProfile(profile, Profile::EXPLICIT_ACCESS);
154 history_service->RemoveHistoryServiceObserver(this);
155 }
156
142 protected: 157 protected:
143 virtual void SetUpOnMainThread() OVERRIDE { 158 virtual void SetUpOnMainThread() OVERRIDE {
144 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser())); 159 ASSERT_TRUE(ui_test_utils::BringBrowserWindowToFront(browser()));
145 ASSERT_NO_FATAL_FAILURE(SetupComponents()); 160 ASSERT_NO_FATAL_FAILURE(SetupComponents());
146 chrome::FocusLocationBar(browser()); 161 chrome::FocusLocationBar(browser());
147 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX)); 162 ASSERT_TRUE(ui_test_utils::IsViewFocused(browser(), VIEW_ID_OMNIBOX));
148 } 163 }
149 164
150 static void GetOmniboxViewForBrowser( 165 static void GetOmniboxViewForBrowser(
151 const Browser* browser, 166 const Browser* browser,
(...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after
276 } 291 }
277 } 292 }
278 293
279 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) { 294 void AddHistoryEntry(const TestHistoryEntry& entry, const Time& time) {
280 Profile* profile = browser()->profile(); 295 Profile* profile = browser()->profile();
281 HistoryService* history_service = HistoryServiceFactory::GetForProfile( 296 HistoryService* history_service = HistoryServiceFactory::GetForProfile(
282 profile, Profile::EXPLICIT_ACCESS); 297 profile, Profile::EXPLICIT_ACCESS);
283 ASSERT_TRUE(history_service); 298 ASSERT_TRUE(history_service);
284 299
285 if (!history_service->BackendLoaded()) { 300 if (!history_service->BackendLoaded()) {
286 content::NotificationRegistrar registrar; 301 history_service->AddHistoryServiceObserver(this);
287 registrar.Add(this, chrome::NOTIFICATION_HISTORY_LOADED,
288 content::Source<Profile>(profile));
289 content::RunMessageLoop(); 302 content::RunMessageLoop();
290 } 303 }
291 304
292 BookmarkModel* bookmark_model = 305 BookmarkModel* bookmark_model =
293 BookmarkModelFactory::GetForProfile(profile); 306 BookmarkModelFactory::GetForProfile(profile);
294 ASSERT_TRUE(bookmark_model); 307 ASSERT_TRUE(bookmark_model);
295 test::WaitForBookmarkModelToLoad(bookmark_model); 308 test::WaitForBookmarkModelToLoad(bookmark_model);
296 309
297 GURL url(entry.url); 310 GURL url(entry.url);
298 // Add everything in order of time. We don't want to have a time that 311 // 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
340 ASSERT_NO_FATAL_FAILURE(SetupHistory()); 353 ASSERT_NO_FATAL_FAILURE(SetupHistory());
341 } 354 }
342 355
343 virtual void Observe(int type, 356 virtual void Observe(int type,
344 const content::NotificationSource& source, 357 const content::NotificationSource& source,
345 const content::NotificationDetails& details) OVERRIDE { 358 const content::NotificationDetails& details) OVERRIDE {
346 switch (type) { 359 switch (type) {
347 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED: 360 case content::NOTIFICATION_WEB_CONTENTS_DESTROYED:
348 case chrome::NOTIFICATION_TAB_PARENTED: 361 case chrome::NOTIFICATION_TAB_PARENTED:
349 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY: 362 case chrome::NOTIFICATION_AUTOCOMPLETE_CONTROLLER_RESULT_READY:
350 case chrome::NOTIFICATION_HISTORY_LOADED:
351 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED: 363 case chrome::NOTIFICATION_HISTORY_URLS_MODIFIED:
352 break; 364 break;
353 default: 365 default:
354 FAIL() << "Unexpected notification type"; 366 FAIL() << "Unexpected notification type";
355 } 367 }
356 base::MessageLoop::current()->Quit(); 368 base::MessageLoop::current()->Quit();
357 } 369 }
358 }; 370 };
359 371
360 // Test if ctrl-* accelerators are workable in omnibox. 372 // Test if ctrl-* accelerators are workable in omnibox.
(...skipping 1454 matching lines...) Expand 10 before | Expand all | Expand 10 after
1815 omnibox_view->Update(); 1827 omnibox_view->Update();
1816 EXPECT_EQ(url_c, omnibox_view->GetText()); 1828 EXPECT_EQ(url_c, omnibox_view->GetText());
1817 } 1829 }
1818 1830
1819 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) { 1831 IN_PROC_BROWSER_TEST_F(OmniboxViewTest, EscDisablesSearchTermReplacement) {
1820 browser()->toolbar_model()->set_url_replacement_enabled(true); 1832 browser()->toolbar_model()->set_url_replacement_enabled(true);
1821 chrome::FocusLocationBar(browser()); 1833 chrome::FocusLocationBar(browser());
1822 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0)); 1834 ASSERT_NO_FATAL_FAILURE(SendKey(ui::VKEY_ESCAPE, 0));
1823 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled()); 1835 EXPECT_FALSE(browser()->toolbar_model()->url_replacement_enabled());
1824 } 1836 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698