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 "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 <vector> | 11 #include <vector> |
12 | 12 |
13 #include "base/bind.h" | 13 #include "base/bind.h" |
14 #include "base/bind_helpers.h" | 14 #include "base/bind_helpers.h" |
15 #include "base/callback.h" | 15 #include "base/callback.h" |
16 #include "base/command_line.h" | 16 #include "base/command_line.h" |
17 #include "base/file_path.h" | 17 #include "base/file_path.h" |
| 18 #include "base/file_util.h" |
18 #include "base/json/json_reader.h" | 19 #include "base/json/json_reader.h" |
19 #include "base/memory/scoped_ptr.h" | 20 #include "base/memory/scoped_ptr.h" |
20 #include "base/message_loop.h" | 21 #include "base/message_loop.h" |
21 #include "base/path_service.h" | 22 #include "base/path_service.h" |
22 #include "base/test/test_timeouts.h" | 23 #include "base/test/test_timeouts.h" |
23 #include "base/time.h" | 24 #include "base/time.h" |
24 #include "base/utf_string_conversions.h" | 25 #include "base/utf_string_conversions.h" |
25 #include "base/values.h" | 26 #include "base/values.h" |
26 #include "chrome/browser/bookmarks/bookmark_model.h" | 27 #include "chrome/browser/bookmarks/bookmark_model.h" |
27 #include "chrome/browser/browser_process.h" | 28 #include "chrome/browser/browser_process.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
308 FilePath GetTestFilePath(const FilePath& dir, const FilePath& file) { | 309 FilePath GetTestFilePath(const FilePath& dir, const FilePath& file) { |
309 FilePath path; | 310 FilePath path; |
310 PathService::Get(chrome::DIR_TEST_DATA, &path); | 311 PathService::Get(chrome::DIR_TEST_DATA, &path); |
311 return path.Append(dir).Append(file); | 312 return path.Append(dir).Append(file); |
312 } | 313 } |
313 | 314 |
314 GURL GetTestUrl(const FilePath& dir, const FilePath& file) { | 315 GURL GetTestUrl(const FilePath& dir, const FilePath& file) { |
315 return net::FilePathToFileURL(GetTestFilePath(dir, file)); | 316 return net::FilePathToFileURL(GetTestFilePath(dir, file)); |
316 } | 317 } |
317 | 318 |
| 319 bool GetRelativeBuildDirectory(FilePath* build_dir) { |
| 320 // This function is used to find the build directory so TestServer can serve |
| 321 // built files (nexes, etc). TestServer expects a path relative to the source |
| 322 // root. |
| 323 FilePath exe_dir = CommandLine::ForCurrentProcess()->GetProgram().DirName(); |
| 324 FilePath src_dir; |
| 325 if (!PathService::Get(base::DIR_SOURCE_ROOT, &src_dir)) |
| 326 return false; |
| 327 |
| 328 // We must first generate absolute paths to SRC and EXE and from there |
| 329 // generate a relative path. |
| 330 if (!exe_dir.IsAbsolute()) |
| 331 file_util::AbsolutePath(&exe_dir); |
| 332 if (!src_dir.IsAbsolute()) |
| 333 file_util::AbsolutePath(&src_dir); |
| 334 if (!exe_dir.IsAbsolute()) |
| 335 return false; |
| 336 if (!src_dir.IsAbsolute()) |
| 337 return false; |
| 338 |
| 339 size_t match, exe_size, src_size; |
| 340 std::vector<FilePath::StringType> src_parts, exe_parts; |
| 341 |
| 342 // Determine point at which src and exe diverge. |
| 343 exe_dir.GetComponents(&exe_parts); |
| 344 src_dir.GetComponents(&src_parts); |
| 345 exe_size = exe_parts.size(); |
| 346 src_size = src_parts.size(); |
| 347 for (match = 0; match < exe_size && match < src_size; ++match) { |
| 348 if (exe_parts[match] != src_parts[match]) |
| 349 break; |
| 350 } |
| 351 |
| 352 // Create a relative path. |
| 353 *build_dir = FilePath(); |
| 354 for (size_t tmp_itr = match; tmp_itr < src_size; ++tmp_itr) |
| 355 *build_dir = build_dir->Append(FILE_PATH_LITERAL("..")); |
| 356 for (; match < exe_size; ++match) |
| 357 *build_dir = build_dir->Append(exe_parts[match]); |
| 358 return true; |
| 359 } |
| 360 |
318 AppModalDialog* WaitForAppModalDialog() { | 361 AppModalDialog* WaitForAppModalDialog() { |
319 content::WindowedNotificationObserver observer( | 362 content::WindowedNotificationObserver observer( |
320 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | 363 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
321 content::NotificationService::AllSources()); | 364 content::NotificationService::AllSources()); |
322 observer.Wait(); | 365 observer.Wait(); |
323 return content::Source<AppModalDialog>(observer.source()).ptr(); | 366 return content::Source<AppModalDialog>(observer.source()).ptr(); |
324 } | 367 } |
325 | 368 |
326 int FindInPage(TabContents* tab_contents, const string16& search_string, | 369 int FindInPage(TabContents* tab_contents, const string16& search_string, |
327 bool forward, bool match_case, int* ordinal) { | 370 bool forward, bool match_case, int* ordinal) { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
660 int state, | 703 int state, |
661 const base::Closure& followup) { | 704 const base::Closure& followup) { |
662 if (!followup.is_null()) | 705 if (!followup.is_null()) |
663 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 706 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
664 else | 707 else |
665 ui_controls::SendMouseEvents(button, state); | 708 ui_controls::SendMouseEvents(button, state); |
666 } | 709 } |
667 | 710 |
668 } // namespace internal | 711 } // namespace internal |
669 } // namespace ui_test_utils | 712 } // namespace ui_test_utils |
OLD | NEW |