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 "testing/gtest/include/gtest/gtest.h" |
| 12 #include "ui/compositor/compositor_switches.h" |
| 13 |
| 14 namespace { |
| 15 |
| 16 // Switch for BrowserDialogTest.Invoke to spawn a subprocess testing the |
| 17 // provided argument under a consistent setup. |
| 18 constexpr const char kDialogSwitch[] = "dialog"; |
| 19 |
| 20 // Pattern to search in test names that indicate support for dialog testing. |
| 21 constexpr const char kDialogPattern[] = "InvokeDialog_"; |
| 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 = invoker.GetSwitchValueASCII(kDialogSwitch); |
| 30 |
| 31 std::set<std::string> dialog_cases; |
| 32 const testing::UnitTest* unit_test = testing::UnitTest::GetInstance(); |
| 33 for (int i = 0; i < unit_test->total_test_case_count(); ++i) { |
| 34 const testing::TestCase* test_case = unit_test->GetTestCase(i); |
| 35 for (int j = 0; j < test_case->total_test_count(); ++j) { |
| 36 const char* name = test_case->GetTestInfo(j)->name(); |
| 37 if (strstr(name, kDialogPattern)) |
| 38 dialog_cases.insert(test_case->name() + std::string(".") + name); |
| 39 } |
| 40 } |
| 41 |
| 42 if (dialog_name.empty()) { |
| 43 std::string case_list; |
| 44 for (const std::string& name : dialog_cases) |
| 45 case_list += "\t" + name + "\n"; |
| 46 VLOG(0) << "\nPass one of the following after --" << kDialogSwitch << "=\n" |
| 47 << case_list; |
| 48 return; |
| 49 } |
| 50 |
| 51 auto it = dialog_cases.find(dialog_name); |
| 52 ASSERT_NE(it, dialog_cases.end()) << "Dialog '" << dialog_name |
| 53 << "' not found."; |
| 54 |
| 55 base::CommandLine command(invoker); |
| 56 |
| 57 // Replace TestBrowserDialog.Invoke with |dialog_name|. |
| 58 command.AppendSwitchASCII(base::kGTestFilterFlag, dialog_name); |
| 59 |
| 60 base::LaunchOptions options; |
| 61 |
| 62 // Disable timeouts and generate screen output if --interactive was specified. |
| 63 if (command.HasSwitch(internal::kInteractiveSwitch)) { |
| 64 command.AppendSwitchASCII(switches::kUiTestActionMaxTimeout, |
| 65 TestTimeouts::kNoTimeoutSwitchValue); |
| 66 command.AppendSwitchASCII(switches::kTestLauncherTimeout, |
| 67 TestTimeouts::kNoTimeoutSwitchValue); |
| 68 command.AppendSwitch(switches::kEnablePixelOutputInTests); |
| 69 } else { |
| 70 options.wait = true; |
| 71 } |
| 72 |
| 73 base::LaunchProcess(command, options); |
| 74 } |
OLD | NEW |