Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(2770)

Unified Diff: chrome/browser/ui/test/browser_dialog_browsertest.cc

Issue 2532793002: Add a TestBrowserDialog helper class for testing browser dialogs in a consistent way. (Closed)
Patch Set: Split out browsertest into browsertest.cc Created 4 years ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: chrome/browser/ui/test/browser_dialog_browsertest.cc
diff --git a/chrome/browser/ui/test/browser_dialog_browsertest.cc b/chrome/browser/ui/test/browser_dialog_browsertest.cc
new file mode 100644
index 0000000000000000000000000000000000000000..0a2e880b5a29289fbb4d6dc0a984971965b8e74e
--- /dev/null
+++ b/chrome/browser/ui/test/browser_dialog_browsertest.cc
@@ -0,0 +1,70 @@
+// Copyright 2016 The Chromium Authors. All rights reserved.
+// Use of this source code is governed by a BSD-style license that can be
+// found in the LICENSE file.
+
+#include "base/command_line.h"
+#include "base/process/launch.h"
+#include "base/test/launcher/test_launcher.h"
+#include "base/test/test_switches.h"
+#include "base/test/test_timeouts.h"
+#include "chrome/browser/ui/test/test_browser_dialog.h"
+#include "ui/compositor/compositor_switches.h"
+
+namespace {
+
+// Name of the test case generated by the TEST_BROWSER_DIALOG macro.
+constexpr char kInvokeTestCase[] = "InvokeDefault";
+
+// Returns the test harness portion of a --dialog= switch argument.
+std::string HarnessFromDialogDescription(const std::string& argument) {
+ return argument.substr(0, argument.find('.'));
+}
+
+} // namespace
+
+// Adds a browser_test entry point into the dialog testing framework. Without a
+// --dialog specified, just lists the available dialogs and exits.
+TEST(BrowserDialogTest, Invoke) {
+ const base::CommandLine& invoker = *base::CommandLine::ForCurrentProcess();
+ const std::string dialog_name =
+ invoker.GetSwitchValueASCII(internal::kDialogSwitch);
+
+ const std::vector<std::string>& all_cases =
+ TestDialogInterface::GetDialogTestCases();
+ ASSERT_FALSE(all_cases.empty());
+
+ if (dialog_name.empty()) {
+ std::string case_list;
+ for (const std::string& name : all_cases)
+ case_list += "\t" + name + "\n";
+ VLOG(0) << "\nPass one of the following after --" << internal::kDialogSwitch
+ << "=\n"
+ << case_list;
+ return;
+ }
+
+ auto it = std::find(all_cases.begin(), all_cases.end(), dialog_name);
+ ASSERT_NE(it, all_cases.end()) << "Dialog '" << dialog_name << "' not found.";
+
+ const std::string harness_name = HarnessFromDialogDescription(dialog_name);
+ base::CommandLine command(invoker);
+
+ // Replace TestBrowserDialog.Invoke with |harness_name|.InvokeDefault.
+ command.AppendSwitchASCII(base::kGTestFilterFlag,
+ harness_name + "." + kInvokeTestCase);
+
+ base::LaunchOptions options;
+
+ // Disable timeouts and generate screen output if --interactive was specified.
+ if (command.HasSwitch(internal::kInteractiveSwitch)) {
+ command.AppendSwitchASCII(switches::kUiTestActionMaxTimeout,
+ TestTimeouts::kNoTimeoutSwitchValue);
+ command.AppendSwitchASCII(switches::kTestLauncherTimeout,
+ TestTimeouts::kNoTimeoutSwitchValue);
+ command.AppendSwitch(switches::kEnablePixelOutputInTests);
+ } else {
+ options.wait = true;
+ }
+
+ base::LaunchProcess(command, options);
+}

Powered by Google App Engine
This is Rietveld 408576698