#include "base/bind_helpers.h"
#include "base/callback.h"
#include "base/command_line.h"
-#include "base/file_util.h"
#include "base/files/file_path.h"
+#include "base/files/file_util.h"
#include "base/json/json_reader.h"
#include "base/memory/ref_counted.h"
#include "base/memory/scoped_ptr.h"
#include "chrome/browser/bookmarks/bookmark_model_factory.h"
#include "chrome/browser/browser_process.h"
#include "chrome/browser/chrome_notification_types.h"
-#include "chrome/browser/devtools/devtools_window.h"
-#include "chrome/browser/extensions/extension_action.h"
#include "chrome/browser/history/history_service_factory.h"
#include "chrome/browser/profiles/profile.h"
-#include "chrome/browser/search_engines/template_url_service.h"
-#include "chrome/browser/search_engines/template_url_service_test_util.h"
-#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog.h"
-#include "chrome/browser/ui/app_modal_dialogs/app_modal_dialog_queue.h"
#include "chrome/browser/ui/browser.h"
#include "chrome/browser/ui/browser_commands.h"
#include "chrome/browser/ui/browser_finder.h"
#include "chrome/browser/ui/find_bar/find_notification_details.h"
#include "chrome/browser/ui/find_bar/find_tab_helper.h"
#include "chrome/browser/ui/host_desktop.h"
-#include "chrome/browser/ui/omnibox/location_bar.h"
+#include "chrome/browser/ui/location_bar/location_bar.h"
#include "chrome/browser/ui/omnibox/omnibox_view.h"
#include "chrome/browser/ui/tabs/tab_strip_model.h"
#include "chrome/common/chrome_paths.h"
#include "chrome/common/pref_names.h"
#include "chrome/test/base/find_in_page_observer.h"
+#include "components/app_modal_dialogs/app_modal_dialog.h"
+#include "components/app_modal_dialogs/app_modal_dialog_queue.h"
#include "components/bookmarks/browser/bookmark_model.h"
+#include "components/search_engines/template_url_service.h"
#include "content/public/browser/dom_operation_notification_details.h"
#include "content/public/browser/download_item.h"
#include "content/public/browser/download_manager.h"
#include "third_party/skia/include/core/SkBitmap.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/gfx/size.h"
-#include "ui/snapshot/test/snapshot_desktop.h"
#if defined(USE_AURA)
#include "ash/shell.h"
namespace {
-#if defined(OS_WIN)
-const char kSnapshotBaseName[] = "ChromiumSnapshot";
-const char kSnapshotExtension[] = ".png";
-
-base::FilePath GetSnapshotFileName(const base::FilePath& snapshot_directory) {
- base::Time::Exploded the_time;
-
- base::Time::Now().LocalExplode(&the_time);
- std::string filename(base::StringPrintf("%s%04d%02d%02d%02d%02d%02d%s",
- kSnapshotBaseName, the_time.year, the_time.month, the_time.day_of_month,
- the_time.hour, the_time.minute, the_time.second, kSnapshotExtension));
-
- base::FilePath snapshot_file = snapshot_directory.AppendASCII(filename);
- if (base::PathExists(snapshot_file)) {
- int index = 0;
- std::string suffix;
- base::FilePath trial_file;
- do {
- suffix = base::StringPrintf(" (%d)", ++index);
- trial_file = snapshot_file.InsertBeforeExtensionASCII(suffix);
- } while (base::PathExists(trial_file));
- snapshot_file = trial_file;
- }
- return snapshot_file;
-}
-#endif // defined(OS_WIN)
-
Browser* WaitForBrowserNotInSet(std::set<Browser*> excluded_browsers) {
Browser* new_browser = GetBrowserNotInSet(excluded_browsers);
if (new_browser == NULL) {
return new_browser;
}
+class AppModalDialogWaiter : public AppModalDialogObserver {
+ public:
+ AppModalDialogWaiter()
+ : dialog_(NULL) {
+ }
+ ~AppModalDialogWaiter() override {
+ }
+
+ AppModalDialog* Wait() {
+ if (dialog_)
+ return dialog_;
+ message_loop_runner_ = new content::MessageLoopRunner;
+ message_loop_runner_->Run();
+ EXPECT_TRUE(dialog_);
+ return dialog_;
+ }
+
+ // AppModalDialogWaiter:
+ void Notify(AppModalDialog* dialog) override {
+ DCHECK(!dialog_);
+ dialog_ = dialog;
+ if (message_loop_runner_.get() && message_loop_runner_->loop_running())
+ message_loop_runner_->Quit();
+ }
+
+ private:
+ AppModalDialog* dialog_;
+ scoped_refptr<content::MessageLoopRunner> message_loop_runner_;
+
+ DISALLOW_COPY_AND_ASSIGN(AppModalDialogWaiter);
+};
+
} // namespace
bool GetCurrentTabTitle(const Browser* browser, base::string16* title) {
void NavigateToURLWithPost(Browser* browser, const GURL& url) {
chrome::NavigateParams params(browser, url,
- content::PAGE_TRANSITION_FORM_SUBMIT);
+ ui::PAGE_TRANSITION_FORM_SUBMIT);
params.uses_post = true;
NavigateToURL(¶ms);
}
content::NotificationService::AllSources());
browser->OpenURL(OpenURLParams(
- url, Referrer(), disposition, content::PAGE_TRANSITION_TYPED, false));
+ url, Referrer(), disposition, ui::PAGE_TRANSITION_TYPED, false));
if (browser_test_flags & BROWSER_TEST_WAIT_FOR_BROWSER)
browser = WaitForBrowserNotInSet(initial_browsers);
if (browser_test_flags & BROWSER_TEST_WAIT_FOR_TAB)
BROWSER_TEST_WAIT_FOR_NAVIGATION);
}
-void WaitUntilDevToolsWindowLoaded(DevToolsWindow* window) {
- scoped_refptr<content::MessageLoopRunner> runner =
- new content::MessageLoopRunner;
- window->SetLoadCompletedCallback(runner->QuitClosure());
- runner->Run();
-}
-
base::FilePath GetTestFilePath(const base::FilePath& dir,
const base::FilePath& file) {
base::FilePath path;
AppModalDialogQueue* dialog_queue = AppModalDialogQueue::GetInstance();
if (dialog_queue->HasActiveDialog())
return dialog_queue->active_dialog();
-
- content::WindowedNotificationObserver observer(
- chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN,
- content::NotificationService::AllSources());
- observer.Wait();
- return content::Source<AppModalDialog>(observer.source()).ptr();
+ AppModalDialogWaiter waiter;
+ return waiter.Wait();
}
int FindInPage(WebContents* tab,
return GetBrowserNotInSet(original_browsers_);
}
-#if defined(OS_WIN)
-
-bool SaveScreenSnapshotToDirectory(const base::FilePath& directory,
- base::FilePath* screenshot_path) {
- bool succeeded = false;
- base::FilePath out_path(GetSnapshotFileName(directory));
-
- MONITORINFO monitor_info = {};
- monitor_info.cbSize = sizeof(monitor_info);
- HMONITOR main_monitor = MonitorFromWindow(NULL, MONITOR_DEFAULTTOPRIMARY);
- if (GetMonitorInfo(main_monitor, &monitor_info)) {
- RECT& rect = monitor_info.rcMonitor;
-
- std::vector<unsigned char> png_data;
- gfx::Rect bounds(
- gfx::Size(rect.right - rect.left, rect.bottom - rect.top));
- if (ui::GrabDesktopSnapshot(bounds, &png_data) &&
- png_data.size() <= INT_MAX) {
- int bytes = static_cast<int>(png_data.size());
- int written = base::WriteFile(
- out_path, reinterpret_cast<char*>(&png_data[0]), bytes);
- succeeded = (written == bytes);
- }
- }
-
- if (succeeded && screenshot_path != NULL)
- *screenshot_path = out_path;
-
- return succeeded;
-}
-
-bool SaveScreenSnapshotToDesktop(base::FilePath* screenshot_path) {
- base::FilePath desktop;
-
- return PathService::Get(base::DIR_USER_DESKTOP, &desktop) &&
- SaveScreenSnapshotToDirectory(desktop, screenshot_path);
-}
-
-#endif // defined(OS_WIN)
-
void OverrideGeolocation(double latitude, double longitude) {
content::Geoposition position;
position.latitude = latitude;
HistoryService* hs = HistoryServiceFactory::GetForProfile(
profile, Profile::EXPLICIT_ACCESS);
- hs->QueryHistory(
- base::string16(),
- history::QueryOptions(),
- &consumer_,
- base::Bind(&HistoryEnumerator::HistoryQueryComplete,
- base::Unretained(this), message_loop_runner->QuitClosure()));
+ hs->QueryHistory(base::string16(),
+ history::QueryOptions(),
+ base::Bind(&HistoryEnumerator::HistoryQueryComplete,
+ base::Unretained(this),
+ message_loop_runner->QuitClosure()),
+ &tracker_);
message_loop_runner->Run();
}
void HistoryEnumerator::HistoryQueryComplete(
const base::Closure& quit_task,
- HistoryService::Handle request_handle,
history::QueryResults* results) {
for (size_t i = 0; i < results->size(); ++i)
urls_.push_back((*results)[i].url());