OLD | NEW |
---|---|
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 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 <utility> | 6 #include <utility> |
7 | 7 |
8 #include "base/base64.h" | 8 #include "base/base64.h" |
9 #include "base/command_line.h" | 9 #include "base/command_line.h" |
10 #include "base/json/json_reader.h" | 10 #include "base/json/json_reader.h" |
11 #include "base/json/json_writer.h" | 11 #include "base/json/json_writer.h" |
12 #include "base/memory/ptr_util.h" | 12 #include "base/memory/ptr_util.h" |
13 #include "base/run_loop.h" | 13 #include "base/run_loop.h" |
14 #include "base/strings/utf_string_conversions.h" | 14 #include "base/strings/utf_string_conversions.h" |
15 #include "base/values.h" | 15 #include "base/values.h" |
16 #include "build/build_config.h" | 16 #include "build/build_config.h" |
17 #include "content/browser/frame_host/interstitial_page_impl.h" | |
18 #include "content/browser/web_contents/web_contents_impl.h" | |
17 #include "content/public/browser/devtools_agent_host.h" | 19 #include "content/public/browser/devtools_agent_host.h" |
20 #include "content/public/browser/interstitial_page_delegate.h" | |
18 #include "content/public/browser/javascript_dialog_manager.h" | 21 #include "content/public/browser/javascript_dialog_manager.h" |
22 #include "content/public/browser/navigation_controller.h" | |
23 #include "content/public/browser/navigation_entry.h" | |
19 #include "content/public/browser/navigation_handle.h" | 24 #include "content/public/browser/navigation_handle.h" |
20 #include "content/public/browser/render_frame_host.h" | 25 #include "content/public/browser/render_frame_host.h" |
21 #include "content/public/browser/render_view_host.h" | 26 #include "content/public/browser/render_view_host.h" |
22 #include "content/public/browser/render_widget_host_view.h" | 27 #include "content/public/browser/render_widget_host_view.h" |
28 #include "content/public/browser/ssl_status.h" | |
23 #include "content/public/browser/web_contents.h" | 29 #include "content/public/browser/web_contents.h" |
24 #include "content/public/common/url_constants.h" | 30 #include "content/public/common/url_constants.h" |
25 #include "content/public/test/browser_test_utils.h" | 31 #include "content/public/test/browser_test_utils.h" |
26 #include "content/public/test/content_browser_test.h" | 32 #include "content/public/test/content_browser_test.h" |
27 #include "content/public/test/content_browser_test_utils.h" | 33 #include "content/public/test/content_browser_test_utils.h" |
28 #include "content/public/test/test_navigation_observer.h" | 34 #include "content/public/test/test_navigation_observer.h" |
29 #include "content/shell/browser/shell.h" | 35 #include "content/shell/browser/shell.h" |
30 #include "net/dns/mock_host_resolver.h" | 36 #include "net/dns/mock_host_resolver.h" |
37 #include "net/test/cert_test_util.h" | |
31 #include "net/test/embedded_test_server/embedded_test_server.h" | 38 #include "net/test/embedded_test_server/embedded_test_server.h" |
39 #include "net/test/test_data_directory.h" | |
32 #include "testing/gmock/include/gmock/gmock.h" | 40 #include "testing/gmock/include/gmock/gmock.h" |
33 #include "third_party/skia/include/core/SkBitmap.h" | 41 #include "third_party/skia/include/core/SkBitmap.h" |
34 #include "ui/compositor/compositor_switches.h" | 42 #include "ui/compositor/compositor_switches.h" |
35 #include "ui/gfx/codec/png_codec.h" | 43 #include "ui/gfx/codec/png_codec.h" |
36 | 44 |
37 #define EXPECT_SIZE_EQ(expected, actual) \ | 45 #define EXPECT_SIZE_EQ(expected, actual) \ |
38 do { \ | 46 do { \ |
39 EXPECT_EQ((expected).width(), (actual).width()); \ | 47 EXPECT_EQ((expected).width(), (actual).width()); \ |
40 EXPECT_EQ((expected).height(), (actual).height()); \ | 48 EXPECT_EQ((expected).height(), (actual).height()); \ |
41 } while (false) | 49 } while (false) |
(...skipping 68 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
110 | 118 |
111 } | 119 } |
112 | 120 |
113 class DevToolsProtocolTest : public ContentBrowserTest, | 121 class DevToolsProtocolTest : public ContentBrowserTest, |
114 public DevToolsAgentHostClient, | 122 public DevToolsAgentHostClient, |
115 public WebContentsDelegate { | 123 public WebContentsDelegate { |
116 public: | 124 public: |
117 DevToolsProtocolTest() | 125 DevToolsProtocolTest() |
118 : last_sent_id_(0), | 126 : last_sent_id_(0), |
119 waiting_for_command_result_id_(0), | 127 waiting_for_command_result_id_(0), |
120 in_dispatch_(false) { | 128 in_dispatch_(false), |
121 } | 129 last_shown_certificate_(nullptr) {} |
122 | 130 |
123 protected: | 131 protected: |
124 // WebContentsDelegate method: | 132 // WebContentsDelegate method: |
125 bool AddMessageToConsole(WebContents* source, | 133 bool AddMessageToConsole(WebContents* source, |
126 int32_t level, | 134 int32_t level, |
127 const base::string16& message, | 135 const base::string16& message, |
128 int32_t line_no, | 136 int32_t line_no, |
129 const base::string16& source_id) override { | 137 const base::string16& source_id) override { |
130 console_messages_.push_back(base::UTF16ToUTF8(message)); | 138 console_messages_.push_back(base::UTF16ToUTF8(message)); |
131 return true; | 139 return true; |
132 } | 140 } |
133 | 141 |
142 void ShowCertificateViewerInDevTools( | |
143 WebContents* web_contents, | |
144 scoped_refptr<net::X509Certificate> certificate) override { | |
145 last_shown_certificate_ = certificate; | |
146 } | |
147 | |
134 void SendCommand(const std::string& method, | 148 void SendCommand(const std::string& method, |
135 std::unique_ptr<base::DictionaryValue> params) { | 149 std::unique_ptr<base::DictionaryValue> params) { |
136 SendCommand(method, std::move(params), true); | 150 SendCommand(method, std::move(params), true); |
137 } | 151 } |
138 | 152 |
139 void SendCommand(const std::string& method, | 153 void SendCommand(const std::string& method, |
140 std::unique_ptr<base::DictionaryValue> params, | 154 std::unique_ptr<base::DictionaryValue> params, |
141 bool wait) { | 155 bool wait) { |
142 in_dispatch_ = true; | 156 in_dispatch_ = true; |
143 base::DictionaryValue command; | 157 base::DictionaryValue command; |
(...skipping 121 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
265 | 279 |
266 std::vector<std::string> GetAllFrameUrls() { | 280 std::vector<std::string> GetAllFrameUrls() { |
267 std::vector<std::string> urls; | 281 std::vector<std::string> urls; |
268 for (RenderFrameHost* render_frame_host : | 282 for (RenderFrameHost* render_frame_host : |
269 shell()->web_contents()->GetAllFrames()) { | 283 shell()->web_contents()->GetAllFrames()) { |
270 urls.push_back(RemovePort(render_frame_host->GetLastCommittedURL())); | 284 urls.push_back(RemovePort(render_frame_host->GetLastCommittedURL())); |
271 } | 285 } |
272 return urls; | 286 return urls; |
273 } | 287 } |
274 | 288 |
289 const scoped_refptr<net::X509Certificate>& last_shown_certificate() { | |
290 return last_shown_certificate_; | |
291 } | |
292 | |
275 std::unique_ptr<base::DictionaryValue> result_; | 293 std::unique_ptr<base::DictionaryValue> result_; |
276 scoped_refptr<DevToolsAgentHost> agent_host_; | 294 scoped_refptr<DevToolsAgentHost> agent_host_; |
277 int last_sent_id_; | 295 int last_sent_id_; |
278 std::vector<int> result_ids_; | 296 std::vector<int> result_ids_; |
279 std::vector<std::string> notifications_; | 297 std::vector<std::string> notifications_; |
280 std::vector<std::string> console_messages_; | 298 std::vector<std::string> console_messages_; |
281 std::unique_ptr<base::DictionaryValue> requested_notification_params_; | 299 std::unique_ptr<base::DictionaryValue> requested_notification_params_; |
282 | 300 |
283 private: | 301 private: |
284 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, | 302 void DispatchProtocolMessage(DevToolsAgentHost* agent_host, |
(...skipping 29 matching lines...) Expand all Loading... | |
314 } | 332 } |
315 } | 333 } |
316 | 334 |
317 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { | 335 void AgentHostClosed(DevToolsAgentHost* agent_host, bool replaced) override { |
318 EXPECT_TRUE(false); | 336 EXPECT_TRUE(false); |
319 } | 337 } |
320 | 338 |
321 std::string waiting_for_notification_; | 339 std::string waiting_for_notification_; |
322 int waiting_for_command_result_id_; | 340 int waiting_for_command_result_id_; |
323 bool in_dispatch_; | 341 bool in_dispatch_; |
342 scoped_refptr<net::X509Certificate> last_shown_certificate_; | |
343 }; | |
344 | |
345 class TestInterstitialDelegate : public InterstitialPageDelegate { | |
346 private: | |
347 // InterstitialPageDelegate: | |
348 std::string GetHTMLContents() override { return "<p>Interstitial</p>"; } | |
324 }; | 349 }; |
325 | 350 |
326 class SyntheticKeyEventTest : public DevToolsProtocolTest { | 351 class SyntheticKeyEventTest : public DevToolsProtocolTest { |
327 protected: | 352 protected: |
328 void SendKeyEvent(const std::string& type, | 353 void SendKeyEvent(const std::string& type, |
329 int modifier, | 354 int modifier, |
330 int windowsKeyCode, | 355 int windowsKeyCode, |
331 int nativeKeyCode, | 356 int nativeKeyCode, |
332 const std::string& key) { | 357 const std::string& key) { |
333 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); | 358 std::unique_ptr<base::DictionaryValue> params(new base::DictionaryValue()); |
(...skipping 596 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
930 params.reset(new base::DictionaryValue()); | 955 params.reset(new base::DictionaryValue()); |
931 params->SetString("policy", "advance"); | 956 params->SetString("policy", "advance"); |
932 params->SetInteger("budget", 1000); | 957 params->SetInteger("budget", 1000); |
933 SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true); | 958 SendCommand("Emulation.setVirtualTimePolicy", std::move(params), true); |
934 | 959 |
935 WaitForNotification("Emulation.virtualTimeBudgetExpired"); | 960 WaitForNotification("Emulation.virtualTimeBudgetExpired"); |
936 | 961 |
937 EXPECT_THAT(console_messages_, ElementsAre("before", "done", "after")); | 962 EXPECT_THAT(console_messages_, ElementsAre("before", "done", "after")); |
938 } | 963 } |
939 | 964 |
965 // Tests that the Security.showCertificateViewer command shows the | |
966 // certificate corresponding to the visible navigation entry, even when | |
967 // an interstitial is showing. Regression test for | |
968 // https://crbug.com/647759. | |
969 IN_PROC_BROWSER_TEST_F(DevToolsProtocolTest, ShowCertificateViewer) { | |
970 // First test that the correct certificate is shown for a normal | |
971 // (non-interstitial) page. | |
972 NavigateToURLBlockUntilNavigationsComplete(shell(), GURL("about:blank"), 1); | |
973 Attach(); | |
974 | |
975 // Set a dummy certificate on the NavigationEntry. | |
976 shell() | |
977 ->web_contents() | |
978 ->GetController() | |
979 .GetVisibleEntry() | |
980 ->GetSSL() | |
981 .certificate = | |
982 net::ImportCertFromFile(net::GetTestCertsDirectory(), "ok_cert.pem"); | |
983 | |
984 std::unique_ptr<base::DictionaryValue> params1(new base::DictionaryValue()); | |
985 SendCommand("Security.showCertificateViewer", std::move(params1), true); | |
986 | |
987 scoped_refptr<net::X509Certificate> normal_page_cert = shell() | |
988 ->web_contents() | |
989 ->GetController() | |
990 .GetVisibleEntry() | |
991 ->GetSSL() | |
992 .certificate; | |
993 ASSERT_TRUE(normal_page_cert); | |
994 EXPECT_EQ(normal_page_cert, last_shown_certificate()); | |
995 | |
996 // Now test that the correct certificate is shown on an interstitial. | |
997 TestInterstitialDelegate* delegate = new TestInterstitialDelegate; | |
pfeldman
2016/09/16 22:03:57
I am not familiar with this code, but I don't see
estark
2016/09/16 22:06:12
It get passed in as an argument to the Interstitia
| |
998 WebContentsImpl* web_contents = | |
999 static_cast<WebContentsImpl*>(shell()->web_contents()); | |
1000 GURL interstitial_url("https://example.test"); | |
1001 InterstitialPageImpl* interstitial = new InterstitialPageImpl( | |
1002 web_contents, static_cast<RenderWidgetHostDelegate*>(web_contents), true, | |
1003 interstitial_url, delegate); | |
1004 interstitial->Show(); | |
1005 WaitForInterstitialAttach(web_contents); | |
1006 | |
1007 // Set the transient navigation entry certificate. | |
1008 NavigationEntry* transient_entry = | |
1009 web_contents->GetController().GetTransientEntry(); | |
1010 ASSERT_TRUE(transient_entry); | |
1011 transient_entry->GetSSL().certificate = | |
1012 net::ImportCertFromFile(net::GetTestCertsDirectory(), "expired_cert.pem"); | |
1013 ASSERT_TRUE(transient_entry->GetSSL().certificate); | |
1014 | |
1015 std::unique_ptr<base::DictionaryValue> params2(new base::DictionaryValue()); | |
1016 SendCommand("Security.showCertificateViewer", std::move(params2), true); | |
1017 EXPECT_EQ(transient_entry->GetSSL().certificate, last_shown_certificate()); | |
1018 } | |
1019 | |
940 } // namespace content | 1020 } // namespace content |
OLD | NEW |