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
3 // found in the LICENSE file.
5 #include "chrome/browser/certificate_viewer.h"
6 #include "chrome/browser/ui/browser.h"
7 #include "chrome/browser/ui/browser_window.h"
8 #include "chrome/browser/ui/tabs/tab_strip_model.h"
9 #include "chrome/browser/ui/webui/certificate_viewer_webui.h"
10 #include "chrome/browser/ui/webui/constrained_web_dialog_ui.h"
11 #include "chrome/common/url_constants.h"
12 #include "chrome/test/base/ui_test_utils.h"
13 #include "chrome/test/base/web_ui_browser_test.h"
14 #include "content/public/browser/render_view_host.h"
15 #include "content/public/browser/web_contents.h"
16 #include "content/public/browser/web_ui.h"
17 #include "content/public/test/browser_test_utils.h"
18 #include "net/cert/x509_certificate.h"
19 #include "net/test/test_certificate_data.h"
21 // Test framework for chrome/test/data/webui/certificate_viewer_dialog_test.js.
22 class CertificateViewerUITest
: public WebUIBrowserTest
{
24 CertificateViewerUITest();
25 ~CertificateViewerUITest() override
;
28 void CreateCertViewerDialog();
29 void ShowCertificateViewer();
30 #if defined(OS_CHROMEOS)
31 void ShowModalCertificateViewer();
36 void CertificateViewerUITest::CreateCertViewerDialog() {
40 void CertificateViewerUITest::ShowCertificateViewer() {
41 scoped_refptr
<net::X509Certificate
> google_cert(
42 net::X509Certificate::CreateFromBytes(
43 reinterpret_cast<const char*>(google_der
), sizeof(google_der
)));
45 ASSERT_TRUE(browser());
46 ASSERT_TRUE(browser()->window());
48 CertificateViewerDialog
* dialog
=
49 new CertificateViewerDialog(google_cert
.get());
50 dialog
->Show(browser()->tab_strip_model()->GetActiveWebContents(),
51 browser()->window()->GetNativeWindow());
52 content::WebContents
* webui_webcontents
=
53 dialog
->GetWebUI()->GetWebContents();
54 content::WaitForLoadStop(webui_webcontents
);
55 content::WebUI
* webui
= webui_webcontents
->GetWebUI();
56 webui_webcontents
->GetRenderViewHost()->SetWebUIProperty(
57 "expectedUrl", chrome::kChromeUICertificateViewerURL
);
58 SetWebUIInstance(webui
);
61 #if defined(OS_CHROMEOS)
62 void CertificateViewerUITest::ShowModalCertificateViewer() {
63 scoped_refptr
<net::X509Certificate
> google_cert(
64 net::X509Certificate::CreateFromBytes(
65 reinterpret_cast<const char*>(google_der
), sizeof(google_der
)));
67 ASSERT_TRUE(browser());
68 ASSERT_TRUE(browser()->window());
70 CertificateViewerModalDialog
* dialog
=
71 new CertificateViewerModalDialog(google_cert
.get());
72 dialog
->Show(browser()->tab_strip_model()->GetActiveWebContents(),
73 browser()->window()->GetNativeWindow());
74 content::WebContents
* webui_webcontents
=
75 dialog
->GetWebUI()->GetWebContents();
76 content::WaitForLoadStop(webui_webcontents
);
77 content::WebUI
* webui
= webui_webcontents
->GetWebUI();
78 webui_webcontents
->GetRenderViewHost()->SetWebUIProperty(
79 "expectedUrl", chrome::kChromeUICertificateViewerDialogURL
);
80 SetWebUIInstance(webui
);