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" | |
19 #include "base/json/json_reader.h" | 18 #include "base/json/json_reader.h" |
20 #include "base/memory/scoped_ptr.h" | 19 #include "base/memory/scoped_ptr.h" |
21 #include "base/message_loop.h" | 20 #include "base/message_loop.h" |
22 #include "base/path_service.h" | 21 #include "base/path_service.h" |
23 #include "base/test/test_timeouts.h" | 22 #include "base/test/test_timeouts.h" |
24 #include "base/time.h" | 23 #include "base/time.h" |
25 #include "base/utf_string_conversions.h" | 24 #include "base/utf_string_conversions.h" |
26 #include "base/values.h" | 25 #include "base/values.h" |
27 #include "chrome/browser/bookmarks/bookmark_model.h" | 26 #include "chrome/browser/bookmarks/bookmark_model.h" |
28 #include "chrome/browser/browser_process.h" | 27 #include "chrome/browser/browser_process.h" |
(...skipping 280 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
309 FilePath GetTestFilePath(const FilePath& dir, const FilePath& file) { | 308 FilePath GetTestFilePath(const FilePath& dir, const FilePath& file) { |
310 FilePath path; | 309 FilePath path; |
311 PathService::Get(chrome::DIR_TEST_DATA, &path); | 310 PathService::Get(chrome::DIR_TEST_DATA, &path); |
312 return path.Append(dir).Append(file); | 311 return path.Append(dir).Append(file); |
313 } | 312 } |
314 | 313 |
315 GURL GetTestUrl(const FilePath& dir, const FilePath& file) { | 314 GURL GetTestUrl(const FilePath& dir, const FilePath& file) { |
316 return net::FilePathToFileURL(GetTestFilePath(dir, file)); | 315 return net::FilePathToFileURL(GetTestFilePath(dir, file)); |
317 } | 316 } |
318 | 317 |
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 | |
361 AppModalDialog* WaitForAppModalDialog() { | 318 AppModalDialog* WaitForAppModalDialog() { |
362 content::WindowedNotificationObserver observer( | 319 content::WindowedNotificationObserver observer( |
363 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, | 320 chrome::NOTIFICATION_APP_MODAL_DIALOG_SHOWN, |
364 content::NotificationService::AllSources()); | 321 content::NotificationService::AllSources()); |
365 observer.Wait(); | 322 observer.Wait(); |
366 return content::Source<AppModalDialog>(observer.source()).ptr(); | 323 return content::Source<AppModalDialog>(observer.source()).ptr(); |
367 } | 324 } |
368 | 325 |
369 int FindInPage(TabContents* tab_contents, const string16& search_string, | 326 int FindInPage(TabContents* tab_contents, const string16& search_string, |
370 bool forward, bool match_case, int* ordinal) { | 327 bool forward, bool match_case, int* ordinal) { |
(...skipping 332 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
703 int state, | 660 int state, |
704 const base::Closure& followup) { | 661 const base::Closure& followup) { |
705 if (!followup.is_null()) | 662 if (!followup.is_null()) |
706 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); | 663 ui_controls::SendMouseEventsNotifyWhenDone(button, state, followup); |
707 else | 664 else |
708 ui_controls::SendMouseEvents(button, state); | 665 ui_controls::SendMouseEvents(button, state); |
709 } | 666 } |
710 | 667 |
711 } // namespace internal | 668 } // namespace internal |
712 } // namespace ui_test_utils | 669 } // namespace ui_test_utils |
OLD | NEW |