Disable view source for Developer Tools.
[chromium-blink-merge.git] / chrome / browser / ui / cocoa / extensions / media_galleries_dialog_cocoa_browsertest.mm
blob63791cea8e238eb9404c82fb4ea499c7263dbad1
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/ui/cocoa/extensions/media_galleries_dialog_cocoa.h"
7 #include "chrome/browser/media_galleries/media_galleries_dialog_controller_mock.h"
8 #include "chrome/browser/ui/browser.h"
9 #include "chrome/browser/ui/cocoa/constrained_window/constrained_window_alert.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/test/test_utils.h"
14 #include "extensions/common/extension.h"
15 #include "extensions/common/test_util.h"
16 #include "testing/gtest/include/gtest/gtest.h"
18 using ::testing::NiceMock;
19 using ::testing::Return;
20 using ::testing::ReturnRef;
21 using web_modal::WebContentsModalDialogManager;
23 class MediaGalleriesDialogBrowserTest : public InProcessBrowserTest {
26 // Verify that programatically closing the constrained window correctly closes
27 // the sheet.
28 IN_PROC_BROWSER_TEST_F(MediaGalleriesDialogBrowserTest, Close) {
29   scoped_refptr<extensions::Extension> dummy_extension =
30       extensions::test_util::CreateExtensionWithID("dummy");
31   NiceMock<MediaGalleriesDialogControllerMock> controller(*dummy_extension);
33   content::WebContents* web_contents =
34       browser()->tab_strip_model()->GetActiveWebContents();
35   EXPECT_CALL(controller, web_contents()).
36       WillRepeatedly(Return(web_contents));
38   MediaGalleriesDialogController::GalleryPermissionsVector attached_permissions;
39   EXPECT_CALL(controller, AttachedPermissions()).
40       WillRepeatedly(Return(attached_permissions));
41   MediaGalleriesDialogController::GalleryPermissionsVector
42       unattached_permissions;
43   EXPECT_CALL(controller, UnattachedPermissions()).
44       WillRepeatedly(Return(unattached_permissions));
46   scoped_ptr<MediaGalleriesDialogCocoa> dialog(
47       static_cast<MediaGalleriesDialogCocoa*>(
48           MediaGalleriesDialog::Create(&controller)));
49   base::scoped_nsobject<NSWindow> window([[dialog->alert_ window] retain]);
50   EXPECT_TRUE([window isVisible]);
52   WebContentsModalDialogManager* web_contents_modal_dialog_manager =
53       WebContentsModalDialogManager::FromWebContents(web_contents);
54   WebContentsModalDialogManager::TestApi test_api(
55       web_contents_modal_dialog_manager);
56   test_api.CloseAllDialogs();
57   EXPECT_FALSE([window isVisible]);