OLD | NEW |
(Empty) | |
| 1 // Copyright 2016 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. |
| 4 |
| 5 #include "base/command_line.h" |
| 6 #include "base/process/launch.h" |
| 7 #include "base/test/launcher/test_launcher.h" |
| 8 #include "base/test/test_switches.h" |
| 9 #include "base/test/test_timeouts.h" |
| 10 #include "chrome/browser/ui/test/test_browser_dialog.h" |
| 11 #include "ui/compositor/compositor_switches.h" |
| 12 |
| 13 namespace { |
| 14 |
| 15 // Name of the test case generated by the TEST_BROWSER_DIALOG macro. |
| 16 constexpr char kInvokeTestCase[] = "InvokeDefault"; |
| 17 |
| 18 // Returns the test harness portion of a --dialog= switch argument. |
| 19 std::string HarnessFromDialogDescription(const std::string& argument) { |
| 20 return argument.substr(0, argument.find('.')); |
| 21 } |
| 22 |
| 23 } // namespace |
| 24 |
| 25 // Adds a browser_test entry point into the dialog testing framework. Without a |
| 26 // --dialog specified, just lists the available dialogs and exits. |
| 27 TEST(BrowserDialogTest, Invoke) { |
| 28 const base::CommandLine& invoker = *base::CommandLine::ForCurrentProcess(); |
| 29 const std::string dialog_name = |
| 30 invoker.GetSwitchValueASCII(internal::kDialogSwitch); |
| 31 |
| 32 const std::vector<std::string>& all_cases = |
| 33 TestDialogInterface::GetDialogTestCases(); |
| 34 ASSERT_FALSE(all_cases.empty()); |
| 35 |
| 36 if (dialog_name.empty()) { |
| 37 std::string case_list; |
| 38 for (const std::string& name : all_cases) |
| 39 case_list += "\t" + name + "\n"; |
| 40 VLOG(0) << "\nPass one of the following after --" << internal::kDialogSwitch |
| 41 << "=\n" |
| 42 << case_list; |
| 43 return; |
| 44 } |
| 45 |
| 46 auto it = std::find(all_cases.begin(), all_cases.end(), dialog_name); |
| 47 ASSERT_NE(it, all_cases.end()) << "Dialog '" << dialog_name << "' not found."; |
| 48 |
| 49 const std::string harness_name = HarnessFromDialogDescription(dialog_name); |
| 50 base::CommandLine command(invoker); |
| 51 |
| 52 // Replace TestBrowserDialog.Invoke with |harness_name|.InvokeDefault. |
| 53 command.AppendSwitchASCII(base::kGTestFilterFlag, |
| 54 harness_name + "." + kInvokeTestCase); |
| 55 |
| 56 base::LaunchOptions options; |
| 57 |
| 58 // Disable timeouts and generate screen output if --interactive was specified. |
| 59 if (command.HasSwitch(internal::kInteractiveSwitch)) { |
| 60 command.AppendSwitchASCII(switches::kUiTestActionMaxTimeout, |
| 61 TestTimeouts::kNoTimeoutSwitchValue); |
| 62 command.AppendSwitchASCII(switches::kTestLauncherTimeout, |
| 63 TestTimeouts::kNoTimeoutSwitchValue); |
| 64 command.AppendSwitch(switches::kEnablePixelOutputInTests); |
| 65 } else { |
| 66 options.wait = true; |
| 67 } |
| 68 |
| 69 base::LaunchProcess(command, options); |
| 70 } |
OLD | NEW |