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_browsertest.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 virtual ~CertificateViewerUITest();
28 void ShowCertificateViewer();
31 void CertificateViewerUITest::ShowCertificateViewer() {
32 scoped_refptr
<net::X509Certificate
> google_cert(
33 net::X509Certificate::CreateFromBytes(
34 reinterpret_cast<const char*>(google_der
), sizeof(google_der
)));
36 ASSERT_TRUE(browser());
37 ASSERT_TRUE(browser()->window());
39 CertificateViewerDialog
* dialog
=
40 new CertificateViewerDialog(google_cert
.get());
41 dialog
->Show(browser()->tab_strip_model()->GetActiveWebContents(),
42 browser()->window()->GetNativeWindow());
43 content::WebContents
* webui_webcontents
= dialog
->dialog()->GetWebContents();
44 content::WaitForLoadStop(webui_webcontents
);
45 content::WebUI
* webui
= webui_webcontents
->GetWebUI();
46 webui_webcontents
->GetRenderViewHost()->SetWebUIProperty(
47 "expectedUrl", chrome::kChromeUICertificateViewerURL
);
48 SetWebUIInstance(webui
);