BookmarkManager: Fix 'new folder text field size changes on clicking it' issue.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / certificate_viewer_mac_browsertest.mm
blobfd425108141b8bbf6644436e80979904e6c07df2
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
3 // found in the LICENSE file.
5 #import "chrome/browser/certificate_viewer.h"
7 #include "chrome/browser/ui/browser.h"
8 #include "chrome/browser/ui/browser_commands.h"
9 #include "chrome/browser/ui/cocoa/certificate_viewer_mac.h"
10 #include "chrome/browser/ui/tabs/tab_strip_model.h"
11 #include "chrome/test/base/in_process_browser_test.h"
12 #include "components/web_modal/web_contents_modal_dialog_manager.h"
13 #include "content/public/browser/web_contents.h"
14 #include "content/public/test/test_utils.h"
15 #include "net/base/test_data_directory.h"
16 #include "net/cert/x509_certificate.h"
17 #include "net/test/cert_test_util.h"
18 #import "testing/gtest_mac.h"
19 #include "ui/base/cocoa/window_size_constants.h"
21 using web_modal::WebContentsModalDialogManager;
23 typedef InProcessBrowserTest SSLCertificateViewerCocoaTest;
25 namespace {
26 scoped_refptr<net::X509Certificate> GetSampleCertificate() {
27   return net::ImportCertFromFile(net::GetTestCertsDirectory(),
28                                  "mit.davidben.der");
30 } // namespace
32 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, Basic) {
33   scoped_refptr<net::X509Certificate> cert = GetSampleCertificate();
34   ASSERT_TRUE(cert.get());
35   content::WebContents* web_contents =
36       browser()->tab_strip_model()->GetActiveWebContents();
37   gfx::NativeWindow window = web_contents->GetTopLevelNativeWindow();
38   WebContentsModalDialogManager* web_contents_modal_dialog_manager =
39       WebContentsModalDialogManager::FromWebContents(web_contents);
40   EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
42   ShowCertificateViewer(web_contents, window, cert.get());
44   content::RunAllPendingInMessageLoop();
45   EXPECT_TRUE(web_contents_modal_dialog_manager->IsDialogActive());
47   WebContentsModalDialogManager::TestApi test_api(
48       web_contents_modal_dialog_manager);
49   test_api.CloseAllDialogs();
50   content::RunAllPendingInMessageLoop();
51   EXPECT_FALSE(web_contents_modal_dialog_manager->IsDialogActive());
54 // Test that switching to another tab correctly hides the sheet.
55 IN_PROC_BROWSER_TEST_F(SSLCertificateViewerCocoaTest, HideShow) {
56   scoped_refptr<net::X509Certificate> cert = GetSampleCertificate();
57   ASSERT_TRUE(cert.get());
58   content::WebContents* web_contents =
59       browser()->tab_strip_model()->GetActiveWebContents();
61   SSLCertificateViewerCocoa* viewer =
62       [[SSLCertificateViewerCocoa alloc] initWithCertificate:cert.get()];
63   [viewer displayForWebContents:web_contents];
65   content::RunAllPendingInMessageLoop();
67   NSWindow* sheetWindow = [[viewer overlayWindow] attachedSheet];
68   NSRect sheetFrame = [sheetWindow frame];
69   EXPECT_EQ(1.0, [sheetWindow alphaValue]);
71   // Switch to another tab and verify that the sheet is hidden.
72   AddBlankTabAndShow(browser());
73   EXPECT_EQ(0.0, [sheetWindow alphaValue]);
74   EXPECT_NSEQ(ui::kWindowSizeDeterminedLater, [sheetWindow frame]);
76   // Switch back and verify that the sheet is shown.
77   chrome::SelectNumberedTab(browser(), 0);
78   EXPECT_EQ(1.0, [sheetWindow alphaValue]);
79   EXPECT_NSEQ(sheetFrame, [sheetWindow frame]);