Chromium Code Reviews| OLD | NEW |
|---|---|
| (Empty) | |
| 1 // Copyright 2017 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 "chrome/browser/extensions/extension_with_management_policy_apitest.h" | |
| 6 #include "components/policy/core/browser/browser_policy_connector.h" | |
| 7 #include "net/test/embedded_test_server/http_request.h" | |
| 8 | |
| 9 ExtensionApiTestWithManagementPolicy::ExtensionApiTestWithManagementPolicy() | |
| 10 : ExtensionApiTest() {} | |
| 11 | |
| 12 ExtensionApiTestWithManagementPolicy::~ExtensionApiTestWithManagementPolicy() {} | |
| 13 | |
| 14 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
| |
| 15 ExtensionApiTest::SetUpInProcessBrowserTestFixture(); | |
| 16 embedded_test_server()->RegisterRequestMonitor( | |
| 17 base::Bind(&ExtensionApiTestWithManagementPolicy::MonitorRequestHandler, | |
| 18 base::Unretained(this))); | |
| 19 EXPECT_CALL(policy_provider_, IsInitializationComplete(testing::_)) | |
| 20 .WillRepeatedly(testing::Return(true)); | |
| 21 policy_provider_.SetAutoRefresh(); | |
| 22 policy::BrowserPolicyConnector::SetPolicyProviderForTesting( | |
| 23 &policy_provider_); | |
| 24 } | |
| 25 | |
| 26 void ExtensionApiTestWithManagementPolicy::MonitorRequestHandler( | |
| 27 const net::test_server::HttpRequest& request) { | |
| 28 auto host = request.headers.find("Host"); | |
| 29 if (host != request.headers.end()) { | |
| 30 ManagementPolicyRequestLog log; | |
| 31 size_t delimiter_pos = host->second.find(":"); | |
| 32 log.host = host->second.substr(0, delimiter_pos); | |
| 33 request_log_.push_back(log); | |
| 34 } | |
| 35 } | |
| 36 | |
| 37 bool ExtensionApiTestWithManagementPolicy::BrowsedTo(const char* test_host) { | |
| 38 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.
| |
| 39 if (it.host == test_host) | |
| 40 return true; | |
| 41 } | |
| 42 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.
| |
| 43 } | |
| 44 | |
| 45 void ExtensionApiTestWithManagementPolicy::ClearRequestLog() { | |
| 46 request_log_.clear(); | |
| 47 } | |
| OLD | NEW |