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

Side by Side 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 unified diff | Download patch
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include <stddef.h> 5 #include <stddef.h>
6 #include <stdint.h> 6 #include <stdint.h>
7 7
8 #include <algorithm> 8 #include <algorithm>
9 #include <memory> 9 #include <memory>
10 #include <string> 10 #include <string>
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after
98 #include "chrome/test/base/in_process_browser_test.h" 98 #include "chrome/test/base/in_process_browser_test.h"
99 #include "chrome/test/base/search_test_utils.h" 99 #include "chrome/test/base/search_test_utils.h"
100 #include "chrome/test/base/ui_test_utils.h" 100 #include "chrome/test/base/ui_test_utils.h"
101 #include "components/bookmarks/common/bookmark_pref_names.h" 101 #include "components/bookmarks/common/bookmark_pref_names.h"
102 #include "components/browsing_data/core/pref_names.h" 102 #include "components/browsing_data/core/pref_names.h"
103 #include "components/component_updater/component_updater_service.h" 103 #include "components/component_updater/component_updater_service.h"
104 #include "components/content_settings/core/common/content_settings.h" 104 #include "components/content_settings/core/common/content_settings.h"
105 #include "components/content_settings/core/common/content_settings_pattern.h" 105 #include "components/content_settings/core/common/content_settings_pattern.h"
106 #include "components/content_settings/core/common/pref_names.h" 106 #include "components/content_settings/core/common/pref_names.h"
107 #include "components/infobars/core/infobar.h" 107 #include "components/infobars/core/infobar.h"
108 #include "components/network_time/network_time_tracker.h"
108 #include "components/omnibox/browser/autocomplete_controller.h" 109 #include "components/omnibox/browser/autocomplete_controller.h"
109 #include "components/omnibox/browser/omnibox_edit_model.h" 110 #include "components/omnibox/browser/omnibox_edit_model.h"
110 #include "components/omnibox/browser/omnibox_view.h" 111 #include "components/omnibox/browser/omnibox_view.h"
111 #include "components/policy/core/browser/browser_policy_connector.h" 112 #include "components/policy/core/browser/browser_policy_connector.h"
112 #include "components/policy/core/common/external_data_fetcher.h" 113 #include "components/policy/core/common/external_data_fetcher.h"
113 #include "components/policy/core/common/mock_configuration_policy_provider.h" 114 #include "components/policy/core/common/mock_configuration_policy_provider.h"
114 #include "components/policy/core/common/policy_map.h" 115 #include "components/policy/core/common/policy_map.h"
115 #include "components/policy/core/common/policy_pref_names.h" 116 #include "components/policy/core/common/policy_pref_names.h"
116 #include "components/policy/core/common/policy_service.h" 117 #include "components/policy/core/common/policy_service.h"
117 #include "components/policy/core/common/policy_service_impl.h" 118 #include "components/policy/core/common/policy_service_impl.h"
(...skipping 57 matching lines...) Expand 10 before | Expand all | Expand 10 after
175 #include "extensions/common/extension.h" 176 #include "extensions/common/extension.h"
176 #include "extensions/common/extension_set.h" 177 #include "extensions/common/extension_set.h"
177 #include "extensions/common/features/feature_channel.h" 178 #include "extensions/common/features/feature_channel.h"
178 #include "extensions/common/manifest_handlers/shared_module_info.h" 179 #include "extensions/common/manifest_handlers/shared_module_info.h"
179 #include "media/media_features.h" 180 #include "media/media_features.h"
180 #include "net/base/net_errors.h" 181 #include "net/base/net_errors.h"
181 #include "net/base/url_util.h" 182 #include "net/base/url_util.h"
182 #include "net/http/http_stream_factory.h" 183 #include "net/http/http_stream_factory.h"
183 #include "net/http/transport_security_state.h" 184 #include "net/http/transport_security_state.h"
184 #include "net/test/embedded_test_server/embedded_test_server.h" 185 #include "net/test/embedded_test_server/embedded_test_server.h"
186 #include "net/test/embedded_test_server/http_request.h"
187 #include "net/test/embedded_test_server/http_response.h"
185 #include "net/test/url_request/url_request_failed_job.h" 188 #include "net/test/url_request/url_request_failed_job.h"
186 #include "net/test/url_request/url_request_mock_http_job.h" 189 #include "net/test/url_request/url_request_mock_http_job.h"
187 #include "net/url_request/url_request.h" 190 #include "net/url_request/url_request.h"
188 #include "net/url_request/url_request_filter.h" 191 #include "net/url_request/url_request_filter.h"
189 #include "net/url_request/url_request_interceptor.h" 192 #include "net/url_request/url_request_interceptor.h"
190 #include "testing/gmock/include/gmock/gmock.h" 193 #include "testing/gmock/include/gmock/gmock.h"
191 #include "testing/gtest/include/gtest/gtest.h" 194 #include "testing/gtest/include/gtest/gtest.h"
192 #include "third_party/WebKit/public/platform/WebInputEvent.h" 195 #include "third_party/WebKit/public/platform/WebInputEvent.h"
193 #include "ui/base/l10n/l10n_util.h" 196 #include "ui/base/l10n/l10n_util.h"
194 #include "ui/base/page_transition_types.h" 197 #include "ui/base/page_transition_types.h"
(...skipping 4299 matching lines...) Expand 10 before | Expand all | Expand 10 after
4494 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests()); 4497 EXPECT_FALSE(manager->TimeZoneResolverShouldBeRunningForTests());
4495 4498
4496 SetEmptyPolicy(); 4499 SetEmptyPolicy();
4497 // Policy not set. 4500 // Policy not set.
4498 CheckSystemTimezoneAutomaticDetectionPolicyUnset(); 4501 CheckSystemTimezoneAutomaticDetectionPolicyUnset();
4499 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false)); 4502 EXPECT_TRUE(CheckResolveTimezoneByGeolocation(true, false));
4500 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests()); 4503 EXPECT_TRUE(manager->TimeZoneResolverShouldBeRunningForTests());
4501 } 4504 }
4502 #endif // defined(OS_CHROMEOS) 4505 #endif // defined(OS_CHROMEOS)
4503 4506
4507 class NetworkTimePolicyTest : public PolicyTest {
4508 public:
4509 // A request handler that returns a dummy response and counts the number of
4510 // times it is called.
4511 std::unique_ptr<net::test_server::HttpResponse> CountingRequestHandler(
4512 const net::test_server::HttpRequest& request) {
4513 net::test_server::BasicHttpResponse* response =
4514 new net::test_server::BasicHttpResponse();
4515 num_requests_++;
4516 response->set_code(net::HTTP_OK);
4517 response->set_content(
4518 ")]}'\n"
4519 "{\"current_time_millis\":1461621971825,\"server_nonce\":-6."
4520 "006853099049523E85}");
4521 response->AddCustomHeader("x-cup-server-proof", "dead:beef");
4522 return std::unique_ptr<net::test_server::HttpResponse>(response);
4523 }
4524
4525 uint32_t num_requests() { return num_requests_; }
4526
4527 private:
4528 uint32_t num_requests_ = 0;
4529 };
4530
4531 IN_PROC_BROWSER_TEST_F(NetworkTimePolicyTest, NetworkTimeQueriesDisabled) {
4532 // Set a policy to disable network time queries.
4533 PolicyMap policies;
4534 policies.Set(key::kNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY,
4535 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
4536 base::MakeUnique<base::Value>(false), nullptr);
4537 UpdateProviderPolicy(policies);
4538
4539 embedded_test_server()->RegisterRequestHandler(base::Bind(
4540 &NetworkTimePolicyTest::CountingRequestHandler, base::Unretained(this)));
4541 ASSERT_TRUE(embedded_test_server()->Start());
4542 g_browser_process->network_time_tracker()->SetTimeServerURLForTesting(
4543 embedded_test_server()->GetURL("/"));
4544
4545 net::EmbeddedTestServer https_server_expired_(
4546 net::EmbeddedTestServer::TYPE_HTTPS);
4547 https_server_expired_.SetSSLConfig(net::EmbeddedTestServer::CERT_EXPIRED);
4548 ASSERT_TRUE(https_server_expired_.Start());
4549
4550 // Navigate to a page with a certificate date error and then check that a
4551 // network time query was not sent.
4552 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
4553 content::WebContents* tab =
4554 browser()->tab_strip_model()->GetActiveWebContents();
4555 content::InterstitialPage* interstitial_page = tab->GetInterstitialPage();
4556 ASSERT_TRUE(interstitial_page);
4557 EXPECT_EQ(0u, num_requests());
4558
4559 // Now enable the policy and check that a network time query is sent.
4560 policies.Set(key::kNetworkTimeQueriesEnabled, POLICY_LEVEL_MANDATORY,
4561 POLICY_SCOPE_USER, POLICY_SOURCE_CLOUD,
4562 base::MakeUnique<base::Value>(true), nullptr);
4563 UpdateProviderPolicy(policies);
4564 ui_test_utils::NavigateToURL(browser(), https_server_expired_.GetURL("/"));
4565 interstitial_page = tab->GetInterstitialPage();
4566 ASSERT_TRUE(interstitial_page);
4567 EXPECT_EQ(1u, num_requests());
4568 }
4569
4504 } // namespace policy 4570 } // namespace policy
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698