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

Side by Side Diff: chrome/browser/ui/cocoa/certificate_viewer_mac_browsertest.mm

Issue 2039823002: MacViews: Refactor certificate viewer tests to work for MacViews browser. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@certview
Patch Set: Rebase onto master & add ignoreMouseEvents fix for hiding/reshowing the certificate viewer. Created 4 years, 6 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) 2013 The Chromium Authors. All rights reserved. 1 // Copyright (c) 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 #import "chrome/browser/certificate_viewer.h" 5 #import "chrome/browser/certificate_viewer.h"
6 6
7 #include "chrome/browser/ui/browser.h" 7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h" 8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/cocoa/certificate_viewer_mac.h" 9 #include "chrome/browser/ui/cocoa/certificate_viewer_mac.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h" 10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h" 11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h" 12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "content/public/browser/web_contents.h" 13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/test_utils.h" 14 #include "content/public/test/test_utils.h"
15 #include "net/base/test_data_directory.h" 15 #include "net/base/test_data_directory.h"
16 #include "net/cert/x509_certificate.h" 16 #include "net/cert/x509_certificate.h"
17 #include "net/test/cert_test_util.h" 17 #include "net/test/cert_test_util.h"
18 #import "testing/gtest_mac.h" 18 #import "testing/gtest_mac.h"
19 #include "ui/base/cocoa/window_size_constants.h" 19 #include "ui/base/cocoa/window_size_constants.h"
20 20
21 using web_modal::WebContentsModalDialogManager; 21 using web_modal::WebContentsModalDialogManager;
22 22
23 typedef InProcessBrowserTest SSLCertificateViewerCocoaTest; 23 typedef InProcessBrowserTest SSLCertificateViewerMacTest;
tapted 2016/06/17 06:11:33 nit: using SSLCertificateViewerMacTest = InProcess
Patti Lor 2016/06/20 03:42:28 Done.
24 24
25 namespace { 25 namespace {
26
26 scoped_refptr<net::X509Certificate> GetSampleCertificate() { 27 scoped_refptr<net::X509Certificate> GetSampleCertificate() {
27 return net::ImportCertFromFile(net::GetTestCertsDirectory(), 28 return net::ImportCertFromFile(net::GetTestCertsDirectory(),
28 "mit.davidben.der"); 29 "mit.davidben.der");
29 } 30 }
31
32 void CheckCertificateViewerVisibility(NSWindow* overlay_window,
33 NSWindow* dialog_sheet,
34 bool visible) {
35 CGFloat alpha = visible ? 1.0 : 0.0;
36 BOOL ignore_events = visible ? NO : YES;
37
38 SCOPED_TRACE(testing::Message() << "visible=" << visible);
39 // The overlay window underneath the certificate viewer should block mouse
40 // events only if the certificate viewer is visible.
41 EXPECT_EQ(ignore_events, [overlay_window ignoresMouseEvents]);
42 // Check certificate viewer sheet visibility and if it accepts mouse events.
43 EXPECT_EQ(alpha, [dialog_sheet alphaValue]);
44 EXPECT_EQ(ignore_events, [dialog_sheet ignoresMouseEvents]);
45 }
46
30 } // namespace 47 } // namespace
31 48
32 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, Basic) { 49 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerMacTest, Basic) {
33 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); 50 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate();
34 ASSERT_TRUE(cert.get()); 51 ASSERT_TRUE(cert.get());
35 content::WebContents* web_contents = 52 content::WebContents* web_contents =
36 browser()->tab_strip_model()->GetActiveWebContents(); 53 browser()->tab_strip_model()->GetActiveWebContents();
37 gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow(); 54 NSWindow* window = web_contents->GetTopLevelNativeWindow();
38 WebContentsModalDialogManager* web_contents_modal_dialog_manager = 55 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
39 WebContentsModalDialogManager::FromWebContents(web_contents); 56 WebContentsModalDialogManager::FromWebContents(web_contents);
40 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); 57 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
41 58
42 ShowCertificateViewer(web_contents, window, cert.get()); 59 ShowCertificateViewer(web_contents, window, cert.get());
43 60
44 content::RunAllPendingInMessageLoop(); 61 content::RunAllPendingInMessageLoop();
45 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive()); 62 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
46 63
47 WebContentsModalDialogManager::TestApi test_api( 64 WebContentsModalDialogManager::TestApi test_api(
48 web_contents_modal_dialog_manager); 65 web_contents_modal_dialog_manager);
49 test_api.CloseAllDialogs(); 66 test_api.CloseAllDialogs();
50 content::RunAllPendingInMessageLoop(); 67 content::RunAllPendingInMessageLoop();
51 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive()); 68 EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
52 } 69 }
53 70
54 // Test that switching to another tab correctly hides the sheet. 71 // Test that switching to another tab correctly hides the sheet.
55 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, HideShow) { 72 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerMacTest, HideShow) {
56 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate(); 73 scoped_refptr<net::X509Certificate> cert = GetSampleCertificate();
57 ASSERT_TRUE(cert.get()); 74 ASSERT_TRUE(cert.get());
58 content::WebContents* web_contents = 75 content::WebContents* web_contents =
59 browser()->tab_strip_model()->GetActiveWebContents(); 76 browser()->tab_strip_model()->GetActiveWebContents();
60 77
61 SSLCertificateViewerCocoa* viewer = 78 NSWindow* window = web_contents->GetTopLevelNativeWindow();
62 [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert.get()]; 79 WebContentsModalDialogManager* web_contents_modal_dialog_manager =
63 [viewer displayForWebContents:web_contents]; 80 WebContentsModalDialogManager::FromWebContents(web_contents);
64 81
82 // Account for any child windows that might be present before the certificate
83 // viewer is open.
84 NSUInteger num_child_windows = [[window childWindows] count];
85 ShowCertificateViewer(web_contents, window, cert.get());
65 content::RunAllPendingInMessageLoop(); 86 content::RunAllPendingInMessageLoop();
87 EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
66 88
67 NSWindow* sheetWindow = [[viewer overlayWindow] attachedSheet]; 89 EXPECT_EQ(num_child_windows + 1, [[window childWindows] count]);
68 NSRect sheetFrame = [sheetWindow frame]; 90 // Assume the last child is the overlay window that was added.
69 EXPECT_EQ(1.0, [sheetWindow alphaValue]); 91 NSWindow* overlay_window = [[window childWindows] lastObject];
92 NSWindow* dialog_sheet = [overlay_window attachedSheet];
93 EXPECT_TRUE(dialog_sheet);
94 NSRect sheet_frame = [dialog_sheet frame];
70 95
71 // Switch to another tab and verify that the sheet is hidden. 96 // Verify the certificate viewer is showing and accepts mouse events.
97 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, true);
98
99 // Switch to another tab and verify that |overlay_window| and |dialog_sheet|
100 // are not blocking mouse events, and |dialog_sheet| is hidden.
72 AddBlankTabAndShow(browser()); 101 AddBlankTabAndShow(browser());
73 EXPECT_EQ(0.0, [sheetWindow alphaValue]); 102 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, false);
74 EXPECT_NSEQ(ui::kWindowSizeDeterminedLater, [sheetWindow frame]); 103 EXPECT_NSEQ(sheet_frame, [dialog_sheet frame]);
75 104
76 // Switch back and verify that the sheet is shown. 105 // Switch back and verify that the sheet is shown.
77 chrome::SelectNumberedTab(browser(), 0); 106 chrome::SelectNumberedTab(browser(), 0);
78 EXPECT_EQ(1.0, [sheetWindow alphaValue]); 107 content::RunAllPendingInMessageLoop();
79 EXPECT_NSEQ(sheetFrame, [sheetWindow frame]); 108 CheckCertificateViewerVisibility(overlay_window, dialog_sheet, true);
80 } 109 }
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698