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

Unified Diff: chrome/browser/policy/policy_browsertest.cc

Issue 2902603002: Add enterprise policy for network time service (Closed)
Patch Set: shorten caption Created 3 years, 7 months 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/policy/policy_browsertest.cc
diff --git a/chrome/browser/policy/policy_browsertest.cc b/chrome/browser/policy/policy_browsertest.cc
index a364e86443864b0a77be83c7bc07c3ffaa724a99..177bea75fd1be10b112d622e3d0c4e1eb1f3b32e 100644
--- a/chrome/browser/policy/policy_browsertest.cc
+++ b/chrome/browser/policy/policy_browsertest.cc
@@ -105,6 +105,7 @@
#include "components/content_settings/core/common/content_settings_pattern.h"
#include "components/content_settings/core/common/pref_names.h"
#include "components/infobars/core/infobar.h"
+#include "components/network_time/network_time_tracker.h"
#include "components/omnibox/browser/autocomplete_controller.h"
#include "components/omnibox/browser/omnibox_edit_model.h"
#include "components/omnibox/browser/omnibox_view.h"
@@ -182,6 +183,8 @@
#include "net/http/http_stream_factory.h"
#include "net/http/transport_security_state.h"
#include "net/test/embedded_test_server/embedded_test_server.h"
+#include "net/test/embedded_test_server/http_request.h"
+#include "net/test/embedded_test_server/http_response.h"
#include "net/test/url_request/url_request_failed_job.h"
#include "net/test/url_request/url_request_mock_http_job.h"
#include "net/url_request/url_request.h"
@@ -4501,4 +4504,67 @@ IN_PROC_BROWSER_TEST_F(ChromeOSPolicyTest, SystemTimezoneAutomaticDetection) {
}
#endif // defined(OS_CHROMEOS)
+class NetworkTimePolicyTest : public PolicyTest {
+ public:
+ // A request handler that returns a dummy response and counts the number of
+ // times it is called.
+ std::unique_ptr<net::test_server::HttpResponse> CountingRequestHandler(
+ const net::test_server::HttpRequest& request) {
+ net::test_server::BasicHttpResponse* response =
+ new net::test_server::BasicHttpResponse();
+ num_requests_++;
+ response->set_code(net::HTTP_OK);
+ response->set_content(
+ ")]}'\n"
+ "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
+ "006853099049523E85}");
+ response->AddCustomHeader("x-cup-server-proof", "dead:beef");
+ return std::unique_ptr<net::test_server::HttpResponse>(response);
+ }
+
+ uint32_t num_requests() { return num_requests_; }
+
+ private:
+ uint32_t num_requests_ = 0;
+};
+
+IN_PROC_BROWSER_TEST_F(NetworkTimePolicyTest, NetworkTimeQueriesDisabled) {
+ // Set a policy to disable network time queries.
+ PolicyMap policies;
+ policies.Set(key::kNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::Value>(false), nullptr);
+ UpdateProviderPolicy(policies);
+
+ embedded_test_server()->RegisterRequestHandler(base::Bind(
+ &NetworkTimePolicyTest::CountingRequestHandler, base::Unretained(this)));
+ ASSERT_TRUE(embedded_test_server()->Start());
+ g_browser_process->network_time_tracker()->SetTimeServerURLForTesting(
+ embedded_test_server()->GetURL("/"));
+
+ net::EmbeddedTestServer https_server_expired_(
+ net::EmbeddedTestServer::TYPE_HTTPS);
+ https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
+ ASSERT_TRUE(https_server_expired_.Start());
+
+ // Navigate to a page with a certificate date error and then check that a
+ // network time query was not sent.
+ ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
+ content::WebContents* tab =
+ browser()->tab_strip_model()->GetActiveWebContents();
+ content::InterstitialPage* interstitial_page = tab->GetInterstitialPage();
+ ASSERT_TRUE(interstitial_page);
+ EXPECT_EQ(0u, num_requests());
+
+ // Now enable the policy and check that a network time query is sent.
+ policies.Set(key::kNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY,
+ POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
+ base::MakeUnique<base::Value>(true), nullptr);
+ UpdateProviderPolicy(policies);
+ ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
+ interstitial_page = tab->GetInterstitialPage();
+ ASSERT_TRUE(interstitial_page);
+ EXPECT_EQ(1u, num_requests());
+}
+
} // namespace policy

Powered by Google App Engine
This is Rietveld 408576698