OLD | NEW |
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 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 | 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 "base/strings/utf_string_conversions.h" | 5 #include "base/strings/utf_string_conversions.h" |
6 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" | 6 #include "chrome/browser/ui/cocoa/extensions/media_galleries_dialog_cocoa.h" |
7 | 7 |
8 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" | 8 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.
h" |
9 #include "chrome/browser/ui/browser.h" | 9 #include "chrome/browser/ui/browser.h" |
10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" | 10 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.h" |
11 #include "chrome/browser/ui/tabs/tab_strip_model.h" | 11 #include "chrome/browser/ui/tabs/tab_strip_model.h" |
12 #include "chrome/test/base/in_process_browser_test.h" | 12 #include "chrome/test/base/in_process_browser_test.h" |
13 #include "components/web_modal/web_contents_modal_dialog_manager.h" | 13 #include "components/web_modal/popup_manager.h" |
14 #include "content/public/test/test_utils.h" | 14 #include "content/public/test/test_utils.h" |
15 #include "testing/gtest/include/gtest/gtest.h" | 15 #include "testing/gtest/include/gtest/gtest.h" |
16 | 16 |
17 using ::testing::_; | 17 using ::testing::_; |
18 using ::testing::AnyNumber; | 18 using ::testing::AnyNumber; |
19 using ::testing::NiceMock; | 19 using ::testing::NiceMock; |
20 using ::testing::Return; | 20 using ::testing::Return; |
21 using ::testing::ReturnRef; | 21 using ::testing::ReturnRef; |
22 using web_modal::WebContentsModalDialogManager; | |
23 | 22 |
24 class MediaGalleriesDialogBrowserTest : public InProcessBrowserTest { | 23 class MediaGalleriesDialogBrowserTest : public InProcessBrowserTest { |
25 }; | 24 }; |
26 | 25 |
27 // Verify that programatically closing the constrained window correctly closes | 26 // Verify that programatically closing the constrained window correctly closes |
28 // the sheet. | 27 // the sheet. |
29 IN_PROC_BROWSER_TEST_F(MediaGalleriesDialogBrowserTest, Close) { | 28 IN_PROC_BROWSER_TEST_F(MediaGalleriesDialogBrowserTest, Close) { |
30 NiceMock<MediaGalleriesDialogControllerMock> controller; | 29 NiceMock<MediaGalleriesDialogControllerMock> controller; |
31 | 30 |
32 content::WebContents* web_contents = | 31 content::WebContents* web_contents = |
33 browser()->tab_strip_model()->GetActiveWebContents(); | 32 browser()->tab_strip_model()->GetActiveWebContents(); |
34 EXPECT_CALL(controller, WebContents()). | 33 EXPECT_CALL(controller, WebContents()). |
35 WillRepeatedly(Return(web_contents)); | 34 WillRepeatedly(Return(web_contents)); |
36 std::vector<base::string16> headers; | 35 std::vector<base::string16> headers; |
37 headers.push_back(base::string16()); // The first section has no header. | 36 headers.push_back(base::string16()); // The first section has no header. |
38 headers.push_back(base::ASCIIToUTF16("header2")); | 37 headers.push_back(base::ASCIIToUTF16("header2")); |
39 ON_CALL(controller, GetSectionHeaders()). | 38 ON_CALL(controller, GetSectionHeaders()). |
40 WillByDefault(Return(headers)); | 39 WillByDefault(Return(headers)); |
41 EXPECT_CALL(controller, GetAuxiliaryButtonText()). | 40 EXPECT_CALL(controller, GetAuxiliaryButtonText()). |
42 WillRepeatedly(Return(base::ASCIIToUTF16("button"))); | 41 WillRepeatedly(Return(base::ASCIIToUTF16("button"))); |
43 EXPECT_CALL(controller, GetSectionEntries(_)). | 42 EXPECT_CALL(controller, GetSectionEntries(_)). |
44 Times(AnyNumber()); | 43 Times(AnyNumber()); |
45 | 44 |
46 scoped_ptr<MediaGalleriesDialogCocoa> dialog( | 45 scoped_ptr<MediaGalleriesDialogCocoa> dialog( |
47 static_cast<MediaGalleriesDialogCocoa*>( | 46 static_cast<MediaGalleriesDialogCocoa*>( |
48 MediaGalleriesDialog::Create(&controller))); | 47 MediaGalleriesDialog::Create(&controller))); |
49 base::scoped_nsobject<NSWindow> window([[dialog->alert_ window] retain]); | 48 base::scoped_nsobject<NSWindow> window([[dialog->alert_ window] retain]); |
50 EXPECT_TRUE([window isVisible]); | 49 EXPECT_TRUE([window isVisible]); |
51 | 50 |
52 WebContentsModalDialogManager* web_contents_modal_dialog_manager = | 51 web_modal::PopupManager* popup_manager = |
53 WebContentsModalDialogManager::FromWebContents(web_contents); | 52 web_modal::PopupManager::FromWebContents(web_contents); |
54 WebContentsModalDialogManager::TestApi test_api( | 53 popup_manager->CloseAllDialogsForTesting(web_contents); |
55 web_contents_modal_dialog_manager); | |
56 test_api.CloseAllDialogs(); | |
57 EXPECT_FALSE([window isVisible]); | 54 EXPECT_FALSE([window isVisible]); |
58 } | 55 } |
OLD | NEW |