OLD | NEW |
1 // Copyright (c) 2006-2008 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2006-2008 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 <fstream> | 5 #include <fstream> |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/file_util.h" | 8 #include "base/file_util.h" |
9 #include "base/path_service.h" | 9 #include "base/path_service.h" |
| 10 #include "base/rand_util.h" |
10 #include "base/string_util.h" | 11 #include "base/string_util.h" |
11 #include "chrome/app/chrome_dll_resource.h" | 12 #include "chrome/app/chrome_dll_resource.h" |
12 #include "chrome/browser/character_encoding.h" | 13 #include "chrome/browser/character_encoding.h" |
13 #include "chrome/browser/view_ids.h" | 14 #include "chrome/browser/view_ids.h" |
14 #include "chrome/common/chrome_paths.h" | 15 #include "chrome/common/chrome_paths.h" |
15 #include "chrome/common/libxml_utils.h" | 16 #include "chrome/common/libxml_utils.h" |
16 #include "chrome/common/rand_util.h" | |
17 #include "chrome/common/win_util.h" | 17 #include "chrome/common/win_util.h" |
18 #include "chrome/test/automated_ui_tests/automated_ui_tests.h" | 18 #include "chrome/test/automated_ui_tests/automated_ui_tests.h" |
19 #include "chrome/test/automation/browser_proxy.h" | 19 #include "chrome/test/automation/browser_proxy.h" |
20 #include "chrome/test/automation/tab_proxy.h" | 20 #include "chrome/test/automation/tab_proxy.h" |
21 #include "chrome/test/automation/window_proxy.h" | 21 #include "chrome/test/automation/window_proxy.h" |
22 #include "chrome/test/ui/ui_test.h" | 22 #include "chrome/test/ui/ui_test.h" |
23 #include "chrome/views/view.h" | 23 #include "chrome/views/view.h" |
24 #include "googleurl/src/gurl.h" | 24 #include "googleurl/src/gurl.h" |
25 | 25 |
26 namespace { | 26 namespace { |
(...skipping 387 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
414 // Get the encoding list that is used to populate the UI (encoding menu) | 414 // Get the encoding list that is used to populate the UI (encoding menu) |
415 const std::vector<int>* encoding_ids = | 415 const std::vector<int>* encoding_ids = |
416 CharacterEncoding::GetCurrentDisplayEncodings( | 416 CharacterEncoding::GetCurrentDisplayEncodings( |
417 L"ISO-8859-1,windows-1252", L""); | 417 L"ISO-8859-1,windows-1252", L""); |
418 DCHECK(encoding_ids); | 418 DCHECK(encoding_ids); |
419 DCHECK(!encoding_ids->empty()); | 419 DCHECK(!encoding_ids->empty()); |
420 unsigned len = static_cast<unsigned>(encoding_ids->size()); | 420 unsigned len = static_cast<unsigned>(encoding_ids->size()); |
421 | 421 |
422 // The vector will contain mostly IDC values for encoding commands plus a few | 422 // The vector will contain mostly IDC values for encoding commands plus a few |
423 // menu separators (0 values). If we hit a separator we just retry. | 423 // menu separators (0 values). If we hit a separator we just retry. |
424 int index = rand_util::RandInt(0, len); | 424 int index = base::RandInt(0, len); |
425 while ((*encoding_ids)[index] == 0) { | 425 while ((*encoding_ids)[index] == 0) { |
426 index = rand_util::RandInt(0, len); | 426 index = base::RandInt(0, len); |
427 } | 427 } |
428 | 428 |
429 return RunCommand((*encoding_ids)[index]); | 429 return RunCommand((*encoding_ids)[index]); |
430 } | 430 } |
431 | 431 |
432 bool AutomatedUITest::CloseActiveTab() { | 432 bool AutomatedUITest::CloseActiveTab() { |
433 bool return_value = false; | 433 bool return_value = false; |
434 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); | 434 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); |
435 if (browser.get() == NULL) { | 435 if (browser.get() == NULL) { |
436 AddErrorAttribute("browser_window_not_found"); | 436 AddErrorAttribute("browser_window_not_found"); |
(...skipping 246 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
683 DoAction("Options"); | 683 DoAction("Options"); |
684 return FuzzyTestDialog(kTestDialogActionsToRun); | 684 return FuzzyTestDialog(kTestDialogActionsToRun); |
685 } | 685 } |
686 | 686 |
687 bool AutomatedUITest::TestViewPasswords() { | 687 bool AutomatedUITest::TestViewPasswords() { |
688 DoAction("ViewPasswords"); | 688 DoAction("ViewPasswords"); |
689 return FuzzyTestDialog(kTestDialogActionsToRun); | 689 return FuzzyTestDialog(kTestDialogActionsToRun); |
690 } | 690 } |
691 | 691 |
692 bool AutomatedUITest::ExerciseDialog() { | 692 bool AutomatedUITest::ExerciseDialog() { |
693 int index = rand_util::RandInt(0, arraysize(kDialogs) - 1); | 693 int index = base::RandInt(0, arraysize(kDialogs) - 1); |
694 return DoAction(kDialogs[index]) && FuzzyTestDialog(kTestDialogActionsToRun); | 694 return DoAction(kDialogs[index]) && FuzzyTestDialog(kTestDialogActionsToRun); |
695 } | 695 } |
696 | 696 |
697 bool AutomatedUITest::FuzzyTestDialog(int num_actions) { | 697 bool AutomatedUITest::FuzzyTestDialog(int num_actions) { |
698 bool return_value = true; | 698 bool return_value = true; |
699 | 699 |
700 for (int i = 0; i < num_actions; i++) { | 700 for (int i = 0; i < num_actions; i++) { |
701 // We want to make sure the first action performed on the dialog is not | 701 // We want to make sure the first action performed on the dialog is not |
702 // Space or Enter because focus is likely on the Close button. Both Space | 702 // Space or Enter because focus is likely on the Close button. Both Space |
703 // and Enter would close the dialog without performing more actions. We | 703 // and Enter would close the dialog without performing more actions. We |
704 // rely on the fact that those two actions are first in the array and set | 704 // rely on the fact that those two actions are first in the array and set |
705 // the lower bound to 2 if i == 0 to skip those two actions. | 705 // the lower bound to 2 if i == 0 to skip those two actions. |
706 int action_index = rand_util::RandInt(i == 0 ? 2 : 0, | 706 int action_index = base::RandInt(i == 0 ? 2 : 0, |
707 arraysize(kTestDialogPossibleActions) | 707 arraysize(kTestDialogPossibleActions) |
708 - 1); | 708 - 1); |
709 return_value = return_value && | 709 return_value = return_value && |
710 DoAction(kTestDialogPossibleActions[action_index]); | 710 DoAction(kTestDialogPossibleActions[action_index]); |
711 if (DidCrash(false)) | 711 if (DidCrash(false)) |
712 break; | 712 break; |
713 } | 713 } |
714 return DoAction("PressEscapeKey") && return_value; | 714 return DoAction("PressEscapeKey") && return_value; |
715 } | 715 } |
716 | 716 |
717 bool AutomatedUITest::ForceCrash() { | 717 bool AutomatedUITest::ForceCrash() { |
718 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); | 718 scoped_ptr<BrowserProxy> browser(automation()->GetLastActiveBrowserWindow()); |
(...skipping 274 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
993 } | 993 } |
994 | 994 |
995 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { | 995 TEST_F(AutomatedUITest, TheOneAndOnlyTest) { |
996 CommandLine parsed_command_line; | 996 CommandLine parsed_command_line; |
997 if (parsed_command_line.HasSwitch(kReproSwitch)) | 997 if (parsed_command_line.HasSwitch(kReproSwitch)) |
998 RunReproduction(); | 998 RunReproduction(); |
999 else | 999 else |
1000 RunAutomatedUITest(); | 1000 RunAutomatedUITest(); |
1001 } | 1001 } |
1002 | 1002 |
OLD | NEW |