Chromium Code Reviews| Index: chrome/browser/extensions/extension_with_management_policy_apitest.cc |
| diff --git a/chrome/browser/extensions/extension_with_management_policy_apitest.cc b/chrome/browser/extensions/extension_with_management_policy_apitest.cc |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..75aed90a29035d4452bd3b386781f0449f3f494d |
| --- /dev/null |
| +++ b/chrome/browser/extensions/extension_with_management_policy_apitest.cc |
| @@ -0,0 +1,47 @@ |
| +// Copyright 2017 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 "chrome/browser/extensions/extension_with_management_policy_apitest.h" |
| +#include "components/policy/core/browser/browser_policy_connector.h" |
| +#include "net/test/embedded_test_server/http_request.h" |
| + |
| +ExtensionApiTestWithManagementPolicy::ExtensionApiTestWithManagementPolicy() |
| + : ExtensionApiTest() {} |
| + |
| +ExtensionApiTestWithManagementPolicy::~ExtensionApiTestWithManagementPolicy() {} |
| + |
| +void ExtensionApiTestWithManagementPolicy::SetUpInProcessBrowserTestFixture() { |
|
Devlin
2017/03/29 21:36:49
Why does this need to be done in SetUpInProcessBro
nrpeter
2017/03/30 00:06:05
This was moved from permissions_apitest.cc since w
Devlin
2017/03/30 00:33:53
Let's try moving it to SetUpOnMainThread(), which
nrpeter
2017/03/31 21:43:35
I tried moving this, but the policy connector isn'
Devlin
2017/04/03 15:58:21
Did you put the call before or after the call to E
nrpeter
2017/04/03 22:35:48
I put the call after.
Devlin
2017/04/04 16:29:10
Try putting it before.
nrpeter
2017/04/05 23:13:26
Tried putting it before, and I got the same error
Devlin
2017/04/07 00:40:26
Let's table it for now. I'd like to get to the bo
|
| + ExtensionApiTest::SetUpInProcessBrowserTestFixture(); |
| + embedded_test_server()->RegisterRequestMonitor( |
| + base::Bind(&ExtensionApiTestWithManagementPolicy::MonitorRequestHandler, |
| + base::Unretained(this))); |
| + EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_)) |
| + .WillRepeatedly(testing::Return(true)); |
| + policy_provider_.SetAutoRefresh(); |
| + policy::BrowserPolicyConnector::SetPolicyProviderForTesting( |
| + &policy_provider_); |
| +} |
| + |
| +void ExtensionApiTestWithManagementPolicy::MonitorRequestHandler( |
| + const net::test_server::HttpRequest& request) { |
| + auto host = request.headers.find("Host"); |
| + if (host != request.headers.end()) { |
| + ManagementPolicyRequestLog log; |
| + size_t delimiter_pos = host->second.find(":"); |
| + log.host = host->second.substr(0, delimiter_pos); |
| + request_log_.push_back(log); |
| + } |
| +} |
| + |
| +bool ExtensionApiTestWithManagementPolicy::BrowsedTo(const char* test_host) { |
| + for (auto it : request_log_) { |
|
Devlin
2017/03/29 21:36:49
this results in a copy for each entry; prefer cons
nrpeter
2017/03/30 00:06:05
Done.
|
| + if (it.host == test_host) |
| + return true; |
| + } |
| + return false; |
|
Devlin
2017/03/29 21:36:49
This would be simpler as:
return std::find_if(requ
nrpeter
2017/03/30 00:06:05
Done.
|
| +} |
| + |
| +void ExtensionApiTestWithManagementPolicy::ClearRequestLog() { |
| + request_log_.clear(); |
| +} |