Commit 7c502920 authored by Greg Thompson's avatar Greg Thompson Committed by Commit Bot

Install rules to appease Windows firewall during test runs.

Tests that tickle local_discovery result in the Windows firewall dialog
appearing. Once onscreen, this dialog hangs around in the foreground
until dismissed by the user. I suspect that this dialog could linger on
bots between test runs, resulting in failures in subsequent
interactive_ui_tests (or similar) runs that require bringing windows to
the foreground.

BUG=951386,711256

Change-Id: If3ad0fdb70b26840ce76f617e1662f58ecd67707
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1564157Reviewed-by: default avatarDavid Roger <droger@chromium.org>
Commit-Queue: Greg Thompson <grt@chromium.org>
Cr-Commit-Position: refs/heads/master@{#649839}
parent 3a77eb64
...@@ -20,7 +20,6 @@ ...@@ -20,7 +20,6 @@
#include "base/run_loop.h" #include "base/run_loop.h"
#include "base/strings/string_util.h" #include "base/strings/string_util.h"
#include "base/test/test_file_util.h" #include "base/test/test_file_util.h"
#include "build/build_config.h"
#include "chrome/app/chrome_main_delegate.h" #include "chrome/app/chrome_main_delegate.h"
#include "chrome/common/chrome_constants.h" #include "chrome/common/chrome_constants.h"
#include "chrome/common/chrome_switches.h" #include "chrome/common/chrome_switches.h"
...@@ -59,8 +58,10 @@ ...@@ -59,8 +58,10 @@
#if defined(OS_WIN) #if defined(OS_WIN)
#include "base/win/registry.h" #include "base/win/registry.h"
#include "base/win/scoped_com_initializer.h"
#include "chrome/app/chrome_crash_reporter_client_win.h" #include "chrome/app/chrome_crash_reporter_client_win.h"
#include "chrome/install_static/install_util.h" #include "chrome/install_static/install_util.h"
#include "chrome/installer/util/firewall_manager_win.h"
#endif #endif
ChromeTestSuiteRunner::ChromeTestSuiteRunner() {} ChromeTestSuiteRunner::ChromeTestSuiteRunner() {}
...@@ -73,6 +74,37 @@ int ChromeTestSuiteRunner::RunTestSuite(int argc, char** argv) { ...@@ -73,6 +74,37 @@ int ChromeTestSuiteRunner::RunTestSuite(int argc, char** argv) {
return test_suite.Run(); return test_suite.Run();
} }
#if defined(OS_WIN)
// A helper class that adds Windows firewall rules for the duration of the test.
class ChromeTestLauncherDelegate::ScopedFirewallRules {
public:
ScopedFirewallRules() {
CHECK(com_initializer_.Succeeded());
base::FilePath exe_path;
CHECK(base::PathService::Get(base::FILE_EXE, &exe_path));
firewall_manager_ = installer::FirewallManager::Create(exe_path);
CHECK(firewall_manager_);
rules_added_ = firewall_manager_->AddFirewallRules();
LOG_IF(WARNING, !rules_added_)
<< "Failed to add Windows firewall rules -- Windows firewall dialogs "
"may appear.";
}
~ScopedFirewallRules() {
if (rules_added_)
firewall_manager_->RemoveFirewallRules();
}
private:
base::win::ScopedCOMInitializer com_initializer_;
std::unique_ptr<installer::FirewallManager> firewall_manager_;
bool rules_added_ = false;
DISALLOW_COPY_AND_ASSIGN(ScopedFirewallRules);
};
#endif // defined(OS_WIN)
ChromeTestLauncherDelegate::ChromeTestLauncherDelegate( ChromeTestLauncherDelegate::ChromeTestLauncherDelegate(
ChromeTestSuiteRunner* runner) ChromeTestSuiteRunner* runner)
: runner_(runner) {} : runner_(runner) {}
...@@ -127,6 +159,16 @@ void ChromeTestLauncherDelegate::PreSharding() { ...@@ -127,6 +159,16 @@ void ChromeTestLauncherDelegate::PreSharding() {
result = distrubution_key.DeleteKey(L"PreferenceMACs"); result = distrubution_key.DeleteKey(L"PreferenceMACs");
LOG_IF(ERROR, result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND) LOG_IF(ERROR, result != ERROR_SUCCESS && result != ERROR_FILE_NOT_FOUND)
<< "Failed to cleanup PreferenceMACs: " << result; << "Failed to cleanup PreferenceMACs: " << result;
// Add firewall rules for the test binary so that Windows doesn't show a
// firewall dialog during the test run.
firewall_rules_ = std::make_unique<ScopedFirewallRules>();
#endif
}
void ChromeTestLauncherDelegate::OnDoneRunningTests() {
#if defined(OS_WIN)
firewall_rules_.reset();
#endif #endif
} }
......
...@@ -8,6 +8,7 @@ ...@@ -8,6 +8,7 @@
#include <memory> #include <memory>
#include "base/macros.h" #include "base/macros.h"
#include "build/build_config.h"
#include "content/public/test/test_launcher.h" #include "content/public/test/test_launcher.h"
// Allows a test suite to override the TestSuite class used. By default it is an // Allows a test suite to override the TestSuite class used. By default it is an
...@@ -37,8 +38,15 @@ class ChromeTestLauncherDelegate : public content::TestLauncherDelegate { ...@@ -37,8 +38,15 @@ class ChromeTestLauncherDelegate : public content::TestLauncherDelegate {
const base::FilePath& temp_data_dir) override; const base::FilePath& temp_data_dir) override;
content::ContentMainDelegate* CreateContentMainDelegate() override; content::ContentMainDelegate* CreateContentMainDelegate() override;
void PreSharding() override; void PreSharding() override;
void OnDoneRunningTests() override;
private: private:
#if defined(OS_WIN)
class ScopedFirewallRules;
std::unique_ptr<ScopedFirewallRules> firewall_rules_;
#endif
ChromeTestSuiteRunner* runner_; ChromeTestSuiteRunner* runner_;
DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate); DISALLOW_COPY_AND_ASSIGN(ChromeTestLauncherDelegate);
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment