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

Side by Side Diff: chrome/test/base/ui_test_utils.cc

Issue 10915002: Convert the history pyauto tests to a browser_tests. (Closed) Base URL: svn://chrome-svn/chrome/trunk/src/
Patch Set: make DEPS clearer/cleaner after discussion with erikwright Created 8 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 | Annotate | Revision Log
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
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 "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
11 #include "base/bind.h" 11 #include "base/bind.h"
12 #include "base/bind_helpers.h" 12 #include "base/bind_helpers.h"
13 #include "base/callback.h" 13 #include "base/callback.h"
14 #include "base/command_line.h" 14 #include "base/command_line.h"
15 #include "base/file_path.h" 15 #include "base/file_path.h"
16 #include "base/file_util.h" 16 #include "base/file_util.h"
17 #include "base/json/json_reader.h" 17 #include "base/json/json_reader.h"
18 #include "base/memory/scoped_ptr.h" 18 #include "base/memory/scoped_ptr.h"
19 #include "base/message_loop.h" 19 #include "base/message_loop.h"
20 #include "base/path_service.h" 20 #include "base/path_service.h"
21 #include "base/test/test_timeouts.h" 21 #include "base/test/test_timeouts.h"
22 #include "base/time.h" 22 #include "base/time.h"
23 #include "base/utf_string_conversions.h" 23 #include "base/utf_string_conversions.h"
24 #include "base/values.h" 24 #include "base/values.h"
25 #include "chrome/browser/bookmarks/bookmark_model.h" 25 #include "chrome/browser/bookmarks/bookmark_model.h"
26 #include "chrome/browser/browser_process.h" 26 #include "chrome/browser/browser_process.h"
27 #include "chrome/browser/history/history_service_factory.h"
27 #include "chrome/browser/infobars/infobar_tab_helper.h" 28 #include "chrome/browser/infobars/infobar_tab_helper.h"
29 #include "chrome/browser/prefs/pref_service.h"
28 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
29 #include "chrome/browser/search_engines/template_url_service.h" 31 #include "chrome/browser/search_engines/template_url_service.h"
30 #include "chrome/browser/search_engines/template_url_service_test_util.h" 32 #include "chrome/browser/search_engines/template_url_service_test_util.h"
31 #include "chrome/browser/tab_contents/thumbnail_generator.h" 33 #include "chrome/browser/tab_contents/thumbnail_generator.h"
32 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h" 34 #include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
33 #include "chrome/browser/ui/browser.h" 35 #include "chrome/browser/ui/browser.h"
34 #include "chrome/browser/ui/browser_commands.h" 36 #include "chrome/browser/ui/browser_commands.h"
35 #include "chrome/browser/ui/browser_finder.h" 37 #include "chrome/browser/ui/browser_finder.h"
36 #include "chrome/browser/ui/browser_list.h" 38 #include "chrome/browser/ui/browser_list.h"
37 #include "chrome/browser/ui/browser_navigator.h" 39 #include "chrome/browser/ui/browser_navigator.h"
38 #include "chrome/browser/ui/browser_tabstrip.h" 40 #include "chrome/browser/ui/browser_tabstrip.h"
39 #include "chrome/browser/ui/browser_window.h" 41 #include "chrome/browser/ui/browser_window.h"
40 #include "chrome/browser/ui/find_bar/find_notification_details.h" 42 #include "chrome/browser/ui/find_bar/find_notification_details.h"
41 #include "chrome/browser/ui/find_bar/find_tab_helper.h" 43 #include "chrome/browser/ui/find_bar/find_tab_helper.h"
42 #include "chrome/browser/ui/tab_contents/tab_contents.h" 44 #include "chrome/browser/ui/tab_contents/tab_contents.h"
43 #include "chrome/common/chrome_notification_types.h" 45 #include "chrome/common/chrome_notification_types.h"
44 #include "chrome/common/chrome_paths.h" 46 #include "chrome/common/chrome_paths.h"
45 #include "chrome/common/extensions/extension_action.h" 47 #include "chrome/common/extensions/extension_action.h"
48 #include "chrome/common/pref_names.h"
46 #include "chrome/test/base/bookmark_load_observer.h" 49 #include "chrome/test/base/bookmark_load_observer.h"
47 #include "content/public/browser/browser_thread.h" 50 #include "content/public/browser/browser_thread.h"
48 #include "content/public/browser/dom_operation_notification_details.h" 51 #include "content/public/browser/dom_operation_notification_details.h"
49 #include "content/public/browser/download_item.h" 52 #include "content/public/browser/download_item.h"
50 #include "content/public/browser/download_manager.h" 53 #include "content/public/browser/download_manager.h"
51 #include "content/public/browser/geolocation.h" 54 #include "content/public/browser/geolocation.h"
52 #include "content/public/browser/navigation_controller.h" 55 #include "content/public/browser/navigation_controller.h"
53 #include "content/public/browser/navigation_entry.h" 56 #include "content/public/browser/navigation_entry.h"
54 #include "content/public/browser/notification_service.h" 57 #include "content/public/browser/notification_service.h"
55 #include "content/public/browser/render_process_host.h" 58 #include "content/public/browser/render_process_host.h"
56 #include "content/public/browser/render_view_host.h" 59 #include "content/public/browser/render_view_host.h"
57 #include "content/public/browser/web_contents.h" 60 #include "content/public/browser/web_contents.h"
58 #include "content/public/browser/web_contents_observer.h" 61 #include "content/public/browser/web_contents_observer.h"
59 #include "content/public/browser/web_contents_view.h" 62 #include "content/public/browser/web_contents_view.h"
60 #include "content/public/common/geoposition.h" 63 #include "content/public/common/geoposition.h"
61 #include "content/public/test/browser_test_utils.h" 64 #include "content/public/test/browser_test_utils.h"
65 #include "content/public/test/download_test_observer.h"
62 #include "content/public/test/test_navigation_observer.h" 66 #include "content/public/test/test_navigation_observer.h"
63 #include "content/public/test/test_utils.h" 67 #include "content/public/test/test_utils.h"
64 #include "net/base/net_util.h" 68 #include "net/base/net_util.h"
65 #include "net/test/python_utils.h" 69 #include "net/test/python_utils.h"
66 #include "third_party/skia/include/core/SkBitmap.h" 70 #include "third_party/skia/include/core/SkBitmap.h"
67 #include "third_party/skia/include/core/SkColor.h" 71 #include "third_party/skia/include/core/SkColor.h"
68 #include "ui/gfx/size.h" 72 #include "ui/gfx/size.h"
69 #include "ui/ui_controls/ui_controls.h" 73 #include "ui/ui_controls/ui_controls.h"
70 74
71 #if defined(USE_AURA) 75 #if defined(USE_AURA)
(...skipping 181 matching lines...) Expand 10 before | Expand all | Expand 10 after
253 return; 257 return;
254 } 258 }
255 WebContents* web_contents = NULL; 259 WebContents* web_contents = NULL;
256 if (disposition == NEW_BACKGROUND_TAB) { 260 if (disposition == NEW_BACKGROUND_TAB) {
257 // We've opened up a new tab, but not selected it. 261 // We've opened up a new tab, but not selected it.
258 web_contents = 262 web_contents =
259 chrome::GetWebContentsAt(browser, browser->active_index() + 1); 263 chrome::GetWebContentsAt(browser, browser->active_index() + 1);
260 EXPECT_TRUE(web_contents != NULL) 264 EXPECT_TRUE(web_contents != NULL)
261 << " Unable to wait for navigation to \"" << url.spec() 265 << " Unable to wait for navigation to \"" << url.spec()
262 << "\" because the new tab is not available yet"; 266 << "\" because the new tab is not available yet";
263 return; 267 if (!web_contents)
268 return;
264 } else if ((disposition == CURRENT_TAB) || 269 } else if ((disposition == CURRENT_TAB) ||
265 (disposition == NEW_FOREGROUND_TAB) || 270 (disposition == NEW_FOREGROUND_TAB) ||
266 (disposition == SINGLETON_TAB)) { 271 (disposition == SINGLETON_TAB)) {
267 // The currently selected tab is the right one. 272 // The currently selected tab is the right one.
268 web_contents = chrome::GetActiveWebContents(browser); 273 web_contents = chrome::GetActiveWebContents(browser);
269 } 274 }
270 if (disposition == CURRENT_TAB) { 275 if (disposition == CURRENT_TAB) {
271 base::RunLoop run_loop; 276 base::RunLoop run_loop;
272 same_tab_observer.WaitForObservation( 277 same_tab_observer.WaitForObservation(
273 base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)), 278 base::Bind(&content::RunThisRunLoop, base::Unretained(&run_loop)),
(...skipping 139 matching lines...) Expand 10 before | Expand all | Expand 10 after
413 } 418 }
414 419
415 void WaitForHistoryToLoad(HistoryService* history_service) { 420 void WaitForHistoryToLoad(HistoryService* history_service) {
416 content::WindowedNotificationObserver history_loaded_observer( 421 content::WindowedNotificationObserver history_loaded_observer(
417 chrome::NOTIFICATION_HISTORY_LOADED, 422 chrome::NOTIFICATION_HISTORY_LOADED,
418 content::NotificationService::AllSources()); 423 content::NotificationService::AllSources());
419 if (!history_service->BackendLoaded()) 424 if (!history_service->BackendLoaded())
420 history_loaded_observer.Wait(); 425 history_loaded_observer.Wait();
421 } 426 }
422 427
428 void DownloadURL(Browser* browser, const GURL& download_url) {
429 ScopedTempDir downloads_directory;
430 ASSERT_TRUE(downloads_directory.CreateUniqueTempDir());
431 browser->profile()->GetPrefs()->SetFilePath(
432 prefs::kDownloadDefaultDirectory, downloads_directory.path());
433
434 content::DownloadManager* download_manager =
435 content::BrowserContext::GetDownloadManager(browser->profile());
436 scoped_ptr<content::DownloadTestObserver> observer(
437 new content::DownloadTestObserverTerminal(
438 download_manager, 1,
439 content::DownloadTestObserver::ON_DANGEROUS_DOWNLOAD_ACCEPT));
440
441 ui_test_utils::NavigateToURL(browser, download_url);
442 observer->WaitForFinished();
443 }
444
423 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) { 445 bool GetNativeWindow(const Browser* browser, gfx::NativeWindow* native_window) {
424 BrowserWindow* window = browser->window(); 446 BrowserWindow* window = browser->window();
425 if (!window) 447 if (!window)
426 return false; 448 return false;
427 449
428 *native_window = window->GetNativeWindow(); 450 *native_window = window->GetNativeWindow();
429 return *native_window; 451 return *native_window;
430 } 452 }
431 453
432 bool BringBrowserWindowToFront(const Browser* browser) { 454 bool BringBrowserWindowToFront(const Browser* browser) {
(...skipping 273 matching lines...) Expand 10 before | Expand all | Expand 10 after
706 int state, 728 int state,
707 const base::Closure& followup) { 729 const base::Closure& followup) {
708 if (!followup.is_null()) 730 if (!followup.is_null())
709 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); 731 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup);
710 else 732 else
711 ui_controls::SendMouseEvents(button, state); 733 ui_controls::SendMouseEvents(button, state);
712 } 734 }
713 735
714 } // namespace internal 736 } // namespace internal
715 737
716 HistoryEnumerator::HistoryEnumerator(HistoryService* history) { 738 HistoryEnumerator::HistoryEnumerator(Profile* profile) {
717 CHECK(history); 739 scoped_refptr<content::MessageLoopRunner> message_loop_runner =
718 BrowserThread::PostTask( 740 new content::MessageLoopRunner;
719 BrowserThread::UI, 741
720 FROM_HERE, 742 HistoryService* hs = HistoryServiceFactory::GetForProfile(
721 base::Bind(&HistoryService::IterateURLs, history, this)); 743 profile, Profile::EXPLICIT_ACCESS);
722 content::RunMessageLoop(); 744 hs->QueryHistory(
745 string16(),
746 history::QueryOptions(),
747 &consumer_,
748 base::Bind(&HistoryEnumerator::HistoryQueryComplete,
749 base::Unretained(this), message_loop_runner->QuitClosure()));
750 message_loop_runner->Run();
723 } 751 }
724 752
725 HistoryEnumerator::~HistoryEnumerator() {} 753 HistoryEnumerator::~HistoryEnumerator() {}
726 754
727 void HistoryEnumerator::OnURL(const GURL& url) { 755 void HistoryEnumerator::HistoryQueryComplete(
728 urls_.push_back(url); 756 const base::Closure& quit_task,
729 } 757 HistoryService::Handle request_handle,
730 758 history::QueryResults* results) {
731 void HistoryEnumerator::OnComplete(bool success) { 759 for (size_t i = 0; i < results->size(); ++i)
732 BrowserThread::PostTask( 760 urls_.push_back((*results)[i].url());
733 BrowserThread::UI, 761 quit_task.Run();
734 FROM_HERE,
735 MessageLoop::QuitClosure());
736 } 762 }
737 763
738 } // namespace ui_test_utils 764 } // namespace ui_test_utils
OLDNEW
« no previous file with comments | « chrome/test/base/ui_test_utils.h ('k') | chrome/test/functional/PYAUTO_TESTS » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698